繁体   English   中英

R中data.frame的条件子集

[英]conditional subsetting from data.frame in R

我在这里有一个data.frame 我想知道如何才能为变量controlFALSE并按字母顺序根据BASE R中的 D$study.name 按字母顺序排列 data.frame中行的子集命名为dot.names请参见下文 )?

这是我没有成功使用的代码:

D <- read.csv("https://raw.githubusercontent.com/izeh/m/master/k.csv") # data.frame

dot.names <- c("ESL", "prof" ,"scope", "type")             

D[dot.names & !control] 

如果D$control是逻辑列-

res1 <- D[order(D$study.name), ]

res2 <- res1[!res1$control, dot.names]

如果D$control是字符列-

D[D$control == "FALSE", dot.names]

使用subset -

subset(D[order(D$study.name), ], !control, select = dot.names)

dplyr

D %>% 
  filter(!control) %>% 
  arrange(study.name) %>% 
  select(dot.names)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM