0

I have a data frame with only two columns. The first column is a bunch of numeric values and the second column is numbers 1-6 (essentially six different classes). I want to convert the data frame into where there are six columns each with their corresponding values. the column headers should be labeled 1-6. How do I do this in R? Should I use split, dplyr or is there another way?

dataframe looks something like this:

prob class
 37.  1.  
 23.  5        
 23   5              
 76.  6

and I want something like this:

`1 2 3. 4. 5. 6

      1. 25 23 76 `
  • 1
    This is a job for something like `tidyr`'s `pivot_wider`. – hmhensen Sep 29 '20 at 01:51
  • 1
    Have you tried solution posted in this thread? https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format – Ronak Shah Sep 29 '20 at 01:58
  • yes i tried that thread and nothing worked – user14262341 Sep 29 '20 at 02:12
  • 1
    Can you add data in a reproducible format? something which we can copy/paste into R and use. Read about how to give a [reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Sep 29 '20 at 02:15
  • Does this answer your question? [How to reshape data from long to wide format](https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format) – Michael Roswell May 17 '23 at 16:16

0 Answers0