Merge dataframe based on column in R -
hi have following data frame:
css_week_end_date bv bvg bvh bvg1 bvg2 bvg3 bvg4 bvh1 bvh2 bvh3 bvh4 bvh5 bvg11 bvg12 bvg13 bvg14 bvg15 bvg16 bvg21 bvg22 bvg23 bvg24 bvg25 bvg31 bvg32 bvg34 1 2012-01-13 28.0 28.3 27.7 28.6 28.7 27.3 28.7 29.5 27.2 26.5 27.8 27.5 34.3 30.7 29.8 25.9 25.7 28.0 29.9 33.9 26.2 32.0 24.4 29.3 24.0 26.9 2 2012-01-20 28.8 29.5 28.4 31.8 29.2 28.2 28.9 30.0 27.8 27.4 28.0 28.7 37.9 34.3 33.3 30.7 27.1 31.6 28.6 32.6 29.3 32.8 24.5 31.5 24.0 27.8 3 2012-01-27 28.2 28.6 27.9 30.7 28.4 27.4 28.0 29.7 27.5 26.9 27.4 28.0 34.8 29.3 32.8 29.5 28.3 31.3 26.9 33.2 27.0 31.3 25.4 30.8 23.4 25.9 4 2012-02-03 28.1 28.2 28.1 30.6 27.6 27.0 27.8 30.5 27.5 25.9 27.5 28.9 37.9 29.1 31.7 30.0 26.8 31.9 26.4 32.3 26.6 31.3 23.5 30.5 21.7 26.3 5 2012-02-10 27.9 28.1 27.7 30.5 27.9 27.0 27.5 30.4 26.8 26.2 26.4 28.5 35.9 30.0 30.8 30.5 25.8 32.9 26.1 32.1 26.2 31.4 25.2 30.6 24.1 25.6 6 2012-02-17 26.4 26.8 26.0 30.6 26.8 24.0 26.5 29.1 25.6 24.3 24.8 26.4 36.1 31.5 29.6 30.0 25.5 33.1 25.2 32.6 24.8 30.3 23.1 26.2 20.3 22.5
i want transform data set this:
css_week_end_date patch drive.per.task 13/01/2012 bv 28 20/01/2012 bv 28.8 27/01/2012 bv 28.2 03/02/2012 bv 28.1 10/02/2012 bv 27.9 13/01/2012 bvg 28.3 20/01/2012 bvg 29.5 27/01/2012 bvg 28.6 03/02/2012 bvg 28.2 10/02/2012 bvg 28.1 13/01/2012 bvh 27.7 20/01/2012 bvh 28.4 27/01/2012 bvh 27.9 03/02/2012 bvh 28.1 10/02/2012 bvh 27.7 ...
how in optimal way in r. having copy , paste in excel painful task have many patches shown in example above
if data frame name df, can try this:
library(reshape2) melt(df, id='css_week_end_date', value.name='drive.per.task', variable.name='patch')
if don't have library reshape2, can install this:
install.packages('reshape2')
let me know if helps.
Comments
Post a Comment