Last chance! 50% off unlimited learning
Sale ends in
extract data from array names
name2factor(x, sep = "_", which, collapse = sep, as.factor = TRUE)name2num(x, sep = "_", which, collapse = sep, dif = TRUE)
data, can be a three-dimensional array, a matrix, a named list or a vector containing names to split
character by which to split the strings
integer or vector of integers, if more entries are selected, they will be concatenated by the string specified with the option 'collapse'.
character by which to collapse data if two strings are to be concatenated
logical: if TRUE, a factor vector will be returned, strings otherwise.
logical: calculate difference if two fields containing numbers are selected.
returns a vector containing factors or numbers
extract data from array names and convert to factors or numbers
If an array is used as input, the data info is expected to be in the 3rd dimension, for a matrix, rownames are used.
# NOT RUN {
data <- matrix(rnorm(200),100,2)
id <- paste("id",1:100,sep="")
pop <- c(rep("pop1",50),rep("pop2",50))
sex <- c(rep("male",50),rep("female",50))
age <- floor(rnorm(100,mean=50,sd=10))
rownames(data) <- paste(id,pop,sex,age,sep="_")
infos <- data.frame(pop=name2factor(data,which=2))
infos$age <- name2num(data,which=4)
infos$pop.sex <- name2factor(data,which=2:3)
# }
Run the code above in your browser using DataLab