Hi:
To condense the output a bit, here's a slight modification that returns, for
each variable
tested, the p-value, confidence limits and odds ratio estimate:
ff<-function(x,y){
m <- fisher.test(table(x,y))
c(m$p.value, m$conf.int, m$estimate)
}
res <- apply(data1[,LETTERS[1:26]], 2, ff, y=data1[
Set up a function for the fisher.test on a 2x2 table and then include
this in the apply function for columns as in the example below. The
result is a list with names A to Z
# set up a dummy data set with 100 rows
Cat<-LETTERS[sample(1:6,100, replace=T)]
GL<-sample(1:6, 100, replace=T)
dat<-matr
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 intern
Hi,
Instead of accessing the data by its name in data.frame, you may use
index by "[[ ]]" as well. For your case, the looping may looks like
for (i in 1:26){
datatable <- table(data1[[i+2]], data1$pLoss) #create a new
datatable2 or 3
fisher.test(datatable)
}
Bests,
Ruihong
On 05/09/
On May 9, 2010, at 12:30 AM, Venkatesh Patel wrote:
-- Forwarded message --
From: Dr. Venkatesh
Date: Sun, May 9, 2010 at 4:55 AM
Subject: R apply() help -urgent
To: r-help@r-project.org
I have a file with 4873 rows of 1s or 0s and has 26 alphabets (A-Z) as
columns. the 27th
-- Forwarded message --
From: Dr. Venkatesh
Date: Sun, May 9, 2010 at 4:55 AM
Subject: R apply() help -urgent
To: r-help@r-project.org
I have a file with 4873 rows of 1s or 0s and has 26 alphabets (A-Z) as
columns. the 27th column also has 1s and 0s but stands for a different
var
6 matches
Mail list logo