Skip to content

Instantly share code, notes, and snippets.

@patperu
Created January 19, 2012 10:20
Show Gist options
  • Save patperu/1639277 to your computer and use it in GitHub Desktop.
Save patperu/1639277 to your computer and use it in GitHub Desktop.
setwd("D:/a")
options(stringsAsFactors = FALSE)
TrimWhiteSpaces <- function(x) {
out <- sub("^[[:space:]]*(.*?)[[:space:]]*$", "\\1", x, perl=TRUE)
}
df <- read.csv("Authors.csv", skip = 1, nrows = 201)[, -1]
df1 <- strsplit(df, ";")
# (see http://stackoverflow.com/questions/5531471/combining-unequal-columns-in-r)
# but this is not necessary, better to use "unlist"
# df2 <- sapply(df1,'[', seq(max(sapply(df1,length))))
# see G. Valbusa r-rante
df2 <- unlist(df1)
df2 <- TrimWhiteSpaces(df2)
df2 <- toupper(df2)
df3 <- as.data.frame(table(df2))
df3 <- df3[order(df3$Freq), ]
df3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment