[R] Splitting up of a dataframe according to the type of variables

2012-12-17 Thread Martin Spindler
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

Re: [R] Splitting up of a dataframe according to the type of variables

2012-12-17 Thread Jim Holtman
most likely the 'split' function, but exactly how would depend on the data which you did not provide. Sent from my iPad On Dec 17, 2012, at 5:02, Martin Spindler martin.spind...@gmx.de wrote: Dear R users, I have a dataframe which consists of variables of type numeric and factor. What is

Re: [R] Splitting up of a dataframe according to the type of variables

2012-12-17 Thread Jessica Streicher
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

Re: [R] Splitting up of a dataframe according to the type of variables

2012-12-17 Thread Rui Barradas
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

Re: [R] Splitting up of a dataframe according to the type of variables

2012-12-17 Thread arun
Hi, You could also use ?colwise() from library(plyr) set.seed(50) dat1-data.frame(Col1=sample(1:20,10,replace=TRUE),Col2=sample(LETTERS[1:10],10,replace=TRUE),Col3=sample(LETTERS[11:20],10,replace=TRUE),Col4=sample(40:60,10,replace=TRUE))  dat1[unlist(colwise(is.factor)(dat1))] #   Col2 Col3 #1