I have an excel file that has this shape
I need to format this data so that it looks like this
In the second image the second column is just the month written as a number. and the concatenation of month and year is the third. The last two are copies of the last two of the first.
I know the simplest way to do this is with tidyxl and a XlsX file. However this file has to be kept as a xls. I'm very new to R so pls forgive me if this had a simple answer I just didn't see
I have thought about mutating the table and adding a row of years from 2007 to 1950 each repeated 12 times. But that would require me to know the amount of years analyzed in the excel before running and I would probably have to make a code to generate such a vector so not exactly user friendly.
something like
VectorBuilder <- function(StartYear,EndYear){
CalculatedVector <- c()
for (x in StartYear:EndYear) {
for (y in 1:12){
CalculatedVector <- append(CalculatedVector,x)
}
}
CalculatedVector
}
years = VectorBuilder(1950,2007)
dataframeClean <- cbind(dataframeDirty, years)
The other formatting problems such as the NA and the month to number I know how to do. I just cant find a clean easy way to create that year column