I have a data set of a group of college with various names such as "x college" "x university" and "x community college" and need to group them by their classification of college, community college, or university.
And then organizing them by state. There are 5 rows: Name, Location, two types of tuition, and private or public.
I have tried this: typeSchool <- c("College", "University", "Community College") filter(tibble, str_detect(words, paste(typeSchool)))
But it has not worked. Looking for suggestions.
Should I try mutating variables and adding a separate variable for each classification and then group_by(classification)?
Sample Rows:
Also would it be possible to use a form of grep for this?
structure(list(Name = structure(c(5L, 1L, 6L, 4L, 3L, 2L), .Label = c("Bard College",
"Brown University", "Connecticut College", "Dartmouth College", "Landmark College", "St. John's College"), class = "factor"), Location = structure(c(5L, 1L, 6L, 2L, 3L, 4L), .Label = c("ANNANDALE-ON-HUDSON, NY", "HANOVER, NH", "NEW LONDON, CT", "PROVIDENCE, RI", "PUTNEY, VT", "SANTA FE, NM"), class = "factor"), In.State.Tuition = c(50080L, 49906L, 49644L, 49506L, 49350L, 49346L), Out.of.State.Tuition = c(50080L, 49906L, 49644L, 49506L, 49350L, 49346L), Type = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "Private", class = "factor")), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))
Name
is one column that have the 'College' substring. So, insted of 'word', should change it to 'Name' – akrun