Questions tagged [r]

R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization, and general computing. Please provide minimal and reproducible example(s) along with the desired output. Use dput() for data and specify all non-base packages with library() calls. Do not embed pictures for data or code, use indented code blocks instead. For statistics related 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 StackOverflow 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 StackExchange 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 StackOverflow 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 R Studio use the rstudio tag. Don't use this tag just because you are working with R Studio.
404559 questions
47
votes
5 answers

Put stars on ggplot barplots and boxplots - to indicate the level of significance (p-value)

It's common to put stars on barplots or boxplots to show the level of significance (p-value) of one or between two groups, below are several examples: The number of stars are defined by p-value, for example one can put 3 stars for p-value < 0.001,…
Ali
  • 8,590
  • 11
  • 55
  • 86
47
votes
3 answers

Here we go again: append an element to a list in R

I am not happy with the accepted answer to Append an object to a list in R in amortized constant time? > list1 <- list("foo", pi) > bar <- list("A", "B") How can I append new element bar to list1? Clearly, c() does not work, it flattens bar: >…
user443854
  • 5,794
  • 12
  • 44
  • 59
47
votes
2 answers

How to use reference variables by character string in a formula?

In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names ("v2+v3+v4") to the formula, not the real meaning of this string (e.g., "v2"…
Eric Green
  • 6,401
  • 11
  • 41
  • 82
47
votes
2 answers

aggregate methods treat missing values (NA) differently

Here's a simple data frame with a missing value: M = data.frame( Name = c('name', 'name'), Col1 = c(NA, 1) , Col2 = c(1, 1)) # Name Col1 Col2 # 1 name NA 1 # 2 name 1 1 When I use aggregate to sum variables by group ('Name') using the…
Ryan Walker
  • 2,928
  • 1
  • 20
  • 26
47
votes
6 answers

How to get the name of the calling function inside the called routine?

Is there a "non-Internal" way to get the caller's name, as the function stop does? The idea is that I have a small function that checks the inputs and halts execution if some condition is not met. This function is called by several others, that use…
Ferdinand.kraft
  • 11,809
  • 7
  • 42
  • 67
47
votes
4 answers

How do I change a single value in a data.frame?

Could anyone explain how to change a single cell in a data.frame to something else. Basically I just want to rename that one cell, not all cells which matches it. I can´t use the edit() command because it will screw up my script since im using the…
Per Månsson
  • 531
  • 2
  • 6
  • 7
47
votes
2 answers

Fully reproducible parallel models using caret

When I run 2 random forests in caret, I get the exact same results if I set a random seed: library(caret) library(doParallel) set.seed(42) myControl <- trainControl(method='cv', index=createFolds(iris$Species)) set.seed(42) model1 <-…
Zach
  • 27,553
  • 31
  • 130
  • 193
47
votes
2 answers

Specifying row names when reading in a file

I have a .txt file that contains row names. However, R set the row names as the first column.
fokos
  • 483
  • 1
  • 4
  • 5
47
votes
3 answers

R knitr: Possible to programmatically modify chunk labels?

I'm trying to use knitr to generate a report that performs the same set of analyses on different subsets of a data set. The project contains two Rmd files: the first file is a master document that sets up the workspace and the document, the second…
aaronwolen
  • 3,543
  • 1
  • 16
  • 21
47
votes
2 answers

R tick data : merging date and time into a single object

I'm currently working in tick data with R and I would like to merge date and time into a single object as I need to get a precise time object to compute some statistics on my data. Here is how my data looks like: date time …
marino89
  • 749
  • 1
  • 9
  • 15
47
votes
6 answers

Local Variables Within aes

I'm trying to use a local variable in aes when I plot with ggplot. This is my problem boiled down to the essence: xy <- data.frame(x=1:10,y=1:10) plotfunc <- function(Data,YMul=2){ …
fabb
  • 11,262
  • 13
  • 57
  • 109
47
votes
2 answers

Is there an R Markdown equivalent to \Sexpr{} in Sweave?

Using R Markdown in knitr is there an equivalent to \Sexpr{} in Sweave?
Jeromy Anglim
  • 30,761
  • 24
  • 109
  • 167
47
votes
1 answer

Plotting lines and the group aesthetic in ggplot2

This question follows on from an earlier question and its answers. First some toy data: df = read.table(text = "School Year Value A 1998 5 B 1999 10 C 2000 15 A 2000 7 B …
Sandy Muspratt
  • 28,701
  • 11
  • 107
  • 117
47
votes
5 answers

Moving files between folders

I want to copy/paste a file from one folder to another folder in windows using R, but it's not working. My code: > file.rename(from="C:/Users/msc2/Desktop/rabata.txt",to="C:/Users/msc2/Desktop/Halwa/BADMASHI/SCOP/rabata.tx") [1] FALSE
Sagar Nikam
  • 1,468
  • 3
  • 22
  • 34
46
votes
2 answers

How to sum a numeric list elements

I'm wondering about an elegant way allowing to sum (or calculate a mean) a numeric values of a list. e.g. x <- list( a = matrix(c(1,2,3,4), nc=2), b = matrix(1, nc=2, nr=2)) and want to get x[[1]]+x[[2]] or a mean: (x[[1]]+x[[2]])/2
user1160354
  • 597
  • 1
  • 5
  • 7
1 2 3
99
100