Let's say I have a dataframe:
df <- data.frame(group = c('A','A','A','B','B','B'),
time = c(1,2,4,1,2,3),
data = c(5,6,7,8,9,10))
What I want to do is insert data into the data frame where it was missing in the sequence. So in the above example, I'm missing data for time
= 3 for group A, and time
= 4 for Group B. I would essentially want to put 0's in the place of the data
column.
How would I go about adding these additional rows?
The goal would be:
df <- data.frame(group = c('A','A','A','A','B','B','B','B'),
time = c(1,2,3,4,1,2,3,4),
data = c(5,6,0,7,8,9,10,0))
My real data is a couple thousand data points, so manually doing so isn't possible.
See Question&Answers more detail:
os