Learn R Programming

ff (version 4.0.4)

Extract.ffdf: Reading and writing data.frames (ffdf)

Description

These are the main methods for reading and writing data from ffdf objects.

Usage

# S3 method for ffdf
[(x, i, j, drop = ncols == 1)
# S3 method for ffdf
[(x, i, j) <- value
# S3 method for ffdf
[[(x, i, j, exact = TRUE)
# S3 method for ffdf
[[(x, i, j) <- value
# S3 method for ffdf
$(x, i)
# S3 method for ffdf
$(x, i) <- value

Arguments

x

an ff object

i

a row subscript or a matrix subscript or a list subscript

j

a column subscript

drop

logical. If TRUE the result is coerced to the lowest possible dimension. The default is to drop if only one column is left, but not to drop if only one row is left.

value

A suitable replacement value: it will be repeated a whole number of times if necessary and it may be coerced: see the Coercion section. If NULL, deletes the column if a single column is selected with [[<- or $<-.

exact

logical: see [, and applies to column names.

Subscript expressions and return values

allowed expression -- example -- returnvalue
row selection x[i, ] data.frame or single row as list if drop=TRUE, like from data.frame
column selection x[ ,i] data.frame or single column as vector unless drop=TRUE, like from data.frame
matrix selection x[cbind(i,j)] vector of the integer-matrix indexed cells (if the column types are compatible)
virtual selection x[i] ffdf with the selected columns only
physical selection x[[i]] the selected ff
physical selection x$i the selected ff

Details

The subscript methods [, [[ and $, behave symmetrical to the assignment functions [<-, [[<- and $<-. What the former return is the assignment value to the latter. A notable exception is assigning NULL in [[<- and $<- which removes the virtual column from the ffdf (and the physical component if it is no longer needed by any virtual column). Creating new columns via [[<- and $<- requires giving a name to the new column (character subscripting). [<- does not allow to create new columns, only to replace existing ones.

See Also

ffdf, Extract.data.frame, Extract.ff

Examples

Run this code
# NOT RUN {
   d <- data.frame(a=letters, b=rev(letters), c=1:26, stringsAsFactors = TRUE)
   x <- as.ffdf(d)

   d[1,]
   x[1,]

   d[1:2,]
   x[1:2,]

   d[,1]
   x[,1]

   d[,1:2]
   x[,1:2]

   d[cbind(1:2,2:1)]
   x[cbind(1:2,2:1)]

   d[1]
   x[1]

   d[[1]]
   x[[1]]

   d$a
   x$a

   d$a[1:2]
   x$a[1:2]

   rm(x); gc()
# }

Run the code above in your browser using DataLab