Questions tagged [r-faq]
The r-faq tag is created to group a limited number of questions discussing problems that come up regularly on the R tag. It is not the official FAQ on R for SO, but should serve as an interesting source of information on common problems.
r-faq
252
questions
30
votes
2
answers
21k
views
Understanding color scales in ggplot2
There are so many ways to define colour scales within ggplot2. After just loading ggplot2 I count 22 functions beginging with scale_color_* (or scale_colour_*) and same number beginging with ...
53
votes
4
answers
36k
views
What does |> (pipe greater than) mean in R?
I have recently come across the code |> in R. It is a vertical line character (pipe) followed by a greater than symbol.
Here is an example:
mtcars |> head()
What is the |> code doing?
121
votes
5
answers
18k
views
What are the differences between R's native pipe `|>` and the magrittr pipe `%>%`?
In R 4.1 (May 2021) a native pipe operator was introduced that is "more streamlined" than previous implementations. I already noticed one difference between the native |> and the magrittr ...
13
votes
1
answer
14k
views
How should I deal with "'someFunction' is not an exported object from 'namespace:somePackage'" error? [closed]
I have this error:
'someFunction' is not an exported object from 'namespace:somePackage'
Does anyone know how to solve it?
16
votes
1
answer
5k
views
How to order data by value within ggplot facets
I have the following data frame:
library(tidyverse)
tdat <- structure(list(term = c("Hepatic Fibrosis / Hepatic Stellate Cell Activation",
"Cellular Effects of Sildenafil (Viagra)", "Epithelial ...
17
votes
1
answer
1k
views
Create a group index for values connected directly and indirectly
I would like to generate indices to group observations based on two columns. But I want groups to be made of observation that share, at least one observation in commons.
In the data below, I want to ...
64
votes
3
answers
179k
views
How to debug "contrasts can be applied only to factors with 2 or more levels" error?
Here are all the variables I'm working with:
str(ad.train)
$ Date : Factor w/ 427 levels "2012-03-24","2012-03-29",..: 4 7 12 14 19 21 24 29 31 34 ...
$ Team ...
13
votes
1
answer
19k
views
`lm` summary not display all factor levels
I am running a linear regression on a number of attributes including two categorical attributes, B and F, and I don't get a coefficient value for every factor level I have.
B has 9 levels and F has ...
21
votes
1
answer
3k
views
What are primitive, internal, builtin, and special functions? [closed]
I have seen that some functions that call C-code are described as primitive, internal, builtin, or special. What are these functions?
107
votes
2
answers
250k
views
What does "The following object is masked from 'package:xxx'" mean?
When I load a package, I get a message stating that:
"The following object is masked from 'package:xxx'
For example, if I load testthat then assertive, I get the following:
library(testthat)
...
39
votes
5
answers
42k
views
dplyr left_join by less than, greater than condition
This question is somewhat related to issues Efficiently merging two data frames on a non-trivial criteria and Checking if date is between two dates in r. And the one I have posted here requesting if ...
30
votes
7
answers
77k
views
R: How to split a data frame into training, validation, and test sets?
I'm using R to do machine learning. Following standard machine learning methodology, I would like to randomly split my data into training, validation, and test data sets. How do I do that in R?
I ...
57
votes
4
answers
46k
views
How do I get a list of built-in data sets in R?
Can someone please help how to get the list of built-in data sets and their dependency packages?
19
votes
1
answer
3k
views
Issue when passing variable with dollar sign notation ($) to aes() in combination with facet_grid() or facet_wrap()
I am doing some analysis in ggplot2 at the moment for a project and by chance I stumbled across some (for me) weird behavior that I cannot explain. When I write aes(x = cyl, ...) the plot looks ...
48
votes
4
answers
108k
views
Read SAS sas7bdat data into R
What options does R have for reading files in the native SAS format, sas7bdat, into R?
The NCES Common Core, for example, contains an extensive repository of data files saved in this format. For ...