I have a big data frame and I want to remove certain rows from it based on first char of a column being a letter or a number. Sample of my data frame looks like a below:
We can use grep
. The regex ^
indicates the beginning of the string. We match numeric element ([0-9]
) at the beginning of the string in the 'y' column using grep
. The output will be numeric index, which we use to subset the rows of the 'abc'.
abc[grep('^[0-9]', abc$y),]
# y z
#1 34TA912 23.12.2015
#4 34CC515 25.12.2015