I'm trying to convert few column of a data frame from char to numeric in R.
Exemple:
transform_function <- function(dataframe, vector){
for (i in vector){
dataframe[[i]] <- as.numeric(dataframe[[i]])
}
return(dataframe)
}
where my data frame has columns from a to z and I do this:
vector <- c("a", "c", "d", "h")
transform_function(dataframe, vector)
Getting the follow error:
Error in `[[<-.data.frame`(`*tmp*`, i, value = numeric(0)) :
replacement has 0 rows, data has 11068
4.
stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
"replacement has %d rows, data has %d"), N, nrows), domain = NA)
3.
`[[<-.data.frame`(`*tmp*`, i, value = numeric(0))
2.
`[[<-`(`*tmp*`, i, value = numeric(0))
1.
transform_function(dataframe, vector)