c*****a 发帖数: 177 | 1 想在R里sort一个dataset. 下面是这个dataset前五行数据:
> upc[1:5,]
State Abb Region Change
1 Alabama AL South 7.5
2 Alaska AK West 13.3
4 Arkansas AR South 9.1
5 California CA West 10.0
6 Colorado CO West 16.9
str显示第四个column是Change:
> str(upc)
'data.frame': 48 obs. of 4 variables:
$ State : chr "Alabama" "Alaska" "Arkansas" "California" ...
$ Abb : chr "AL" "AK" "AR" "CA" ...
$ Region: Factor w/ 4 levels "Northeast","South",..: 2 4 2 4 4 1 2 2 2 4 ...
$ Change: num 7.5 13.3 9.1 10 16.9 4.9 14.6 17.6 18.3 12.3 ...
可我用Change排序却总是报错,用其他column也有同样问题。不知道是何原因。请高手
指教,多谢!!
> x=upc[order(Change),]
Error in order(Change) : object 'Change' not found | s***d 发帖数: 81 | 2 x=upc[order(upc$Change),] | A****t 发帖数: 141 | 3 x=upc[order(upc$Change),]
或者
attach(upc)
x=upc[order(Change),] | c*****a 发帖数: 177 | |
|