# Way to get started with and learn R?

I have tried several times to "go it on my own" - but with limited success. I am a casual SPSS user and have some SAS experience.

Would appreciate a pointer or two from someone who has similar background and now uses R.

I think the only way to get into it is the next time you you need to do something in SAS or SPSS fire up R instead. It is tough at the beginning and at first you will spend a lot of time on simple tasks. When you get stuck google the problem and you will probably find a solution. You can check your results with SPSS or SAS.

Eventually you start to get the hang of it and jobs start going quicker. Referencing old code always helps. Hopefully you find some sense of pride in the progress you make.

Then as you become more advanced and read blogs plus this site you start to learn the true power of R, the tricks, and what all is possible with it.

• One big issue: R's help system is good when you know what you want details on. It's not so good if you don't have a clue what you need to do. So do find a resource that shows you the basics like: how to read in data, how to save your work so far, how to make and save graphs, how to get help, etc. For example, if you say, "Hey, I want to forecast something, so I'll type in ?forecast to get help on that." You'll come up with nothing. In R, the usual term is "predict". I LOVE R, but have to keep it real. Also, realize R is a programming language, unlike SAS or SPSS: harder at first, better later. – Wayne Jan 25 '12 at 15:54

A few pointers:

1. The answer by @Glen is key. You need to force yourself to do something in R, even when you know you could do it easily with SPSS.
2. A few months ago I made a list of R programming books that didn't try to teach statistics, rather they just described R.
3. Subscribe to the RSS feeds of r-bloggers.com and the stackoverflow R tag. I find it very helpful just to skim read the articles to get hints and tips.

This book might be right down your alley: R. Muenchen (2008). R for SAS and SPSS Users.

I've had very similar experiences starting R several times. I am a Stata user though. Muenchen and Hilbe (a lo-ong time editor in charge of statistical software section of The American Statistician) have a similar book R for Stata users, and I found it entertaining at times, when they provide a 20-line segment of code for something that is doable in three lines in Stata. (On the other hand, there are of course situations when you just simply cannot do an object-oriented thing meaningfully in Stata.) I guess the message is, you should abstract from your SPSS and SAS experience, as R thinks in totally different terms about nearly everything. Your prior experience will likely be more of a hindrance, at least in the case of R (you can probably relearn from SPSS to Stata quite quickly if you had to). There are no more rectangular data sets, and there are no CARDS to read from. You would need to eventually learn to do R things, rather than trying to do SPSS things in R.

I've been in your shoes - indeed am probably still in your shoes - as I use both R and SAS regularly for different tasks. As mentioned above, there's "R for SAS Users", and you might also want to consider looking at the "SAS and R" blog: http://sas-and-r.blogspot.com/ and the accompanying book, which provides worked examples in both SAS and R.

Generally speaking, the experience in switching between SAS and R is somewhat disorienting, because they're different philosophically. At its core, SAS isn't a programming language - it's a powerful command line interface. R...is a programming language. R made more sense to me when I started learning Python and C than when I knew SAS. Admittedly its a programming language built for statistics, but there you have it.

While the approach of forcing yourself to fire up R instead of SAS is a decent one, I would suggest something else when you first start out, as plunging feet first into new project and new software is scary as hell. Repeat an old analysis. Take a paper you've written, a problem set you've done, whatever in SAS (or SPSS) and repeat it in R. Step by step, Googling and asking questions here as you go. This has three advantages:

1. You won't accidentally kill a new project with a "I should learn a new language" decision.
2. You know the answer already. This means you can be sure you've arrived at the correct answer in R.
3. It will illustrate the differences between the different languages better. "Wow, that was way easier to do in R...", "I'd never really looked at that kind of graph", etc.

Plenty of good advice here, but I think the single most helpful thing you could do would be to just sit down with someone who knows R for a couple of hours. I probably took years off my life learning R alone; just having someone to say, "Nah, it's much easier to do it this way" would have saved me so much grief. I think this is especially crucial with regard to learning to do R things, rather than SPSS things in R, as StasK mentions, but it will also stop you from spending hours chasing around stupid little syntax errors.

It doesn't look like Pittsburgh has an R User Group, which baffles me, but there must be many Rgonauts in the vicinity. Try to find them. Bribe someone to just hang out with you while you work through anything described above - translating an old project into R sounds especially good.

• I think determining the health effects of getting over the R learning curve would be an excellent study! – N Brouwer Sep 10 '12 at 4:37

I agree with @Matt Parker that there is plenty of good advice. One thing I want to stress in my answer is that it's vital to understand basic programming if you want to work with R.

### Basic programming

My favourite site for learning new things is Khan Academy that has some videos on Python scripting that is very similar to R and there is actually a plugin that allows you to use Python in SPSS that you can find here. I've used the Python plugin a lot doing complex merges, counting occurences, creating custom tables etc. It's a very good way to get started with programming.

### What's the deal with R?

I know several different programming languages and the thing that makes R special is it's vectors/matrices and it's graphical output. I recommend learning the different ways of manipulating vectors because they're the basis of dataframes and most of the data that you will use, here's a good tutorial. When it comes to the graphical output there are good functions for most of the available graphs and you probably don't need to worry about this part.

Another fundamental part of R is the install.packages("my_package_name") function that makes fetching new components and installing them hassle free - something that a lot of other languages make considerable harder.

### Getting started in R

My favourit R site is Quick-R and I would suggest on trying out some of their code. Once you've gotten the same graph try to change colors, number of columns, xlabel etc. There are also plenty of R-tutorials on YouTube that probably can help you get started.

### Learning by examining others code

An excellent way to learn R is to try to understand how different functions work. Write the functions name (without parenthesis), press enter and you get the code - look at it's code and try to understand what it does. The debug() function can also be of help when trying to understand how stuff works.

### Using R without coding

Yes, you can choose to use R in a SPSS similar environment:

install.packages("Rcmdr")
library(Rcmdr)


### R compared with SAS

I've also worked some with SAS that is a very unintuitive language that differs a lot from all other programming languages and unfortunately you'll probably have very little that you can use from your SAS experience when your work with R. That said, R is much easier that SAS ;-)

### GUI

It is nice to have a good environment to work with when you use R, my recommendation to beginners is RStudio.

Good luck!

• Heh - I disagree that SAS is harder than R. They're...different. If one comes from a tradition of programming languages, R may make more sense than SAS. But really when it comes down to it, they're different - as I said in my post, SAS is more of a command line interface than a proper programming language. – Fomite Sep 20 '11 at 20:47
• I agree that they're very different and it's more of an opinion than a statement. There are some basic features that I lacked when trying to learn SAS where the most basic was a good help function, I never dug deep into SAS. One thing I've noticed is that many using SAS copy their old syntax without understanding. I've seen people writing code where half of the command isn't even used. That is why I believe that once you get the hang of programming learning R is not so hard. Good help, syntax highlighting, rich on-line community is worth a lot and knowing programming is really helpful 2011. – Max Gordon Sep 21 '11 at 19:50
• SAS's help system is concentrated in its support documents. But yeah, its mostly that they're quite different. Annoyingly, there are functions of both languages that are somewhat harder to duplicate in the other, which leaves me occasionally using both. Which I'd really prefer not to do. – Fomite Sep 21 '11 at 20:01

I think the answer mentioned by @Glen is very imporntant however you do need some books to start with.

With regards to R I believe you need 3 books.

First, for doing statistics with R i can recommend you R in Action . Robert maintains a very active R site and blog (http://www.statmethods.net/) and his book and efforts are fantastic.

Second, you may need a book for programming in R, as R is not only a statistics program but also a mighty language. Programming is very helpful when doing complex analyses or when combining analysis, or for writing functions that perform the same thing on different datasets. I can only recommend you The Art of R Programming . No major statistics are presented here, but you will get a grip how to combine, connect and automate your analyses.

Third, you will need a reference book, an encyclopedia. I can recommend you The R Book . This is not the book you will read from start to finish but its the book you open now and then to see if some things are possible, if there are other ways to analyse data etc.

And most important stop using anything else and try to tackle all your problems in R. Solving problems in the best way to learn.

Also, before I forget. There are some wonderful blogs from some fantastic people writing about all sort of stuff one can do in R. Search and you will find. Highly recommended is the aggregation site http://www.r-bloggers.com/ where R relevant blogs are gathered.

Have fun!

If I could add two item to the many good suggestions here already;

1)Find an R group. I know in the Boston area there is a fairly strong R group. It is sponsored by RStudio, which by the way is one of the BEST IDE around.
Go on Meetup or Google group or RSeek.org to search them out.

2)One more thing, I found learning R on my own a steep climb but my general advice is keep looking for books that help AND DON'T STOP until you find the right one.

MarketingEngineer:

I know your issues as the best & worst thing of R is too functional until we don't know where to start with.

First, you need to know what's purpose you learn R. If you're just for learning a new language then, I think SAS and R Blog might be useful, as a SAS/SPSS user.

However, R is not that hard if compared to SAS or SPSS, it's just looked complex due to the ever increasing packages and functions. So, I suggest you can learn from scratch using any manuals or webs suggested, such as Quick-R, by the author of R in Action. Note: R in Action is a good book to start with.

What if, you used R for specific purposes, then it's better you have a look of the R Book list at R Project Web. There are 129 R and S related books in specific applications, such as Econometric, Graphical, Modelling, ... so on.

Recently, I'm thinking of Interactive R Language Online Learning Platform and I had asked for feedback here too. It's open source (not yet released) project. I had started making a working prototype with 3 R Language basic lessons. You can give it a try.

Hope it help :-)