I'm trying to expand my data set using R. I have recorded the observations for each sample and calculated percentages based on those observations. I need now to expand each sample to list each possible observation without doing any calculations. Example of myData: Starting data set:
Sample Observation Percent
A Y 50
A N 50
B Y 10
B N 80
B Don't know 10
Desired data set:
Sample Observation Percent
A Y 50
A N 50
A Don't know NA
B Y 10
B N 80
B Don't know 10
So in this case, I would need to expand all of sample A to include the "Don't know" category and fill that in with "NA".
I have tried
myTable <- table(myData)
TableFrame2 <- data.frame(myTable)
Which expands the data set but messes up the Percentage column (?why). I thought I could merge the percentages back, but I need to match that column to the expanded set by both the sample and Observation columns to get an exact match. Any suggestions?