Formatting of Data Frames in R

I have a data.frame with the following structure:

enter image description here

What I need is that in case that a value in the first column occures more than once, all corresponding entries in column V18 are concluded in one cell. I applied the folling code.

p <- function(v) {
  Reduce(f=paste0, x = v)
}

Data %>% 
    group_by(V1) %>% 
    summarise(test = p(as.character(V18))) %>%
    merge(., M_TEST, by = 'V1') %>%
    select(V1, V18, test)

It gives:

enter image description here

What I need is that instead of 4344, it is {43,44}. How can I do this?

Thank you really much for your help!

Sincerely



Read more here: https://stackoverflow.com/questions/68459734/formatting-of-data-frames-in-r

Content Attribution

This content was originally published by A321 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: