How do I determine the number of significant figures in data in R

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have a large dataset that I m analyzing in R and I m interested in one column or vector of information. Each entry in this vector has a varied number (ranging from 1-5) of significant figures, and I want to subset this vector so I m not seeing data with only one significant digit. What kind of test or function can I use to get R to report the number of significant figures for each entry? I ve looked into the signif() function but that is more for rounding data to a specified number of significant digits, not querying how many sig figs are there.

Example: Suppose I have this vector:
4
28.382
120
82.3
100
30.0003

I want to remove the entries that only have one significant digit. That would be entries 1 (value of 4) and entry 5 (value of 100). I know how to subset data in R, but I don t know how to tell R to "find" all the values with only one significant figure.

Answers

x <- c(4, 28.382, 120, 82.3, 100, 30.0003)
#compare the values with result of signif
#you need to consider floating point precision
keep <- abs(signif(x, 1) - x) > .Machine$double.eps
x[keep]
#[1]  28.3820 120.0000  82.3000  30.0003

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/27767841/how-do-i-determine-the-number-of-significant-figures-in-data-in-r

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils