Skip to content
Prev 342855 / 398506 Next

extract descriptive stats for categorial data from dataframe

On Tue, 5 Aug 2014 11:36:36 AM Alain D. wrote:
out a
as.data.frame(cbind(i1=rep("+"),i2=rep("+",10),i3=rep("-",10),i4=c(rep("
-",2),"0",rep("-",7)),i5=rep("+",10),i6=c(rep("-",9),"+"),i7=c(rep("+",4),"0
",rep("+",5)),i8=c(rep(0,4),rep("+",3),"-","+","-"),i9=c(rep("+",5),"-",rep(
first
obvious
Hi Alain,
You can get pretty much what you want if your variables are all factors 
with the same levels like this:

varlevels<-c("+","-","0","1")
df<-data.frame(
 i1=factor(rep("+",10),levels=varlevels),
 i2=factor(rep("+",10),levels=varlevels),
 i3=factor(rep("-",10),levels=varlevels),
 i4=factor(c(rep("-",2),"0",rep("-",7)),levels=varlevels),
 i5=factor(rep("+",10),levels=varlevels),
 i6=factor(c(rep("-",9),"+"),levels=varlevels),
 i7=factor(c(rep("+",4),"0",rep("+",5)),levels=varlevels),
 i8=factor(c(rep(0,4),rep("+",3),"-","+","-"),levels=varlevels),
 i9=factor(c(rep("+",5),"-",rep("+",2),rep(0,2)),levels=varlevels))
library(prettyR)
describe(df,horizontal=TRUE,fname.space=10)

Jim