El 17/12/10 10:40, Amy Milano escribió:
> Dear R helpers
>
> I have one data as given below.
>
> date                     value1          value2             value3
> 30-Nov-2010           100                 40                 61
> 25-Nov-2010           108                 31                 88
> 14-Sep-2010            11                 180               56
>
> I want the following output
>
> date                 name       amount
> 30-Nov-2010      value1        100
> 30-Nov-2010      value2         40
> 30-Nov-2010      value3         61
> 25-Nov-2010      value1       108
> 25-Nov-2010      value2         31
> 25-Nov-2010      value3         88 
> 14-Sep-2010      value1        11
> 14-Sep-2010      value2      180
> 14-Sep-2010      value3      56
>
>
> I have presented here a small part of large data. I tried to convert the data 
> into matrix, then transpose etc. but things are not working for me. Please 
> guide
>
> Thanking in advance
>
> Amy Milano
>
>
>   
>
>
>
>
>       [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
First, you must load the following libraries:

library( plyr )
library( reshape )


Next, define the following function:

Transform <- function(d.f){aux <- dim(d.f);files <- aux[1];columnes <- 
aux[2];aux2<-as.factor(rep(1:files,columnes));return(cbind(aux2,melt(d.f)))}

So, if you put your data.frame into object aux:

aux <- data.frame(c(100,108,11),c(40,31,180),c(61,88,56))
colnames(aux) <- c("value1","value2","value3")
rownames(aux) <- c("30 Nov 2010","25 Nov 2010","14 Sep 2010")


you can transform it in the following way:

aux2 <- Transform(aux)
aux2[,1] <- as.factor(rep(rownames(aux),3))

Finally, you obtain what you want.

Arnau.


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to