Hello i have a dataFrame with 15167 rows like this:
> head(datExpr)
F02234_L1_S1_L001 F02235_L1_S2_L001
ENSG00000182199 1546 1710
ENSG00000157870 3491 2951
ENSG00000077092 35 22
ENSG00000047936 49 12
ENSG00000156282 0 0
ENSG00000183856 265 365
F02236_L1_S3_L001 F02237_L1_S4_L001
ENSG00000182199 3530 3582
ENSG00000157870 2372 2360
ENSG00000077092 111 34
ENSG00000047936 43 6
ENSG00000156282 0 0
ENSG00000183856 768 1489
and a list with 15167 elements like this:
> distances
[[1]]
end_position
1 12883
2 100722
3 119629
4 57174
5 78317
6 453372
7 21772
8 30102
9 116734
..........
I want to divide all in the dataframe by equivalent values of my list. For example 1546/12883,1710/12883, 3530/12883 ... and 3491/100722, 2951/100722...
How can i do that with R?
CodePudding user response:
We could directly divide the list element after extracting as it gets recycled
datExpr/distances[[1]]$end_position
-output
F02234_L1_S1_L001 F02235_L1_S2_L001 F02236_L1_S3_L001 F02237_L1_S4_L001
ENSG00000182199 0.1200031049 0.1327330591 0.2740045021 0.2780408290
ENSG00000157870 0.0346597566 0.0292984651 0.0235499692 0.0234308294
ENSG00000077092 0.0002925712 0.0001839019 0.0009278687 0.0002842120
ENSG00000047936 0.0008570329 0.0002098856 0.0007520901 0.0001049428
ENSG00000156282 0.0000000000 0.0000000000 0.0000000000 0.0000000000
ENSG00000183856 0.0005845090 0.0008050784 0.0016939732 0.0032842787
data
datExpr <- structure(list(F02234_L1_S1_L001 = c(1546L, 3491L, 35L, 49L,
0L, 265L), F02235_L1_S2_L001 = c(1710L, 2951L, 22L, 12L, 0L,
365L), F02236_L1_S3_L001 = c(3530L, 2372L, 111L, 43L, 0L, 768L
), F02237_L1_S4_L001 = c(3582L, 2360L, 34L, 6L, 0L, 1489L)), class = "data.frame", row.names = c("ENSG00000182199",
"ENSG00000157870", "ENSG00000077092", "ENSG00000047936", "ENSG00000156282",
"ENSG00000183856"))
distances <- list(structure(list(end_position = c(12883L, 100722L, 119629L,
57174L, 78317L, 453372L)), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6")))