Ines22
Ines22

Reputation: 21

Error in na.interpolation(data[, i], option): Input x is not numeric

I have the following problem. I have a data.frame consisting of country "identifier" (letters+numbers), "year" (numbers), "unique identifier" (identifier+year), statistics on "labour market1" (numbers) and statistics on "labour market2" (numbers), where some data for labour market2 is missing and needs to be interpolated. Once I run the library(imputeTS), I get the following message:

library(imputeTS) Warning message: Unknown or uninitialised column: 'x'.

After running

data <- na.interpolation(data)

I get the following errors:

Warning messages: 1: Unknown or uninitialised column: 'x'. 2: imputeTS: No imputation performed for column 1 because of this Error >in na.interpolation(data[, i], option): Input x is not numeric

3: imputeTS: No imputation performed for column 2 because of this Error >in na.interpolation(data[, i], option): Input x is not numeric

4: imputeTS: No imputation performed for column 3 because of this Error >in na.interpolation(data[, i], option): Input x is not numeric

5: imputeTS: No imputation performed for column 5 because of this Error >in na.interpolation(data[, i], option): Input x is not numeric

What is interesting is that the na.interpolation(data) stopped working after I updated the R version from 3.2.3 to the latest 3.5.1 (2018-07-02) -- "Feather Spray".

I wonder if there is a solution to get rid of the warning and perform the interpolatioN without reverting back to the older version of R.

Thank you in advance!

Upvotes: 2

Views: 966

Answers (1)

LisboaFJG
LisboaFJG

Reputation: 21

I guess there is a problem with one of the columns of your dataset. The message clearly says you have a non-numeric column. Have you tried to jump non-numeric columns? I have come across the same issue recently working on element-wise imputation with the imputeTS package. My workaround was to skip the character columns. In my case, I had a list of dataframes representing countries. Some of the dataframes had only the two first columns (country and year) which were characters.

list_imputed_values <- lapply(list_of_dataframes, function(x){
if (ncol(x) == 3) { # apply imputation to the third column only
name <- names(x)[3]
fixed <- x[, 1:2]
imputable <- x[, 3]
imputed <- as.data.frame(imputeTS::na.interpolation(imputable))
names(imputed) <- name
x <- cbind(fixed, imputed)
} else if (ncol(x) == 2) { # do not apply imputation because columns are non-numeric
x <- x[, 1:2]
 } else {  # apply imputation to all non-numeric columns
fixed <- x[, 1:2]
imputable <- x[, 3:ncol(x)]
imputed <- imputeTS::na.interpolation(imputable)
x <- cbind(fixed, imputed)
  }})

Upvotes: 1

Related Questions