Need to create function to add 5 to randomly generated numbers


I created a set of randomly generated numbers and now I need to add five to each number. I know I need to create a function, but I cannot see to get it right. Any help for this budding researcher?

Could you show us the code of what you've done so far? A good way to do that is via a REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Base R and packages offer a number of ways to generate random numbers. An introduction here

A good tidyverse way to update a vector of numbers in a table is with dplyr's mutate.

For example,


  col1 = 1:5
) %>%
    col1 = col1 + 5
#> # A tibble: 5 x 1
#>    col1
#>   <dbl>
#> 1     6
#> 2     7
#> 3     8
#> 4     9
#> 5    10

Created on 2021-02-12 by the reprex package (v0.3.0)


These are the steps I have done so far:

To create the random numbers: rnorm(1000, mean = 5, sd = 10)

To create a variable: randomNumbers <- rnorm(1000, mean = 5, sd = 10)

To find the mean: mean(randomNumbers)

To find the max number within the 1000: max(randomNumbers)

Now step 5 is to add five to all the numbers?

(Sorry, I'm a first year Phd and just learning R. I truly appreciate any help!)


randomNumbers + 5

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.