I have a data file of about 350 rows and 20 columns. When I try to insert the file with Data=read.csv(file.choose(), header = T, sep=","), it changes the scale values in some columns, I don't know why. When I then try to make a Lmer, R gets stuck and I am not able to quit or to continue; this happened on both my laptop and the university computer. What do I need to do?
It's not 100% obvious to me what you mean by "changes the scale values". Can you share an explicit example of a few lines of an input file and then the code you ran and the result you received? The exact input file is really important here as there could be funny notation in the CSV that is getting converted oddly. We can only guess what that might be unless you share an example.
The main problem is when I try to make a variable numeric with as.numeric, R changes the values of that variable to something else. I have tried to overcome this by making the variable first a factor and then numeric but this does not work. An example is the first values of my variable are 0.8 and 1.6 but after as.numeric, they change into 9 and 17.
@Fer is correct that your issue is with conversions from factors to numeric. However, you can avoid this all together by including the argument stringAsFactors = FALSE in your read.csv command or you could use readr::read_csv which by default doesn't coerce to factors.
This is almost certainly an issue with the values being read in as factors initially. You will find that read_csv from the readr package will not automatically convert to factors and may be helpful.
Without a reproducible example of your data and your code it's impossible for me to be more helpful. Good luck.
I have tried both options but still the values change. I have attached one printscreen after I run the lines with numeric; the values change in NA. When I remove "supresswarning", it says
Warning message:
NAs introduced by coercion
Any idea what I should do with this? I noticed that before, without the stringsAsfactors, values of the variables change when i run the numeric line...
Thanks for the help and kind regards,
Nicky
Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.
If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.