This question already has an answer here:
这个问题在这里已有答案:
- Subset of table in R using row numbers? 1 answer
- R中的表的子集使用行号? 1个答案
I have a large data frame which I would like to break down into smaller data frames. I know which rows I would like to split up (i.e I want to separate rows 1 - 33, 34 - 60, ....). I know I have to use subset(), but I cant seem to find the specific parameters.
我有一个大型数据框,我想分解成更小的数据帧。我知道我想分开哪些行(即我想分开行1 - 33,34 - 60,......)。我知道我必须使用subset(),但我似乎无法找到具体的参数。
1 个解决方案
#1
1
If you mean from the 1st to the 33th row, just do this
如果你的意思是从第1行到第33行,就这样做吧
df[1:33,]
as an example:
举个例子:
> df<-data.frame(A=LETTERS[1:10], B=c(1:10))
> df
A B
1 A 1
2 B 2
3 C 3
4 D 4
5 E 5
6 F 6
7 G 7
8 H 8
9 I 9
10 J 10
> df[1:3,]
A B
1 A 1
2 B 2
3 C 3
#1
1
If you mean from the 1st to the 33th row, just do this
如果你的意思是从第1行到第33行,就这样做吧
df[1:33,]
as an example:
举个例子:
> df<-data.frame(A=LETTERS[1:10], B=c(1:10))
> df
A B
1 A 1
2 B 2
3 C 3
4 D 4
5 E 5
6 F 6
7 G 7
8 H 8
9 I 9
10 J 10
> df[1:3,]
A B
1 A 1
2 B 2
3 C 3