Reputation: 89
I've a db like this
v1 <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
v2 <- c(2.2, 3.2, 1.2, 4.2, 2.2, 3.2, 2.2, 1.2, 5.2)
v3 <- c("a","a","a","b","b","b","c","c","c")
d <- data.frame(v1,v2,v3)
I would like to create subsets of d basing on unique values of v1
.
Can anyone help?
Upvotes: 1
Views: 1143
Reputation: 4187
You can use the split
-function for that:
split(d, d$v1)
The result:
> split(d, d$v1)
$`1`
v1 v2 v3
1 1 2.2 a
2 1 3.2 a
3 1 1.2 a
$`2`
v1 v2 v3
4 2 4.2 b
5 2 2.2 b
6 2 3.2 b
$`3`
v1 v2 v3
7 3 2.2 c
8 3 1.2 c
9 3 5.2 c
Upvotes: 1