0

这是我的数据集

# A tibble: 5 × 5
     id    t1    t2    t3    t4
  <dbl> <dbl> <dbl> <dbl> <dbl>
1     1   4.4   4     3.2   4.8
2     2   3.8   3.8   3.8   4.2
3     3   3.6   3.4   3.2   2.2
4     4   2     2.2   2.2   2.2
5     5   3     2.4   2.8   3.2

我想运行此代码以将列 t1~t4 收集为长格式。将 id 和 task 变量转换为因子(或分组)变量。我运行了以下代码:

df <- df >%>
  gather(key = "task", value = "motivation", t1, t2, t3, t4) >%>
  convert_as_factor(id, task)

但是,我收到意外错误:

Error: unexpected input in "df <- df >%>"
>   gather(key = "task", value = "motivation", t1, t2, t3, t4) >%>
Error: unexpected input in "  gather(key = "task", value = "motivation", t1, t2, t3, t4) >%>"
>   convert_as_factor(id, task)
Error in UseMethod("tbl_vars") : 
  no applicable method for 'tbl_vars' applied to an object of class "function"

我做错了什么,我该怎么做才能解决?

4

0 回答 0