I am trying to subset a dataframe based on a factor (here, ID). What I would like is to subset based on factor levels starting with a specific character. Here is an example dataframe:
ID = c("100", "100a", "101", "103", "204", "206", "207", "207a", "207b") # ID is a factor
Value = rnorm(9)
df = data.frame(ID, Value)
I would like to end up with two separate dataframes, one with ID starting with "1" and one with ID starting with "2". My dataframe is much longer than the one provided, I can thus not subset based on a list of factor levels. Here it was done with a continuous variable, but I haven't found an example with factors.
Thank you for your help!