"Dimitris Rizopoulos" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:
> try this (also look at R-FAQ 7.10): > > sapply(df, function (x) as.numeric(levels(x))[as.integer(x)]) That looks rather dangerous. By the time I saw your suggestion, I had already added an extra variable with: df$testdata1<-as.numeric(levels(df$testdata))[as.integer(df$testdata)] When I tried your suggestion I got no error, but there was also no effect. When I tried: df2<-sapply(df, function (x) as.numeric(levels(x))[as.integer(x)]) I discovered that the numeric variable, testdata1, had been entirely coverted to NA's and str(df2) did not look data.frame-like. > is.data.frame(df2) [1] FALSE -- David Winsemius > > ----- Original Message ----- > From: "Antje" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, December 04, 2007 11:46 AM > Subject: [R] Dataframe manipulation > > >> Hello, >> >> can anybody help me with this problem? >> I have a dataframe, which contains its values as factors though I >> have numbers >> but it was read as factors with "scan". Now I would like to convert >> these >> columns (multiple) to a numeric format. >> >> >> # this example creates a similar situation >> >> testdata <- as.factor(c("1.1",NA,"2.3","5.5")) >> testdata2 <- as.factor(c("1.7","4.3","8.5",10.0)) >> >> df <- data.frame(testdata, testdata2) >> >> what do I have to do to get the same datafram but with numeric >> values??? >> ______________________________________________ R-help@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.