how to add an observation to an existing column

Hi, i am a very beginnerin Rstudio .
I have this data frame and i found blank observatios in existing column.
I filtered out :
filter(classicrock, Album=="" )
Artist Music Album Year Genre 2022 2021 2020 2019 2018 2017 2016 2015
1 Van Halen Panama 1984 Glam Metal 98 191 84 305 57 125 350 30
2 Van Halen Jump 1984 Pop Rock 82 128 6 126 44 87 201 40
3 Yes Owner of a Lonely Heart 1983 Progressive Pop 79 60 106 304 81 150 143 271

there are 3 blank fields in Album column, i got the names of those albums. How can i add the names of them there with a code chunk?

library(tidyverse)

(incomplete_df <- data.frame(numbers=1:5,
                            letters=c("a",NA,NA,"d",NA),
                            othernums=6:10))

(gapfill_raw <- letters[c(2:3,5)])

(gapfill_contained <- filter(incomplete_df,
                             is.na(letters)))
gapfill_contained$letters <- gapfill_raw
gapfill_contained

(keynames <- setdiff(names(gapfill_contained),"letters"))

(complete_df <- incomplete_df |> rows_patch(gapfill_contained,
                                            by=keynames))
  numbers letters othernums
1       1       a         6
2       2    <NA>         7
3       3    <NA>         8
4       4       d         9
5       5    <NA>        10
  numbers letters othernums
1       1       a         6
2       2       b         7
3       3       c         8
4       4       d         9
5       5       e        10
1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.