Skip to content
Prev 307939 / 398525 Next

transforming a .csv file column names as per a particular column rows using R code

You can also get the Tool column repeated by tricking reshape() into letting
you use Tool in the v.name and idvar arguments:
+ "Tool,Step_Number,Data1,Data2
+ A,1,0,1
+ A,2,3,2
+ A,3,2,3
+ B,1,3,2
+ B,2,1,2
+ B,3,3,2
+ ")
# Repeat the first column. R will append .1 to the second copy.
timevar="Step_Number", idvar="Tool.1", direction="wide")
Tool_1 Data1_1 Data2_1 Tool_2 Data1_2 Data2_2 Tool_3 Data1_3 Data2_3
1      A       0       1      A       3       2      A       2       3
2      B       3       2      B       1       2      B       3       2

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352