I have a dataframe where the first column is a price indices, the second is a commodity group, the third is the year and month and the last is a numeric value. I wrote such a script.
data <- data.frame(read.px(file ='http://data.csb.gov.lv/Resources/PX/Databases/ekfin/isterm/PCI/PC00231m.px', encoding =''))
data <- subset(data, data[[2]] ==levels(data[[2]])[2])
names <- levels(data[[3]])
temp <-subset(data, data[[3]] == levels)data[[3]])[1])
years <- as.numeric(as.character(temp[[4]]))
months <-rep(levels(temp[[1]]), times=lenght(years)/12))
index_df <-data.frame(years, months)
R gives me this:
Error in data.frame(years, months): arguments imply differing number of rows: 4, 0
If I am correct, it’s mean that the lenght of years didn’t match the length of months. I don’t know how to solve the problem. Can someone help me to solve this error?