如何学习 R 作为一种编程语言

我想知道如何把 R 语言作为“编程”语言来学习,而不是把它作为一个统计系统来学习。我的问题是由于缺乏对诸如解析、计算等函数的理解而引起的,这些函数可能不会被具有“统计”说服力的 R 用户频繁使用。

编辑: 我一直在探索像 Rpy RSPerl rJava 这样的工具,并希望(至少)能够理解一些概念,这些概念可以帮助 R 与其他编程语言进行通信。

R (R-PHP、 RApache 等)的 Web 应用程序的可用性是另一个激励我更深入、更结构化地理解 R 的因素。

最后但并非最不重要的,我希望能够编写 R 包,这样的理解将是有益的,如果不是必要的。

91491 次浏览

For starters, you might want to look at this article by John Cook. Also make sure that you read "The R Inferno".

There are many good resources on the R homepage, but in particular, read "An Introduction to R" and "The R Language Definition".

Some very closely related stackoverflow questions:

My favorite book on the subject: "Software for Data Analysis: Programming with R", by John Chambers, the creator of the S language.

I'm a very hands-on learner, so this advice may be specific to my learning style. I would suggest that the best place to start "learning to program" in any language involves finding problems outside of your normal range of experience and then trying to solve them using a programming language.

The projects that taught me the most about how to program with R had nothing to do with statistics at all.

Knowing functions like parse() and eval() is by no means a measure for being "a good R programmer". Applications that require heavy use of these functions do not make up a majority of the problem space in which you can apply R. Instead, I think you should try to be "a good programmer" who knows R. This involves refining your problem-solving approaches.

Programming is not a spectator sport-- a good book is indispensable as a reference on the tools available, but you need to find some problems upon which to hone your skills.

I would rather suggest a good and comprehensive start, like The R Book by Michael Crawley. It's an easy-to-read and complete book on R core functions, with statistical tips and a few exercises. It focuses a lot on R strengths (e.g. linear models) and gives also useful coding tricks. It helped me a lot while I was struggling on cryptic online courses.

alt text

A good book for learning R-as-a-programming-language (as opposed to R-for-statistics) is The Art of R Programming, by Norman Matloff.

enter image description here

It's very readable, doesn't assume you're a computer scientist, and is quite inexpensive as R books go.