我需要回答
no fac date count
1 fac1 2015-01 3
2 fac1 2016-01 5
3 fac1 2017-01 7
4 fac2 2015-01 9
5 fac2 2017-01 11
6 fac3 2016-01 13
7 fac4 2015-01 15
8 fac5 2017-01 17
做
date fac1 fac2 fac3 fac4 fac5
2015-01 3 9 0 15 0
2016-01 5 0 13 0 0
2017-01 7 11 0 0 17
像这样。
我正在尝试使用左连接,但会发生此错误。
# first Data
Data0 <-mid[1:31,]
# Separate Data by factor
for (i in 1:72) {
assign(paste0("Data", i), subset(mid, midnames %in% mid_names[i]))
}
# Make first dataset
df3 <- Data0
df3$date[is.na(df3$date)] <- Sys.time()
df3[is.na(df3)]<-0
#leftjoin Datas by factor
for (i in 1:72) {
df3 <- sqldf(paste("SELECT *
FROM df3
LEFT OUTER JOIN Data",i," USING(year,month,date)",sep=""))
df3[is.na(df3)]<-0
}
错误:无法将 NA 传递给 dbQuoteIdentifier()
另外:警告消息:在 field_types[] <- field_types[names(data)] 中:要替换的项目数不是替换长度的倍数