Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread arun
Hi, set.seed(15) dat1<-data.frame(col1=rnorm(6),col2=rep(1:2,each=3),col3=rep(letters[1:3],2),col4=runif(6),col5=rep(LETTERS[3:5],2)) dat1[,sapply(dat1,class)!="factor"] #    col1 col2  col4 #1  0.2588229    1 0.5090904 #2  1.8311207    1 0.7066286 #3 -0.3396186    1 0.8623137 #4  0.8971982

Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread Barry DeCicco
Thanks to all who responded! I've taken those responses, and found out what works: myNumericColumns<-mydataframe[sapply(mydataframe, is.numeric)] produces a subset of columns with just the numeric vectors. Sincerely, Barry [[alternative HTML version deleted]] __

Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread Rui Barradas
Hello, You should provide us with a data example, like the posting guide says. Anyway, see the following example. # make up some data dat <- data.frame(X = 1:4, Y = rnorm(4), Z = letters[1:4]) str(dat) # this returns the numeric/integer columns dat[sapply(dat, is.numeric)] Hope this helps, Ru

Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread John Kane
http://stackoverflow.com/questions/5863097/selecting-only-numeric-columns-from-a-data-frame John Kane Kingston ON Canada > -Original Message- > From: bdecicco2...@yahoo.com > Sent: Sat, 16 Feb 2013 10:15:35 -0800 (PST) > To: r-help@r-project.org > Subject: [R] Extracting Numeric Columns

Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread Phil Spector
Barry = Suppose your data frame is called "mydat". Then something like mydat[,sapply(mydat,class) %in% c('numeric','integer')] might do what you want. - Phil On Sat, 16 Feb 2013, Barry DeCicco wrote: Hello, I've got a data frame wi

Re: [R] Extracting Numeric Columns from Data Fram

2013-02-16 Thread Marc Schwartz
On Feb 16, 2013, at 12:15 PM, Barry DeCicco wrote: > Hello, > > I've got a data frame with a mix of numeric, integer and factor columns. > I'd like to pull out (or just operate only on) the numeric/integer columns. > Every thing I've found in searches is about how to subset by rows, > or how to