2017-02-23 1 views
-1

저는 R이 처음이므로 손에 닿지 않는 것을 용서하십시오.경고 : 인수가 숫자가 아닌 것입니다.

다음과 같은 데이터 세트가 있습니다. jetleg.dat 내 데이터 집합입니다.

treatment phaseshift 
control  0.53 
control  0.36 
    light  -0.78 
    light  -0.86 

치료 및 단계 이동을 위해 평균을 구해야합니다.

경고 메시지 :

내가 계산을

,
control <- jetlag.dat[jetlag.dat$treatment == 'control',]$percent 
light <- jetlag.dat[jetlag.dat$treatment == 'light',]$percent 

mean(control) 
mean(light) 

나는이 알림을 mean.default에서 (제어) : 인수는 숫자 또는 논리되지 않습니다 :

NA 반환

컨트롤 및 표시등은 숫자가 아닌 것으로 알고 있지만 계산시이를 고려한 것으로 알고 있습니다. 전에 이런 짓을했는데 효과가있었습니다. 어떤 도움을 주시면 감사하겠습니다. 고맙습니다.

+0

재생산 코드를 제공 할 수 있습니까? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example을 방문하십시오. –

답변

0

내가 볼 수없는 percent이라는 열을 참조하고 있습니다. 나는 그것이 $phaseshift이어야한다고 생각할 것이다.

control <- jetlag.dat[jetlag.dat$treatment == 'control',]$phaseshift 
light <- jetlag.dat[jetlag.dat$treatment == 'light',]$phaseshift 

mean(control) 
mean(light) 

그래도 같은 오류가 발생하는 경우 as.numeric에 넣어보세요.

mean(as.numeric(control))

0

여기에 귀하의 문제가 주로 구문 것 같다.

변수가 phaseshift 인 경우 먼저 $percent을 호출합니다. 괄호

그리고 마지막으로는, jetlag.dat$treatment == "control" 문 뒤의 쉼표가 안 전에

둘째, $percent 또는 $phaseshift 필요가되게합니다.

여기에 코드의 수정 된 버전이며 작동이 도움이

df <- data.frame(treatment = c("control", "control", "light", "light"), 
      phaseshift = c(0.53, 0.36, -0.78, -0.86)) 

control <- df$phaseshift[df$treatment == "control"] 
light <- df$phaseshift[df$treatment == "light"] 

control_mean <- mean(control) 
light_mean <- mean(light) 

희망!

관련 문제