How to select some rows with specific date from a data frame in R

前端 未结 1 590
刺人心
刺人心 2021-01-07 14:30

I have a large dataset and I want to pick out some of the rows particularly, I am wondering if anyone could help me with this? Thank you so much for your help!!

For

相关标签:
1条回答
  • Convert your date column to Date-type:

    df$date <- as.Date(df$date)
    

    Then subset according to your specifications:

    with(df, df[(date >= "2008-01-02" & date <= "2008-01-05") | 
                                     (date >= "2008-01-09" & date <= "2008-01-11"), ])
    #         date mpressure mxtemp
    #2  2008-01-02    1025.6   16.0
    #3  2008-01-03    1023.6   18.1
    #4  2008-01-04    1021.8   18.4
    #5  2008-01-05    1020.1   20.9
    #9  2008-01-09    1015.3   24.5
    #10 2008-01-10    1014.3   21.8
    #11 2008-01-11    1012.9   23.4
    
    0 讨论(0)
提交回复
热议问题