Interpolation of decimal numbers in R

1

Hello! I have a sequence of broken numbers (eg, 191.1, 191.48, 191.87) and wanted to turn those numbers into integers (all 191. turn 191). Is it possible to do this in R or excel? I can not do a simple function because there is no exact sequence of numbers (sometimes 3 numbers are broken, sometimes only 2). Thank you!

    
asked by anonymous 23.08.2018 / 22:49

2 answers

3

In R, you can use the trunc function

> trunc(191.1)
#[1] 191
> trunc(191.48)
#[1] 191
> trunc(191.8755)
#[1] 191

In Excel the Truncate

= TRUNCAR(191,8755;0)

Dataset

   > dados
       wavelength spectra
#1      190.10  -13.10
#2      190.48  -10.30
#3      190.87   -3.55
#4      191.25   -0.82
#5      191.63   -4.14
#6      192.02   -1.06
#7      192.40    5.21
#8      192.78   12.23
#9      193.17   10.88
#10     193.55    5.95
#11     193.93    7.80
#12     194.31   13.10
#13     194.70   10.88

Average of each spectra second wavelength

library(dplyr)
dados %>% group_by(trunc(wavelength)) %>%
  summarise(media_spectra = mean(spectra))
# A tibble: 5 x 2
#  'trunc(wavelength)' media_spectra
#                <dbl>         <dbl>
#1                 190         -8.98
#2                 191         -2.48
#3                 192          5.46
#4                 193          8.21
#5                 194         12.0 
    
23.08.2018 / 22:53
1

If you prefer, round these numbers to the nearest integer with the function round :

x<-c(191.1, 191.48, 191.87)
x
#[1] 191.10 191.48 191.87

round(x,0) # onde 0 é o número de casas decimais
#[1] 191 191 192
    
23.08.2018 / 23:44