你如何跳过R中的空向量(How do you skip empty vectors in R)
我有一个没有任何内容的向量x。
dput(x) ""当我这样做时, length(x)或nrow(data.frame(x)) ,它出现为1。
我如何设置if语句,如果它是空的,请转到下一个?
我有它:
if(length(x)>1){似乎没有工作。
I have a vector x with nothing in it.
dput(x) ""When I do, length(x) or nrow(data.frame(x)), it comes out as 1.
How would I set up a if statement where if it is empty, go to the next?
I have it as:
if(length(x)>1){does not seem to be working.
最满意答案
您的向量不为空,它由1个空字符串(长度为零的字符串)组成。
x <- "" dput(x) ## ""在这里,您要测试nchar(x) == 0或all(nchar(x) == 0) 。 或者,您可能希望检查nzchar(x)返回FALSE 。
Your vector is not empty, it consist of 1 empty string (a string of zero length).
x <- "" dput(x) ## ""Here, you want to test if nchar(x) == 0 or all(nchar(x) == 0). Alternatively, you may wish to check if nzchar(x) returns FALSE.
更多推荐
发布评论