I use following code to map the month name to number and I find it's low efficiency compared to other dataframe computation without for loop.
Sys.time()
head(df[,4])
for (i in 1:nrow(df)){
df$monthnum[i]<-match(tolower(as.character(df[i,4])), tolower(month.name))
}
Sys.time()
and I got output like this:
> Sys.time()
[1] "2016-03-07 19:20:53 CST"
> dim(df)
[1] 229464 6
> head(df[,4])
[1] January January January January January January
Levels: April August December February January July June March May November October September
> for (i in 1:nrow(df)){
+ df$monthnum[i]<-match(tolower(as.character(df[i,4])), tolower(month.name))
+ }
> Sys.time()
[1] "2016-03-07 19:23:23 CST"
Can anyone the logic of for loop in dataframe. Any information will be appreciated.