I am trying to combine two dataframes and with the following code. The problem I'm having is that for rbind it is literally just adding "Hello World" in each column of the last row. What I want to actually do is if i in the column name is "Hello World" add that row to newlist.
I realize more background maybe helpful, but I am really just trying to figure out this error. I am still learning R and any suggestions would be helpful.
MasterList <- function(group1, group) {
first <- data.frame(group1)
second <- data.frame(group)
for (x in first$Name) {
for (y in second$Name) {
if (x != y) {
newlist <- first[first$Name %in% second$Name, ]
}
}
}
for (x in first$Name) {
for (y in second$Name) {
if (x == "Hello World") {
NL <- rbind(newlist, i)
}
}
return(NL)
}
output is
A header | Another header |
---|---|
First | row1 |
Second | row2 |
Hello World | Hello World |
but I want the output to be
A header | Another header |
---|---|
First | row1 |
Second | row2 |
Hello World | row3 |