Dear list, I'm looking for an inverse function of melt(which is in package reshape).Namely, I had a data frame like this (Table1) YEAR VAR1 VAR2 VAR3 1995 7 3 45 1996 5 6 32 1997 6 10 15 I transformed my data by using the melt function and my data was reshaped in the following format: (Table2) YEAR variable value 1995 VAR1 7 1996 VAR1 5 1997 VAR1 6 1995 VAR2 7 1996 VAR2 5 1997 VAR2 6 1995 VAR3 7 1996 VAR3 5 1997 VAR3 6 Now I would like to come back to the original format, namely table1. Anyone could help me?? Thanks for your attention! [[alternative HTML version deleted]]
Try this: xtabs(value ~ YEAR + variable, x) On Fri, Jun 18, 2010 at 10:39 AM, n.vialma@libero.it <n.vialma@libero.it>wrote:> > Dear list, > I'm looking for an inverse function of melt(which is in package > reshape).Namely, I had a data frame like this > (Table1) > > YEAR VAR1 VAR2 VAR3 > 1995 7 3 45 > > 1996 5 6 32 > > 1997 6 10 15 > I transformed my data by using the melt function and my data was reshaped > in the following format: > (Table2) > > YEAR variable value > > 1995 VAR1 7 > > 1996 VAR1 5 > > 1997 VAR1 6 > 1995 VAR2 7 > > 1996 VAR2 5 > > 1997 VAR2 6 > 1995 VAR3 7 > > 1996 VAR3 5 > > 1997 VAR3 6 > > Now I would like to come back to the original format, namely table1. > Anyone could help me?? > Thanks for your attention! > > > > > > > [[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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
http://had.co.nz/reshape/ please, do at least some effort before you post a question, so people don't have to point out that your question can easily be solved by reading the f*cking manual. cheers Joris On Fri, Jun 18, 2010 at 3:39 PM, n.vialma at libero.it <n.vialma at libero.it> wrote:> > Dear list, > I'm looking for an inverse function of melt(which is in package reshape).Namely, I had a data frame like this > (Table1) > > YEAR ?VAR1 ?VAR2 ?VAR3 > 1995 ? ? ?7 ? ? ? ? ? 3 ? ? ? ? 45 > > 1996 ? ? ? 5 ? ? ? ? 6 ? ? ? ? ? ?32 > > 1997 ? ? ? 6 ? ? ? ? ?10 ? ? ? ? 15 > I transformed my data by using the melt function and my data was reshaped in the following format: > (Table2) > > YEAR ? ?variable ? ? ? ? ?value > > 1995 ? ? ? ?VAR1 ? ? ? ? ? ? ?7 > > 1996 ? ? ? ? VAR1 ? ? ? ? ? ? 5 > > 1997 ? ? ? ? VAR1 ? ? ? ? ? ? 6 > 1995 ? ? ? ?VAR2 ? ? ? ? ? ? ?7 > > 1996 ? ? ? ? VAR2 ? ? ? ? ? ? 5 > > 1997 ? ? ? ? VAR2 ? ? ? ? ? ? 6 > 1995 ? ? ? ?VAR3 ? ? ? ? ? ? ?7 > > 1996 ? ? ? ? VAR3 ? ? ? ? ? ? 5 > > 1997 ? ? ? ? VAR3 ? ? ? ? ? ? 6 > > ?Now I would like to come back to the original format, namely table1. > Anyone could help me?? > Thanks for your attention! > > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 Joris.Meys at Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
?cast A reproducible example would get you more feedback. Steven McKinney ________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of n.vialma at libero.it [n.vialma at libero.it] Sent: June 18, 2010 6:39 AM To: r-help at r-project.org Subject: [R] inverse function of melt Dear list, I'm looking for an inverse function of melt(which is in package reshape).Namely, I had a data frame like this (Table1) YEAR VAR1 VAR2 VAR3 1995 7 3 45 1996 5 6 32 1997 6 10 15 I transformed my data by using the melt function and my data was reshaped in the following format: (Table2) YEAR variable value 1995 VAR1 7 1996 VAR1 5 1997 VAR1 6 1995 VAR2 7 1996 VAR2 5 1997 VAR2 6 1995 VAR3 7 1996 VAR3 5 1997 VAR3 6 Now I would like to come back to the original format, namely table1. Anyone could help me?? Thanks for your attention! [[alternative HTML version deleted]] ______________________________________________ R-help at 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.