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
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
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
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
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
5 matches
Mail list logo