[R] Finding unique terms

Robert Baer
Tue, 16 Oct 2018 01:32:17 -0000

> Thank you for any help given

# load data

# Enter dataframe by hand
dat <- structure(list(STUDENT_ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L), .Label = c("AA15285", "AA15286"), class
= "factor"),
 ??? COURSE_CODE = structure(c(1L, 2L, 5L, 6L, 7L, 8L, 2L, 3L,
 ??? 4L, 5L, 6L), .Label = c("BAA1113", "BAA1322",
"BAA2113",
 ??? "BAA2513", "BAA2713", "BAA2921",
"BAA4273", "BAA4513"), class "factor"),
 ??? PO1M = c(155.7, 48.9, 83.2, NA, NA, NA, 48.05, 68.4, 41.65,
 ??? 82.35, NA), PO1T = c(180, 70, 100, NA, NA, NA, 70, 100, 60,
 ??? 100, NA), PO2M = c(NA, NA, NA, 37, NA, NA, NA, NA, NA, NA,
 ??? 41), PO2T = c(NA, NA, NA, 50, NA, NA, NA, NA, NA, NA, 50),
 ??? X = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), X.1 = c(NA,
 ??? NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names =
c("STUDENT_ID",
"COURSE_CODE", "PO1M", "PO1T", "PO2M",
"PO2T", "X", "X.1"), class "data.frame",
row.names = c(NA,
-11L))

# Create sums by student ID

library(dplyr)
dat %>%
 ? group_by(STUDENT_ID) %>%
 ? summarize(sum.PO1M = sum(PO1M, na.rm = TRUE),
 ??????????? sum.PO1T = sum(PO1M, na.rm = TRUE),
 ??????????? sum.PO2M = sum(PO1M, na.rm = TRUE),
 ??????????? sum.PO2T = sum(PO1M, na.rm = TRUE))