99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2018-11-07 閱讀量: 1026
關于數(shù)據(jù)轉換的問題

屏幕快照 2018-11-05 下午3.22.12.png

如上圖所示,

想讓同一個sub條件下,SD==1 條件下的 rating_indif2 減去 SD==0 條件下的rating_indif2,

這樣,每一個sub,計算出一個差值。

另外需要注意,數(shù)據(jù)中SD==1 和SD==0的條件并不一定是固定的前后順序

能不能不使用循環(huán)就能實現(xiàn)計算?

可以如下參考辦法:

df <- data.frame(sub=rep(26:28, each=2),

? ?? ?? ?? ?? ???sd=rep(c(0,1), times=3),

? ?? ?? ?? ?? ???rating_indif=rnorm(6))

subb <- df$sub %>% unique()

noforloop <- function(subb) {

??sub_temp <- df[df$sub==subb,]

??dif_temp <- sub_temp[sub_tempsd==1,"ratingindif"]?subtemp[subtempsd==0, "rating_indif"]

??return(c(subb,dif_temp))

}

your_dif <- lapply(subb, noforloop) %>% unlist %>% matrix(nrow=length(subb), byrow=T) %>%

??as.data.frame %>% `names<-`(c("sub", "diff"))

0.0000
4
關注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子