我想基于以下条件对以下data.frame进行子集化。
> head(df1)
timeStamp g_id p_k_id weekday
1 2015-01-05 15:00:00 848 266 Mon
2 2015-01-05 15:01:00 848 266 Mon
3 2015-01-05 15:02:00 848 266 Mon
4 2015-01-05 15:02:00 848 266 Mon
5 2015-01-05 15:02:00 848 266 Mon
6 2015-01-05 15:03:00 848 266 Mon
> str(df1)
'data.frame': 33150 obs. of 4 variables:
$ timeStamp : POSIXct, format: "2015-01-05 15:00:00" "2015-01-05 15:00:00" "2015-01-05 15:00:00" ...
$ g_id : Factor w/ 2 levels "","848": 2 2 2 2 2 2 2 2 2 2 ...
$ p_k_id : Factor w/ 5 levels "","265","266",..: 3 3 3 3 3 3 3 3 3 3 ...
$ weekday : Factor w/ 4 levels "Fri","Mon","Sat",..: 2 2 2 2 2 2 2 2 2 2 ...
条件: 时间戳> = 2015-01-05 15:01:00& < = 2015-01-05 15:02:00
不使用subset(),因为我需要使用它来创建一个函数,而不是交互使用。
我试过了:
df2 <- df1[df1$timestamp >= 2015-01-05 15:01:00 & <= 2015-01-05 15:02:00]
但这引发了错误:
Error: unexpected '<=' in...
感谢您的指示。