假設我有中的R日曆狀數據幀:提取元件由索引
df = data.frame(Sun = c("*","*","*","*","*","*","*","*","*","*"),
Mon= c("*","s","*","*","*","*","*","*","*","*"),
Tues = c("*","*","*","*","*","*","*","*","*","*"),
Wedn = c("*","*","*","*","*","*","*","*","*","*"),
Thur = c("*","*","*","*","*","*","*","*","*","*"),
Fri = c("*","*","*","*","*","*","*","*","*","*"),
Sat = c("*","*","*","*","e","*","*","*","*","*"))
> df
Sun Mon Tues Wedn Thur Fri Sat
1 * * * * * * *
2 * s * * * * *
3 * * * * * * *
4 * * * * * * *
5 * * * * * * e
6 * * * * * * *
7 * * * * * * *
8 * * * * * * *
9 * * * * * * *
10 * * * * * * *
我們可以索引此日曆如下:
df_index[1,1] = 1
df_index[1,2] = 2
.
.
.
df_index[2,1] = 8
df_index[2,2] = 9
等等等等。也就是說,df [1,1]是第一天,df [2,1]是第8天。 (並且df_index [,]不存在,只是爲了更好地理解)。
我想要做的是按索引子集這個數據幀。例如,我想從9日提取到第35天,並生成新的數據幀:
Sun Mon Tues Wedn Thur Fri Sat
1 NA s * * * * *
2 * * * * * * *
3 * * * * * * *
4 * * * * * * e
你只是想做到這一點:df [1:5,1:3]? –
是的....我知道了......謝謝@Ben_its – skyindeer