12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Starting Your First R SessionIf you’re anything like the two of us, you’re probably just itching to get hold ofsome real code. In this section, you get to do exactly that. Get ready to get yourhands dirty!Saying hello to the worldProgramming books typically start with a very simple program. Often, theobjective of this first program is to create the message “Hello world!” In R, thisprogram consists of one line of code.Start a new R session, type the following in your console, and press Enter:> print(“Hello world!”)R responds immediately with this output:[1] “Hello world!”Congratulations! You’ve just completed your first R script.As we explain in the introduction to this book, we collapse these two thingsinto a single block of code, like this:> print(“Hello world!”)[1] “Hello world!”Doing simple mathType the following in your console to calculate the sum of five numbers:> 1+2+3+4+5[1] 15The answer is 15, which you can easily verify for yourself. You may think thatthere’s an easier way to calculate this value, though — and you’d be right. Weexplain how in the following section.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!