R how to remove rows in a data frame based on the first character of a column

前端 未结 1 612
孤独总比滥情好
孤独总比滥情好 2020-12-07 05:48

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:

相关标签:
1条回答
  • 2020-12-07 06:29

    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
    
    0 讨论(0)
提交回复
热议问题