Last active
August 29, 2015 14:24
-
-
Save retrography/250bca72707cab10bef7 to your computer and use it in GitHub Desktop.
GROUP BY for strings in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env Rscript | |
| lics<-read.csv("~/Temp/csvdb/license-union-norownum.csv", header = TRUE, sep = ",", stringsAsFactors = FALSE) | |
| # Using dplyr | |
| licsgr<-dplyr::group_by(lics, gem) | |
| licsgrsum<-summarise(licsgr, list(license)) | |
| colnames(licsgrsum)<-c("gem", "licenses") | |
| # Using sqlf | |
| licsgrsum2<-sqldf('select gem, group_concat(license) as licenses from lics group by gem') | |
| # We can't write licsgrsum to file because it contains lists | |
| write.csv(licsgrsum2, "~/Temp/csvdb/ri.csv", row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment