I have a simple data frame as the following:
v1 <- c(1,2)
v2 <- c(1,3)
v3 <- c(2,1)
df.test <- data.frame(rbind(v1,v2,v3))
colnames(df.test) <- c('from', 'to')
I want to use a for
loop to find & append all rows into a separate vector and then use unique
or some set
function to get the unique vector pair and store them into a new data frame. For now, I have:
c <- c()
for (row in 1:nrow(df.test)) {
from <- df.test[row, "from"]
to <- df.test[row, "to"]
new.row <- c(from, to)
c <- c(c, new.row)
# having trouble storing unique values here...
}
Ideally, after taking only the unique value pairs, the new dataframe should look like this:
Can anyone please help? Thank you!