在數據幀的專欄中,我想就問題展開:Find the index of the column in data frame that contains the string as value查找具有價值
我有數據
data<-data.frame(expert=c("class.1","class.4","class.2"),
choice1=c("class.3","class.8","class.10"),
score1=c(0.92,0.91,0.30),
choice2=c("class.1","class.7","class.9"),
score2=c(0.70,0.78,0.30),
choice3=c("class.6","class.1","class.2"),
score3=c(0.01,0.58,0.30),
stringsAsFactors=FALSE
)
我想獲得與專家的選擇有關的分數。目標是找出1)選擇是否正確,但是我需要檢查是否有專家選擇的代碼與分數相關。
在例子中的數據,使用dplyr:
data %>% mutate(Right=expert==choice1)
得到答案的一部分,但不處理的關係。 Find the index of the column in data frame that contains the string as value的答案使用grepl,我不認爲它可以處理正則表達式模式的向量。
我已經嘗試了max,max.col,以及哪個,哪一個,以及與rowwise()的組合,但我不能得到正確的答案。我還用整形數據「整齊」(謝謝加州大學洛杉磯分校IDRE http://stats.idre.ucla.edu/r/faq/how-can-i-reshape-my-data-in-r/),但我無法適當地過濾數據。
tidydata <- reshape(data,varying =list(paste0("choice",1:3),
paste0("score",1:3)),direction="long",v.names=c("choice","score")) %>%
arrange(id) %>% filter(expert==choice)
我知道專家選擇的列,但輸給choice.1
的最佳解決方案的連接必須返回一個因素的函數(右,領帶,錯),其中排3將返回平局。
編輯: 該數據比較分類器的結果和人類註釋器。分類器有時可以得出相同的結果(2個或更多類的分數相同)。我試圖確定何時分類器是正確的(choice1 == expert),但不是綁定的(我稱之爲RIGHT);綁定(當專家和分類器選擇的分類具有相同的分數,但不是我稱之爲TIE的相同代碼時);否則分類是錯誤的。 謝謝
我有點不明白'第3行會返回領帶'的意思。 – Mons2us
您能製作樣品結果嗎? – akash87