You can use mutate_at() from dplyr with round().
library(tibble)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
DFgrid = data.frame(longitude = c(44.00, 44.50, 45.00, 44.00, 44.50, 45.00, 44.00, 44.50, 45.00),
latitude = c(-64.00, -64.00, -64.00, -63.50, -63.50, -63.50, -63.00, -63.00, -63.00),
elevation = c( 0.0, 0.5, 1.0, 0.5, 1.0, 1.5, 1.0, 1.5, 2.0),
precip = c(1.001000,1.502222,1,1.211000,0.165556,0.100122,1.330709,1.4,1.890990),
temp = c(12.123445,8.210112,9.155560,10.1,11,6.556890,2.2,4.112335,3))
#create a raster object using all the attributes (X and Y first)
rast_obj <- DFgrid %>%
raster::rasterFromXYZ()
#create an X, Y data frame
new_points <- tibble(
longitude = c(44.1, 44.9),
latitude = c(-63.9, -63.1),
elevation = c(-5, 10)
)
#predict values at the point locations
pnt.pred = bind_cols(
new_points[,1:2],
as_tibble(raster::extract(rast_obj, new_points[,1:2]))
)
pnt.pred <- pnt.pred %>% mutate_at(c(4,5), round, digits = 2)
Created on 2019-05-07 by the reprex package (v0.2.1)