R - Character type

> Procedural Languages > R

1 - About

A vector containing character values.

Advertising

3 - Example

  • One
> v = "My Name";
> class(v)
[1] "character"
  • List
> v <- c("My Name","Is","Nico")
> class(v)
[1] "character"

4 - Management

4.1 - Counting the number of occurrence

library(stringr)
str_count("/mt/path", "/")
[1] 2

4.2 - Concatenate

Concatenate vectors after converting to character.

helloWorld <- paste0("Hello", "world", sep=" ")

where:

  • sep is the separator character between the arguments
Advertising

4.3 - Escape \ Quotes

4.4 - Substring

substr(x, start, stop)
substring(text, first, last = 1000000L)
substr(x, start, stop) <- value
substring(text, first, last = 1000000L) <- value

4.5 - Contain

  • grepl returns a logical vector (match or not for each element of the input x).
test = "[nqSError: 46066]"
grepl("46066",test)
[1] TRUE
  • grep will filter the vector.
lang/r/character.txt · Last modified: 2018/04/17 17:25 by gerardnico