[R] problem on using read.csv function

Joshua Wiley jwiley.psych at gmail.com
Fri Oct 22 04:22:46 CEST 2010


Hi Sonia,

This suggests that those columns have something in them that is not
numeric (e.g., "." to represent missing data, text, etc.).  You can
avoid them being converted to factor using:

read.csv("yourfile.csv", stringsAsFactors = FALSE)

however, they will still be character class, not numeric.  You will
then either need to use as.numeric() on those columns, or figure out
what is making R think those are character columns in the first place
and correct that in your CSV file.

Cheers,

Josh

On Thu, Oct 21, 2010 at 7:17 PM, mou sonia <paperhome at gmail.com> wrote:
> Hi,
>
> I'm using read.csv to import a table. But sevel columns are changed to
> factor variables automatically. They are actually numbers not factor levels.
> Why this happened? How can I get the correct table? Thanks a lot.
>
> Sonia
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list