2
u/jdnewmil Jun 20 '20
Mistakes:
seq(2,3, by=0.5)is not a complex sequence (there is no square root of -1 involved), but a floating point sequence. Note that using fractions to step by can lead to vectors that don't include all of the values you think they should. Compare:length( seq( 0.2, 1000000, by=0.1 ) )
with
length( seq( 0.3, 1000000, by=0.1 ) )Should only differ by one, right? The length.out argument is the more consistent way to make floating point sequences.
The
forloop operates on any vector, not just a sequence. Also, the braces are only needed if you want multiple statements inside the loop:for ( i in c( 3, 2, 4, 3, 5 ) ) print( i )
2
u/FourCatsLater Jun 20 '20
Wow. As someone who just began their R journey, this is immensely helpful. Thank you!!