Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 350
pocketlizard Avatar asked Jan 04 '15 16:01

pocketlizard


People also ask

How do you specify the number of significant figures in R?

signif() function in R Language is used to round to the specified number of significant digits.

How do you determine the number of significant figures in your data?

Use the least number of significant figures past the decimal point when adding or subtracting numbers. For example, the answer to 123.45 + 543.2 would have 1 significant figure past the decimal point.

How many significant figures are there in 30100?

In 30100 , there are three significant figures .


1 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
like image 97
Roland Avatar answered Sep 21 '22 11:09

Roland