有人能帮我修改下面的函数来检查一个数字是否是数字吗?
# handy function that checks if something is numeric
check.numeric <- function(N){
!length(grep("[^[:digit:]]", as.character(N)))
}
check.numeric(3243)
#TRUE
check.numeric("sdds")
#FALSE
check.numeric(3.14)
#FALSE
我希望check.numeric()
在遇到像3.14这样的小数时返回TRUE
。
is.numeric
不够用呢? - joranis.numeric(x)
,其中x
被赋值为x<- NA_real_
,结果为TRUE
。我该如何修复这个问题? - user1313954is.numeric
和is.na
。 - joranNA_real_
的意义在于同时表示NA
和数值型。 - Drew Steen