你如何跳过R中的空向量(How do you skip empty vectors in R)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
你如何跳过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.

更多推荐

本文发布于:2023-04-24 20:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/0442567e3decf20cbbcc22256cfe62af.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   跳过   skip   empty   vectors

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!