This is (I think) purely an R question, which I show with Climatic data from Cameroon. They have been tidied and imported by @jkmusyoka from a sequence of Excel files. The resulting Excel file has been tidied (and shortened) slightly in R-Instat.
One problem is that there are 45 months in these years. This has come because the months have been variously coded in the original Excel sheets. I attempted a recode of the levels and here is the R-command. It gives an error.
I think the error may be because I have recoded values into new levels (jan, feb, mar, etc) that were not present in the original factor. If I am correct, then I wonder if there is an option in the plyr::revalue function to permit this, perhaps making the resulting variable into a character?
# Dialog: Recode Factor
month <- data_book$get_columns_from_data(data_name="Sheet1", col_names="month", use_current_filter=FALSE)
month_recoded <- plyr::revalue(x=month, replace=c(`AVRIL`="apr", `AOÛT`="aug", `DÉCEMBRE`="dec", `FÉVRIER`="feb", `JANVIER`="jan", `JUILLET`="jul", `JUIN`="jun", `MAI`="may", `MARS`="mar", `NOVEMBRE`="nov", `OCTOBRE`="oct", `SEPTEMBRE`="sep", `AOUT`="aug", `DECEMBRE`="dec", `FEVRIER`="feb", `JANVRIER`="jan", `AUOT`="aug", `NOV`="nov", `DECEMBTRE`="dec", `AVR`="apr", `DEC`="dec", `FEV`="feb", `JAN`="jan", `OCT`="oct", `SEPT`="sep", `Decembre`="dec", `Octobre`="oct", `Septembre`="sep", `Avril`="apr", `Mai`="may", `Aout`="aug", `Décembre`="dec", `Novembre`="nov", `janvier`="jan", `juillet`="jul", `juin`="jun", `Fevrier`="feb", `Janvier`="jan", `Juillet`="jul", `Juin`="jun", `Mars`="mar", `Decemmbre`="dec", `Maroua`="mar", `OCTBRE`="oct", `jan`="jan"))
data_book$add_columns_to_data(data_name="Sheet1", col_name="month_recoded", col_data=month_recoded, before=FALSE, adjacent_column="month")
I wonder if the mapvalues function might be better? It is also in plyr. I'll check.
This is (I think) purely an R question, which I show with Climatic data from Cameroon. They have been tidied and imported by @jkmusyoka from a sequence of Excel files. The resulting Excel file has been tidied (and shortened) slightly in R-Instat.
One problem is that there are 45 months in these years. This has come because the months have been variously coded in the original Excel sheets. I attempted a recode of the levels and here is the R-command. It gives an error.
I think the error may be because I have recoded values into new levels (jan, feb, mar, etc) that were not present in the original factor. If I am correct, then I wonder if there is an option in the plyr::revalue function to permit this, perhaps making the resulting variable into a character?
Here is the data:
Maroua_edited.xlsx
I wonder if the mapvalues function might be better? It is also in plyr. I'll check.