I have a data frame that looks like this:
line = c(1, 2, NA, 4 ,5, NA, 7)
group = c("1.0 Group A", "2.0 Group B", "3.0 Group C", "4.0 Group D", "5.0 Group E", "6.0 Group F", "7.0 Group G")
df <- data.frame(line, group)
view(df)
line group
1 1 1.0 Group A
2 2 2.0 Group B
3 NA 3.0 Group C
4 4 4.0 Group D
5 5 5.0 Group E
6 NA 6.0 Group F
7 7 7.0 Group G
What I want to do is to find all the NA value in the "line" column and place a row underneath that row in "group" column saying "Not Applicable". So that the new data frame should look like:
view(df)
line group
1 1 1.0 Group A
2 2 2.0 Group B
3 NA 3.0 Group C
4 NA Not Applicable
5 4 4.0 Group D
6 5 5.0 Group E
7 NA 6.0 Group F
8 NA Not Applicable
9 7 7.0 Group G
I am thinking about using an ifelse statement or using case_when from dplyr. But I don't know how to work it out. Does anyone have any suggestion?
Thank you!