gpt4 book ai didi

r - 如何用R中的readLines删除空行?

转载 作者:行者123 更新时间:2023-12-04 18:12:00 30 4
gpt4 key购买 nike

如果文件中有很多空行,如何用R中的readLines删除空行?

我知道我可以使用 blank.lines.skip=Tread.table要删除它,如何在readLines ?

另外,如何删除最后一个 \n用 readLines 吗?

最佳答案

如何使用选择运算符从 readLines 返回的字符向量中查找非空行?

# character vector mimicking readLine output, lines 2, 4, and 5 are blank
lines <- c("aaa", "", "ccc", "", "")
# [1] "aaa" "" "ccc" "" ""

# select lines which are blank
lines[which(lines=="")]
# [1] "" "" ""

# conversely, lines which are not
lines[which(lines!="")]
# [1] "aaa" "ccc"

我用的是假的 readLine上面的数据,但实际上我没有看到 readLines 返回 \n对于空行或最后一行。

关于r - 如何用R中的readLines删除空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11865747/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com