的by
這裏的輸出是一個列表,這樣你就可以使用基本目錄索引,無論是數字或名稱。從your question from a few hours ago中的數據,並the answer from Matthew Lundberg,我們能指標如下:
> x[[1]]
Time Velocity
1 0.0 0.00
2 1.5 1.21
3 3.0 1.26
4 4.5 1.31
> x[["[6,12)"]]
Time Velocity
5 6.0 1.36
6 7.5 1.41
7 9.0 1.46
8 10.5 1.51
您可以通過使用str
審查對象的結構在R上。這對於幫助您決定如何提取某些信息通常很有用。這裏的str(x)
:
> str(x)
List of 7
$ [0,6) :Classes ‘AsIs’ and 'data.frame': 4 obs. of 2 variables:
..$ Time : num [1:4] 0 1.5 3 4.5
..$ Velocity: num [1:4] 0 1.21 1.26 1.31
$ [6,12) :Classes ‘AsIs’ and 'data.frame': 4 obs. of 2 variables:
..$ Time : num [1:4] 6 7.5 9 10.5
..$ Velocity: num [1:4] 1.36 1.41 1.46 1.51
$ [12,18):Classes ‘AsIs’ and 'data.frame': 6 obs. of 2 variables:
..$ Time : num [1:6] 12 13 14 15 16 17
..$ Velocity: num [1:6] 1.56 1.61 1.66 1.71 1.76 1.81
$ [18,24):Classes ‘AsIs’ and 'data.frame': 5 obs. of 2 variables:
..$ Time : num [1:5] 18 19 20 21 22.5
..$ Velocity: num [1:5] 1.86 1.91 1.96 2.01 2.06
$ [24,30):Classes ‘AsIs’ and 'data.frame': 4 obs. of 2 variables:
..$ Time : num [1:4] 24 25.5 27 28.5
..$ Velocity: num [1:4] 2.11 2.16 2.21 2.26
$ [30,36):Classes ‘AsIs’ and 'data.frame': 4 obs. of 2 variables:
..$ Time : num [1:4] 30 31.5 33 34.5
..$ Velocity: num [1:4] 2.31 2.36 2.41 2.42
$ [36,42):Classes ‘AsIs’ and 'data.frame': 1 obs. of 2 variables:
..$ Time : num 36
..$ Velocity: num 2.43
- attr(*, "dim")= int 7
- attr(*, "dimnames")=List of 1
..$ cuts: chr [1:7] "[0,6)" "[6,12)" "[12,18)" "[18,24)" ...
- attr(*, "call")= language by.data.frame(data = mydf, INDICES = cuts, FUN = I)
- attr(*, "class")= chr "by"
從這裏我們可以看到,我們有七個項目命名列表,每個列表包含data.frame
。因此,如果我們想要第三個區間的「速度」變量(第二列)的向量,我們將使用類似於:
> x[[3]][[2]]
[1] 1.56 1.61 1.66 1.71 1.76 1.81
我假設您使用'by'來生成此項。你使用了什麼命令? – 2013-03-26 07:48:09
@ sebastian-c,'by'確實有明顯的視覺輸出,不是。看原始問題[這裏](http://stackoverflow.com/questions/15628289/cut-function-in-r-program) – A5C1D2H2I1M1N2O1R2T1 2013-03-26 07:52:43