[R] numeric data being interpreted as a factor -trouble with reading data into a dataframe in R

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Oct 28 02:23:18 CET 2013


No data came through (I don't think "CSV" is one of the approved file types.)

You probably have some odd characters somewhere in the data. Try adding the argument stringsAsFactors=FALSE to the read.csv call before converting the troublesome column.. Converting factors to numeric converts the integer representation, not the character representation. Once you identify which rows are corrupt, you can look at them more closely. You may be able to formulate a regex pattern that removes the invalid characters with the sub function before conversion.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Bill <william108 at gmail.com> wrote:
>Hello.
>trying to do one of the simplest actions -read in data into R.
>I don't know why the FBfollowers column is being read as a factor and
>also
>if I use as.numeric on it, it looks really strange and actually
>complety
>alters the data.
>I am attaching the data set here called ddd.csv
>I used
>data=read.csv("ddd.csv",header=TRUE)
>
>fb=data$FBfollowers
>fb
>fb=as.numeric(fb)
>fb
>
>Thnxs in advance
>
>
>------------------------------------------------------------------------
>
>______________________________________________
>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.



More information about the R-help mailing list