0
我試圖將基於月份和年份的數據框分成幾個較小的數據框。所以我用一個循環來提取滿足月份和年份條件的數據幀(見下面的代碼)。如何避免從R中的子集創建空的數據幀?
但是,在某些情況下,特定年份中的某些月份的數據不可用,並且通過使用下面的代碼,它會創建空白數據框。 有沒有辦法避免它?
Weather.df = read.table(file = "D:/Program Files/R Projects/Weather_Pattern/Weather.txt", header = TRUE, sep = ",")
for (YEAR in min(Weather.df$year):max(Weather.df$year)){
for (MONTH in month.abb){
temp.df = subset(Weather.df, month == MONHT & year == YEAR)
assign(paste(YEAR,MONTH,"luna",sep="."), temp.df)
}
}
您可以提供一個可重複比如http://stackoverflow.com/questions/5963269/how-to-make-a -great-r-reproducible-example – lizzie