w*******n 发帖数: 469 | 1 【 以下文字转载自 DataSciences 讨论区 】
发信人: wwwscopin (四目丁), 信区: DataSciences
标 题: Ask help for R data restructure, Thanks!!!
发信站: BBS 未名空间站 (Mon Jul 6 12:58:54 2015, 美东)
Given the data like:
ID comp1 Num1 comp2 Num2 comp3 Num3
1 A 2 A 2 D NA
2 B 2 C NA F NA
3 C 2 E NA G NA
4 A 2 D NA H NA
5 B 1 K 1 A 1
6 C 1 B 1 C 1
7 A 2 D 2 B NA
8 B 2 C NA A NA
Want a data like:
ID comp Num
1 A 2
2 B 2
3 C 2
4 A 2
5 B 1
6 C 1
7 A 2
8 B 2
1 A 2
2 C NA
3 E NA
4 D NA
5 K 1
6 B 1
7 D 2
8 C NA
1 D NA
2 F NA
3 G NA
4 H NA
5 A 1
6 C 1
7 B NA
8 A NA | s*********a 发帖数: 2623 | 2 典型的multivariate转univariate。sas里面可以用transpose+merge做 | w*******n 发帖数: 469 | 3 need R code, something like cast, melt, reshape ... |
|