【发布时间】:2020-01-28 15:40:52
【问题描述】:
一个数据框have包含三个变量:
-
from- 字符 - 度量的名称 -
to- 字符 - 另一个度量的名称 -
covariance- numeric - 两个度量之间的协方差
Here's a link 到数据。下面是head(have)的结果:
from to covariance
a_airportscreener a_airportscreener 4.419285714
a_airportscreener e_airportscreener -1.328928571
a_airportscreener g_airportscreener -3.038928571
a_airportscreener p_airportscreener 0.3292857143
a_airportscreener pres_airportscreener 0.6452857143
a_automechanic a_automechanic 2.635535714
a_automechanic e_automechanic -0.3439285714
我想创建一个名为need 的数据框,它在不同的列中记录同一职位的前缀版本之间的协方差。例如,第一行看起来像:
job a_a a_e a_g a_p a_pres e_a e_e e_g e_p e_pres g_a g_e g_g g_p g_pres p_a p_e p_g p_p p_pres pres_a pres_e pres_g pres_p pres_pres
airportscreener 4.419 -1.329 -3.039 0.329 0.645 -1.329 2.333 2.441 -1.015 0.659 -3.039 2.441 14.253 3.070 0.977 0.329 -1.015 3.070 6.505 0.366 0.645 0.659 0.977 0.366 0.697
(我将have 中的值四舍五入以在页面上保留need 的示例,但这不是问题的一部分。)
【问题讨论】:
-
能否请您填写预期输出中的所有值
-
我完成了第一行想要的输出。
标签: r reshape transpose data-manipulation reshape2