Reading and writing data.frames (ffdf)
Extract.ffdf.rdThese are the main methods for reading and writing data from ffdf objects.
Usage
# S3 method for class 'ffdf'
x[i, j, drop = ncols == 1]
# S3 method for class 'ffdf'
x[i, j] <- value
# S3 method for class 'ffdf'
x[[i, j, exact = TRUE]]
# S3 method for class 'ffdf'
x[[i, j]] <- value
# S3 method for class 'ffdf'
x$i
# S3 method for class 'ffdf'
x$i <- valueArguments
- 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.
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.
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 |
Examples
d <- data.frame(a=letters, b=rev(letters), c=1:26, stringsAsFactors = TRUE)
x <- as.ffdf(d)
d[1,]
#> a b c
#> 1 a z 1
x[1,]
#> a b c
#> 1 a z 1
d[1:2,]
#> a b c
#> 1 a z 1
#> 2 b y 2
x[1:2,]
#> a b c
#> 1 a z 1
#> 2 b y 2
d[,1]
#> [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
x[,1]
#> [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
d[,1:2]
#> a b
#> 1 a z
#> 2 b y
#> 3 c x
#> 4 d w
#> 5 e v
#> 6 f u
#> 7 g t
#> 8 h s
#> 9 i r
#> 10 j q
#> 11 k p
#> 12 l o
#> 13 m n
#> 14 n m
#> 15 o l
#> 16 p k
#> 17 q j
#> 18 r i
#> 19 s h
#> 20 t g
#> 21 u f
#> 22 v e
#> 23 w d
#> 24 x c
#> 25 y b
#> 26 z a
x[,1:2]
#> a b
#> 1 a z
#> 2 b y
#> 3 c x
#> 4 d w
#> 5 e v
#> 6 f u
#> 7 g t
#> 8 h s
#> 9 i r
#> 10 j q
#> 11 k p
#> 12 l o
#> 13 m n
#> 14 n m
#> 15 o l
#> 16 p k
#> 17 q j
#> 18 r i
#> 19 s h
#> 20 t g
#> 21 u f
#> 22 v e
#> 23 w d
#> 24 x c
#> 25 y b
#> 26 z a
d[cbind(1:2,2:1)]
#> [1] "z" "b"
x[cbind(1:2,2:1)]
#> [1] z b
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
d[1]
#> a
#> 1 a
#> 2 b
#> 3 c
#> 4 d
#> 5 e
#> 6 f
#> 7 g
#> 8 h
#> 9 i
#> 10 j
#> 11 k
#> 12 l
#> 13 m
#> 14 n
#> 15 o
#> 16 p
#> 17 q
#> 18 r
#> 19 s
#> 20 t
#> 21 u
#> 22 v
#> 23 w
#> 24 x
#> 25 y
#> 26 z
x[1]
#> ffdf (all open) dim=c(26,1), dimorder=c(1,2) row.names=NULL
#> ffdf virtual mapping
#> PhysicalName VirtualVmode PhysicalVmode AsIs VirtualIsMatrix
#> a a integer integer FALSE FALSE
#> PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol
#> a FALSE 1 1 1
#> PhysicalIsOpen
#> a TRUE
#> ffdf data
#> a
#> 1 a
#> 2 b
#> 3 c
#> 4 d
#> 5 e
#> 6 f
#> 7 g
#> 8 h
#> : :
#> 19 s
#> 20 t
#> 21 u
#> 22 v
#> 23 w
#> 24 x
#> 25 y
#> 26 z
d[[1]]
#> [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
x[[1]]
#> ff (open) integer length=26 (26) levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
#> [1] [2] [3] [4] [5] [6] [7] [8] [19] [20] [21] [22] [23] [24] [25]
#> a b c d e f g h : s t u v w x y
#> [26]
#> z
d$a
#> [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
x$a
#> ff (open) integer length=26 (26) levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
#> [1] [2] [3] [4] [5] [6] [7] [8] [19] [20] [21] [22] [23] [24] [25]
#> a b c d e f g h : s t u v w x y
#> [26]
#> z
d$a[1:2]
#> [1] a b
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
x$a[1:2]
#> [1] a b
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
rm(x); gc()
#> used (Mb) gc trigger (Mb) max used (Mb)
#> Ncells 1109566 59.3 2239654 119.7 2239654 119.7
#> Vcells 2015970 15.4 8388608 64.0 5871749 44.8