Extracting rows from a data.frame

后端 未结 2 953
-上瘾入骨i
-上瘾入骨i 2021-01-21 16:26

I have a n by m data.frame where column 1 has the information of interest. I want to create sub data.frames based upon what the value in a row of colum

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 17:03

    Instead of :

    s <- data.frame(df1$P = S)
    

    try:

    s <- data.frame(df1[df1$P == S,])
    

    or

    s <- data.frame(df1[df1$P == 'S',])
    

    if you want to control number of rows try:

    s <- data.frame(df1[df1$P == 'S',1:5])
    

提交回复
热议问题