Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用字符串映射数据帧的列_R - Fatal编程技术网

R 使用字符串映射数据帧的列

R 使用字符串映射数据帧的列,r,R,我有一个2x5数据框,行名和列名如下: test <- matrix(NA,nrow=2,ncol=5) test[1,] = c(2,3,6,8,9) test[2,] = c(5,3,2,7,8) colnames(test) = c('aa','bb','cc','dd','ee') rownames(test) = c('first','second') test = data.frame(test) 有人知道我怎么做吗?我不明白这个问题。你想要的产量是多少?你不想对这些列

我有一个2x5数据框,行名和列名如下:

test <- matrix(NA,nrow=2,ncol=5)
test[1,] = c(2,3,6,8,9)
test[2,] = c(5,3,2,7,8)
colnames(test) = c('aa','bb','cc','dd','ee')
rownames(test) = c('first','second')
test = data.frame(test)   

有人知道我怎么做吗?

我不明白这个问题。你想要的产量是多少?你不想对这些列重新排序吗?也就是说,这就是你想要的test[,test2]?如果你想更改列顺序,那么它将是test2=test[,c'ee','cc','dd','bb','aa']。是的,我想更改列顺序,非常有效,谢谢!!
test2 = c('ee','cc','dd','bb','aa')