Skip to main content
Filter by
Sorted by
Tagged with
34 votes
2 answers
29k views

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 ...
LulY's user avatar
  • 1,385
141 votes
5 answers
25k views

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 ...
sieste's user avatar
  • 9,177
16 votes
1 answer
5k views

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 ...
littleworth's user avatar
  • 5,199
67 votes
3 answers
197k views

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 ...
Troy's user avatar
  • 733
21 votes
1 answer
3k views

I have seen that some functions that call C-code are described as primitive, internal, builtin, or special. What are these functions?
Richie Cotton's user avatar
113 votes
2 answers
263k views

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) library(...
Richie Cotton's user avatar
30 votes
7 answers
80k views

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 ...
stackoverflowuser2010's user avatar
19 votes
1 answer
4k views

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 ...
Christoph's user avatar
  • 575
134 votes
10 answers
107k views

I have a file: ABCD.csv The length before the .csv is not fixed and vary in any length. How can I extract the portion before the .csv?
Matrix.cursor's user avatar
67 votes
1 answer
12k views

on.exit calls code when a function exits, but how and when should I use it?
Richie Cotton's user avatar
7 votes
4 answers
67k views

What is the difference between = and ==? I have found cases where the double equal sign will allow my script to run while one equal sign produces an error message. When should I use == instead of =?
bubbalouie's user avatar
45 votes
5 answers
338k views

I got the error message: Error: object 'x' not found Or a more complex version like Error in mean(x) : error in evaluating the argument 'x' in selecting a method for function 'mean': ...
Richie Cotton's user avatar
45 votes
1 answer
87k views

I received the error Error in <my code> : target of assignment expands to non-language object or Error in <my code> : invalid (do_set) left-hand side to assignment or Error in <my ...
Richie Cotton's user avatar
213 votes
7 answers
694k views

I have seen the use of %>% (percent greater than percent) function in some packages like dplyr and rvest. What does it mean? Is it a way to write closure blocks in R?
alfakini's user avatar
  • 4,747
18 votes
2 answers
12k views

Note: The title of this question has been edited to make it the canonical question for issues when plyr functions mask their dplyr counterparts. The rest of the question remains unchanged. Suppose I ...
Ignacio's user avatar
  • 7,958
300 votes
10 answers
242k views

I want to use dplyr::mutate() to create multiple new columns in a data frame. The column names and their contents should be dynamically generated. Example data from iris: library(dplyr) iris <- ...
Timm S.'s user avatar
  • 5,445
723 votes
19 answers
1.1m views

I tried to install a package, using install.packages("foobarbaz") but received the warning Warning message: package 'foobarbaz' is not available (for R version x.y.z) Why doesn't R think that the ...
Richie Cotton's user avatar
163 votes
18 answers
206k views

In a dataset with multiple observations for each subject. For each subject I want to select the row which have the maximum value of 'pt'. For example, with a following dataset: ID <- c(1,1,1,2,2,...
Xinting WANG's user avatar
  • 1,985
12 votes
1 answer
1k views

I am trying to extract values from a vector using numeric vectors expressed in two seemingly equivalent ways: x <- c(1,2,3) x[2:3] # [1] 2 3 x[1+1:3] # [1] 2 3 NA I am confused why the ...
Marc's user avatar
  • 776
71 votes
3 answers
66k views

df <- structure(list(`a a` = 1:3, `a b` = 2:4), .Names = c("a a", "a b" ), row.names = c(NA, -3L), class = "data.frame") and the data looks like a a a b 1 1 2 2 2 3 3 3 4 Following ...
Flux's user avatar
  • 845
38 votes
3 answers
30k views

How to generate sequences of r objects from n objects? I'm looking for a way to do either permutations or combinations, with/without replacement, with distinct and non-distinct items (aka multisets). ...
Randy Lai's user avatar
  • 3,194
287 votes
2 answers
161k views

What are the main differences between .RData, .Rda and .Rds files? Are there differences in compression, etc.? When should each type be used? How can one type be converted to another?
Carlos Cinelli's user avatar
127 votes
21 answers
311k views

Someone should have asked this already, but I couldn't find an answer. Say I have: x = data.frame(q=1,w=2,e=3, ...and many many columns...) what is the most elegant way to rename an arbitrary ...
qoheleth's user avatar
  • 2,319
39 votes
4 answers
29k views

I have data like this, where some "name" occurs more than three times: df <- data.frame(name = c("a", "a", "a", "b", "b", "c", "c", "c", "c"), x = 1:9) name x 1 a 1 2 a 2 3 a 3 4 b ...
SJSU2013's user avatar
  • 675
69 votes
10 answers
52k views

What is the most effective (ie efficient / appropriate) way to clean up a factor containing multiple levels that need to be collapsed? That is, how to combine two or more factor levels into one. Here'...
Ricardo Saporta's user avatar

1
2 3 4 5 6