1 meteo_df = read.csv("meteo.csv")
4 #http://stackoverflow.com/questions/8214303/conditional-replacement-of-values-in-a-data-frame
8 meteo_df$Pollution = -1
10 #Need to load and aggregate PM10 by days: use getData() from package
11 data = getData(..., predict_at=0) #TODO:
13 for (i in 1:nrow(meteo_df))
15 pm10_level = data$getLevel(i)
16 #Fill Pollution column: -1 if no info, 0 to 2 for pollution level
17 if (!is.nan(pm10_level))
20 meteo_df$Pollution[i] = 0
21 else if (pm10_level <= 50)
22 meteo_df$Pollution[i] = 1
24 meteo_df$Pollution[i] = 2
27 #Also fill season + days of week variables
28 meteo_df$Season[i] = ifelse(
29 strsplit(as.character(meteo_df$Date[i]),'/')[[1]][1] %in% c("4","5","6","7","8"),
31 current_datetime = strptime(as.character(meteo_df$Date[i]), "%m/%d/%Y", tz="GMT")
32 meteo_df$Week[i] = ifelse(current_datetime$wday %in% c(6,0), 0, 1)
35 #Finally write new data
36 write.csv(meteo_df, file="meteo_extra.csv", row.names=FALSE)