Is it possible to extract/subset a dataframe by indicating only a chunk of the wanted entries-string?
The filter criteria is stored in an factor vector. But there are only the first three digits indicated. This should determine to subset all entries of the dataframe starting with them.
Example:
# Input dataframe
data <- read.table(header=T, text='
ID sex size
0120010 M 7
0120020 F 6
0121031 F 9
0130010 M 11
0130020 M 11
0130030 F 14
0130040 M 11
0150030 F 11
0150110 F 12
0180030 F 9
1150110 F 12
9180030 F 9
'colClasses =c("character", "factor", "integer"))
# Input vector/factor with the ID chunk, containing only the fist three digits
# of the targeted entries in data$ID
IDfilter <- c("012", "015", "115")
# My try/idea which sadly is not working - PLEASE HELP HERE
subset <- data[ID %in% paste(IDfilter, "?.", sep=""),]
# Expected subset
> subset
ID sex size
1 0120010 M 7
2 0120020 F 6
3 0121031 F 9
4 0150030 F 11
5 0150110 F 12
6 1150110 F 12
Thank you! :)