2015-01-22 2 views
0

나는 몇 가지 분류 모델의 성능 매트릭스 보유 할 데이터 프레임을 생성하기위한 것입니다이 코드를 가지고 : 데이터의 첫 번째 열을 업데이트하려고 할 때R 데이터 프레임 업데이트 전체 열

eval_table <- data.frame(norm_method_1=c("","","","",""),norm_method_2=c("","","","",""),norm_method_3=c("","","","",""),norm_method_4=c("","","","",""),norm_method_5=c("","","","",""),norm_method_6=c("","","","",""),norm_method_7=c("","","","",""),norm_method_8=c("","","","","")) 
    rownames(eval_table) <- c("Log. Model Coeff","Log. Model Confusion Matrix","Log. Model AUC","Linear Modl Coeff","Linear Model overfit ratio") 

    col <- list(mnm_coef,cm,auc,lm_summary$coefficients,lm_summary$training_testing_error_ratio) 
    eval_table[,c("norm_method_1")] <- col 

을 왜

Error in `[<-.data.frame`(`*tmp*`, , c("norm_method_1"), value = list(: 
    replacement element 1 is a matrix/data frame of 2 rows, need 5 

어떤 생각 : 나는 사전 (데이터 프레임은 5 개 행이) 나는 다음과 같은 오류가 준비 5 요소의 목록 프레임 (마지막 행)?

UPDATE :

당신이 당신의 데이터의 크기는 당신이 무슨 생각인지 확인하기 위해 필요한이 같은 상황에서 얻을 경우
dim(col) 
NULL 
str(col) 
> str(col) 
List of 5 
$ : num [1:2, 1:30] 21.436 40.828 -0.785 0.54 -1.375 ... 
    ..- attr(*, "dimnames")=List of 2 
    .. ..$ : chr [1:2] "2" "3" 
    .. ..$ : chr [1:30] "(Intercept)" "is_top_rated_listing1" "seller_is_top_rated_seller" "is_auto_pay1" ... 
$ :List of 5 
    ..$ positive: NULL 
    ..$ table : 'table' int [1:3, 1:3] 414 73 433 101 329 1186 147 60 10546 
    .. ..- attr(*, "dimnames")=List of 2 
    .. .. ..$ Prediction: chr [1:3] "1" "2" "3" 
    .. .. ..$ Reference : chr [1:3] "1" "2" "3" 
    ..$ overall : Named num [1:7] 0.849 0.402 0.843 0.856 0.809 ... 
    .. ..- attr(*, "names")= chr [1:7] "Accuracy" "Kappa" "AccuracyLower" "AccuracyUpper" ... 
    ..$ byClass : num [1:3, 1:8] 0.45 0.204 0.981 0.98 0.989 ... 
    .. ..- attr(*, "dimnames")=List of 2 
    .. .. ..$ : chr [1:3] "Class: 1" "Class: 2" "Class: 3" 
    .. .. ..$ : chr [1:8] "Sensitivity" "Specificity" "Pos Pred Value" "Neg Pred Value" ... 
    ..$ dots : list() 
    ..- attr(*, "class")= chr "confusionMatrix" 
$ :Classes 'auc', 'numeric' atomic [1:1] 0.592 
    .. ..- attr(*, "partial.auc")= logi FALSE 
    .. ..- attr(*, "percent")= logi FALSE 
    .. ..- attr(*, "roc")=List of 8 
    .. .. ..$ percent  : logi FALSE 
    .. .. ..$ sensitivities: num [1:1021] 1 0.998 0.998 0.998 0.996 ... 
    .. .. ..$ specificities: num [1:1021] 0 0 0.00151 0.00302 0.00302 ... 
    .. .. ..$ thresholds : num [1:1021] -Inf 0.358 0.359 0.36 0.361 ... 
    .. .. ..$ direction : chr "<" 
    .. .. ..$ cases  : num [1:462] 0.51 0.727 0.725 0.667 0.667 ... 
    .. .. ..$ controls  : num [1:662] 0.903 0.967 0.756 0.966 0.981 ... 
    .. .. ..$ fun.sesp  :function (thresholds, controls, cases, direction) 
    .. .. ..- attr(*, "class")= chr "roc" 
$ : num [1:28, 1:4] 3.18 3.49 -3.55 -1.16 4.1 ... 
    ..- attr(*, "dimnames")=List of 2 
    .. ..$ : chr [1:28] "(Intercept)" "is_top_rated_listing1" "seller_is_top_rated_seller" "is_auto_pay1" ... 
    .. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)" 
$ : num 0.819 
> 
+5

오류가 이유를 말한다. – Roland

+0

당신이 정교 할 수 있으면 고맙겠습니다 : 내 목록에는 5 개의 요소가 있고 내 데이터 프레임에도 5 개의 행이 있습니다. 첫 번째 열을 5 개의 요소 목록으로 업데이트하면 각 요소가 다른 행에 쓰여집니다. – user3628777

+0

글쎄, 오류 IMHO는 'mnm_coef'는 2 행의 행렬 (또는 데이터 프레임)이라고 말합니다. 그래서 당신이 시도하는 것은 전혀 맞지 않습니다. 그러나 재현 할 수있는 예제 (사용자가 아닌 다른 오류없이 복사/붙여 넣기 및 실행할 준비가 됨)를 제공하지 않았으므로 아무도 확실하게 말할 수 없습니다. – lukeA

답변

0

.

length(col) 

을 사용하여 col에 대한 가정을 확인하십시오. 크기가 호환되지 않는다는 메시지가 표시됩니다.

가 있다면, 할당이 작동합니다 - 예를 들어,이 경우

col <- c(1,2,3,4,5) 
eval_table[,c("norm_method_1")] <- col 

, length(col) 반환 5.

또 다른 유용한 명령이 str이다 - 즉 str(eval_table)str(col). 이렇게하면 크기가 호환되지 않는 것을 볼 수 있습니다.

이 경우 첫 번째 요소는 행렬입니다. 그래서 우리는 이것을 이렇게 조롱 할 수 있습니다 :

mat <- matrix(1,2) 
col <- list(mat, 2, 3, 4, 5) 

그런 다음 오류가 표시됩니다. 이 문제를 극복하기 위해, 첫 번째 요소로 행렬의 첫 번째 요소로 목록을 구축하고, 벡터로 구축 :

col <- c(mat[1][1], 2,3, 4,5) 

다음이 작동 :

eval_table[,c("norm_method_1")] <- col 
+0

길이가 5이고 여전히 작동하지 않습니다 (같은 오류). 반면에 : eval_table $ norm_method_1 <- col이 작동합니다. 열 이름 변경 이후 첫 번째 (현재 결함이있는) 방법으로 데이터 프레임에 액세스 할 수있는 방법은 무엇입니까? – user3628777

+0

'str (col) '은 무엇을 보여줍니까? 'dim (col) '을 사용할 수 있습니까? –

+0

Q에서 위의 업데이트를 참조하십시오. – user3628777