R中的顺序函数:参数长度不同
我在 R 中遇到以下错误:
I'm getting the following error in R:
argument lengths differ.
我有一个数据集,我想在两列上排序,首先是 caseID,然后是包含时间戳的列.我使用以下代码:
I have a data set I would like to order on two columns, first on caseID, then on a column that contains a timestamp. I use the following code:
mydata <- mydata[order(mydata[ ,col1], mydata[ ,col2], decreasing = FALSE),]
Col1 和 col2 是两个保存整数的变量.我查看了类似的问题并尝试了那里提出的解决方案,但没有任何效果;)
Col1 and col2 are two variables holding an integer. I have looked at similar questions and tried the solutions that were proposed there, but nothing worked ;).
有人可以帮我吗?
亲切的问候
R 认为你 2 列有不同的长度,有时当你不小心访问一个不存在的列时会发生这种情况,检查 col1 和
col2
以确保它们是适当的数字.还要查看 length(mydata[,col1])
和 length(mydata[,col2])
以查看这两个值是否匹配.还要检查是否缺少 、
或其他标点符号,有时如果您的语法不完全正确,那么您会得到一个长度为 1 的列表,或者一个与其他向量长度不匹配的单元素向量.
R thinks that you 2 columns have different lengths, sometimes that happens when you accidentally access a column that does not exist, check the values of col1
and col2
to make sure that they are appropriate numbers. Also look at length(mydata[,col1])
and length(mydata[,col2])
to see if those 2 values match. Also check for missing ,
or other punctuation, sometimes if you don't have the syntax exactly right then you get a list of length 1, or a single element vector which does not match the other vector in length.