I provide a small example of a large data frame I am working >1,000 columns & >200 rows. I would like to make per each repetitive row per column a single row instead of two rows, and at the same time take the average of each value related to the Column # 1 (The columns for average are Col 6-8 and so on).
Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10
A-001 7 40 1 J 3.985645 4.231623 2.36987 9.36545852 8.369663
A-001 7 40 1 J 1.458798 7.652123 1.236985 4.236987 1.22556633
B-002 8 50 0 K 5.00212 8.369562 7.4569852 5.36692 4.6632121
B-002 8 50 0 K 9.02336 1.2120145 3.0014588 8.214569 5.2223698
C-003 10 60 1 L 1.451203 5.321455 8.25963 2.03369878 4.3336988
C-003 10 60 1 L 1.65653 2.369898 8.2136999 7.21458777 5.3366
D-004 3 70 0 M 5.323211 1.147852 7.20014 5.36989 2.36555
D-004 3 70 0 M 4.36969 5.231478 4.23698 3.645478 9.214563
E-005 4 80 1 N 8.123256 9.2356478 5.3696 4.698889 7.366695
E-005 4 80 1 N 7.9632145 0.004555 1.24789 7.3696969 1.23655
Expected Output:
col 1 col 2 col 3 col 4 col 5 col 6
A-001 7 40 1 J 2.49282
B-002 8 50 0 K 7.01274
C-003 10 60 1 L 1.55387
D-004 3 70 0 M 4.84645
E-005 4 80 1 N 8.04324
My apologize in advance for not making it in the proper format Anticipated thanks for any help provided in advance
dd <- structure(list(col1 = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L,
4L, 5L, 5L), .Label = c("A-001", "B-002", "C-003", "D-004", "E-005"
), class = "factor"), col2 = structure(c(1L, 1L, 2L, 2L, 3L,
3L, 4L, 4L, 5L, 5L), .Label = c("7", "8", "10", "3", "4"), class = "factor"),
col3 = c(40L, 40L, 50L, 50L, 60L, 60L, 70L, 70L, 80L, 80L
), col4 = c(1, 1, 0, 0, 1, 1, 0, 0, 1, 1), col5 = c(JL, JL, KL, KL, LL, LL, ML, ML, NL,
NL), col6 = c(3.985645, 1.458798, 5.00212, 9.02336, 1.451203, 1.65653, 5.323211,
4.36969, 8.123256, 7.9632145), col7 = c(4.231623, 7.652123, 8.369562, 1.2120145,
5.321455, 2.369898, 1.147852, 5.231478, 9.2356478, 0.004555), col8 = c(2.36987,
1.236985, 7.4569852, 3.0014588, 8.25963, 8.2136999, 7.20014, 4.23698, 5.3696,
1.24789), col9 = c(9.36545852, 4.236987, 5.36692, 8.214569, 2.03369878, 7.21458777,
5.36989, 3.645478, 4.698889, 7.3696969), col10 = c(8.369663, 1.22556633, 4.6632121,
5.2223698, 4.3336988, 5.3366, 2.36555, 9.214563, 7.366695, 1.23655)), .Names =
c("col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8", "col9", "col10"),
class = "data.frame", row.names = c(NA, -10L))