Learn R Programming

gdata (version 2.2.0)

trim: Remove leading and trailing spaces from character strings

Description

Remove leading and traling spaces from character strings

Usage

trim(s)

Arguments

s
object to be processed

Value

  • s with all leading and traling spaces removed in its elements.

Details

trim is a generic function, where default method does nothing, while method for character s trims its elements and method for factor s trims levels. There are also methods for list and data.frame.

See Also

sub, gsub

Examples

Run this code
s <- "this is an example string    "
trim(s)

f <- c(s, s, "A", "B ", "C ", "D ")
trim(f)

l <- list(s=rep(s, times=6), f=f, i=1:6)
trim(l)

df <- as.data.frame(l)
trim(df)

Run the code above in your browser using DataLab