I wanted to create a new table OR dataframe from an existing dataframe.
My original dataframe looks like the below:
| fruit | col1 | col2 | col3 |
|---|---|---|---|
| apple | 1 | 3 | 2 |
| banana | 4 | 7 | 3 |
| lime | 8 | 10 | 5 |
| orange | 2 | 6 | 8 |
| grape | 7 | 5 | 10 |
I would like it to look like this:
| id | fruit |
|---|---|
| 1 | apple |
| 2 | apple |
| 2 | apple |
| 3 | apple |
| 3 | banana |
| 4 | banana |
| 5 | lime |
| 5 | grape |
| ... | ... |
I know how to rename columns so renaming to id is fine. I just don't know how to pull the data from the dataframe to create a new table as I am fairly new to R.
Any help would be appreciated!