R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization, and general computing. Please provide minimal and reproducible example(s) along with the desired output. Use `dput()` for data and specify all non-base packages with `library()` calls. Do not embed pictures for data or code, use indented code blocks instead. For statistics related questions, use https://stats.stackexchange.com.
When discussing performance with colleagues, teaching, sending a bug report or searching for guidance on mailing lists and here on Stack Overflow, a reproducible example is often asked and always ...
I want to sort a data.frame by multiple columns. For example, with the data.frame below I would like to sort by column z (descending) then by column b (ascending):
dd <- data.frame(b = factor(c("...
asked Aug 18 '09 at 21:33
Given two data frames:
df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3)))
df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1)))
...
asked Aug 19 '09 at 13:18
Dan Goldstein
20.6k1717 gold badges3333 silver badges4141 bronze badges
Whenever I want to do something "map"py in R, I usually try to use a function in the apply family.
However, I've never quite understood the differences between them -- how {sapply, lapply, etc.} ...
asked Aug 17 '10 at 18:31
grautur
27.1k3232 gold badges8989 silver badges122122 bronze badges
I have a number of columns that I would like to remove from a data frame. I know that we can delete them individually using something like:
df$x <- NULL
But I was hoping to do this with fewer ...
asked Jan 5 '11 at 14:34
Btibert3
32.1k3939 gold badges119119 silver badges162162 bronze badges
I'd like to remove the lines in this data frame that:
a) contain NAs across all columns. Below is my example data frame.
gene hsap mmul mmus rnor cfam
1 ENSG00000208234 0 NA NA ...
asked Feb 1 '11 at 11:52
Benoit B.
9,98288 gold badges2222 silver badges2929 bronze badges
Overview
I'm relatively familiar with data.table, not so much with dplyr. I've read through some dplyr vignettes and examples that have popped up on SO, and so far my conclusions are that:
data....
asked Jan 29 '14 at 15:21
BrodieG
47.1k77 gold badges7676 silver badges126126 bronze badges
I have a data frame and some columns have NA values.
How do I replace these NA values with zeroes?
asked Nov 17 '11 at 3:45
Renato Dinhani
28.1k4646 gold badges122122 silver badges189189 bronze badges
What are the differences between the assignment operators = and <- in R?
I know that operators are slightly different, as this example shows
x <- y <- 5
x = y = 5
x = y <- 5
x <- y = ...
asked Nov 16 '09 at 12:14
csgillespie
52.4k1313 gold badges127127 silver badges169169 bronze badges
Apparently, folk have figured out how to make xkcd style graphs in Mathematica and in LaTeX. Can we do it in R? Ggplot2-ers? A geom_xkcd and/or theme_xkcd?
I guess in base graphics, par(xkcd=TRUE)? ...
asked Oct 1 '12 at 14:22
jebyrnes
8,22044 gold badges2525 silver badges2929 bronze badges
I have a plot where the x-axis is a factor whose labels are long. While probably not an ideal visualization, for now I'd like to simply rotate these labels to be vertical. I've figured this part out ...
asked Aug 25 '09 at 21:05
When I convert a factor to a numeric or integer, I get the underlying level codes, not the values as numbers.
f <- factor(sample(runif(5), 20, replace = TRUE))
## [1] 0.0248644019011408 0....
asked Aug 5 '10 at 18:53
Adam SO
8,73177 gold badges2424 silver badges2727 bronze badges
I would like to plot y1 and y2 in the same plot.
x <- seq(-2, 2, 0.05)
y1 <- pnorm(x)
y2 <- pnorm(x, 1, 1)
plot(x, y1, type = "l", col = "red")
plot(x, y2, type = "l", col = "green")
But ...
What is the difference between require() and library()?
asked Apr 8 '11 at 13:09
Marco
8,17677 gold badges2828 silver badges4545 bronze badges
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 ...
asked Sep 8 '14 at 10:11
Richie Cotton
103k3838 gold badges217217 silver badges338338 bronze badges