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.

How can I view the source code for a function?

I want to look at the source code for a function to see how it works. I know I can …

r function r-faq
Filter data.frame rows by a logical condition

I want to filter rows from a data.frame based on a logical condition. Let's suppose that I have data …

r dataframe subset r-faq
Concatenate a vector of strings/character

If I have a vector of type character, how can I concatenate the values into string? Here's how I would …

r string r-faq
What does %>% function mean in R?

I have seen the use of %>% (percent greater than percent) function in some packages like dplyr and rvest. What …

r syntax dplyr magrittr r-faq
How to remove all whitespace from a string?

So " xx yy 11 22 33 " will become "xxyy112233". How can I achieve this?

r regex string r-faq
How to write trycatch in R

I want to write trycatch code to deal with error in downloading from the web. url <- c( "http://…

r exception exception-handling try-catch r-faq
How to find the statistical mode?

In R, mean() and median() are standard functions which do what you'd expect. mode() tells you the internal storage mode …

r statistics r-faq
Error: unexpected symbol/input/string constant/numeric constant/SPECIAL in my code

I received one of these errors. Error: unexpected symbol in "<my code>" Error: unexpected input in "<my …

r r-faq
Add regression line equation and R^2 on graph

I wonder how to add regression line equation and R^2 on the ggplot. My code is: library(ggplot2) df <…

r ggplot2 linear-regression r-faq
Add legend to ggplot2 line plot

I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want …

r ggplot2 legend r-faq