You can use the pivot_longer function from the tidyr package to transform a wide dataframe to a long dataframe in R. Here is an example:
main.r469 chars25 lines
In this example, the pivot_longer function transforms the dataframe df into a long format by melting all columns except the id column. The resulting dataframe df_long will have one column for the variable names (variable) and one column for the corresponding values (value).
The output will look like this:
main.r442 chars19 lines
This shows that the original 5 columns (column1 to column5) have been transformed into a single column variable with the corresponding values in the value column.
gistlibby LogSnag