Top "R-faq" questions

The r-faq tag is created to group a limited number of questions discussing problems that come up regularly on the R tag.

Remove rows with all or some NAs (missing values) in data.frame

I'd like to remove the lines in this data frame that: a) contain NAs across all columns. Below is my …

r dataframe filter missing-data r-faq
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 …

r dataframe r-faq
Plot two graphs in same plot in R

I would like to plot y1 and y2 in the same plot. x <- seq(-2, 2, 0.05) y1 <- …

r plot ggplot2 r-faq
How to join (merge) data frames (inner, outer, left, right)

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), …

r join merge dataframe r-faq
Counting the number of elements with the values of x in a vector

I have a vector of numbers: numbers <- c(4,23,4,23,5,43,54,56,657,67,67,435, 453,435,324,34,456,56,567,65,34,435) How can I have R count the number of times …

r vector count r-faq
How to sort a dataframe by multiple column(s)

I want to sort a data.frame by multiple columns. For example, with the data.frame below I would like …

r sorting dataframe r-faq
Extracting specific columns from a data frame

I have an R data frame with 6 columns, and I want to create a new dataframe that only has three …

r dataframe r-faq
How to convert a factor to integer\numeric without loss of information?

When I convert a factor to a numeric or integer, I get the underlying level codes, not the values as …

r casting r-faq
Create an empty data.frame

I'm trying to initialize a data.frame without any rows. Basically, I want to specify the data types for each …

r dataframe r-faq
Test if a vector contains a given element

How to check if a vector contains a given value?

r vector r-faq