我有一个数据框(getListOfIds().pipe(
bufferCount(5),
map(arrayOf5Ids => getDataForId(objArray.id).pipe(
map(data => populate(obj, data))
)),
switchMap(arrayOf5Observables => forkJoin(arrayOfObservables)),
)
.subscribe(arrayOf5Items => // do what you want}
),我想将第2列中的数值乘以一个因数而异,该因数取决于“ sub
”列中的“值”。
数据:
domain
代码:
sub <- structure(list(domain = c("Bacteria", "Bacteria", "Bacteria",
"Eukaryota", "Eukaryota", "Eukaryota", "Bacteria", "Bacteria",
"Eukaryota", "Bacteria"), `60781` = c(12471263.2580165, 0, 24942526.516033,
9845734.15106566, 0, 19691468.3021313, 122788742566383, 0, 0,
245577485132767), `60782` = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), `60783` = c(2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L),
`60784` = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), `60785` = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), `60786` = c(5L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L), `60787` = c(2L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 5L), `60759` = c(3L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 8L), `60773` = c(1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), `60774` = c(0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 4L), `60775` = c(2L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 6L), `60776` = c(2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 2L), `60777` = c(4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
4L), `60778` = c(1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 5L),
`60779` = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 4L), `60780` = c(1L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L)), .Names = c("domain",
"60781", "60782", "60783", "60784", "60785", "60786", "60787",
"60759", "60773", "60774", "60775", "60776", "60777", "60778",
"60779", "60780"), row.names = c(4549L, 9581L, 14048L, 17710L,
19822L, 17650L, 15353L, 13170L, 20622L, 157L), class = "data.frame")
Q16S <- structure(list(s = structure(c(10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), .Label = c("60759",
"60773", "60774", "60775", "60776", "60777", "60778", "60779",
"60780", "60781", "60782", "60783", "60784", "60785", "60786",
"60787"), class = "factor"), q = c(12471263.2580165, 9779600.35102098,
4233335.65669403, 4233335.65669403, 5861610.84202048, 3608701.24759829,
1911945.62045948, 5286624.33414104, 23126648.4362759, 4358019.31046983,
8226827.34243214, 4359062.63714278, 2351302.71868581, 5938544.50162295,
2772726.13977936, 7168230.19241166)), .Names = c("s", "q"), row.names = c(10L,
11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L), class = "data.frame")
Q18S <- structure(list(s = structure(c(10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L), .Label = c("60759",
"60773", "60774", "60775", "60776", "60777", "60778", "60779",
"60780", "60781", "60782", "60783", "60784", "60785", "60786",
"60787"), class = "factor"), q = c(9845734.15106566, 7720737.11922709,
3342107.09739003, 3342107.09739003, 4627587.50685827, 2848974.66915655,
1509430.75299433, 4173650.79011135, 18257880.3444283, 3440541.56089723,
6494863.6913938, 3441365.23984957, 1856291.62001511, 4688324.60654444,
2188994.32087844, 5659129.09927236)), .Names = c("s", "q"), row.names = c(10L,
11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L), class = "data.frame")
最终,我想做一个 sub[[2]][sub$domain =="Bacteria"] <- sub[[2]]*Q16S$q[1]
sub[[2]][sub$domain =="Eukaryota"] <- sub[[2]]*Q18S$q[1]
-在第11:16列循环,并根据'for loop
'乘以Q16S或Q18S中指定的不同因子。
domain
但是现在输出中的数字以前是0,例如2则是数百万。...
我要做,但收到一条警告消息,但我无法解释它:
for (i in 1:16){
qdata[[10+i]][qdata$domain =="Bacteria"] <- qdata[[10+i]]*Q16S$q[i]
qdata[[10+i]][qdata$domain =="Eukaryota"] <- qdata[[10+i]]*Q18S$q[i]
}
关于我在做什么错的任何建议?