Ich habe 2 Datenrahmen, die erste Spalte von einem ist eine Liste (df A), die erste Spalte des anderen enthält Elemente aus der Liste, aber in einigen Fällen Jede Zeile hat mehrere Elemente (df B). Was ich tun möchte, durch wird gehen und neue Zeilen von df A für jedes Element erstellen, tritt das in der ersten Spalte von df B.Erstellen neuer Datenrahmen Zeilen basierend auf einer Spalte aus einem anderen Datenrahmen
DF A
dfA
Index X
1 1 alpha
2 2 beta
3 3 gamma
4 4 delta
DF B
dfB
list X
1 1 4 alpha
2 3 2 1 beta
3 4 1 2 gamma
4 3 delta
Wunsch
dfC
Index x
1 1 alpha
2 4 alpha
3 3 beta
4 2 beta
5 1 beta
6 4 gamma
7 1 gamma
8 2 gamma
9 3 delta
Die eigentlichen Daten ich verwende: DF A
dput(head(allwines))
structure(list(Wine = c("Albariño", "Aligoté", "Amarone", "Arneis",
"Asti Spumante", "Auslese"), Description = c("Spanish white wine grape that makes crisp, refreshing, and light-bodied wines.",
"White wine grape grown in Burgundy making medium-bodied, crisp, dry wines with spicy character.",
"From Italy’s Veneto Region a strong, dry, long- lived red, made from a blend of partially dried red grapes.",
"A light-bodied dry wine the Piedmont Region of Italy", "From the Piedmont Region of Italy, A semidry sparkling wine produced from the Moscato di Canelli grape in the village of Asti",
"German white wine from grapes that are very ripe and thus high in sugar"
)), .Names = c("Wine", "Description"), row.names = c(NA, 6L), class = "data.frame")
DF B
> dput(head(cheesePairing))
structure(list(Wine = c("Cabernet Sauvignon\r\n \r\n \r\n \r\n \r\n \r\n Pinot Noir\r\n \r\n \r\n \r\n \r\n \r\n Sauvignon Blanc\r\n \r\n \r\n \r\n \r\n \r\n Zinfandel",
"Chianti\r\n \r\n \r\n \r\n \r\n \r\n Pinot Noir\r\n \r\n \r\n \r\n \r\n \r\n Sangiovese",
"Chardonnay", "Bardolino\r\n \r\n \r\n \r\n \r\n \r\n Malbec\r\n \r\n \r\n \r\n \r\n \r\n Riesling\r\n \r\n \r\n \r\n \r\n \r\n Rioja\r\n \r\n \r\n \r\n \r\n \r\n Sauvignon Blanc",
"Tempranillo", "Asti Spumante"), Cheese = c("Abbaye De Belloc Cheese",
"Ardrahan cheese", "Asadero cheese", "Asiago cheese", "Azeitao",
"Baby Swiss Cheese"), Suggestions = c("Pair with apples, sliced pears OR a sampling of olives and thin sliced salami. Pass around slices of baguette.",
"Serve with a substantial wheat cracker and apples or grapes.",
"Rajas (blistered chile strips) fresh corn tortillas", "Table water crackers, raw nuts (almond, walnuts)",
"Nutty brown bread, grapes", "Server with dried fruits, whole grain, nutty breads, nuts"
)), .Names = c("Wine", "Cheese", "Suggestions"), row.names = c(NA,
6L), class = "data.frame")
Es wäre hilfreich, wenn Sie Ihre Frage bearbeiten könnten, um Ihre Beispieldaten in ein R-Parse-Format aufzunehmen. Z.B. 'dput (dfA)' und 'dput (dfB)'. –
@CurtF. Ich fügte meine Beispieldaten hinzu, ich war besorgt, dass es zu verwirrend sein könnte, also hatte ich es entfernt und das erfundene Beispiel eingefügt. –
Ich bin mir nicht sicher, was die Verwendung von 'DFA' ist. die Weine in 'DFB' haben eine Menge extra Leerzeichen in ihnen, so können Sie das für Kommas' cheesePairing $ Wine <- gsub ('\\ s {2,}', ',', df $ Wine) 'herausfiltern und verwende nun eine der Antworten in [diese Frage] (http://stackoverflow.com/questions/28285169/split-comma-separated-column-entry-into-rows) oder andere ähnliche – rawr