nth
In [1]:
Copied!
# https://dplyr.tidyverse.org/reference/nth.html
%run nb_helpers.py
from datar.all import nth, first, last
nb_header(nth, first, last)
# https://dplyr.tidyverse.org/reference/nth.html
%run nb_helpers.py
from datar.all import nth, first, last
nb_header(nth, first, last)
Try this notebook on binder.
★ nth¶
Extract the nth element of a vector¶
The original API:
https://dplyr.tidyverse.org/reference/nth.html
Args:¶
x
: A vector
n
: The index of the element to extract.
order_by
: A variable or function of variables to order by.
default
: A default value to return if n
is out of bounds.
Returns:¶
A value
★ first¶
Extract the first element of a vector¶
The original API:
https://dplyr.tidyverse.org/reference/nth.html
Args:¶
x
: A vector
order_by
: A variable or function of variables to order by.
default
: A default value to return if x
is empty.
Returns:¶
A value
★ last¶
Extract the last element of a vector¶
The original API:
https://dplyr.tidyverse.org/reference/nth.html
Args:¶
x
: A vector
order_by
: A variable or function of variables to order by.
default
: A default value to return if x
is empty.
Returns:¶
A value
In [2]:
Copied!
x = range(10)
y = range(9, -1, -1)
first(x)
x = range(10)
y = range(9, -1, -1)
first(x)
Out[2]:
0
In [3]:
Copied!
last(y)
last(y)
Out[3]:
0
In [4]:
Copied!
nth(x, 1)
nth(x, 1)
Out[4]:
1
In [5]:
Copied!
nth(x, 5)
nth(x, 5)
Out[5]:
5
In [6]:
Copied!
nth(x, -2)
nth(x, -2)
Out[6]:
8
In [7]:
Copied!
nth(x, 11)
nth(x, 11)
Out[7]:
nan
In [8]:
Copied!
last(x)
last(x)
Out[8]:
9
In [9]:
Copied!
last(x, y)
last(x, y)
Out[9]:
0
In [11]:
Copied!
with try_catch():
first()
with try_catch():
first()
[TypeError] _first_obj() missing 1 required positional argument: 'x'