在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
R语言中根据日期筛选数据 1、测试数据 manager <- 1:5
date <- c("10/24/08","10/28/08","10/1/08","10/12/08","5/1/09")
country <- c("US","US","UK","UK","UK")
gender <- c("M","F","F","M","F")
age <- c(32,45,25,39,99)
q1 <- c(5,3,3,3,2)
q2 <- c(4,5,5,3,2)
q3 <- c(5,2,5,4,1)
q4 <- c(5,5,5,NA,2)
q5 <- c(5,5,2,NA,1)
leadership <- data.frame(manager,date,country,gender,age,q1,q2,q3,q4,q5,
stringsAsFactors = F)
leadership$age[leadership$age == 99] <- NA
leadership <- within(leadership,{
agecat = NA
agecat[age > 75] <- "Elder"
agecat[age >= 55 & age <= 75] <- "Middle age"
agecat[age < 55] <- "Young"
})
leadership
2、依据第二列筛选2008.10.5到2008.10.25的数据 leadership$date <- as.Date(leadership$date, "%m/%d/%y")
leadership
startday <- as.Date("2008-10-05")
endday <- as.Date("2008-10-25")
new<-leadership[which(leadership$date >= startday & leadership$date <= endday),]
new
|
请发表评论