split: Split a Spectra* object using factors

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Splits a Spectra* object into groups using a factor, either a provided as a vector or as an attribute in the features of the object.

Usage

1
split(x, f, drop = FALSE, ...)

Arguments

x

Spectra object

f

either a vector of factors (for objects inheriting from Spectra), or the name or indice of an attribute in the data slot of an object inheriting from SpectraDataFrame

drop

ignored

...

further potential arguments passed to methods.

Details

This is an adaptation of the split function in the base package.

Value

A list of objects of same class as x.

Author(s)

Pierre Roudier pierre.roudier@gmail.com

See Also

separate, melt_spectra, lapply, and the l*pply family of function inthe plyr package.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Loading example data
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500

# On a Spectra object, we need to provide a vector of factors
# to split the object
s <- as(australia, 'Spectra')
# We make up some kind of factor to split the data. 
idx <- sample(letters[1:5], replace = TRUE, size = nrow(s)) # This is a vector
r <- split(s, idx)
str(r)

# On a SpectradataFrame object, we can also provide the name or index 
# of an attribute
australia$fact <- sample(LETTERS[1:3], size = nrow(australia), replace = TRUE) # Generate some kind of factor
summary(australia)
r <- split(australia, 'fact')
str(r)

# A list is returned, and is thus ready for use with lapply, or any
# of the l*ply functions from the plyr package
lapply(r, nrow)

inspectr documentation built on May 2, 2019, 5:45 p.m.