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

Creating column that lists distinct observations

$
0
0

I have a data frame of observations that looks like this (showing course numbers of college classes offered each term). The columns are very long and of varying lengths

  spring   summer   fall
   4a       5b       5c
   4a       9c       11b
   7c       5b       8a 
   ...      ...      ...

I want to reformat it to make it look like this. First, I want to create a column, "Course_Names", that shows all names of distinct course offerings possible. Then, I want to count the number of sections of each course offered each semester.

   Course_Names   spring   summer   fall
   4a             2        0        0
   5b             0        2        0
   5c             0        0        1
   7c             1        0        0
   8a             1        0        1
   9c             0        1        0
   11b            0        0        1        

Any advice or links to relevant posts would be very much appreciated! Thank you!


Viewing all articles
Browse latest Browse all 205330

Trending Articles



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