I am sure there is an answer to this, but I can't find it. I have attempted several solutions using several R functions including reshape, gather, and pivot_longer. My problem is that the data comes from a spreadsheet that has multiple columns. I will attempt to represent a sample of the spreadsheet:
| FullName | SOCW725 | SOCW748 | SOCW799 | Average | SOCW725 | SOCW752 | SOCW782 | Average | SOCW725 | SOCW748 | SOCW752 | Average |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Beavis B | 3.5 | 3.22 | 2.56 | 3.07 | 2.33 | 3.33 | 4.2 | 3.5 | 3.33 | 3.23 | No Data | 3.00 |
| El Guapo | 3.25 | 3.02 | 2.75 | 3.18 | 3.33 | 4.33 | 4.15 | 2.25 | 2.67 | 3.42 | 4 | 2.44 |
The actual data file is much wider. Each set of three courses (e.g., SOCW725, SOCW748, SOCW799) represents a competency and there are nine competencies. I left those off the table as I believe I can insert those into a dataframe once I figure this out (I hope). So, I am trying to pivot_longer into three columns (will be 4 when the CompetencyID is added). The columns are: Name, Course, and Rating. I do not need the average as I can recalculate that. Following is an example of the code I am using:
d1 <- pivot_longer(my_data,
cols = !1,
names_to = "Course",
values_to = "Ratings",
)
This works, but the repeating rownames (i.e., Course names) have a . followed by a number (e.g., SOCW725.1, SOCW725.2, etc.). I understand why, but I don't know how to get rid of it. I can probably figure out how to edit the .#'s out of the result, but wanted to find a faster way with dplyr::pivot_table.
Thank you in advance.