Hellow i have the following df and pattern
df <- data.frame(class=c(5,8,10,15),student=c("US_NORTH","US_SOUTH","UK_EAST","BRAZIL"))
pattern <- c("US","UK")
I would identify US and UK students without using a loop.
The US student should be together in a list and the UK students in sublist as shown below:
target <- list(US=c(5,8),UK=10)
I know a loop could be used but i would like to have a vector solution.
Thanks