简体   繁体   中英

prop.test for multiply compare in R

kk=structure(list(items = structure(c(2L, 4L, 5L, 11L, 1L, 3L, 6L, 
7L, 8L, 9L, 10L, 12L), .Label = c("ak47", "aks47", "colt", "dubstepgun", 
"moneygun", "paintballgun", "portalgun", "s", "scar20", "spas12", 
"tank", "watergun"), class = "factor"), N = c(3L, 3L, 3L, 3L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("items", "N"), class = "data.frame", row.names = c(NA, 
-12L))

to perform prop.test for each item i use simple way. count of item(12) and total number of obs.(N)=20,

prop.test(1,20)

so colt item met 1 time in 20 ! How to do single prop.test for all items at once, no manualy.

prop.test(3,20)
prop.test(2,20)

and so on, but with name of item

#tank
prop.test(3,20)
#spas12
prop.test(1,20)

An option is to get the unique elements of 'N' column, loop it with lapply and apply the prop.test

lst1 <- lapply(unique(kk$N), function(i) prop.test(i, 20))
names(lst1) <- unname(tapply(as.character(kk$items), 
      factor(kk$N, levels = unique(kk$N)), FUN = tail, 1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM