136 Answered Questions for the topic R
R
09/10/19
How to disable "Save workspace image?" prompt in R?
When I exit the interactive R shell, it displays an annoying prompt every time:<pre>>>Save workspace image? [y/n/c]: n</pre>I'm always answering "no" to it, because if I wished to...
more
R
09/10/19
Omit rows containing specific column of NA?
I want to know how to omit `NA` values in a data frame, but only in some columns I am interested in.For example, DF <- data.frame(x = c(1, 2, 3), y = c(0, 10, NA), z=c(NA, 33, 22))but I only...
more
R
09/10/19
Remove duplicated rows using dplyr?
I have a data.frame like this - set.seed(123) df = data.frame(x=sample(0:1,10,replace=T),y=sample(0:1,10,replace=T),z=1:10) > df x y z 1 0 1 1 2 1 0 2 3 0 1 3 ...
more
R
09/09/19
How can I remove an element from a list?
I have a list and I want to remove a single element from it. How can I do this?I've tried looking up what I think the obvious names for this function would be in the reference manual and I haven't...
more
R
09/09/19
How to reorder data.table columns (without copying)?
I'd like to reorder columns in my `data.table` `x`, given a character vector of column names, `neworder`: library(data.table) x <- data.table(a = 1:3, b = 3:1, c = runif(3)) neworder...
more
R
09/07/19
Paste multiple columns together?
I have a bunch of columns in a dataframe which I want to paste together (seperated by "-") as follows: data <- data.frame('a' = 1:3, 'b' = c('a','b','c'), ...
more
R
09/06/19
How to create an empty R vector to add new items?
I want to use R in Python, as provided by the module Rpy2. I notice that R has very convenient `[]` operations by which you can extract the specific columns or lines. How could I achieve such a...
more
R
09/05/19
Drop data frame columns by name?
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 <- NULLBut I was hoping to do this with fewer...
more
R
09/05/19
How to get row from R data.frame?
I have a data.frame with column headers. How can I get a specific row from the data.frame as a list (with the column headers as keys for the list)?Specifically, my data.frame is <pre> A ...
more
R
09/03/19
What are the differences between vector and list data types in R?
What are the main differences between vector and list data types in R? What are the advantages or disadvantages of using (or not) these two data types?I would appreciate seeing examples that...
more
R
09/01/19
How to delete the first row of a dataframe in R?
I have a dataset with 11 columns with over a 1000 rows each. The columns were labeled V1, V2, V11, etc..I replaced the names with something more useful to me using the "c" command.I didn't realize...
more
R
09/01/19
How do I save my plots to a PDF file?
R
08/29/19
How to create a numeric vector of zero length in R?
I wonder, how can I create a numeric zero-length vector in R?
R
08/24/19
How to increase font size in a plot in R?
I am confused. What is the right way to increase font size of text in the title, labels and other places of a plot? For example x <- rnorm(100) hist(x, xlim=range(x), xlab= "Variable...
more
R
08/20/19
Opposite of %in%?
A categorical variable V1 in a data frame D1 can have values represented by the letters from A to Z. I want to create a subset D2, which excludes some values, say, B, N and T. Basically, I want a...
more
R
08/18/19
How to set limits for axes in ggplot2 R plots?
I plot the following: library(ggplot2) carrots <- data.frame(length = rnorm(500000, 10000, 10000)) cukes <- data.frame(length = rnorm(50000, 10000, 20000)) carrots$veg <-...
more
R
08/15/19
How to substract a column by row?
I want to do an easy subtract in R, but I don't know how to solve it. I would like to know if I have to do a loop or if there is a function.
I have a column with numeric variables, and I would...
more
R
08/09/19
Remove an entire column from a data.frame in R?
Does anyone know how to remove an entire column from a data.frame in R? For example if I am given this data.frame: > head(data) chr genome region 1 chr1 hg19_refGene CDS ...
more
R
08/04/19
How to succinctly write a formula with many variables from a data frame?
Suppose I have a response variable and a data containing three covariates (as a toy example): y = c(1,4,6) d = data.frame(x1 = c(4,-1,3), x2 = c(3,9,8), x3 = c(4,-4,-2))I want to fit a linear...
more
R
07/30/19
How do I read data into R?
R
07/16/19
Scheduling R Script?
I have written an R script that pulls some data from a database, performs several operations on it and post the output to a new database. I would like this script to run every day at a specific...
more
R
07/14/19
Importing Excel files into R, xlsx or xls?
What is the best way to import an excel 2007 (.xlsx) file into R? I keep receiving this error: Error in .jnew("java/io/FileInputStream", file) : java.io.FileNotFoundException:...
more
R
07/06/19
Mean per group in a data.frame?
I have a `data.frame` and I need to calculate the mean per group (i.e. per `Month`, below). Name Month Rate1 Rate2 Aira 1 12 23 Aira 2 18 73 ...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.