Dear all, I have a dataset as below:
id code1 code2 p 1 4 8 0.1 1 5 7 0.9 2 1 8 0.4 2 6 2 0.2 2 4 3 0.6 3 5 6 0.7 3 7 5 0.9 I just want to rewrite it as this (vertical to horizontal): id var1 var2 var3 var4 var5 var6 var7 var8 1 0 0 0 0.1 0.9 0 0.9 0.1 2 0.4 0.2 0.6 0.6 0 0.2 0 0.4 3 0 0 0 0 0.8 0.7 0.9 0 For the third subject, there are two values being equal to 5 in code1 and code2, but different values in p: 0.7 and 0.9, so I assigned their average 0.8 in var5. Does anybody can help me to handle this? Many thanks for your consideration and time. Legen -- View this message in context: http://old.nabble.com/Data-transformation-tp26291568p26291568.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.