[R] How to get Quartiles when data contains both numeric variables and factors

aajit75 aajit75 at yahoo.co.in
Mon Oct 31 14:09:54 CET 2011


When data contains both factor and numeric variables, how to get quartiles
for all numeric variables?
n <- 100 
x1 <- runif(n) 
x2 <- runif(n) 
x3 <- x1 + x2 + runif(n)/10 
x4 <- x1 + x2 + x3 + runif(n)/10 
x5 <- factor(sample(c('a','b','c'),n,replace=TRUE))
x6 <- factor(1*(x5=='a' | x5=='c')) 
data1 <- cbind(x1,x2,x3,x4,x5,x6) 
data <- data.frame(data1) 

data <- within(data,{x5 <- factor(x5)})
x <- data

qs <- sapply(x, function(x) quantile(x, c(0.01, 0.99))) 

I get an error: Error in quantile.default(x, c(min_pct, max_pct)) : factors
are not allowed

Thanks for the help.


--
View this message in context: http://r.789695.n4.nabble.com/How-to-get-Quartiles-when-data-contains-both-numeric-variables-and-factors-tp3955750p3955750.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list