first: Select first element(s)

Description Usage Arguments Value Methods Author(s) References See Also Examples

View source: R/first.r

Description

Selects the first n elements of an object.

Usage

1
first(x, ...)

Arguments

x

ANY-class. The object from which to select elements.

...

Further arguments passed to the respective methods that are being called

Value

Depends on the actual method being called

Methods

Author(s)

Janko Thyson janko.thyson@gmail.com

References

http://github.com/rappster/selectr

See Also

first.default, first.data.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
##------------------------------------------------------------------------------
## Vector //
##------------------------------------------------------------------------------

x <- letters
first(x)
first(x, 3)
first(x, 3, keep = TRUE)

## Conditions //
first(x, 30)
first(x, 30, strict = 1)
first(x, 30, strict = 2)
try(first(x, 30, strict = 3))

##------------------------------------------------------------------------------
## List //
##------------------------------------------------------------------------------

x <- as.list(letters)
first(x)
first(x, 3)
res <- first(x, 3, keep = TRUE)
attributes(res)

## Conditions //
first(x, 30)
first(x, 30, strict = 1)
first(x, 30, strict = 2)
try(first(x, 30, strict = 3))

##------------------------------------------------------------------------------
## Data frame //
##------------------------------------------------------------------------------

x <- data.frame(a= 1:5, b = letters[1:5], stringsAsFactors = FALSE)

## Rows:
first(x)
first(x, 3)
first(x, 3, keep = TRUE)

## Columns:
first(x, margin = 2)
first(x, 2, margin = 2)
first(x, 3, margin = 2)

first(x, margin = 2, drop = TRUE)
first(x, 2, margin = 2, drop = TRUE)

## Conditions:
first(x, 10)
first(x, 10, strict = 1)
first(x, 10, strict = 2)
try(first(x, 10, strict = 3))

first(x, 3, margin = 2)
first(x, 3, margin = 2, strict = 1)
first(x, 3, margin = 2, strict = 2)
try(first(x, 3, margin = 2, strict = 3))

rappster/selectr documentation built on May 26, 2019, 11:57 p.m.