Novice to R here. I am looking to do the following:
I have a dataset, let's call it dataset1, and I a looking to make a new dataframe (dataset2). In dataset1 are peoples' names and then the states that they are in (thus, there are duplicate states, but no duplicate combo of names/states). There are no more than 3 people listed per state. In dataset2, I am looking to create new columns named person1, person2, person3 associated with each state (i.e: each state only has one row). So, if Alice, Bob, and Cathy are from Alabama, and then Dave and Edwin are from Alaska, there should be two rows: one for Alabama, one for Alaska, and then person1....person3 will have their names in it (and the last column, p3, for Alaska will be empty).
I am looking at trying to store state name as a dummy variable, and then using an if statement to sort through the rows of dataset1 and then appending the dataset as needed. Something tells me, though, there is a more concise way to do this as opposed to using for/if statements.
Any help?