Questions tagged [r]

R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible examples others can run using copy & paste. Show desired output entirely. Use dput() for data & specify all non-base packages with library(). Don't embed pictures for data or code, use indented code blocks instead. For statistics questions, use https://stats.stackexchange.com.

R Programming Language

R is a free, open-source programming language and software environment for statistical computing, bioinformatics, information graphics, and general computing. It is a multi-paradigm language and dynamically typed. R is an implementation of the S programming language combined with lexical scoping semantics inspired by Scheme. R was created by Ross Ihaka and Robert Gentleman and is now developed by the R Development Core Team. The R environment is easily extended through a packaging system on CRAN, the Comprehensive R Archive Network.

Scope of questions

This tag should be used for programming-related questions about R. Including a minimal reproducible example in your question will increase your chances of getting a timely, useful answer. Questions should not use the tag unless they relate specifically to the RStudio interface and not just the R language.

If your question is more focused on statistics or data science, use Cross Validated or Data Science, respectively. Bioinformatics-specific questions may be better received on Bioconductor Support or Biostars. General questions about R (such as requests for off-site resources or discussion questions) are unsuitable for Stack Overflow and may be appropriate for one of the general, or special-interest, R mailing lists.

Please do not cross-post across multiple venues. Do research (read tag wikis, look at existing questions, or search online) to determine the most appropriate venue so that you have a better chance of receiving solutions to your question. Your question may be automatically migrated to a more appropriate Stack Exchange site. If you receive no response to your questions after a few days, or if your question is put on hold for being off-topic, it is then OK to post to another venue, giving a link to your Stack Overflow question - but don't cross-post just because your question is down-voted or put on hold for being unclear. Instead, work on improving your question.

Stack Overflow resources

Official CRAN Documentation

Other CRAN resources

Free Resources

Interactive R learning

  • Coursera - Learn how to use R for effective data analysis
  • DataCamp - Many interactive R and data science courses
  • Dataquest - Interactive R courses for data science
  • edX - Basic Statistics and R (basic course, not just for life sciences)
  • edX - Introduction to R Programming
  • R-exercises - 1000+ R exercises and solutions
  • RPubs - Easy web publishing from R
  • Swirl - R-package to learn R interactively

Free books on R:

Programming Chrestomathy (problems written in many languages)

Other free resource materials

IDEs and editors for R

Web application framework for R

  • Shiny - Turn your analyses into interactive web applications. No HTML, CSS, or JavaScript knowledge required.
  • FastRWeb - Fast Interactive Web Framework for Data Mining Using R

Graphical User Interfaces (GUI) in R

Code style guides

Other Resources

Recommended additional R resources include:

Alternative R engines

All alternative R engines have the goal of increasing R's performance and memory management.

Downstream distributions with complete compatibility

Forks of R with near 100% code compatibility

  • pqR by Radford Neal (C-based).
  • Rho by Karl Millar, based upon CXXR by Andrew Runnalls (C++-based). The development on Rho has been suspended indefinitely.

Rewrites with high code compatibility

  • Renjin by BeDataDriven (Java-based).
  • TERR by Tibco (C++-based).

Experimental and early-stage rewrites

  • Riposte by Justin Talbot (C++-based).
  • FastR by Jan Vitek and Tomas Kalibera (Java-based).

Unrelated tags

Due to R's simple name, questions sometimes get tagged with the tag when a different topic is meant. Here is a list of tags that mistagged R questions might be re-tagged to

  • for questions related to the file R.java on
  • "A command line tool for running JavaScript scripts that use the Asynchronous Module Definition API (AMD) for declaring and using JavaScript modules and regular JavaScript script files. It is part of the RequireJS project, and works with the RequireJS implementation of AMD." (from the wiki summary)
  • for questions related to RStudio use the rstudio tag. Don't use this tag just because you are working with RStudio.
496613 questions
57
votes
4 answers

Emacs ESS Mode - Tabbing for Comment Region

I am using the Emacs-Speaks-Statistics (ESS) mode for Emacs. When editing R code, any comment lines (those starting with #) automatically get tabbed to the far right when I create a new line above it. How should I change my .emacs.el file to fix…
Christopher DuBois
  • 42,350
  • 23
  • 71
  • 93
57
votes
12 answers

How to order a data frame by one descending and one ascending column?

I have a data frame, which looks like that: P1 P2 P3 T1 T2 T3 I1 I2 1 2 3 5 52 43 61 6 "b" 2 6 4 3 72 NA 59 1 "a" 3 1 5 6 55 48 60 6 "f" 4 2 4 4 65 64 58 2 "b" I want to sort it by I1…
rumtscho
  • 2,474
  • 5
  • 28
  • 42
57
votes
5 answers

Plot 3D data in R

I have a 3D dataset: data = data.frame( x = rep( c(0.1, 0.2, 0.3, 0.4, 0.5), each=5), y = rep( c(1, 2, 3, 4, 5), 5) ) data$z = runif( 25, min = (data$x*data$y - 0.1 * (data$x*data$y)), max = (data$x*data$y + 0.1 *…
R_User
  • 10,682
  • 25
  • 79
  • 120
57
votes
2 answers

Initializing data.frames()

Is there a quick way to initialize an empty data frame? If you know what the dimensions will be? For example: Suppose I would like a blank data frame that has 100 rows and 10: x <- data.frame(1:100,2,3,4,5,6,7,8,9,10) dim(x) ## that's right But…
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
57
votes
1 answer

What is R's multidimensional equivalent of rbind and cbind?

When working with matrices in R, one can put them side-by-side or stack them top of each other using cbind and rbind, respectively. What is the equivalent function for stacking matrices or arrays in other dimensions? For example, the following…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
57
votes
11 answers

Converting a data frame to xts

I'm trying to convert a data frame to xts object using the as.xts()-method. Here is my input dataframe q: q t x 1 2006-01-01 00:00:00 1 2 2006-01-01 01:00:00 2 3 2006-01-01 02:00:00 3 str(q) 'data.frame': 10…
user442446
  • 1,099
  • 3
  • 12
  • 13
57
votes
1 answer

dev.hold, dev.flush and resizing windows

In R, it is possible to hold a device, draw the picture, and then flush the device to render the graphics. This is useful for very complex plots with thousands of data points, color gradients etc since without holding, the device would be refreshed…
January
  • 16,320
  • 6
  • 52
  • 74
57
votes
5 answers

Replace NA with previous or next value, by group, using dplyr

I have a data frame which is arranged by descending order of date. ps1 = data.frame(userID = c(21,21,21,22,22,22,23,23,23), color = c(NA,'blue','red','blue',NA,NA,'red',NA,'gold'), age =…
Tarak
  • 1,035
  • 2
  • 8
  • 14
57
votes
1 answer

Cannot log-in to rstudio-server

I have previously successfully installed rstudio-server with brew install rstudio-server on a Mac OS X 10.11.4. Now, I am trying to login to rstudio-server 0.99.902 without success. From the client side, I get a pop-up window saying - "RStudio…
Ramiro Magno
  • 3,085
  • 15
  • 30
57
votes
6 answers

R: removing the last elements of a vector

How can I remove the last 100 elements of a zoo series? I know the name[-element] notation but I can't get it work to substract a full section
skan
  • 7,423
  • 14
  • 59
  • 96
57
votes
4 answers

Where should I put data for automated tests with testthat?

I am using Hadley's testthat-based approach for automated testing of my package. With this approach, what is the most suitable place to put test data files that is files only used by the test scripts in tests/testthat), but not by any other…
Aditya
  • 1,554
  • 1
  • 13
  • 23
57
votes
7 answers

Installing rgl on Ubuntu and Mac: X11 not found

I have seen this question here: Error in loading rgl package with Mac OS X but there is no mentioning about installation error, which is my case. I cannot install rgl package, using this command in…
Matin Kh
  • 5,192
  • 6
  • 53
  • 77
57
votes
3 answers

Error - replacement has [x] rows, data has [y]

I have a numeric column ("value") in a dataframe ("df"), and I would like to generate a new column ("valueBin") based on "value." I have the following conditional code to define df$valueBin: df$valueBin[which(df$value<=250)] <-…
Max Power
  • 8,265
  • 13
  • 50
  • 91
57
votes
9 answers

How to send an email with attachment from R in windows

I have a scheduled an R script running from a windows machine. After it finishes, I wish this script to automatically send an email with some log file attached. Using shell() with some other scripts may be possible, but I was wondering if there…
ahala
  • 571
  • 1
  • 5
  • 3
57
votes
11 answers

Essential skills of a Data Scientist

What are the relevant skills in the arsenal of a Data Scientist? With new technologies coming in every day, how does one pick and choose the essentials? A few ideas germane to this discussion: Knowing SQL and the use of a DB such as MySQL,…
harshsinghal
  • 3,720
  • 8
  • 35
  • 32