KosiB
KosiB

Reputation: 1156

How to merge the two rows with multiple columns into one

enter image description here

How to clean the above data in R dataframe to

enter image description here

Upvotes: 0

Views: 209

Answers (1)

Kra.P
Kra.P

Reputation: 15123

You may try using dplyr,

Data

dummy <- data.frame(
  tic = c("FCCY", "FCCY"),
  conm = c("FiveC", "FiveC"),
  Records = c(1,1),
  Fourcent = c(7,NA),
  Fivecent = c(NA,9)
)
   tic  conm Records Fourcent Fivecent
1 FCCY FiveC       1        7       NA
2 FCCY FiveC       1       NA        9

Code

library(dplyr)
dummy %>%
  group_by(tic, conm) %>%
  summarise(across(everything(), ~unique(na.omit(.x))))

  tic   conm  Records Fourcent Fivecent
  <chr> <chr>   <dbl>    <dbl>    <dbl>
1 FCCY  FiveC       1        7        9

Upvotes: 1

Related Questions