Skip to content
Back to formatted view

Raw Message

Message-ID: <50CF1523.1010500@sapo.pt>
Date: 2012-12-17T12:50:43Z
From: Rui Barradas
Subject: Splitting up of a dataframe according to the type of variables
In-Reply-To: <20121217100245.8530@gmx.net>

Hello,

Try the following.

dat <- data.frame(X = rnorm(10), Y = factor(sample(letters, 10)), Z = 1:10)

num <- sapply(dat, is.numeric)
dat[num]

# or
dat[, num]


Hope this helps,

Rui Barradas
Em 17-12-2012 10:02, Martin Spindler escreveu:
> Dear R users,
>
> I have a dataframe which consists of variables of type numeric and factor.
> What is the easiest way to split up the dataframe to two dataframe which contain all variables of the type numeric resp. factors?
>
> Thank you very much for your efforts in advance!
>
> Best,
>
> Martin
>
> ______________________________________________
> 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.