Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-21 Thread William Dunlap
ep("Q1_", names(scs.c2))) { scs.c2[, iCol] <- factor(scs.c2[, iCol], levels=c(...)) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message- > From: Lopez, Dan [mailto:lopez...@llnl.gov] > Sent: Thursday, February 21, 2013 2:51 PM &

Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-21 Thread Lopez, Dan
2L, 2L, 2L, 2L, 2L), .Label = c("", "yes" ), class = "factor"), Q16 = structure(c(4L, 4L, 4L, 3L, 3L, 3L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 3L, 4L, 3L, 3L, 3L, 4L, 3L, 4L), .Label = c("", "did not meet expectations",

Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-21 Thread Mark Lamias
,"Bill",..: 1 2 3   - attr(*, "Date")= POSIXlt, format: "2013-02-21"   > str(f3(x)) # mangles column names, drops unused levels, drops Date attribute   'data.frame':  3 obs. of  3 variables:   $ No.Yes: Factor w/ 1 level "Yes": 1 1 1   $ Size 

Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-21 Thread William Dunlap
r(*, "Date")= POSIXlt, format: "2013-02-21" > str(f3(x)) # mangles column names, drops unused levels, drops Date attribute 'data.frame': 3 obs. of 3 variables: $ No.Yes: Factor w/ 1 level "Yes": 1 1 1 $ Size : Ord.factor

Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-21 Thread Lopez, Dan
roject.org) Subject: Re: [R] Having trouble converting a dataframe of character vectors to factors Pleaser re-read ?sapply and pay particular attention to the "simplify" argument. The following should help explain the issues: > z <- data.frame(a=letters[1:3],b=letters[4:6],stringsAsFacto

Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-20 Thread Mark Lamias
How about this? scs2<-data.frame(lapply(scs2, factor)) From: "Lopez, Dan" To: "R help (r-help@r-project.org)" Sent: Wednesday, February 20, 2013 7:09 PM Subject: [R] Having trouble converting a dataframe of character vectors to fact

Re: [R] Having trouble converting a dataframe of character vectors to factors

2013-02-20 Thread Bert Gunter
Pleaser re-read ?sapply and pay particular attention to the "simplify" argument. The following should help explain the issues: > z <- data.frame(a=letters[1:3],b=letters[4:6],stringsAsFactors=FALSE) > sapply(z,class) a b "character" "character" > z1 <- sapply(z,as.factor) > sa

[R] Having trouble converting a dataframe of character vectors to factors

2013-02-20 Thread Lopez, Dan
R Experts, I have a dataframe made up of character vectors--these are results from survey questions. I need to convert them to factors. I tried the following which did not work: scs2<-sapply(scs2,as.factor) also this didn't work: scs2<-sapply(scs2,function(x) as.factor(x)) After doing either of