Numeric data not being read as numeric data

Hi everyone,

I'm doing a mediation analysis using complex sample survey. But when I try to upload data from SPSS into R, It gives me an error that data is not numeric, even though is numeric...I looked at others that had similar issues and it seems that commas were an issue and I tried to add the argument "stringsAsFactors=false", but code still not working....

read.csv("C:/...pathcases.sav", stringsAsFactors = FALSE)

(I put the actual C:/ path to the dataset in the code).

Gives this error:
Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote, :
line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote, :
line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote, :
line 3 appears to contain embedded nulls
4: In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on 'C:/...path cases.sav'

I also tried to reformat before, but still didn't work..
library('tidyverse')
152,821" %>% factor %>% str_replace(',', '') %>% as.numeric

I'm at a loss...how can I make R see that the data uploaded is numeric/or how to convert it from factor to numeric, so I can run the medication analysis ? (I'm doing survey mediation analysis using med.fit.BRR.

The dependent variable that I have is coded as numeric: cognition score raging from 20-35 for 16000 participants.
Thank you!!

Usually reflects an encoding issue. Save the csv file and convert to UTF-8. Sorry I don’t know how that’s done on Windows.

Final line should be blank.

This should be generating errors of all sorts. How to do it depends on how many variables (columns) are typeof character.

If you are working with a sav file, this post may help.

You're working with sav file not csv that's the problem. Use package: haven for reading sav file.

2 Likes

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.