R Newbie


Based on posts I’ve seen on this forum, there seems to be quite a few people who use R. I’m always keen to expand my toolbox and am considering spending a bit of time learning R.

I was hoping to hear what you guys think is so awesome about R. Why do you / don’t you use it over other languages/packages? What frustrates you about it, what can’t it do?

In terms of what I want from R. I’m not after anything specific at this point, it’s just that from reading all the hype there is about R and seeing some really cool/sexy looking stuff on r-bloggers.com, it looks like something I want to learn and that is going to be useful to me somehow at some point. It looks sexy and I want it.

A bit of background about myself to give you an idea about what I might be after. My main tools that I use now are combining Excel/VBA/C#/MSSQL (i.e. front end Excel/VBA, back end / middleware in C#, MSSQL database). The stuff I build is varied. I’m an Assistant PM working for a small (i.e. still no clients, just seed a fund) startup investment management firm, so I’ve had to build stuff from Monte Carlo simulations to implementing our strategy models down to crap like position/corpaction reconcilliation and issue management software (snooze…). I also tend to do a lot of one-off data analysis, like analysing trading data over the last year trying to identify liquidity trends, that sort of thing. I’m hoping R might be useful for the last thing mentioned.

Lastly, what are you sugestions on the least painful way to go from zero to hero with R? What resources did you find most helpful? I’m after the basic stuff (i.e. “hello world” type resources), but am also hoping more advanced stuff (i…e fully built solutions that I can learn from example). I’ve downloaded a few packages I found on r-bloggers.com, so far they’re all a bit over my head. Anyway, suggestions welcome.

Play around with this. It’s a Three card Poker game I wrote.

threeCardPoker r1 dealHand deck cat(“Bet=”,bet," ") cards cat("Player: “,cards[1:3],” ") play play while(play !=“Y” && play !=“y” && play !=“N”&& play !=“n”){ play play if(play==“Y” || play==“y”){play if(play){ cat("Dealer: “,cards[4:6],” ") cards num num pnum dnum if(pnum[1]==2 &&pnum[2]==3 &&pnum[3]==14){(pnum[1] if(dnum[1]==2 &&dnum[2]==3 &&dnum[3]==14){(dnum[1] suit psuit dsuit pflush pflushC if(psuit[1]==“D”&&psuit[2]==“D”&&psuit[3]==“D”){pflush if(psuit[1]==“S”&&psuit[2]==“S”&&psuit[3]==“S”){pflush if(psuit[1]==“H”&&psuit[2]==“H”&&psuit[3]==“H”){pflush if(psuit[1]==“C”&&psuit[2]==“C”&&psuit[3]==“C”){pflush if(pflush){pflushC dflush dflushC if(dsuit[1]==“D”&&dsuit[2]==“D”&&dsuit[3]==“D”){dflush if(dsuit[1]==“S”&&dsuit[2]==“S”&&dsuit[3]==“S”){dflush if(dsuit[1]==“H”&&dsuit[2]==“H”&&dsuit[3]==“H”){dflush if(dsuit[1]==“C”&&dsuit[2]==“C”&&dsuit[3]==“C”){dflush if(dflush){dflushC if(pflushC==dflushC && pflushC !=0){(pflushC if(pflushC==dflushC && pflushC !=0){(pflushC pstraight pstraightC if(pnum[3]-pnum[2]==1 &&pnum[2]-pnum[1]==1){(pstraight dstraight dstraightC if(dnum[3]-dnum[2]==1 &&dnum[2]-dnum[1]==1){(dstraight pstrfl pstrflC if(pflush==TRUE && pstraight==TRUE){(pstrfl dstrfl dstrflC if(dflush==TRUE && dstraight==TRUE){(dstrfl if(pstrfl){pstraight if(pstrfl){pflush if(dstrfl){dstraight if(dstrfl){dflush pthreekind pthreekindC if(pnum[3]==pnum[2] &&pnum[2]==pnum[1]){(pthreekind dthreekind dthreekindC if(dnum[3]==dnum[2] &&dnum[2]==dnum[1]){(dthreekind if(pthreekind==TRUE &&pflush==TRUE){pflush if(dthreekind==TRUE &&dflush==TRUE){dflush ppair ppairC if(pthreekind==FALSE){if(pnum[1]==pnum[2] || pnum[2]==pnum[3]){ppair if(pthreekind==FALSE){if(ppair){if(pnum[1]==pnum[2]){ppairC if(pthreekind==FALSE){if(ppair){if(pnum[2]==pnum[3]){ppairC dpair dpairC if(dthreekind==FALSE){if(dnum[1]==dnum[2] || dnum[2]==dnum[3]){dpair if(dthreekind==FALSE){if(dpair){if(dnum[1]==dnum[2]){dpairC if(dthreekind==FALSE){if(dpair){if(dnum[2]==dnum[3]){dpairC if(ppairC==dpairC && ppairC !=0){(ppairC phc if(pstrfl==FALSE && pflush==FALSE && pstraight==FALSE && pthreekind==FALSE && ppair==FALSE){phc dhc if(dstrfl==FALSE && dflush==FALSE && dstraight==FALSE && dthreekind==FALSE && dpair==FALSE){dhc if(phc==dhc &&phc!=0){(phc if(phc==dhc &&phc!=0){(phc dQual if(dstrfl==TRUE || dflush==TRUE || dstraight==TRUE || dthreekind==TRUE || dpair==TRUE || max(dnum)>11){dQual cat("Dealer Qualifies? “,dQual,” ") value pHand pHandC pHand dHand dHandC dHand pWin pname dname cat("Player: ") if(pname){cat("HIGH CARD: “) if(pname==11){pname if(pname==12){pname if(pname==13){pname if(pname==14){pname cat(pname,” “)} if(ppair){cat(“PAIR”,” “)} if(pflush){cat(“FLUSH”,” “)} if(pstraight){cat(“STRAIGHT”,” “)} if(pthreekind){cat(“THREE OF A KIND”,” “)} if(pstrfl){cat(“STRAIGHT FLUSH”,” ")} cat("Dealer: ") if(dname){cat("HIGH CARD: “) if(dname==11){dname if(dname==12){dname if(dname==13){dname if(dname==14){dname cat(dname,” “)} if(dpair){cat(“PAIR”,” “)} if(dflush){cat(“FLUSH”,” “)} if(dstraight){cat(“STRAIGHT”,” “)} if(dthreekind){cat(“THREE OF A KIND”,” “)} if(dstrfl){cat(“STRAIGHT FLUSH”,” ")} if(dQual){ if(max(pHand)>max(dHand)){pWin if(max(pHand) if(max(pHand)==max(dHand)){if(max(pHandC)>max(dHandC)){pWin if(max(pHand)==max(dHand)){if(max(pHandC) if(max(pHand)==max(dHand)&&max(pHand)==0){if(phc>dhc){pWin if(max(pHand)==max(dHand)&&max(pHand)==0){if(phc if(pstrfl>0){pWin if(pthreekind>0){pWin if(pstraight>0){pWin } if(dQual==FALSE){ pWin if(pstrfl>0){pWin if(pthreekind>0){pWin if(pstraight>0){pWin } if(max(dHand)>max(pHand)){ if(pstrfl>0){pWin if(pthreekind>0){pWin if(pstraight>0){pWin } }#end if loop if(play==“FALSE”){return(bet*-1)} else{return(pWin)} } p chips while (is.na(chips)) chips g w l maxDD minDD while§{ cat("Total Chips: “,chips,” ") b while(is.na(b)){b while(b>chips*.5){b tmp if(tmp>0){ cat("You won! “,tmp,” ") g w if(tmp<0){ cat("You lost: “,tmp,” ") g l if(tmp==0){ cat("Push: “,” “) g chips if(chips>maxDD){maxDD if(chips cat(“Total Chips: “,(chips),” “) if(chips==0){break} p p while(p!=“Y” && p!=“y” && p!=“N” && p!=“n”){ p p if(p==“Y” || p==“y”){p else{p cat(” “) }#end while cat(“G: “,g,” “) cat(“W: “, w, " “,paste(r1(w/g*100),”%”,sep=””, " “)) cat(“L: “,l,” “,paste(r1(l/g*100),”%”,sep=””,” “)) cat(“P: “,g-w-l,” “,paste(r1((g-w-l)/g*100),”%”,sep=””,” ")) cat("Max: “,maxDD,” ") cat("Min: “,minDD,” ") }

R is probably one of the most powerful languages you can get for mathematical modeling for free. It’s not too far removed from MATLAB, although there are enough differences that you can drive yourself crazy if you mix them up.

Universities use it because it is inexpensive and powerful, and so you have lots of university coders writing R packages that can be reused. It’s grown handsomely over time, although the packages grow faster than the documentation.

Like most programming languages, it’s probably best to do a quick tutorial to get you started “I like the one in the book ‘R in a nutshell’” and then have a few reference books to help you through more complex problems. I like “The R Book” and “R in a nutshell” myself.

If you are just getting started and don’t feel like going out and buying books, this PDF is helpful:


However, it can be a little strange to get into the “R mindset” where data and funcitons are all objects, but not quite full objects in the Java or C++ sense. If you’ve done MATLAB before, it is a bit easier, because they use the same model.