这是我的问题:如何在此使用tidyverse或base-r函数,以便我得到
判断海报分数
来自
法官海报评分海报评分海报评分......
library(tidyverse)
pn <- paste0("poster_", as.character(1:10))
sn <- paste0("score_", as.character(1:10))
cn <- as.vector(rbind(pn, sn))
df <- read_delim(file = "
j1 4 98 5 95 6 89
j2 1 88 2 79 3 90
j3 1 78 4 88 6 87
j4 2 77 3 87 5 92
j5 4 98 5 95 6 89
j6 1 88 2 79 3 90
j7 1 78 4 88 6 87
j8 2 77 3 87 5 92
j9 1 88 2 88 3 87 4 90 5 91 6 90
j10 1 66 2 56
",
delim = " ",
trim_ws = TRUE,
col_names = c("judge", cn))
我有一个data.table解决方案:
library(data.table)
x <-melt(setDT(as.data.frame(df)),
id.vars = "judge",
measure = patterns("^poster", "^score"),
verbose = TRUE)
x <- x[complete.cases(x)][, c(1, 3, 4)]
names(x) <- c("judge", "poster", "score")