R - Character type

Card Puncher Data Processing

About

A vector containing character values.

Example

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

Management

Counting the number of occurrence

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

Concatenate

Concatenate vectors after converting to character.

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

where:

  • sep is the separator character between the arguments

Escape \ Quotes

https://stat.ethz.ch/R-manual/R-devel/library/base/html/Quotes.html

Substring

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

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.





Discover More
Card Puncher Data Processing
R - (Datatype|Type|Storage Mode) of an object (typeof, mode)

In the C code underlying R, all objects are pointers to a structure with typedef SEXPREC; the different R data types are represented in C by SEXPTYPE, which determines how the information in the various...
Card Puncher Data Processing
R - Class

A class is just an attribute of an object. You can remove the attribute with the function . The class with then become the type A list can have different class. unclass returns (a copy of) its...
Card Puncher Data Processing
R - String

See
Card Puncher Data Processing
R - Vector

The Vector in R contains elements of the same class. A Vector with different class of objects is a list. A vector (as every object) can also have . Almost all data in R is a vector or is based upon...



Share this page:
Follow us:
Task Runner