我有一个空的data.frame
write.df <- data.frame(Title=character(),
Date=character(),
Type=character(),
NoDataPer=numeric(),
stringsAsFactors=FALSE)
我需要在循环中存储结果
for(i in 1:5){
#do some stuff
write.df[i,] <- data.frame(MyTitle,MyDate,MyType,MyNoDataPer)
}
当我看到data.frame时,我得到了这个而不是字符值
> write.df
Title Date Type NoDataPer
1 1 1 1 95.8
2 1 1 1 96.9
3 1 1 1 99.6
4 1 1 1 61.8
5 1 1 1 60.5
其中Title
,Date
和Type
例如MYD11A1_2012.06.07.LST_Night_1km
,2012-06-07
和Night
答案 0 :(得分:1)
写
write.df[i,] <- list(raster_name,date_r,type,NANvalidPER)
而不是
write.df[i,] <- data.frame(raster_name,date_r,type,NANvalidPER)
我得到了正确的write.df
write.df
Title Date Type NoDataPer
1 MYD11A1_2012.03.01.LST_Day_1km 2012-03-01 Day 95.8
2 MYD11A1_2012.06.06.LST_Day_1km 2012-06-06 Day 96.9
3 MYD11A1_2012.06.06.LST_Night_1km 2012-06-06 Night 99.6
4 MYD11A1_2012.06.07.LST_Day_1km 2012-06-07 Day 61.8
5 MYD11A1_2012.06.07.LST_Night_1km 2012-06-07 Night 60.5