Let us say I have a data.table
col1 col2 col3
a 123 1
a 433 2
a 322 3
b 43 1
b 4333 2
c 43 1
In the above table each category of col1
should have 3 rows. But only category a
has 3 rows. So I want to insert blank rows with NAs for missing cases of other categories of col1
. Output will look like
col1 col2 col3
a 123 1
a 433 2
a 322 3
b 43 1
b 4333 2
b NA 3
c 43 1
c NA 2
c NA 3
How do I achieve it with just one call of a function?