[R] Splitting up of a dataframe according to the type of variables
Jessica Streicher
j.streicher at micromata.de
Mon Dec 17 11:36:04 CET 2012
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.
More information about the R-help
mailing list