I'm new to R and have scoured the site to find a solution - I've found lots of similar, but slightly different questions. I'm stumped.
I have a dataset in this structure:
SURVEY_ID CHILD_NAME CHILD_AGE
Survey1 Billy 4
Survey2 Claude 12
Survey2 Maude 6
Survey2 Constance 3
Survey3 George 22
Survey4 Marjoram 14
Survey4 LeBron 37
I'm trying to pivot the data wider so that there's a) only one unique SURVEY_ID per row, and, critically, b) a new column for second, third, etc. children for surveys with more than one child.
So the result would look like:
SURVEY_ID CHILD_NAME1 CHILD_NAME2 CHILD_NAME3 CHILD_AGE1 CHILD_AGE2 CHILD_AGE3
Survey1 Billy 4
Survey2 Claude Maude Constance 12 6 3
Survey3 George 22
Survey4 Marjoram Lebron 14 37
The actual data has thousands of surveys and the number of "child names" and "child ages" could be as high as 10. It's the issue of creating the new columns not from existing value names and only where there are multiple children that has me perplexed.