Subset multiple rows with condition

后端 未结 3 1233
星月不相逢
星月不相逢 2021-01-27 11:47

I have a .txt file read into a table called power with over 2 million observations of 9 variables. I am trying to subset power

3条回答
  •  我在风中等你
    2021-01-27 12:20

    Try:

    > subpower = power[power$Date %in% c("01/02/2007", "02/02/2007") ,]
    > subpower
            Date Val
    1 01/02/2007  14
    8 02/02/2007  28
    

    (Using power data from @akrun's answer)

    Moreover, your own code will work if you use proper name of subset: "subpower" instead of "powersub"!

    > subpower <- subset(power, Date %in% c("01/02/2007", "02/02/2007"))
    > subpower
            Date Val
    1 01/02/2007  14
    8 02/02/2007  28
    >
    > str(subpower)
    'data.frame':   2 obs. of  2 variables:
     $ Date: chr  "01/02/2007" "02/02/2007"
     $ Val : int  14 28
    

提交回复
热议问题