Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205491

R - Using column indexing in gather function

$
0
0

I'm trying to use the gather function to combine multiple rows and lengthen my wide data. Example data below:

enter image description here

Ideally, I want the data to look like the below table so I can summarize info about the books: enter image description here

When I try to use column indexing in the gather function...

data_clean <- gather(data, Book_Num, Book, data[c(2,4,6,8)]

I get the following error: "Error: data[c(2,4,6,8)] must evaluate to column positions or names, not a list"

Anyone know what that error means and/or if there is a better way to handle this task?


Viewing all articles
Browse latest Browse all 205491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>