Ich kann ein Duplikat ab sofort nicht finden.multiplizieren Sie zwei data.tables, behalten Sie alle Möglichkeiten
Mein Problem ist folgendes:
Ich habe zwei data.tables
. Eins mit zwei Spalten (featurea, count), ein weiteres mit drei Spalten (featureb, featurec, count). Ich möchte multiplizieren (?), Damit ich ein neues data.table
mit allen Möglichkeiten habe. Der Trick ist, dass diese Funktionen nicht übereinstimmen, so dass merge
Lösungen nicht den Trick machen können.
MRE wie folgt:
# two columns
DT1 <- data.table(featurea =c("type1","type2"), count = c(2,3))
# featurea count
#1: type1 2
#2: type2 3
#three columns
DT2 <- data.table(origin =c("house","park","park"), color =c("red","blue","red"),count =c(2,1,2))
# origin color count
#1: house red 2
#2: park blue 1
#3: park red 2
Mein erwartetes Ergebnis, in diesem Fall ist ein data.table
wie folgt:
> DT3
origin color featurea total
1: house red type1 4
2: house red type2 6
3: park blue type1 2
4: park blue type2 3
5: park red type1 4
6: park red type2 6
Würde 'DT2 [(featurea = DT1 [[ "featurea"]], count = zählen * DT1 [[“ Graf "]]), durch =. (Herkunft, Farbe)]' ausreichend effizient sein? – Roland
@Roland scheint so, und das klingt die beste Antwort, also sollten Sie es als solche posten – Tensibai