Test for numeric elements in a character string

前端 未结 6 2058
我在风中等你
我在风中等你 2020-12-05 01:38

I want to test a character string and see which elements could actually be numeric. I can use regex to test for integer successful but am looking to see which elements have

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 02:04

    Avoid re-inventing the wheel with check.numeric() from package varhandle.

    The function accepts the following arguments:

    v The character vector or factor vector. (Mandatory)

    na.rm logical. Should the function ignore NA? Default value is FLASE since NA can be converted to numeric. (Optional)

    only.integer logical. Only check for integers and do not accept floating point. Default value is FALSE. (Optional)

    exceptions A character vector containing the strings that should be considered as valid to be converted to numeric. (Optional)

    ignore.whitespace logical. Ignore leading and tailing whitespace characters before assessing if the vector can be converted to numeric. Default value is TRUE. (Optional)

提交回复
热议问题