R array permutation naming columns and rows -


this follow question convert 4-dimensional array 2-dimensional data set in r answered @ben-bolker.

i have 3d array called 'y' dimensions [37,29,2635] (i.e. firms, years, class). using ben's formula:

avm11<-matrix(aperm(y,c(1,3,2)),prod(dim(y)[c(1,3)])) 

i managed convert 2d array dimensions [37*2635,29]. however, row names have become meaningless numbers , i'd need generate row names during permutation i'd 97495 unique row names of type firm_class.

i've been trying via paste0() i'm doing wrong. suggestions?

you use seq_len() this. e.g.

rownames(avm11)<-paste(seq_len(length(avm11[,1])),"observation",sep=" ")

to make rownames dependable on variable firm_class:

#create data frame: df<-data.frame(x=c(0,1,2,3,4,5),y=c("a","b","c","d","e","f")) n<-length(df[,1])  #generate names containing class name , unique number: namevector<-sapply(seq_len(n),function(i) names_vector[i]<-paste("class", df[i,1], i,sep="."))  #equate rownames generated names: rownames(df)<-namevector 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -