R: Adding NAs into Data Frame
I have a data frame like so: Name Position Value a 1 0.2 a 3 0.4 a 4 0.3 b 1 0.5 b 2 0.4 b 5 0.3 c 2 0.3 c 3 0.4 c 5 0.1 d 1 0.2 d 2 0.4 d 3 0.5 I want to make it so that Position always go from 1 to 5 for each Name and fill in NAs into Value like so: Name Position Value a 1 0.2 a 2 NA a 3 0.4 a 4 0.3 a 5 NA b 1 0.5 b 2 0.4 b 3 NA b 4 NA b 5 0.3 c 1 NA c 2 0.3 c 3 0.4 c 4 NA c 5 0.1 d 1 0.2 d 2 0.4 d 3 0.5 d 4 NA d 5 NA Is there a way to do it without creating a dummy data frame with the first 2 columns then doing some sort of outer join with merge? Thanks. You can use the reshape2 package: #