R 为什么重新排序会将单列数据帧变成向量?
我只是好奇为什么对单列数据帧(或矩阵)重新排序会将其转换为向量。这有什么原因吗R 为什么重新排序会将单列数据帧变成向量?,r,R,我只是好奇为什么对单列数据帧(或矩阵)重新排序会将其转换为向量。这有什么原因吗 k <- data.frame(a=c(2,10,3), b=c(8,3,9)) k <- k[order(k[,1]),] class(k) # [1] "data.frame" k <- data.frame(a=c(2,10,3)) k <- k[order(k[,1]),] class(k) # [1] "numeric" k查看?'['尤其是drop参数 drop: For ma
k <- data.frame(a=c(2,10,3), b=c(8,3,9))
k <- k[order(k[,1]),]
class(k)
# [1] "data.frame"
k <- data.frame(a=c(2,10,3))
k <- k[order(k[,1]),]
class(k)
# [1] "numeric"
k查看?'['
尤其是drop
参数
drop: For matrices and arrays. If ‘TRUE’ the result is coerced to
the lowest possible dimension (see the examples). This only
works for extracting elements, not for the replacement. See
‘drop’ for further details.
要回答您的问题,您需要
k[order(k[,1]), , drop=FALSE]
查看?“[”
尤其是drop
参数
drop: For matrices and arrays. If ‘TRUE’ the result is coerced to
the lowest possible dimension (see the examples). This only
works for extracting elements, not for the replacement. See
‘drop’ for further details.
要回答您的问题,您需要
k[order(k[,1]), , drop=FALSE]
谢谢!这是我在帮助文档中的第二个问题和答案。我应该阅读它!谢谢!这是我在帮助文档中的第二个问题和答案。我应该阅读它!