我有一个这样的变量
NewDate
02-11-2021
02-11-2021
02-11-2021
02-11-2021
02-11-2021
02-11-2021
02-11-2021
我希望它看起来像这样
NewDate
02-11-2021
09-10-2009
05-05-2011
02-11-2021
09-10-2009
05-05-2011
...(1200 times)
答案 0 :(得分:1)
您可以使用:
insertDates<- c("09-10-2009", "05-05-2011")
c(sapply(df1$NewDate, function(x) {c(x,insertDates)}))
得到更像最终结果的东西:
data.frame(NewDate = c(sapply(df1$NewDate, function(x) {c(x,insertDates)})), stringsAsFactors = FALSE)
数据:
df1<-
structure(list(NewDate = c("02-11-2021", "02-11-2021", "02-11-2021",
"02-11-2021", "02-11-2021", "02-11-2021", "02-11-2021")), row.names = c(NA,
-7L), class = "data.frame")
答案 1 :(得分:1)
您可以按行拆分,COALESCE
包含请求日期的新数据框,NULLIF
整个列表,即
rbind