[R] convert factor data to numeric

Joshua Wiley jwiley.psych at gmail.com
Fri Oct 15 06:15:35 CEST 2010


On Thu, Oct 14, 2010 at 8:41 PM, andreas <andreasseger at web.de> wrote:
>
> cheers for the quick reply.
>
> Sorry I am getting a bit confused I have never used the anything else any
> from of extension on read.csv what I did was:
>
> 1. enter the data into excel and save it as comma delimited
> 2. then used: s1 <- read.csv("book1.csv")
>
> If i try to run this
>
> s1 <- read.table(textConnection("treat   absorb
> + 0          1.8052
> + 0.5       2.07075
> + 1.0       2.2345"), header = TRUE)
>
> it comes with up with the following:
>
>> source(.trPaths[7], echo=TRUE, max.deparse.length=150)
> Fehler in source(.trPaths[7], echo = TRUE, max.deparse.length = 150) :
>  Objekt '.trPaths' nicht gefunden
>
> the way i have done is is the following
>
>> s1 <- read.csv("Book1.csv")
>> head(s1)
>  treat.absorb
> 1     0;1.8052
> 2  0.5;2.07075
> 3     1;2.2345
>> str(s1)
> 'data.frame':   3 obs. of  1 variable:
>  $ treat.absorb: Factor w/ 3 levels "0.5;2.07075",..: 2 1 3

The semicolons ";" suggest your data may not actually (or only) be
comma separated.  Does this produce any better results?

read.table("Book1.csv", sep = ";", stringsAsFactors = FALSE)

--Josh


>
> hope that gives u a better insight
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/convert-factor-data-to-numeric-tp1012855p2996471.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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