r - Need help creating the following sequence: -
in r, need create vector b = (1, 1+pi, 1+2pi, 1+3pi,...,1+19pi)
. unsure how this. keep trying use seq
command (i.e. seq(1, 1+npi n = 1:19)
, that's totally wrong!), don't know proper syntax make work, never does.
any appreciated.
r needs multiplication operator.
b <- 1+ seq(0,19)*pi
or faster in situations speed might matter:
b <- 1+ seq.int(0,19)*pi
you use equivalent:
b <- 1+ 0:19*pi
because ":" operator has high precedence ( see ?syntax
), it's reasonable safe. careful understand precedence when use minus or plus sign might parse binary operator (remembering spaces ignored , unary-minus has higher precedence single-colon, binary minus or plus has lower precedence :
> 1: 5+5 [1] 6 7 8 9 10
Comments
Post a Comment