ZeekDSA ZeekDSA - 1 year ago 99
R Question

crossJoining two data frames without repeating values

I have two dataframes

DataFrame1 <- data.frame(StudentId = c(1:20), Subject = c(rep("Algebra", 4), rep("Geometry", 4), rep("English", 4), rep("Zoology", 4), rep("Botany", 4)), CGPA = c(random::randomNumbers(20, 70, 100, 1)), Country = c(rep("USA", 4), rep("UK", 4), rep("Germany", 4), rep("France", 4), rep("Japan", 4)))


and

DataFrame2 <- data.frame(StudentId = c(1:10), State = c(rep("NYC", 2), rep("Illinois", 2), rep("Texas", 2), rep("Virginia", 2), rep("Florida", 2)), Age = c(random::randomNumbers(10, 16, 20, 1)), Gender = c(rep("Male", 3), rep("Female", 3), rep("Male", 2), rep("Female", 2)))


I can merge the above two using inner join as

merge(DataFrame1, DataFrame2)


How to merge as cross Joining two data frames without repeating values?

Answer Source

Try this for cross join..

knitr::kable(merge(x = DataFrame1, y = DataFrame2, by = NULL))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download