这个问题已经有答案了:
Reshape large dataset with multiple columns from wide to long(7个回答)
Reshaping multiple sets of measurement columns (wide format) into single columns (long format)(8个回答)
Data frame from wide to long with multiple variables and ids R [duplicate](4个回答)
Wide to Long format with multiple variables? [duplicate](1个回答)
17天前关闭
这是我的数据
STUDENT CLASS TIME_1 TIME_2 math1 math2 hist1 hist2
1 90 119 106 4 6 3 10
2 8 115 4 7 2
3 3 74 112 5 7 8 10
字符串
我想把这个文件从宽到长,
STUDENT CLASS TIME math hist
1 90 119 4 3
1 90 106 6 10
2 8 4 2
2 8 115 7
3 3 74 5 8
3 3 112 7 10
型
我尽力了,
melt(setDT(DATA), measure = patterns("TIME_", "math", "hist"), variable.name = 'var', value.name = c('TIME_', 'math', 'hist')
型
没有成功
1条答案
按热度按时间k97glaaz1#
您可以使用
tidyr::pivot_longer
尝试以下操作。将names_to
中的第二个参数设置为NA
将删除不需要的列:字符串
输出
型
数据
型