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
2 answers

What is the current state of Unit testing support in the R language

R is a statistics programming language. Part of R is the use of Packages, which themselves are written in the R language. Programming best practice includes the use of unit-testing to test the functions within these packages while they are being…
PaulHurleyuk
  • 7,589
  • 14
  • 50
  • 75
47
votes
2 answers

R Shiny set DataTable column width

I am trying to set the width of columns in a DataTable rendered in Shiny and am not able to implement it using the aoColumnDefs options. Has anyone tried this before ? My table has 1 text followed by 3 numeric columns. The numeric columns need to be…
xbsd
  • 2,298
  • 2
  • 22
  • 34
47
votes
5 answers

Get the mean across multiple Pandas DataFrames

I'm generating a number of dataframes with the same shape, and I want to compare them to one another. I want to be able to get the mean and median across the dataframes. Source.0 Source.1 Source.2 Source.3 cluster …
Tim
  • 1,666
  • 2
  • 22
  • 40
47
votes
2 answers

Conditionally replacing column values with data.table

I have the following data.table: dt <- data.table(col1 = rep("a",6), col2 = c(1,1,1,2,3,1)) Now I want to replace all the 1 in col2 with value "bigDog". I can do it using the data.frame spirit: dt$col2[dt$col2==1,] <- "bigDog" But I wonder if…
Colonel Beauvel
  • 28,120
  • 9
  • 39
  • 75
47
votes
4 answers

dplyr: How to use group_by inside a function?

I want to use use the dplyr::group_by function inside another function, but I do not know how to pass the arguments to this function. Can someone provide a working example? library(dplyr) data(iris) iris %.% group_by(Species) %.% summarise(n = n())…
47
votes
4 answers

Stacked bar chart

I would like to create a stacked chart using ggplot2 and geom_bar. Here is my source data: Rank F1 F2 F3 1 500 250 50 2 400 100 30 3 300 155 100 4 200 90 10 I want a stacked chart where x is the rank and…
WongSifu
  • 518
  • 1
  • 5
  • 11
47
votes
5 answers

Calculating percentile of dataset column

A quick one for you, dearest R gurus: I'm doing an assignment and I've been asked, in this exercise, to get basic statistics out of the infert dataset (it's in-built), and specifically one of its columns, infert$age. For anyone not familiar with the…
Dimitris Sfounis
  • 2,142
  • 4
  • 27
  • 46
47
votes
4 answers

Replace characters from a column of a data frame R

I have a data frame a <- runif (10) b <- letters [1:10] c <- c(rep ("A-B", 4), rep("A_C", 6)) data1 <- data.frame (a, b, c) data1 And I wan to replace _ in A_C of column c for - to have a data frame like data2: z <- c(rep ("A-B", 4), rep("A-C",…
AEM
  • 829
  • 1
  • 8
  • 20
47
votes
2 answers

Return row number(s) for a particular value in a column in a dataframe

I have a data frame (df) and I was wondering how to return the row number(s) for a particular value (2585) in the 4th column (height_chad1) of the same data frame? I've tried: row(mydata_2$height_chad1, 2585) and I get the following error: Error…
pkg77x7
  • 795
  • 2
  • 6
  • 10
47
votes
2 answers

In RStudio/RMarkdown, how to setwd?

setwd in an Rmd file in RStudio does not appear to change the directory in subsequent chunks. Is there a way to set the working directory for good? Example: ```{r} setwd("/tmp") getwd() ``` ```{r} getwd() ``` Output: setwd("/tmp") getwd() ## [1]…
user650654
  • 4,255
  • 2
  • 31
  • 37
47
votes
3 answers

How can I take pairwise parallel maximum between two vectors?

Suppose I have two vectors in R, defined as follows. a = c(3,3,5) b = c(2,4,6) Is there a function that will give me the pairwise maximum between the elements of a and the elements of b, which can be run inside a formula? I tried to do, max(a, b)…
merlin2011
  • 63,368
  • 37
  • 161
  • 279
47
votes
2 answers

R Shiny - add tabPanel to tabsetPanel dynamically (with the use of renderUI)

I am developing a shiny application in which I use tabsetPanel, which is generated when user enters some particular input. Thus, I want to use renderUI function to make a tabsetPanel appear / disappear. My struggle now is that number of tabPanel…
Marta Karas
  • 4,428
  • 10
  • 37
  • 70
47
votes
6 answers

Export data from R to Excel

I am writing codes to export database from R into Excel, I have been trying others codes including: write.table(ALBERTA1, "D:/ALBERTA1.txt", sep="\t") write.csv(ALBERTA1,":\ALBERTA1.csv") your_filename_in_R =…
ntamjo achille
  • 651
  • 1
  • 6
  • 10
47
votes
2 answers

R mtcars dataset, meaning of "vs" variable?

What does the "vs" variable mean in the "mtcars" dataset in R? The helpfile says it means "V/S" but that is not enlightening. Commands: data(mtcars) head(mtcars) ?mtcars
ddunn801
  • 1,836
  • 1
  • 13
  • 20
47
votes
3 answers

Multivariate time series modelling in R

I want do fit some sort of multi-variate time series model using R. Here is a sample of my data: u cci bci cpi gdp dum1 dum2 dum3 dx 16.50 14.00 53.00 45.70 80.63 0 0 1 6.39 17.45 16.00 64.00 …
Karl
  • 4,753
  • 7
  • 41
  • 65
1 2 3
99
100