Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"..1" in the body of "[[.data.frame"

When I look at the contents of [[.data.frame on my PC, this is what I get:

> get("[[.data.frame")
function (x, ..., exact = TRUE) 
{
    na <- nargs() - (!missing(exact))
    if (!all(names(sys.call()) %in% c("", "exact"))) 
        warning("named arguments other than 'exact' are discouraged")
    if (na < 3L) 
        (function(x, i, exact) if (is.matrix(i)) 
            as.matrix(x)[[i]]
        else .subset2(x, i, exact = exact))(x, ..., exact = exact)
    else {
        col <- .subset2(x, ..2, exact = exact)
        i <- if (is.character(..1)) 
            pmatch(..1, row.names(x), duplicates.ok = TRUE)
        else ..1
        .subset2(col, i, exact = exact)
    }
}
<environment: namespace:base>

I've gotten used to ..., but this is the first time I saw ..1 and ..2. A quick search both in R help and Google returned mostly rubbish, since the dots are often interpreted as placeholders, so I'm hoping someone here can give me a pointer? Or am I missing something dreadfully obvious? Where do these come from and how can I use them?

like image 413
Nick Sabbe Avatar asked Aug 30 '11 12:08

Nick Sabbe


People also ask

What is in a data frame?

A DataFrame is a data structure that organizes data into a 2-dimensional table of rows and columns, much like a spreadsheet. DataFrames are one of the most common data structures used in modern data analytics because they are a flexible and intuitive way of storing and working with data.

What is the frame data type?

Explanation: A frame is an artificial intelligence data structure used to divide knowledge into substructures by representing “stereotyped situations.”.

What is the size of data frame?

The long answer is the size limit for pandas DataFrames is 100 gigabytes (GB) of memory instead of a set number of cells. In effect, this benchmark is so large that it would take an extraordinarily large data set to reach it.

How do I find a specific value in a DataFrame in R?

You can use the following basic syntax to find the rows of a data frame in R in which a certain value appears in any of the columns: library(dplyr) df %>% filter_all(any_vars(. %in% c('value1', 'value2', ...)))


2 Answers

This is a way to reference the 1st, 2nd, ... elements of the special pairlist that is .... So ..1 is the way to refer to the first element of ..., ..2 refers to the second element of ... and so on.

This is mentioned in the R Internals manual in section 1.5.2 Dot-dot-dot arguments, the relevant bit of which is:

The value of ... is a (special) pairlist whose elements are referred to by the special symbols ..1, ..2, ... which have the DDVAL bit set: when one of these is encountered it is looked up (via ddfindVar) in the value of the ... symbol in the evaluation frame.

like image 60
Gavin Simpson Avatar answered Oct 26 '22 02:10

Gavin Simpson


To add to Gavin's answer:

They are also mentioned briefly in the help page for reserved words (?Reserved).

A really simple example of usage is

f <- function(...) print(..1)
f(x = 99)  #prints 99
f()        #throws an error
like image 25
Richie Cotton Avatar answered Oct 26 '22 01:10

Richie Cotton