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"))) Thanks very much, J. Magalh?es
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.) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Dear Peter: Does the following not work in certain situations: A <- array(1:4, dim=c(2,2)) dimnames(A) <- list(NULL, c("a", "b")) as.data.frame(A) Or is it deprecated for other reasons? Thanks, 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.) >
Hi, Suppose i have two factors: factor1<-Structure(factor(c(1,3,2,1,2,1,2,1,3),levels=1:3), .Label=c("Yes","No","NY"))) factor2<-Structure(factor(c(2,1,2,1,3,2,2,1,3),levels=1:3), .Label=c("Yes","No", "NY"))) i want define a new factor from the factors 1 and 2. For that i tried:>array3<- is.numeric(factor1)+is.numeric(factor2)array3=(3,4,4,2,5,3,4,2,6) Now i need to define two new classes: if 2,3 and 4 ----->> class1 else class2 What is the best way for making that? Thanks in the advance. Jorge M.
Jorge Magalh?es wrote:> > Hi, > > Suppose i have two factors: > > factor1<-Structure(factor(c(1,3,2,1,2,1,2,1,3),levels=1:3), > .Label=c("Yes","No","NY")))For sure you mean factor1 <- structure(factor(c(1,3,2,1,2,1,2,1,3), levels=1:3), Label=c("Yes","No","NY"))> factor2<-Structure(factor(c(2,1,2,1,3,2,2,1,3),levels=1:3), > .Label=c("Yes","No", "NY"))) > > i want define a new factor from the factors 1 and 2. For that i tried: > > >array3<- is.numeric(factor1)+is.numeric(factor2)But using as.numeric(), I guess.> array3=(3,4,4,2,5,3,4,2,6) > > Now i need to define two new classes: if 2,3 and 4 ----->> class1 else class2 > > What is the best way for making that? > > Thanks in the advance. > > Jorge M.For example: factor(ifelse(array3 < 5, 1, 2)) Uwe Ligges