Error: Data source must be a dictionary (dplyr) : <p>Im very new to R and did not find a solution for my problem. I really hope you can help me.</p>

<p>Although there are more columns and observations, my dataframe looks like the following:   </p>

<pre><code>dt &lt;- data.frame(hid = c(1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4),
                     syear = c(2000, 2001, 2003, 2003, 2003, 2000, 2000, 2001, 2001, 2002, 2002),
                     employlvl = c("Full-time", "Part-time", "Part-time", "Unemployed", "Unemployed",
                                    "Full-time", "Full-time", "Full-time", "Unemployed", "Part-time", 
                                    "Full-time"),
                     relhead = c("Head", "Head", "Head", "Partner", "other", "Head", 
                                                  "Partner", "Head", "Partner", "Head", "Partner")) 
</code></pre>

<hr>

<pre><code>| hid | syear |  employlvl  |       relhead         |
|-----|-------|-------------|-----------------------|
|  1  | 2000  |  Full-time  |         Head          |
|  2  | 2001  |  Part-time  |         Head          |
|  2  | 2003  |  Part-time  |         Head          |
|  2  | 2003  |  Unemployed |        Partner        |
|  2  | 2003  |  Unemployed |         other         |
|  4  | 2000  |  Full-time  |         Head          |
|  4  | 2000  |  Full-time  |        Partner        |
|  4  | 2001  |  Full-time  |         Head          |
|  4  | 2001  |  Unemployed |        Partner        |
|  4  | 2002  |  Part-time  |         Head          |
|  4  | 2002  |  Full-time  |        Partner        |
</code></pre>

<p>I would like to create another column which indicates the employmentlevel of the Partner and hope to get the following output:</p>

<pre><code>| hid | syear |  employlvl  |         relhead       |      Partner      |
|-----|-------|-------------|-----------------------|-------------------|
|  1  | 2000  |  Part-time  |         Head          |        NA         |
|  2  | 2001  |  Part-time  |         Head          |        NA         |
|  2  | 2003  |  Part-time  |         Head          |    Unemployed     |
|  2  | 2003  |  Unemployed |       Partner         |        NA         |
|  2  | 2003  |  Unemployed |         other         |        NA         |
|  4  | 2000  |  Full-time  |         Head          |     Full-time     |
|  4  | 2000  |  Full-time  |        Partner        |        NA         |
|  4  | 2001  |  Full-time  |         Head          |    Unemployed     |
|  4  | 2001  |  Unemployed |        Partner        |        NA         |
|  4  | 2002  |  Part-time  |         Head          |     Full-time     |
|  4  | 2002  |  Full-time  |        Partner        |        NA         |
</code></pre>

<p>Currently I am using the following code. (Thanks again user ycw)</p>

<pre><code>library(dplyr)
library(tidyr)

dt2 &lt;- dt %&gt;%
  group_by(hid, syear) %&gt;%
  filter(n() &gt; 1) %&gt;%
  filter(`relhead` != "Child") %&gt;%
  spread(relhead, employlvl) %&gt;%
  mutate(Relation = "Head") %&gt;%
  rename(`Employment Partner` = Partner) %&gt;%
  select(-Head)

dt3 &lt;- dt %&gt;%
  left_join(dt2, by = c("hid", "syear", "relhead" = "Relation"))
</code></pre>

<p>The code works absolutely fine for this small data set. But as soon as I try for my whole data I get the following:</p>

<pre><code>Error: Data source must be a dictionary
</code></pre>

<p>Thank you so much for your help.</p>
