8 ms·
Learn R Through Examples (2020)
- AuthorizedCust 5y agoR plus the tidyverse is what makes it a great language. Some tidyverse concepts are being baked into base R, like the pipe, but base R by itself feels hollow. R’s future is inseparable from the tidyverse. We need to just lump them together in any serious discussion of R. I teach a graduate level R course mainly for economics and statistics majors. (My educational background and career are computer science and technical; while that may stereotype me into Python, I just love R.) I spend the first three weeks on base R, to convey language-essential concepts, like vectorized objects, then the rest of the course is tidyverse-centric.
- acomjean 5y agoFor those that don’t know the “tidyverse” is a set of R packages that make using base R much easier/better (in my opinion) https://www.tidyverse.org/ https://www.tidyverse.org/ There is also a free ebook that’s a good reference. ggplot2 the plotting package included is pretty awesome I took a biostatistics class and after the basic examples in R using the tidyverse to analyze data for projects was very helpful.
- CalChris 5y agoI spend the first three weeks on base R, to convey language-essential concepts ... Awesome. When I was at Berkeley, Linear Systems had Matlab assignments. The real engineers (ME, CE, NE, ...) had taken a Matlab class and knew the language. We computer scientists hadn't and suffered horribly as a consequence. Your three weeks of learning base R instead of sink or swim will pay dividends.
- notagoodidea 5y agoGot the reverse experience. Trained in Matlab, R and Python, we had to follow a database/application class with computer scientist and software engineers where the big project was to make a basic Android application with sqlite database. That was painfully to be dropped in Android Studio without any Java knowledge. And because the class was focused on database, we had no Java introduction or whatever. We were able to team up with students from the other cursus that already had multiple Java projects and classes under their belt but the pill was bitter swallow.
- ProjectArcturis 5y agoPersonally I much prefer data.table. The syntax is a bit harder to get a handle on, but you can do just about anything with it, and it's much faster at runtime than tidyverse.
- kgwgk 5y agoJust for the record, many users are happy with base R. There are dozens of us! R by itself is nice. But the tidyverse is creeping in and bringing dependency hell with it. http://www.tinyverse.org/ http://www.tinyverse.org/
- meanmrmustard92 5y agohard second. ggplot2 was the last (only) good package hadley ever wrote; the rest is more about reinventing the wheel and viral-marketing with hex-stickers than about getting work done. the newer stuff in particular is atrocious; heaven forfend function calls that don't require understanding the lore of a package (`recipes` has stupid functions like `recipe`, `bake` and similar nonsense). at a push, base + data.table + ggplot2 get everything done. tinyverse ftw.
- specproc 5y agoR is such a horrible language to learn. I gave up entirely and now just use rpy2 for the few things it can do that Python can't.
- vasili111 5y agoHave you tried to read R book? Lots of people are learning from videos, tutorials and etc and that is not a good approach to learn R.
- qntty 5y agoIf you already know another dynamic language and want to understand R, I would recommend skipping all the intros to R based around data analysis and start with Advanced R by Hadley Wickham. It will explain all the weirdness you'll encounter right up front before it confuses you. Then you can read the data analysis tutorials and focus on the content rather than the R weirdness.
- claytonjy 5y agoIt's also available online under a creative commons license: https://adv-r.hadley.nz/ https://adv-r.hadley.nz/
- wodenokoto 5y agoI was quite surprised how easy that book was to read and understand. I’d expected “advanced” any language to be much more difficult.
- beforeolives 5y agoThe title is kind of misleading - the book is more of a list of exceptions, edge cases, unexpected behaviour and other gotchas.
- carljv 5y agoThat is not an accurate description of the book.
- CornCobs 5y agoI agree that Advanced R is a fantastic resource; however I do not think reading it is a good way to learn R. Advanced R explains the whys not the whats, and someone coming into R, who hasn't encountered any of the stuff Wickham gives intuitions for will likely find it an inexplicable truck of concepts. Instead I would propose using R in some capacity, encountering it's weird quirks (why sometimes evaluating an expression prints something to console and sometimes it doesn't? How is dplyr using my column names as variables? Why do I get warnings when using & instead of &&?) And then turning to Advanced R as a source of sanity Another source I would recommend is in fact the R language definition. It's very approachable and you quickly realize that R is pretty simple at the core, buried under piles of cruft
- auto 5y agoI consider myself a pretty experienced developer/software engineer/whatever. Decade into my career, started in iOS in Obj-C, learned Swift along the way, eventually migrated to the backend with Java/SQL, and finally found myself where I really wanted to be, embedded doing C/C++ work for a household name. That said, about halfway through my master's about two years ago, I found myself in an intro to data mining course that was sold as an "we will teach you R". I had heard non-programmer math friends talk about what they had accomplished in R, and was excited to dive in. Now, it didn't help that the class ended up being heavy on the statistics side (which despite a math/cs double major, stats was never my thing), but the actually learning R part was 99% left as an exercise to us alongside of the classwork required. I can say without a doubt, learning R is the worst programming experience I've ever had. Our assignments would give some high level direction on which libraries to use, but getting the right libraries setup and in the environment was just an absolute nightmare. All I remember from that class is hours every week googling unreadable python pukes from R studio (because apparently everything data mining/ML related in R is actually just python), and then spending an hour or less actually doing the statistics work. I feel bad because I feel like I was setup to not be able to give it a fair chance, but if that's what non-programmer math types are subjected to when told "you need to do some programming for your job", I can understand the apprehension.
- CapmCrackaWaka 5y ago> All I remember from that class is hours every week googling unreadable python pukes from R studio (because apparently everything data mining/ML related in R is actually just python) I’m curious what libraries you were using, I’ve had to go into the source of quite a few popular libraries and I don’t think I’ve ever encountered Python. Lots of C and it’s derivatives, lots of Stan and FORTRAN, but I don’t think I’ve seen Python yet.
- auto 5y agoJust going back and looking through some of the homework, here's what I'm seeing imported: readr, caret, lattice, ggplot2, RColorBrewer, mlbench, ElemStatLearn, klaR, dplyr, arules, arulesViz, tensorflow
- nojito 5y agoR's such a fantastic language and is leagues ahead of all others for data work. I do however recommend picking up data.table along the way because that is easily one of the best reasons to continue using R today.
- temp8964 5y agoI recently tried to migrate my R code to Julia. Even though I already knew R data.table is faster than DataFrames.jl, I was totally blown away by how slow Julia is. So I quickly gave up. I think I will have to write unavoidable hard loop in cpp, which I really don't want to do...
- glial 5y agoFor whatever it’s worth, I was pleasantly surprised at how easy Rcpp is to use.
- nojito 5y agoif it's grouping related check out the collapse package https://sebkrantz.github.io/collapse/ https://sebkrantz.github.io/collapse/
- xiaodai 5y agoyeah. time to first plot (ttfp) is a real issue.
- ku-man 5y agoMy experience as well. In order to get those so much vaunted C-like speeds the Julia fanboys claim, you need lots of contortions and hacks. Off the bat, Julia speeds are mediocre.
- cbkeller 5y agoThere are a few tricks to getting Julia to be actually fast, and while it's not hard per se if you know them all (at least for numerical work), it's definitely not trivial. IMHO, you really have to embrace dispatch-oriented programming, and that includes being scrupulous about avoiding type instability. You also have to be a bit conscious about allocations, since it's easy to write Julia code (especially if you're trying to write in a "vectorized" style as is common in R, Python, Matlab) that generates absurd numbers of allocations, which must then be garbage-collected. But also easy to avoid those allocations if you know. It took about two years, but after picking up more of this, I was eventually able to switch everything my group does from a two-language solution of matlab for scripts and plotting and C (with MPI) for HPC to all-Julia. This [1] was originally targeted at academics making the same switch, but much of it could be relevant to those with an R background as well. [1] https://github.com/brenhinkeller/JuliaAdviceForMatlabProgrammers https://github.com/brenhinkeller/JuliaAdviceForMatlabProgram...
- baron_harkonnen 5y agoLot's of negative comments in here about learning R from experienced programmers. I've found this is largely because experienced programmers have this unjustified bias that R is some toy language that should be easy to learn and has nothing to teach them. If you approached a language like Rust in the same way you would likely be just as frustrated with it. Certainly R has its quirks, but most of this comes from being one of the oldest continuing existing programming languages there is. It derives from S which was written 46 years ago. Because of this it has multiple object/class systems reflecting the changing standards for OOP. It's most dominant one, S3, predates Java and therefore uses the Generic Function paradigm of OOP similar to Common Lisp's ClOS. If you're experienced but have never worked with non-Java style OOP you're going to be a bit confused. R's most important feature, which is well worth studying and mastering for any serious programmer, is that it is a completely vectorized programming language. It borrows this style from APL (though is a million times more readable). Every value in R is a vector and for the vast majority of operations the best approach to solve your problem is by thinking in vector operations. This makes simple things like string formatting with `paste` seem like a confusing nightmare, but there is a real logic there. Functions like `ifelse` can seem strange, and writing C-style code in R, while possible will result in horrible performance. Once you do learn to think in vectors you realize that R isn't just popular in the stats world because most statisticians haven't seen a "real" programming language, but because you can very rapidly iterate on models. Translating mathematical notation into R, for the experience R programmer, is easier than any other language I've worked with by a long shot. My advice to any experienced programmer approaching R is to have some respect for the language. Most of the frustrations you'll have aren't because R is a bad language, but because you have less experience than you think and learning R well can expand your programming views in a similar way to Haskell.
- ttz 5y agoTo add: in my experience, programmers who denigrate R think of it as a software engineering language. Not all programming languages are meant to be languages for building large scale applications. Programming is not just about building business applications, it's about getting a computer to do things. And R excels at doing statistics and data science. If you keep that mindset, I believe many will find that its an excellent programming language.
- Closi 5y agoI currently do lots of data analysis in excel and know basic Python. I would be interested to get opinions on if R is better suited to data analysis than python if that’s all I was doing.
- trailrunner46 5y agoPython is certainly more popular and for job prospects I always tell that to newer data folks. That being said if you want to load in some data do some SQL like manipulation, run some stats and make a graph or output a report I would argue R is way better experience than Python but that’s much more about the package ecosystem and less a comment on the language. Dplyr is just more friendly to use than pandas (often 3-5 ways to do something and as a beginner this can be disorienting) and ggplot2 vs matlibplot. For interactive graphs you are probably going to use plotless anyway from both languages. One other thing I would mention is knowing SQL well is the most translatable skill. A lot of dplyr and pandas are doing SQL like operations (in fact dbplyr will generate SQL equivalent commands for your dplyr code for various backends). In summary know how to manipulate data in SQL then pick a language (because you will need to do some IO/reporting stuff outside just data work) where the ecosystem of packages feels user friendly to you and your work flow and roll with that.
- scottmcdot 5y agoThese days I usually prefer to use sqldf. It's so powerful how it let's you reference existing dataframes within the SQL command. It's like spark.sql in Python and temporary views but much more simple.
- scottmcdot 5y agoI'm strong in R, Python and Excel. I'd say anyone transitioning from Excel would be better off using R first. Because the R Integrated Development Environment (IDE) RStudio is fantastic compared to any Python IDEs that you can actually figure out how to install. The IDE makes it easy to visualise what you're actually doing to your dataframes by using multiple table tabs.
- montmorencie 5y agoI am currently a data scientist. Educational background in cs, few hobby web projects and currently updating my skills in java/ kotlin with the idea to go in mobile dev. I use only Python in my work. I learnt R and honestly, it's the same thing as using Python scientific packages. It's mostly vectorized operations, spaghetti functional, if people know how to write functions, code just to get it done. To make graphs, web dashboard(no, we are not doing web dev, it's dark magic frameworks), build machine learning and eventually some reports. Stuff like that. I do some software engineering but that s optional and I do it because I can. Most data scientists/ ml engineers can't. So you guys are not fair. R and Python in these environments are not even being used for building stuff. This language is not build for that. Hence it's not good from the perspective you look at it from(software engineers). Unlike Python , R is solely for statistics, data science and probably some basic ml( I haven't tried tho). Also Shiny for building web dashboards. But don't look at the code for dashboards, it's bad, with 'get it done and forget' approach. That being said. Good luck scrapping, mining, cleaning data with something not called R/Python. Good luck with data engineering. Exploring and visualizing trends. Creating dashboards even. Machine learning. Monitoring and reporting in scientific manner. Try This type of work with your favorite languages. Then see how quickly and easily it's done with R/Python . Come back and say it's bad language. It's the same thing as embedded dev complaining about how bad js is for his job. You just totally ignore the context.
- civilized 5y agoHere is my take on R as a guy who does stats as well as some software engineering in more mainstream languages like Python. R is a fantastic DSL for data manipulation and statistical analysis, with both traditional and modern tools, on datasets up to the gigabyte scale. It has great, easy-to-use data structures and unparalleled APIs in the tidyverse. It is not the thing for the latest deep learning implementation on petascale data, but most data science work doesn't need or benefit from that. Surprisingly, some machine learning methods have their nicest APIs in R, because that's where the users of those methods are. It has its warts, but so do JavaScript and SQL, and I think few people dispute that these are very powerful DSLs. Statistical analysis is just as legitimate a computing task as building webpages or querying databases. It is not the same as general-purpose programming, and it needs a good DSL.
- ryando 5y agoAgree with this. Nvim-R plus dplyr and the plotting libraries are the best tools I've found for manipulating and understanding the characteristics of a dataset quickly. Eventually I moved to Python for the specific reason that the R packages for interacting with cloud platforms couldn't really keep up with the development of those platforms, and I got tired of having projects that mashed together both languages. I haven't checked, maybe things have stabilized enough now that I would be happy going back to R.
- civilized 5y agoThat makes sense. I don't much like crossing streams between languages on a project. It's great if you can keep R for analysis and Python for production, but if R can't keep up with the wrangling part, you're a bit up a creek. I'm lucky in that most of my analysis only needs to query fairly well-behaved SQL databases.
- tylurp 5y agoAs an experienced R programmer that doesn’t do much statistics or have a background in computer science. What language characteristics does R lack that makes it a DSL instead of GPL? Edit: I found an interesting quote from a guy named Martin Fowler about the subject. “Languages can have a domain focus but still be general-purpose languages. A good example of this is R, a language and platform for statistics; it is very much targeted at statistics work, but has all the expressiveness of a general-purpose programming language. Thus, despite its domain focus, I would not call it a DSL.”
- deleted 5y ago[deleted]
- AndyPatterson 5y agoI work using R almost everyday and I think many of the problems that are unique to R could be solved by having a couple of experienced SWE in the core team to point R in the right direction. As it stands, I think R will be left behind until it fixes things like performance and scalability (e.g. intuitive byref semantics and a faster runtime) and a consistent scoping model and OOP. Apart from that, I think there's a bigger challenge which still needs to be addressed is that analysis/modelling projects tend to be worked on by individuals and/or thrown away after the initial value is pulled out of them. Going forward, I think we need to start identifying design methodologies that would make collaborating on this sort of work pain-free and more agile. Doing so should give us more value and sooner and for longer.
- noctilux 5y agoComing from writing OOP-style code in Python and C++, I initially disliked R quite a lot. My code is becoming more functional-style by the year and I'm now finding myself enjoying R more and more. There are issues with R: lots of weird quirks; many different ways of doing things, often just supported for legacy reasons; poor error messages; to name just a few. But on the positive side, it really encourages functional-style programming through the use of apply functions and many of the new tidyverse packages. The resulting code can be very neat and less error-prone than equivalent python code. The S3 system of OOP initially struck me as very weird, but now I see it as essentially just single dispatch, not really much of OOP at all. It works quite well and is extremely simple. I guess my thoughts are: approach R as a functional language, and I think you'll find much to like. Try to write C++ or python-style OOP in it, and you'll just find it very strange.