Skip to content
Back to formatted view

Raw Message

Message-ID: <ED7F13A8-152F-429A-8F0D-6BD9DFB45656@micromata.de>
Date: 2012-12-17T10:36:04Z
From: Jessica Streicher
Subject: Splitting up of a dataframe according to the type of variables
In-Reply-To: <20121217100245.8530@gmx.net>

f<-factor(c(1,1,2,3))
n<-c(1,1,2,3)
df<-data.frame(f,n)

sapply(df,is.factor)
f     n 
TRUE FALSE 
df[sapply(df,is.factor)]
f
1 1
2 1
3 2
4 3

 df[sapply(df,is.numeric)]
  n
1 1
2 1
3 2
4 3

something like that? 


On 17.12.2012, at 11:02, Martin Spindler wrote:

> 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.