I'm new to functions and just discovered split.
I have a list of dataframes from the split function. For each dataframe I would like to count the number of a specific regular expression and dump the overall count in a vector (which I then intend to add to a matrix for all the dataframes).
Although its easy to create the counts, I don't know how to then translate this into a function that will do the same thing for all the dataframes in the list:
Here is my attempt so far
Error in x$Dx : $ operator is invlaid for atomic vectors
we could do something like this:
list <- split(mtcars, mtcars$cyl) sapply(list, function(x) sum(grepl("2", x$carb)))
we would get a named vector as output:
4 6 8 6 0 4