2014-10-02 2 views
0

r에 루프를 쓰고 있습니다. 마지막 줄의 오류 메시지는 입니다. "match.names 오류 (clabs, names (xi)) : 이름 이전 이름과 일치하지 않습니다. " 마지막 줄은 모든 루프 라운드마다 모든 행 값을 유지하려고합니다. 모두에게 감사드립니다. 당신이 for (id in unique_index) 루프를 시작하기 전에루프의 이전 행에 모든 행을 추가하는 방법 R

a = 20 # resample times 
for (id in unique_index){ 

    jeep_id <- jeep_boot[which(jeep$index == id),] 

    #sample_size is 0.8 of the whole data 
    sample_size <- floor((0.8)*length(jeep_id$PR)) 

    #bootstrap sample means 
    samplemeans = rep(NA, a) 

    for (i in 1:a) { 

    bootsample.i = sample(jeep_id$PR, sample_size, replace=T) 
    samplemeans[i] = mean(bootsample.i) 

    } 
    #combine mean of 20 sample means and stand dieviation of sample means to be one row 
    bootresult_id <- cbind(id, mean(samplemeans), sd(samplemeans)) 
    #retain every row value for each round looping 
    bootresult <- rbind(bootresult, bootresult_id) 
} 
+0

작업 할 몇 가지 예제 데이터 (및 예상되는 결과)를 제공하는 것을 고려해보십시오. 그렇게함으로써 더 많은 반응을 얻을 수 있습니다. 테스트 용 예제 데이터를 만들 수 있습니다. 그러나 실제 데이터 집합을 모방하지 않을 수 있습니다. – akrun

답변

0

bootresult에 무엇입니까? 이 부분은 나에게 분명하지 않다, 어쩌면 당신이 처음에 선언하는 방법에 따라 달라

이에 대한

Alternativo 솔루션

bootresult <- matrix(nrow = length(unique_index), ncol=3) 

로 선언과 함께 마지막 줄을 교체입니다

bootresult[id, ] <- bootresult_id 
관련 문제