1

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?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Alex
  • 11
  • 1
  • 1
    you types `lenght` instead of `length`. Next to that, make sure levels(temp[[1]]) isn't empty, and if years has only a length of 4, then `rep(x, times = 4/12)` gives you an empty vector regardless. Please provide us with a reproducible example (see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 ) – Joris Meys Feb 18 '16 at 13:48

0 Answers0