如果我们以一些示例数据为例,我们可以获得如下所示的各种输出
A <- (1:10)
B <- (20:29)
df1 <- data.frame(A,B)
D <- c(1,2,3,3)
# with this command, output the first, second, third and third row
df1[D,]
D <- c(5,7,3,3)
# and here the 5th, 7th ....
df1[D,]
但是我想获得第二个数据帧,其中D
值对应于一个等效项A
# here we reomve the first two rows of data
df2 <- df1[-c(1,2),]
# now we want to call upon our D and obtain a new data frame with
# A==5,A==7, and 2x A==3
df2[match(df2$A==D),]
如果使用此方法,则不会得到重复的值
df2[(df2$A %in% D),]
该match
论点不正确
df2[match(D,df2$A),]
# A B
#5 5 24
#7 7 26
#3 3 22
#3.1 3 22
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句