I worked on my Data in SPSS and saved it as csv. In SPSS all variables are type numeric. Now I am working on it in R and there are some variables that are somehow in the wrong format.
mean(PISA$MATH, na.rm = TRUE)
[1] NA
Warning message:
In mean.default(PISA$MATH, na.rm = TRUE) :
Argument ist weder numerisch noch boolesch: gebe NA zurück
It says it`s not numeric.
However if I use the as.numeric function I loose a huge amount of data:
Warning message:
NAs introduced by coercion
Is there an option to transform the data to numeric without introducing NAs? Or does anyone know if I made a mistake in the process from SPSS to R?
@F_user
Hi there,
Did you load your original data into R from a CSV file OR a PASS file?
Would you like to provide a snippet of your code here to show us how you loaded your source data into R?
Hi @F_user, for put all columns as numeric you could try in this form:
data <- read.csv("yourfile.csv", stringsAsFactors = FALSE)
data <- sapply(data, as.numeric)
But as.numeric() return NA for any values that cannot be converted to numeric, such as character strings.
To replace NA values with zero, you can use the is.na().