[R] array to data.frame

Martin Maechler maechler at stat.math.ethz.ch
Sat Apr 26 18:30:22 CEST 2003


    Spencer> Dear Peter:
    Spencer> Does the following not work in certain situations:

    Spencer> A <- array(1:4, dim=c(2,2))
    Spencer> dimnames(A) <- list(NULL, c("a", "b"))
    Spencer> as.data.frame(A)

Of course,  array -> data.frame is trivial for 2-dim arrays aka
matrices.  But Jorge had a 3-dim. array (of a special type,
namely a contingency table!) for which Peter gave the solution.

For most other 3-or-more-dim.arrays, there's no corresponding
data frame structure I can think of.

    Spencer> Or is it deprecated for other reasons?

    Spencer> Thanks,
    Spencer> Spencer Graves

Peter Dalgaard BSA wrote:
> Jorge Magalhães <jmagalhaes at oninetspeed.pt> writes:
> 
> 
>>Hi,
>>
>>How i can convert a array in to data.frame structure?
>>
>>For example,
>>
>>vinteesete<-array(c(1,0,6,4,22,29,11,7,6,2,8,7,21,25,5,6,1,0,11,6,14,24,13,10,2,2,15,13,14,17,9,8,1,2,16,9,14,23,9,6,6,2,17,13,10,20,7,5), 
>>dim=c(2,4,6), dimnames=list(grupo=c("I","II"), 
>>opiniao=c("Ma","Regular","Boa","MBoa",), 
>>relacao=c("atencao","sensibilidade","compreensao","tertempo","ouvir","envolvencia")))
> 
> 
> as.data.frame(as.table(vinteesete))
> 
> (or as.data.frame.table(vinteesete), but with S4 methods coming in it
> is increasingly considered bad style to apply methods to objects that
> are not of the requisite class.)
>

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list