Problems with inserting Data


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?

Kind regards,

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.

Dear jdlong,

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.

Kind regards,

Looks like you have a non-numeric value in these columns. You shall not transform a factor directly as numeric, rather, make it character first:

a = factor(c(3,4,3,5.2))
[1] 3   4   3   5.2
Levels: 3 4 5.2
[1] 1 2 1 3
[1] 3.0 4.0 3.0 5.2


1 Like

@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.

Thank you for the help.

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,

It's quite difficult to read from a screenshot.

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've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

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.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ.

This topic was automatically closed 21 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.