Skip to content

Instantly share code, notes, and snippets.

View lc0's full-sized avatar

Sergii Khomenko lc0

View GitHub Profile
@lc0
lc0 / agecount.R
Created February 5, 2013 00:30
Computing for data analysis. Week4
agecount <- function(age = NULL) {
if (is.null(age)){
stop("age couldn't be NULL")
}
homicides <- readLines("homicides.txt")
r <- regexec("(\\d+) years old", homicides)
m <- regmatches(homicides, r)
causes <- sapply(m, function(x) as.integer(x[2]))
return(length(which(causes==age)))