Skip to main content
The 2024 Developer Survey results are live! See the results
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 2k times
Part of R Language Collective
17
2464 votes
23 answers
469k 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
251 votes
9 answers
335k views

Reshaping data.frame from wide to long format

Common data wrangling task
M--'s user avatar
383 votes
15 answers
494k views

How to reshape data from long to wide format

Common data wrangling task
M--'s user avatar
50 votes
6 answers
58k views

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

Common question
M--'s user avatar
1547 votes
14 answers
1.8m views

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

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

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

High view count
Berthold's user avatar
1500 votes
22 answers
1.4m views

Sort (order) data frame rows by multiple columns

High view count
M--'s user avatar
393 votes
16 answers
584k 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
708 votes
14 answers
1.1m views

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

High view count
Berthold's user avatar
957 votes
9 answers
378k views

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

High view count
Berthold's user avatar
371 votes
5 answers
642k views

Plotting two variables as lines using ggplot2 on the same graph

Common misconception about ggplot and base R
Ian Campbell's user avatar
121 votes
5 answers
18k 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
371 votes
5 answers
642k 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
716 votes
19 answers
1.0m 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
311 votes
7 answers
69k views

Why are these numbers not equal?

The question is asked repeatedly. Beginners often don't understand flaoting point arithmetic.
G5W's user avatar
158 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
28 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
110 votes
10 answers
233k views

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

Commonly encountered error
M--'s user avatar
30 votes
2 answers
21k views

Understanding color scales in ggplot2

Commonly used functions with ggplot2
M--'s user avatar
2
  • Is it possible to change the order of the questions? "Reshaping data.frame from wide to long format", "How to reshape data from long to wide format", and "Convert data from long format to wide format with multiple measure columns" should be all next to each other. Commented Oct 25, 2023 at 22:42
  • 4
    @BrianDiggs thank you for this suggestion! I just made that change. Collective admins and Recognized Members can change the order of items in collections.
    – Sasha
    Commented Oct 26, 2023 at 14:28