如果我有如下数据框:
v2 <- c(4.5, 2.5, 3.5, 5.5, 7.5, 6.5, 2.5, 1.5, 3.5)
v1 <- c(2.2, 3.2, 1.2, 4.2, 2.2, 3.2, 2.2, 1.2, 5.2)
lvl <- c("a","a","a","b","b","b","c","c","c")
d <- data.frame(v1,v2,lvl)
> d
v1 v2 lvl
1 2.2 4.5 a
2 3.2 2.5 a
3 1.2 3.5 a
4 4.2 5.5 b
5 2.2 7.5 b
6 3.2 6.5 b
7 2.2 2.5 c
8 1.2 1.5 c
9 5.2 3.5 c
在 的每个级别中d$lvl
,我想提取值为中d$v1
位数的行(对于最简单的情况,每个级别d$lvl
都有三行)。所以我想得到:
v1 v2 l
1 2.2 4.5 a
6 3.2 6.5 b
7 2.2 2.5 c