我想知道有没有一种方法可以宽格式我的long_data
,以达到我的desired_output
以下?
我试了pivot_wider(long_data, id_cols= -c(class, sub, order),names_from= DV, values_from= score)
次,但没有成功.
library(tidyverse)
m="
class sub order time DV score task_type
1 1 s-c 1 ac 1 simple
1 1 s-c 1 bc 2 simple
1 1 s-c 2 ac 3 complex
1 1 s-c 2 bc 4 complex
"
long_data = read.table(text = m, header = TRUE)
desired_output =
"
class sub order DV_ac_T1 DV_ac_T2 DV_bc_T1 DV_bc_T2 task_type_T1 task_type_T2
1 1 s-c 1 3 2 4 simple complex
"