Skip to contents

Accessing columns, rows, or cells via $, [[, or [ is mostly similar to regular data frames. However, the

  • [ always returns a similar dataset by default, even if only one column is accessed. The title is modified to from 'Original Title' to 'Original Title [subset]'

  • [[ always returns a vector.

  • $ always returns a vector.

Usage

# S3 method for class 'dataset'
x[i, j, drop = FALSE, ...]

# S3 method for class 'dataset'
x$name

# S3 method for class 'dataset'
x[[i, j, ..., exact = TRUE]]

Arguments

x

A dataset object created with dataset.

i, j

Row and column indices. If j is omitted, i is used as column index.

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.

...

Ignored.

name

A name or a string.

exact

Ignored, with a warning.

See also

Examples

# Subsetting single columns:
iris_dataset[, "Species"]
#> Anderson E (1935). "Iris Dataset [subset]."
#>              Species
#> iris:o1       setosa
#> iris:o2       setosa
#> iris:o3       setosa
#> iris:o4       setosa
#> iris:o5       setosa
#> iris:o6       setosa
#> iris:o7       setosa
#> iris:o8       setosa
#> iris:o9       setosa
#> iris:o10      setosa
#> iris:o11      setosa
#> iris:o12      setosa
#> iris:o13      setosa
#> iris:o14      setosa
#> iris:o15      setosa
#> iris:o16      setosa
#> iris:o17      setosa
#> iris:o18      setosa
#> iris:o19      setosa
#> iris:o20      setosa
#> iris:o21      setosa
#> iris:o22      setosa
#> iris:o23      setosa
#> iris:o24      setosa
#> iris:o25      setosa
#> iris:o26      setosa
#> iris:o27      setosa
#> iris:o28      setosa
#> iris:o29      setosa
#> iris:o30      setosa
#> iris:o31      setosa
#> iris:o32      setosa
#> iris:o33      setosa
#> iris:o34      setosa
#> iris:o35      setosa
#> iris:o36      setosa
#> iris:o37      setosa
#> iris:o38      setosa
#> iris:o39      setosa
#> iris:o40      setosa
#> iris:o41      setosa
#> iris:o42      setosa
#> iris:o43      setosa
#> iris:o44      setosa
#> iris:o45      setosa
#> iris:o46      setosa
#> iris:o47      setosa
#> iris:o48      setosa
#> iris:o49      setosa
#> iris:o50      setosa
#> iris:o51  versicolor
#> iris:o52  versicolor
#> iris:o53  versicolor
#> iris:o54  versicolor
#> iris:o55  versicolor
#> iris:o56  versicolor
#> iris:o57  versicolor
#> iris:o58  versicolor
#> iris:o59  versicolor
#> iris:o60  versicolor
#> iris:o61  versicolor
#> iris:o62  versicolor
#> iris:o63  versicolor
#> iris:o64  versicolor
#> iris:o65  versicolor
#> iris:o66  versicolor
#> iris:o67  versicolor
#> iris:o68  versicolor
#> iris:o69  versicolor
#> iris:o70  versicolor
#> iris:o71  versicolor
#> iris:o72  versicolor
#> iris:o73  versicolor
#> iris:o74  versicolor
#> iris:o75  versicolor
#> iris:o76  versicolor
#> iris:o77  versicolor
#> iris:o78  versicolor
#> iris:o79  versicolor
#> iris:o80  versicolor
#> iris:o81  versicolor
#> iris:o82  versicolor
#> iris:o83  versicolor
#> iris:o84  versicolor
#> iris:o85  versicolor
#> iris:o86  versicolor
#> iris:o87  versicolor
#> iris:o88  versicolor
#> iris:o89  versicolor
#> iris:o90  versicolor
#> iris:o91  versicolor
#> iris:o92  versicolor
#> iris:o93  versicolor
#> iris:o94  versicolor
#> iris:o95  versicolor
#> iris:o96  versicolor
#> iris:o97  versicolor
#> iris:o98  versicolor
#> iris:o99  versicolor
#> iris:o100 versicolor
#> iris:o101  virginica
#> iris:o102  virginica
#> iris:o103  virginica
#> iris:o104  virginica
#> iris:o105  virginica
#> iris:o106  virginica
#> iris:o107  virginica
#> iris:o108  virginica
#> iris:o109  virginica
#> iris:o110  virginica
#> iris:o111  virginica
#> iris:o112  virginica
#> iris:o113  virginica
#> iris:o114  virginica
#> iris:o115  virginica
#> iris:o116  virginica
#> iris:o117  virginica
#> iris:o118  virginica
#> iris:o119  virginica
#> iris:o120  virginica
#> iris:o121  virginica
#> iris:o122  virginica
#> iris:o123  virginica
#> iris:o124  virginica
#> iris:o125  virginica
#> iris:o126  virginica
#> iris:o127  virginica
#> iris:o128  virginica
#> iris:o129  virginica
#> iris:o130  virginica
#> iris:o131  virginica
#> iris:o132  virginica
#> iris:o133  virginica
#> iris:o134  virginica
#> iris:o135  virginica
#> iris:o136  virginica
#> iris:o137  virginica
#> iris:o138  virginica
#> iris:o139  virginica
#> iris:o140  virginica
#> iris:o141  virginica
#> iris:o142  virginica
#> iris:o143  virginica
#> iris:o144  virginica
#> iris:o145  virginica
#> iris:o146  virginica
#> iris:o147  virginica
#> iris:o148  virginica
#> iris:o149  virginica
#> iris:o150  virginica
#> Further metadata: describe(x)

# Subsetting single column to vector:
iris_dataset$Species
#>   [1] setosa     setosa     setosa     setosa     setosa     setosa    
#>   [7] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [13] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [19] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [25] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [31] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [37] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [43] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [49] setosa     setosa     versicolor versicolor versicolor versicolor
#>  [55] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [61] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [67] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [73] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [79] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [85] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [91] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [97] versicolor versicolor versicolor versicolor virginica  virginica 
#> [103] virginica  virginica  virginica  virginica  virginica  virginica 
#> [109] virginica  virginica  virginica  virginica  virginica  virginica 
#> [115] virginica  virginica  virginica  virginica  virginica  virginica 
#> [121] virginica  virginica  virginica  virginica  virginica  virginica 
#> [127] virginica  virginica  virginica  virginica  virginica  virginica 
#> [133] virginica  virginica  virginica  virginica  virginica  virginica 
#> [139] virginica  virginica  virginica  virginica  virginica  virginica 
#> [145] virginica  virginica  virginica  virginica  virginica  virginica 
#> Levels: setosa versicolor virginica
iris_dataset[, "Species"]
#> Anderson E (1935). "Iris Dataset [subset]."
#>              Species
#> iris:o1       setosa
#> iris:o2       setosa
#> iris:o3       setosa
#> iris:o4       setosa
#> iris:o5       setosa
#> iris:o6       setosa
#> iris:o7       setosa
#> iris:o8       setosa
#> iris:o9       setosa
#> iris:o10      setosa
#> iris:o11      setosa
#> iris:o12      setosa
#> iris:o13      setosa
#> iris:o14      setosa
#> iris:o15      setosa
#> iris:o16      setosa
#> iris:o17      setosa
#> iris:o18      setosa
#> iris:o19      setosa
#> iris:o20      setosa
#> iris:o21      setosa
#> iris:o22      setosa
#> iris:o23      setosa
#> iris:o24      setosa
#> iris:o25      setosa
#> iris:o26      setosa
#> iris:o27      setosa
#> iris:o28      setosa
#> iris:o29      setosa
#> iris:o30      setosa
#> iris:o31      setosa
#> iris:o32      setosa
#> iris:o33      setosa
#> iris:o34      setosa
#> iris:o35      setosa
#> iris:o36      setosa
#> iris:o37      setosa
#> iris:o38      setosa
#> iris:o39      setosa
#> iris:o40      setosa
#> iris:o41      setosa
#> iris:o42      setosa
#> iris:o43      setosa
#> iris:o44      setosa
#> iris:o45      setosa
#> iris:o46      setosa
#> iris:o47      setosa
#> iris:o48      setosa
#> iris:o49      setosa
#> iris:o50      setosa
#> iris:o51  versicolor
#> iris:o52  versicolor
#> iris:o53  versicolor
#> iris:o54  versicolor
#> iris:o55  versicolor
#> iris:o56  versicolor
#> iris:o57  versicolor
#> iris:o58  versicolor
#> iris:o59  versicolor
#> iris:o60  versicolor
#> iris:o61  versicolor
#> iris:o62  versicolor
#> iris:o63  versicolor
#> iris:o64  versicolor
#> iris:o65  versicolor
#> iris:o66  versicolor
#> iris:o67  versicolor
#> iris:o68  versicolor
#> iris:o69  versicolor
#> iris:o70  versicolor
#> iris:o71  versicolor
#> iris:o72  versicolor
#> iris:o73  versicolor
#> iris:o74  versicolor
#> iris:o75  versicolor
#> iris:o76  versicolor
#> iris:o77  versicolor
#> iris:o78  versicolor
#> iris:o79  versicolor
#> iris:o80  versicolor
#> iris:o81  versicolor
#> iris:o82  versicolor
#> iris:o83  versicolor
#> iris:o84  versicolor
#> iris:o85  versicolor
#> iris:o86  versicolor
#> iris:o87  versicolor
#> iris:o88  versicolor
#> iris:o89  versicolor
#> iris:o90  versicolor
#> iris:o91  versicolor
#> iris:o92  versicolor
#> iris:o93  versicolor
#> iris:o94  versicolor
#> iris:o95  versicolor
#> iris:o96  versicolor
#> iris:o97  versicolor
#> iris:o98  versicolor
#> iris:o99  versicolor
#> iris:o100 versicolor
#> iris:o101  virginica
#> iris:o102  virginica
#> iris:o103  virginica
#> iris:o104  virginica
#> iris:o105  virginica
#> iris:o106  virginica
#> iris:o107  virginica
#> iris:o108  virginica
#> iris:o109  virginica
#> iris:o110  virginica
#> iris:o111  virginica
#> iris:o112  virginica
#> iris:o113  virginica
#> iris:o114  virginica
#> iris:o115  virginica
#> iris:o116  virginica
#> iris:o117  virginica
#> iris:o118  virginica
#> iris:o119  virginica
#> iris:o120  virginica
#> iris:o121  virginica
#> iris:o122  virginica
#> iris:o123  virginica
#> iris:o124  virginica
#> iris:o125  virginica
#> iris:o126  virginica
#> iris:o127  virginica
#> iris:o128  virginica
#> iris:o129  virginica
#> iris:o130  virginica
#> iris:o131  virginica
#> iris:o132  virginica
#> iris:o133  virginica
#> iris:o134  virginica
#> iris:o135  virginica
#> iris:o136  virginica
#> iris:o137  virginica
#> iris:o138  virginica
#> iris:o139  virginica
#> iris:o140  virginica
#> iris:o141  virginica
#> iris:o142  virginica
#> iris:o143  virginica
#> iris:o144  virginica
#> iris:o145  virginica
#> iris:o146  virginica
#> iris:o147  virginica
#> iris:o148  virginica
#> iris:o149  virginica
#> iris:o150  virginica
#> Further metadata: describe(x)

# Subsetting a single cell in tabular data:
iris_dataset[[1,2]]
#> [1] 3.5

#Subsetting a variable into a vector.
iris_dataset$Species
#>   [1] setosa     setosa     setosa     setosa     setosa     setosa    
#>   [7] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [13] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [19] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [25] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [31] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [37] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [43] setosa     setosa     setosa     setosa     setosa     setosa    
#>  [49] setosa     setosa     versicolor versicolor versicolor versicolor
#>  [55] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [61] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [67] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [73] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [79] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [85] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [91] versicolor versicolor versicolor versicolor versicolor versicolor
#>  [97] versicolor versicolor versicolor versicolor virginica  virginica 
#> [103] virginica  virginica  virginica  virginica  virginica  virginica 
#> [109] virginica  virginica  virginica  virginica  virginica  virginica 
#> [115] virginica  virginica  virginica  virginica  virginica  virginica 
#> [121] virginica  virginica  virginica  virginica  virginica  virginica 
#> [127] virginica  virginica  virginica  virginica  virginica  virginica 
#> [133] virginica  virginica  virginica  virginica  virginica  virginica 
#> [139] virginica  virginica  virginica  virginica  virginica  virginica 
#> [145] virginica  virginica  virginica  virginica  virginica  virginica 
#> Levels: setosa versicolor virginica