Search code examples
rmultiple-columnsrowstranspose

transfer rows to columns in r


I'm already struggling for two days just to transfer a selection of rows to a new column in r. My dataset looks like this: My starting point is "big_data". This is the data I have in a dataframe. The output should be "blub" in a dataframe. In blub the cdolumns should have names representing the value of i. data mutatie

Finally I came up with:

code I tried so many things already, but he doesn't want to give me the output as in the picture above. Is there someone who can help me whit this?


Solution

  • You can use pivot_wider, from the tidyr package. For example:

    library(tidyr)
    
    blub <- pivot_wider(
      data = big_data,
      id_cols = id,
      names_from = i,
      values_from = Outstanding_LCY,
      names_glue = "kolom{.value}"
    )