first: Extract first / last object

Description Usage Arguments Value Author(s) See Also Examples

Description

Extract first / last object

Usage

1
2
3
first(x)

last(x)

Arguments

x

object indexable by [

Value

object of same mode as x

Author(s)

Thomas P. Harte

See Also

Extract, na.omit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  # from the following phrases
  str<- c("hello there", "how are you?")
  cat(paste(str), sep="\n")
  # extract the first words:
  sapply(strsplit(str, " "), first)
  # extract the last words:
  sapply(strsplit(str, " "), last)

  # in fact this is a very useful idiom, e.g. with stock tickers:
  tickers<- c("INDU Index", "USD Curncy")
  cat(paste(tickers), sep="\n")
  short.tickers<- sapply(strsplit(tickers, " "), first)
  short.tickers
  category<- sapply(strsplit(tickers, " "), last)
  category

tharte/tutils documentation built on Feb. 11, 2020, 9:17 a.m.