Tuesday, September 15, 2015

R: Dataframe slice example

R dataframe slice example.

Note: slice = whole[rows satisfying this condition, tuple of column names]



    > head(mywhole)
      obs ew id ba x
    1   1  E  1  B 8
    2   2  E  1  A 9
    3   3  E  2  B 4
    4   4  E  2  A 3
    5   5  E  3  B 6
    6   6  E  3  A 7
    > myslice = mywhole[ba=="B", c("id","x")]
    > myslice
       id x
    1   1 8
    3   2 4
    5   3 6
    7   4 6
    9   5 5
    11  6 9
    13  7 6
    15  8 5
    17  9 7
    19 10 9





No comments:

Post a Comment