-2

In the R manual there is one example of seq as follows:

seq(stats::rnorm(20))

Can someone explain to me what it is doing and is supposed to generate?

Jaap
  • 81,064
  • 34
  • 182
  • 193
student
  • 289
  • 2
  • 14

2 Answers2

4

You are effectively using this argument along.with in the seq function. This argument will tell seq to simply make a vector of the length of the object, which is 20 in your case.

From ?seq:

generates the sequence 1, 2, ..., length(from) (as if argument along.with had been specified), unless the argument is numeric of length 1 when it is interpreted as 1:from (even for seq(0) for compatibility with S). Using either seq_along or seq_len is much preferred

Jaap
  • 81,064
  • 34
  • 182
  • 193
Stephen
  • 324
  • 2
  • 9
0

The help also says

seq(stats::rnorm(20)) # effectively 'along'

So you are using the argument along.with, which reads:

along.with take the length from the length of this argument.

That's why it generates a sequence with 20 integers, as it's length(rnorm(20L))

RHertel
  • 23,412
  • 5
  • 38
  • 64
catastrophic-failure
  • 3,759
  • 1
  • 24
  • 43