1
有什么方法可以像这样过滤数据框吗?我想保留所有行和列出现某个子字符串,以及下一列。如何根据行值选择列
df <- read.table(header=TRUE, stringsAsFactors = FALSE, text =
"date col2 col3 col4 col5 col6
1 boston 22 new_york 15 atlanta 5
2 boston 21 new_york 15 atlanta 0
")
cities <- c('boston', 'atlanta')
#filter by cities
#output
#col2 col3 col5 col6
#boston 22 atlanta 5
#boston 21 atlanta 0