Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

dplyr syntax in R - full join

$
0
0

I'm pretty sure I'm going to embarrass myself here with my lack of knowledge of query languages, etc. Hopefully this is a simple query.

If I have two dataframes in R, I want to create what I thought was a "full join", which is a table containing one record for each combination of records in the first and the second frames.

So if I set this up (as a very simple example):

df_1 <- data.frame(
  Col_1 = c("Alan", "Bob")
)

df_2 <- data.frame(
  Year = c(2005, 2006, 2007, 2008)
)

I would like to create a data frame that looks like:

Col_1   Col_2
=====  =====
Alan    2005
Alan    2006
Alan    2007
Alan    2008
Bob     2005
Bob     2006
Bob     2007
Bob     2008

I hoped I could do this using:

df_output <- full_join(df_1, df_2)

but I get an error message

Error: by required, because the data sources have no common variables

which I understand...but i don't know how to get to where I'm trying to go.

Can anyone help please? Thanks Alan


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>