Reputation: 141
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)
Upvotes: 1
Views: 112
Reputation: 887691
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))
Upvotes: 1