r/StatisticsZone • • Jun 19 '20

base R cheat sheet

Post image
46 Upvotes

3 comments sorted by

2

u/FourCatsLater Jun 20 '20

Wow. As someone who just began their R journey, this is immensely helpful. Thank you!!

1

u/[deleted] Jun 20 '20

no problem! I am intermediate as well, and this helps out a lot.

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 for loop 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 )