around | R Documentation |
This is a function like head
or tail
for dataframes which displays the values around a specified position.
around(dataframe, position, n = 3, return = "list", verbose = TRUE)
dataframe |
A dataframe. |
position |
A position/numeric vector of positions around which you want to examine the rows of a dataframe. |
n |
The number of adjacent positions around each position in |
return |
A character specifying |
verbose |
A logical input that defines whether or not to print a helpful message describing the rows that are being examined. |
The function returns a dataframe or a list depending on the input to return
.
Edward Lavender
#### Example (1): A single position
# Define data
set.seed(1)
nrows <- 50
x <- runif(nrows, 1, 50)
y <- rnorm(nrows, x * 10 - 5, 60)
dat <- data.frame(x = x, y = y)
around(dat, 10, 3, "data.frame")
#### Example (2): Multiple positions, returned as a list
around(dat, c(10, 30, 39), 3, "list")
#### Example (3): Multiple positions returned as a dataframe
around(dat, c(10, 30, 39), 3, "data.frame")
#### Example (4): The function accounts for position at the start/end of the dataframe
around(dat, c(1, 10, nrow(dat)), 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.