0

This is an elementary question so I apologize if I am missing something obvious. I'm in an advanced statistics class, albeit the first at my university to use R software. The question is primarily to get us used to using R and asks us to calculate the log of the square root of 125 and to use the set.seed() function. I am confused about the set.seed aspect. I understand that it is used as a random number generator in simulations but I don't understand where it is applied within the code. This is what I did.

125 %>%
log() %>%
sqrt() %>%
set.seed(100)

Is this how it is supposed to be used?

  • 1
    The `set.seed` call comes *before* you do any functions which have a random element. And you wouldn't chain `%>%` it. See the examples here - https://stackoverflow.com/questions/14380096/set-seed-with-r-2-15-2 for a typical usage. There is nothing random about `sqrt(log(125))` however - I'm thinking the homework might have more parts to it or expect you to do the calculation in some other way if `set.seed` is asked for explicitly. – thelatemail Jul 01 '21 at 03:14

1 Answers1

1

No. Someone will probably give a fuller answer, but:

  • set.seed() does not affect the log() or sqrt() operations at all. Maybe this was supposed to be a two-part question ("(1) calculate the log of the square root of 125; (2) use set.seed() to set the state of the pseudo-random number generator")
  • You can use the pipe (%>%) operator in this way to compose the log() and sqrt() functions, but (unless you have been specifically instructed to do it this way, for some reason) it's overkill. You really might as well write it in the more "normal" way log(sqrt(125)).
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453