PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 10, 2022

[FIXED] How to check if the value is numeric?

 August 10, 2022     decimal, numeric, r, regex     No comments   

Issue

Can someone help me modify the function below to check if a number is numeric?

# 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

I want check.numeric() to return TRUE when it's a decimal like 3.14.


Solution

Sounds like you want a function like this:

f <- function(x) is.numeric(x) & !is.na(x)


Answered By - joran
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing