Mathematical functions for vectors and tables

Do math functions also work on tables?

Sure they do. For instance you can do log10() on mtcars (see script):

log10(mtcars)

It will return log transformed values. However, if the table contains non-numeric elements the command will give an error since math functions only work on numbers.

How to save the log transformed values?

Simple! By doing an assignment (see script):

mtcars$mpg <- log10(mtcars$mpg)

It will replace the original mpgs by the log transformed values.

How to define the number of digits after the decimal point?

If you want to set the number of digits for one number use the round() function (see script):

round(1/7,digits=3)

1/7 will be rounded to 3 digits after the decimal point, but all other numbers from here on will not be rounded.

If you want to set the number of digits for all numbers in this Rstudio session use the options() function (see script):

options(digits=2)

from here on all numbers will be rounded to 2 digits after the decimal point until RStudio is closed.
If you open RStudio again, no rounding will be done. The options are only valid for the current RStudio session.