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
55
votes
1 answer

What exactly is a connection in R?

I've read through and successfully use ?connections in R but I really don't understand what they are. I get that I can download a file, read and write a compressed file, ... (that is I understand what the result of using a conection (open, do stuff,…
andrew wong
  • 827
  • 1
  • 7
  • 9
55
votes
5 answers

How do I add a URL to R markdown?

I want to refer a URL link to the R markdown and I already tried the input such as "addlink" or "address <- ...." Both of them do not work. How can I add a link in R markdown? Thanks! EDIT: op's code from comment was {r} [linked phrase]…
Jennifer Liu
  • 571
  • 1
  • 5
  • 6
55
votes
7 answers

How to hold figure position with figure caption in pdf output of knitr?

I am using knitr (1.9.5 and 1.9.17) and rmarkdown (0.5.3.1), and would like to hold figure position in the pdf output. The generated pdf file is working fine when chunk option fig.pos="H" is used. However, the figure position is not hold when…
Bangyou
  • 9,462
  • 16
  • 62
  • 94
55
votes
2 answers

R:how to get grep to return the match, rather than the whole string

I have what is probably a really dumb grep in R question. Apologies, because this seems like it should be so easy - I'm obviously just missing something. I have a vector of strings, let's call it alice. Some of alice is printed out…
Mike Dewar
  • 10,945
  • 14
  • 49
  • 65
55
votes
1 answer

How to rotate only text in annotation in ggplot?

I have a plot like this: fake = data.frame(x=rnorm(100), y=rnorm(100)) ggplot(data=fake, aes(x=x, y=y)) + geom_point() + theme_bw() + geom_vline(xintercept=-1, linetype=2, color="red") + annotate("text", x=-1, y=-1, label="Helpful annotation",…
half-pass
  • 1,851
  • 4
  • 22
  • 33
55
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,438
  • 4
  • 25
  • 35
55
votes
5 answers

Overlap join with start and end positions

Consider the following data.tables. The first defines a set of regions with start and end positions for each group 'x': library(data.table) d1 <- data.table(x = letters[1:5], start = c(1,5,19,30, 7), end = c(3,11,22,39,25)) setkey(d1, x, start) # …
MrFlick
  • 195,160
  • 17
  • 277
  • 295
55
votes
4 answers

Change the color and font of text in Shiny App

I am using below code in server.R to display the text in the main panel. This is working exactly the way it should work. output$text1 <- renderText({ if(input$ag == 0) return(NULL) return('First 20 rows for requested AG') }) Is there any way to…
Piyush
  • 1,571
  • 4
  • 14
  • 21
55
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
  • 919
  • 1
  • 9
  • 22
55
votes
5 answers

How can you read a CSV file in R with different number of columns

I have a sparse data set, one whose number of columns vary in length, in a csv format. Here is a sample of the file text. 12223, University 12227, bridge, Sky 12828, Sunset 13801, Ground 14853, Tranceamerica 14854, San Francisco 15595, shibuya,…
CompChemist
  • 903
  • 2
  • 8
  • 15
55
votes
4 answers

How can I know if R is running on 64 bits versus 32?

My version output is: > version _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 …
maziar
  • 663
  • 1
  • 6
  • 8
55
votes
3 answers

Generate a set of random unique integers from an interval

I am trying to build some machine learning models, so I need training data and a validation data so suppose I have N number of examples, I want to select random x examples in a data frame. For example, suppose I have 100 examples, and I need 10…
Low Yi Xiang
  • 697
  • 1
  • 5
  • 10
55
votes
2 answers

Unlist a list of dataframes

This is possibly a really simple question. I have a list of dataframes (df1, df2.... dfn), i.e. each element of the list is a dataframe. So basically, the list was created like this: mylist = list(df1, df2,...., dfn) But how do I do the reverse,…
user702432
  • 11,898
  • 21
  • 55
  • 70
55
votes
1 answer

Plot data in descending order as appears in data frame

I've been battling to order and plot a simple dataframe as a bar chart in ggplot2. I want to plot the data as it appears, so that the values ('count' variable) for the corresponding categories (e.g. 'humans', 'male') are plotted from high to low.…
Ben G Small
  • 585
  • 1
  • 5
  • 12
55
votes
6 answers

Getting imported json data into a data frame

I have a file containing over 1500 json objects that I want to work with in R. I've been able to import the data as a list, but am having trouble coercing it into a useful structure. I want to create a data frame containing a row for each json…
Andrew Staroscik
  • 2,675
  • 1
  • 24
  • 26
1 2 3
99
100