Dear Barry,
I saw that you received several nice answers on how to 'pull out' numeric
columns. You also wrote that an alternative could be to 'just operate only on'
numerics. Here is one possibility:
library(plyr)
# some dummy data
df <- data.frame(nonnum1 = letters[1:5], num1 = 1:5, nonnum2
7851
#5 0.4880163 2 0.4474437
#6 -1.2553858 2 0.9646670
A.K.
- Original Message -
From: Barry DeCicco
To: "r-help@R-project.org"
Cc:
Sent: Saturday, February 16, 2013 1:15 PM
Subject: [R] Extracting Numeric Columns from Data Fram
Hello,
I've got a data frame wit
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]]
__
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
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
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
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
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 operate assuming you have the column names. I'd like to pull
by
8 matches
Mail list logo