2013-06-05 2 views
0

나는 약 1000 행과 2 열의 data.frame 있습니다. prop.test (k, n) 을 수행하고 싶습니다. 여기서 k == Column1은 my data.frame이고 n은 == Column2는 my data.frame입니다. 예를 들어prop.test 행 큰 data.frame에서 현명한

:

Column1(k) Column2(n)  
    60   500  
    50   500  
    70   500  
    40   500  

I는 각 행 prop.test (K, N)를 실행하고 싶다.

prop.test(60, 500) 
prop.test(50, 500) 
prop.test(70, 500) 

등 : 예를 들면. 내가 약 1000 행을 가지고 있기 때문에 나는 행 당 수작업으로 prop.test를 수행 할 수 없다. 각 행을 입력 할 때마다 prop.test를 수행하는 함수를 작성하려면 어떻게해야합니까?

고마워,

E.

+1

일반적으로 함수가 벡터화되어 있는지, 그리고 짧은 샘플 벡터를 전달하고 어떻게되는지 확인하는 것이 좋습니다. – John

+1

prop.test가 반환하는 목록의 구성 요소가 관심 대상이지만 기본으로 반환되는 긴 목록을 필요로하지 않을 수 있습니다. –

답변

1

당신은 mapply의 래퍼 인 Map를 사용할 수 있습니다 : 예를 들어

prop.test(col1, col2) 

prop.test 데이터가 너무 deparsing에 문제를 가지고하는 것으로
dfr <- data.frame(k=c(60,50,70,40),n=rep(500,4)) 
Map(prop.test,x=dfr$k,n=dfr$n) 
[[1]] 

     1-sample proportions test with continuity correction 

data: dots[[1L]][[1L]] out of dots[[2L]][[1L]], null probability 0.5 
X-squared = 287.282, df = 1, p-value < 2.2e-16 
alternative hypothesis: true p is not equal to 0.5 
95 percent confidence interval: 
0.09348364 0.15251247 
sample estimates: 
    p 
0.12 


[[2]] 

     1-sample proportions test with continuity correction 

data: dots[[1L]][[2L]] out of dots[[2L]][[2L]], null probability 0.5 
X-squared = 318.402, df = 1, p-value < 2.2e-16 
alternative hypothesis: true p is not equal to 0.5 
95 percent confidence interval: 
0.07580034 0.13052865 
sample estimates: 
    p 
0.1 

... 

어느 것이 어느 것인지 식별하기가 어려울 수 있습니다.

3

prop.test는 벡터화되어있다. 이 작업을 수행 할 수 있습니다

dat <- data.frame(Column1 =c(83, 90, 129, 70),Column2= c(86, 93, 136, 82)) 
> prop.test(dat$Column1,dat$Column2) 

    4-sample test for equality of proportions without continuity correction 

data: dat$Column1 out of dat$Column2 
X-squared = 12.6004, df = 3, p-value = 0.005585 
alternative hypothesis: two.sided 
sample estimates: 
    prop 1 prop 2 prop 3 prop 4 
0.9651163 0.9677419 0.9485294 0.8536585 
+0

이것은 OP가 요구했던 것이 아닙니다. 이것은 4- 샘플 테스트입니다. OP는 3 개의 개별 샘플 테스트를 원합니다. – Joe