Skip to main content
Collection

R Language Frequently Asked Questions

The questions that get asked repeatedly, gathered together in one place. What’s a question every R programmer asks at some point? Add it here! Grab questions from the tag to get them added visibility. This collection also serves as a repository for excellent Q&As for curators to propose as duplicate targets for commonly asked questions.

Created
Active
Last edited
Viewed 3k times
Part of R Language Collective
18
49 votes
4k views
2 minute read
How-to guide

How to write a good R question with a reproducible example

M--'s user avatar
How-to guide for writing good questions in R
M--'s user avatar
2464 votes
23 answers
483k views

How to make a great R reproducible example

This question helps with creating a minimal, but complete and verifiable example that can be reproduced by others in order to answer your question.
M--'s user avatar
261 votes
10 answers
365k views

Reshaping data.frame from wide to long format

Common data wrangling task
M--'s user avatar
386 votes
15 answers
525k views

How to reshape data from long to wide format

Common data wrangling task
M--'s user avatar
53 votes
6 answers
61k views

Convert data from long format to wide format with multiple measure columns

Common question
M--'s user avatar
1570 votes
14 answers
1.9m views

How to join (merge) data frames (inner, outer, left, right)

Common data wrangling task -- high-level post.
Maël's user avatar
988 votes
30 answers
2.2m views

How do I replace NA values with zeros in an R dataframe?

High view count
Berthold's user avatar
1511 votes
21 answers
1.4m views

Sort (order) data frame rows by multiple columns

High view count
M--'s user avatar
403 votes
16 answers
600k views

Order Bars in ggplot2 bar graph

Users often struggle to affect the order in which ggplot plots data. This question contains several good ways to do that.
jdobres's user avatar
716 votes
14 answers
1.2m views

How to convert a factor to integer\numeric without loss of information?

High view count
Berthold's user avatar
969 votes
9 answers
391k views

What are the differences between "=" and "<-" assignment operators?

High view count
Berthold's user avatar
374 votes
5 answers
656k views

Plotting two variables as lines using ggplot2 on the same graph

Common misconception about ggplot and base R
Ian Campbell's user avatar
137 votes
5 answers
23k views

What are the differences between R's native pipe `|>` and the magrittr pipe `%>%`?

It is important to be aware of the differences in the native pipe and that by magrittr
mhovd's user avatar
374 votes
5 answers
656k views

Plotting two variables as lines using ggplot2 on the same graph

Answer

The general approach is to convert the data to long format (using melt() from package reshape or reshape2) or gather()/pivot_longer() from the tidyr package: library("ggplot2") library("...

View answer
rcs's user avatar
Users accustomed to other plotting libraries often miss that ggplot is meant to work with "long" data, and this answer explains a simple example nicely.
jdobres's user avatar
721 votes
19 answers
1.1m views

How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?

Great canonical duplicate target for a common error
Ian Campbell's user avatar
316 votes
7 answers
71k views

Why are these numbers not equal?

The question is asked repeatedly. Beginners often don't understand flaoting point arithmetic.
G5W's user avatar
162 votes
6 answers
54k views

Split comma-separated strings in a column into separate rows

Very frequent question where users wish to separate comma separated string/column `c("a, b")` into separate rows `c("a", "b")`. This dup target mostly focuses on doing this within a `data.frame`.
Maël's user avatar
29 votes
11 answers
10k views

Expand ranges defined by "from" and "to" columns

Common question about how to expand data where every row has a start and end date into repeated observations
SamR's user avatar
111 votes
10 answers
240k views

Problems when trying to load a package in R due to rJava

Commonly encountered error
M--'s user avatar
34 votes
2 answers
28k views

Understanding color scales in ggplot2

Commonly used functions with ggplot2
M--'s user avatar
242 votes
7 answers
180k views

Annotating text on individual facet in ggplot2

Common question with ggplot2 facets
M--'s user avatar
0