R语言随手记-数据处理

dplyr包

  • mutate(),将一列向量加入到已有的数据框,向量长度和数据框列数要一样
  • select(),选择数据框的某几列
  • filter(),对数据框的行进行筛选
df1 <- data.frame(
      name = c("Alice", "Alice", "Bob", "Bob", "Carol", "Carol"),
      type = c("english", "math", "english", "math", "english", "math")
)
## mutate()
df2<-mutate(df1, newcol=c(60, 85, 70, 75, 85, 90))

## select()
select(df2, name, newcol)
select(df2, !newcol)

## filter()
filter(newcol>75) #比如筛选newcol大于75的行
filter(type=="english",newcol>75) #只看英语成绩大于75

https://bookdown.org/wangminjie/R4DS/dplyr.html

grep

target <- row.names(s1dat)[grep("fore", s1dat$mark)]

"=="

d$ccc[d$node==nodeid(s1tree,target)]<-"red"
原文地址:https://www.cnblogs.com/RyannBio/p/14551006.html