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
205
votes
9 answers

For each row in an R dataframe

I have a dataframe, and for each row in that dataframe I have to do some complicated lookups and append some data to a file. The dataFrame contains scientific results for selected wells from 96 well plates used in biological research so I want to do…
Carl Coryell-Martin
  • 3,410
  • 3
  • 26
  • 23
204
votes
9 answers

How to remove all whitespace from a string?

So " xx yy 11 22 33 " will become "xxyy112233". How can I achieve this?
waanders
  • 8,907
  • 22
  • 70
  • 102
204
votes
9 answers

Add a common Legend for combined ggplots

I have two ggplots which I align horizontally with grid.arrange. I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else. My data looks like this; # Data plot 1 …
jO.
  • 3,384
  • 7
  • 28
  • 38
203
votes
16 answers

How to add a row to a data frame in R?

In R, how do you add a new row to a data frame once the data frame has already been initialized? So far I have this: df <- data.frame("hi", "bye") names(df) <- c("hello", "goodbye") #I am trying to add "hola" and "ciao" as a new row de <-…
Rilcon42
  • 9,584
  • 18
  • 83
  • 167
203
votes
1 answer

What does %>% mean in R

I am following this example, the server.R, file is here. I plan to do a similar filter, but am lost as to what %>% does. # Apply filters m <- all_movies %>% filter( Reviews >= reviews, Oscars >= oscars, Year >=…
ben_says
  • 2,433
  • 4
  • 17
  • 18
202
votes
10 answers

R: += (plus equals) and ++ (plus plus) equivalent from c++/c#/java, etc.?

Does R have a concept of += (plus equals) or ++ (plus plus) as c++/c#/others do?
Suraj
  • 35,905
  • 47
  • 139
  • 250
202
votes
10 answers

Repeat each row of data.frame the number of times specified in a column

df <- data.frame(var1 = c('a', 'b', 'c'), var2 = c('d', 'e', 'f'), freq = 1:3) What is the simplest way to expand each row the first two columns of the data.frame above, so that each row is repeated the number of times specified in…
wkmor1
  • 7,226
  • 3
  • 31
  • 23
202
votes
6 answers

What does %>% function mean in R?

I have seen the use of %>% (percent greater than percent) function in some packages like dplyr and rvest. What does it mean? Is it a way to write closure blocks in R?
alfakini
  • 4,635
  • 2
  • 26
  • 35
201
votes
4 answers

Force the origin to start at 0

How can I set the origin / interception of the y-axis and x-axis in ggplot2? The line of the x-axis should be exactly at y=Z. With Z=0 or another given value.
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72
200
votes
6 answers

How to interpret dplyr message `summarise()` regrouping output by 'x' (override with `.groups` argument)?

I started getting a new message (see post title) when running group_by and summarise() after updating to dplyr development version 0.8.99.9003. Here is an example to recreate the output: library(tidyverse) library(hablar) df <- read_csv("year, week,…
Susie Derkins
  • 2,506
  • 2
  • 13
  • 21
200
votes
24 answers

session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium

I'm trying to run RSelenium using the rsDriver function, but when I run rD <- rsDriver() I get a message telling me I need a newer version of Chrome: > rD <- rsDriver() checking Selenium Server versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN:…
Matthew Law
  • 2,293
  • 2
  • 13
  • 16
200
votes
10 answers

Fixing a multiple warning "unknown column"

I have a persistent multiple warning of "unknown column" for all types of commands (e.g., str(x) to installing updates on packages), and not sure how to debug this or fix it. The warning "unknown column" is clearly related to a variable in a tbl_df…
ssp3nc3r
  • 3,662
  • 2
  • 13
  • 23
200
votes
14 answers

Select rows from one data.frame that are not present in a second data.frame

I have two data.frames: a1 <- data.frame(a = 1:5, b=letters[1:5]) a2 <- data.frame(a = 1:3, b=letters[1:3]) I want to find the rows a1 have that a2 doesn't. Is there a built in function for this type of operation? (p.s: I did write a solution for…
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
200
votes
14 answers

Remove columns from dataframe where ALL values are NA

I have a data frame where some of the columns contain NA values. How can I remove columns where all rows contain NA values?
Gnark
  • 4,080
  • 7
  • 33
  • 44
200
votes
4 answers

Find file name from full file path

Is there a way to extract the file name from the file full path (part of a file path) without the hassle of manipulating string? The equivalent in Java would be: File f = new File ("C:/some_dir/a") f.getName() //output a f.getFullAbsolutePath()…
defoo
  • 5,159
  • 11
  • 34
  • 39