Questions tagged [r-faq]

The r-faq tag is created to group a limited number of questions discussing problems that come up regularly on the R tag. It is not the official FAQ on R for SO, but should serve as an interesting source of information on common problems.

The tag is created to group a limited number of questions discussing problems that come up regularly on the tag. It is not the official FAQ on R for SO, but should serve as an interesting source of information on common problems.

The "real" original R-FAQ is reliably found at: https://cran.r-project.org/doc/FAQ/R-FAQ.html and is typically the first google hit for "r-faq".

251 questions
45
votes
4 answers

Calculate group mean, sum, or other summary stats. and assign column to original data

I want to calculate mean (or any other summary statistics of length one, e.g. min, max, length, sum) of a numeric variable ("value") within each level of a grouping variable ("group"). The summary statistic should be assigned to a new variable which…
Mike
  • 761
  • 2
  • 7
  • 5
45
votes
5 answers

What does "Error: object '' not found" mean?

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': Error: object 'x' not found What does this mean?
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
45
votes
6 answers

How to get help in R?

What is the possible documentation available for R package? For example I try to understand sp package. In addition to help(sp), what are the other functions for searching through help and documentation?
Tomas Greif
  • 21,685
  • 23
  • 106
  • 155
43
votes
8 answers

Changing date format in R

I have some very simple data in R that needs to have its date format changed: date midpoint 1 31/08/2011 0.8378 2 31/07/2011 0.8457 3 30/06/2011 0.8147 4 31/05/2011 0.7970 5 30/04/2011 0.7877 6 31/03/2011 0.7411 7 …
indigo
  • 1,067
  • 4
  • 15
  • 26
43
votes
1 answer

Error in : target of assignment expands to non-language object

I received the error Error in : target of assignment expands to non-language object or Error in : invalid (do_set) left-hand side to assignment or Error in : invalid (NULL) left side of assignment What does it mean,…
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
43
votes
2 answers

FAQ markup to R data structure

I'm reading the R FAQ source in texinfo, and thinking that it would be easier to manage and extend if it was parsed as an R structure. There are several existing examples related to this: the fortunes package bibtex entries Rd files each with some…
baptiste
  • 75,767
  • 19
  • 198
  • 294
41
votes
7 answers

Why can't I get a p-value smaller than 2.2e-16?

I've found this issue with t-tests and chi-squared in R but I assume this issue applies generally to other tests. If I do: a <- 1:10 b <- 100:110 t.test(a,b) I get: t = -64.6472, df = 18.998, p-value < 2.2e-16. I know from the comments that…
arandomlypickedname
  • 1,349
  • 1
  • 11
  • 12
41
votes
2 answers

How to end a 'debug' mode?

In RStudio, I started a debug mode by debug(ls) ls() Then I do not know how to end this mode. The prompt changed to Browse[2]> How can I end this debugging mode?
user67275
  • 1
  • 9
  • 38
  • 64
41
votes
6 answers

How to find all functions in an R package?

What is the best way to find all the functions associated in a package?? I am currently going through the caTools package. If I do ?caTools or ??caTools I am simply going to get search for functions called that but not the functions in the package.…
jessica
  • 1,325
  • 2
  • 21
  • 35
39
votes
3 answers

How to get mean, median, and other statistics over entire matrix, array or dataframe?

I know this is a basic question but for some strange reason I am unable to find an answer. How should I apply basic statistical functions like mean, median, etc. over entire array, matrix or dataframe to get unique answers and not a vector over rows…
user2760
  • 2,273
  • 7
  • 25
  • 34
39
votes
5 answers

Dealing with TRUE, FALSE, NA and NaN

Here is a vector a <- c(TRUE, FALSE, FALSE, NA, FALSE, TRUE, NA, FALSE, TRUE) I'd like a simple function that returns TRUE everytime there is a TRUE in "a", and FALSE everytime there is a FALSE or a NA in "a". The three following things do not…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
39
votes
1 answer

What are the differences between concatenating strings with cat() and paste()?

What are the differences between concatenating strings with cat and paste? In particular, I have the following questions. Why does R not use the double quote (") when it prints the results of calling cat (but it uses quotes when using paste)? >…
Sam
  • 4,357
  • 6
  • 36
  • 60
38
votes
5 answers

dplyr left_join by less than, greater than condition

This question is somewhat related to issues Efficiently merging two data frames on a non-trivial criteria and Checking if date is between two dates in r. And the one I have posted here requesting if the feature exist: GitHub issue I am looking to…
rajvijay
  • 1,641
  • 4
  • 23
  • 28
38
votes
4 answers

Subset data frame based on number of rows per group

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 4 5 b 5 6 c 6 7 c 7 8 c 8 9 c 9 I…
SJSU2013
  • 585
  • 3
  • 8
  • 18
38
votes
3 answers

How can I remove all duplicates so that NONE are left in a data frame?

There is a similar question for PHP, but I'm working with R and am unable to translate the solution to my problem. I have this data frame with 10 rows and 50 columns, where some of the rows are absolutely identical. If I use unique on it, I get one…
Lilith-Elina
  • 1,613
  • 4
  • 20
  • 31