cut - Accessing data from output R program -


i have output generated cuts functions 1 below...lets call ouput 'data'.

cuts: [20,25)    time kilometres 21   20        7.3 22   21        8.4 23   22        9.5 24   23       10.6 25   24       11.7 ------------------------------------------------------------  cuts: [25,30)    time kilometres 26   25       12.8 27   26       13.9 28   27       15.0 29   28       16.1 30   29       17.2 ------------------------------------------------------------  cuts: [30,35)    time kilometres 31   30       18.3 32   31       19.4 33   32       20.5 34   33       21.6 35   34       22.7 

how access data in each cut..like kilometres data cuts:[20,25]..etc tried doing data$kilometres...but not work...so want new data frame use kilometres data seperately each cut

the output of by here list, can use basic list indexing, either number or name. using data your question few hours ago, , the answer matthew lundberg, can index follows:

> 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 

you can review structure of objects in r using str. useful decide how can extract information. here's str(x):

> str(x) list of 7  $ [0,6)  :classes ‘asis’ , '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’ , '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’ , '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’ , '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’ , '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’ , '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’ , '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" 

from can see have named list of 7 items, , each list contains data.frame. thus, if wanted vector of "velocity" variable (second column) third interval, use like:

> x[[3]][[2]] [1] 1.56 1.61 1.66 1.71 1.76 1.81 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -