R 跨行匹配成对评级的数据
我有一个数据框架,其中有对个人,他们分别给自己(1,0)和伴侣(1,0)打分 什么是一种聪明的方式来获得其他人的评分?我想这正是你想要的:R 跨行匹配成对评级的数据,r,R,我有一个数据框架,其中有对个人,他们分别给自己(1,0)和伴侣(1,0)打分 什么是一种聪明的方式来获得其他人的评分?我想这正是你想要的: library(dplyr) want <- have %>% group_by(group) %>% mutate(ratedByOther = rev(rateOther)) group person rateSelf rateOther ratedByOther <dbl> <dbl>
library(dplyr)
want <- have %>%
group_by(group) %>%
mutate(ratedByOther = rev(rateOther))
group person rateSelf rateOther ratedByOther
<dbl> <dbl> <dbl> <dbl> <dbl>
1 1 1 1 1 1
2 1 2 0 1 1
3 2 1 1 1 0
4 2 2 0 0 1
5 3 1 1 0 0
6 3 2 0 0 0
库(dplyr)
想要%
分组依据(分组)%>%
变异(ratedByOther=rev(rateOther))
团体人员评分自己评分其他评分其他人评分其他人
1 1 1 1 1 1
2 1 2 0 1 1
3 2 1 1 1 0
4 2 2 0 0 1
5 3 1 1 0 0
6 3 2 0 0 0
我们可以使用数据表
library(data.table)
setDT(have)[, ratedByOther := rev(rateOther), group]
我们不清楚从另一方获得ratedByOther
的逻辑,假设我是group
2中的person
1,而你是group
2中的person
2。我给自己评分(有[3,3]==1
),给你评分(有[3,4]==1
)。我想比较一下我对自己的评价(1)和你对我的评价(have[4,4]==0
)。我需要得到您对我所在行的评分。让$rateByOtherrev()
来拯救我。美好的
library(dplyr)
want <- have %>%
group_by(group) %>%
mutate(ratedByOther = rev(rateOther))
group person rateSelf rateOther ratedByOther
<dbl> <dbl> <dbl> <dbl> <dbl>
1 1 1 1 1 1
2 1 2 0 1 1
3 2 1 1 1 0
4 2 2 0 0 1
5 3 1 1 0 0
6 3 2 0 0 0
library(data.table)
setDT(have)[, ratedByOther := rev(rateOther), group]