[R] Fwd: R apply() help -urgent
Pete B
Peter.Brecknock at bp.com
Mon May 10 03:43:10 CEST 2010
Venkatesh
Is this what you are looking for?
# Example data
df=data.frame(A=c(1,0,0,0,1),B=c(1,1,0,0,0),C=c(1,0,0,0,0),Val=c(1,0,1,0,1))
# Variation of code of David Winsemius
tbl = lapply(df[, 1:3] , function(x) table(x, df$Val))
fet = lapply(tbl, function(x) fisher.test(x))
# Identify internal objects of fet
names(fet$A)
# get p values
p.val = do.call(rbind,fet)[,1]
p.val.df=data.frame(pval=matrix(unlist(p.val)))
# get conf int
ci = do.call(rbind,fet)[,2]
ci.df=data.frame(matrix(unlist(ci),byrow=TRUE,ncol=2))
# add back id of letter
id = data.frame(idletter=colnames(df[,-4]))
# results
res = data.frame(id,pvalue=p.val.df,confint=ci.df)
There is undoubtly a more elegant way of handling getting the p-values and
conf int than my attempt.
HTH
Pete
--
View this message in context: http://r.789695.n4.nabble.com/Fwd-R-apply-help-urgent-tp2164281p2164867.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list