Hi: You can also use the melt() function in the reshape package: using a small snippet of your data as a test case,
library(reshape) > df Scenario Numbers ABC XYZ PQR 1 Sc_1 1 22 18.0 6 2 Sc_2 2 24 16.5 11 > melt(df, id = c('Scenario', 'Numbers')) Scenario Numbers variable value 1 Sc_1 1 ABC 22.0 2 Sc_2 2 ABC 24.0 3 Sc_1 1 XYZ 18.0 4 Sc_2 2 XYZ 16.5 5 Sc_1 1 PQR 6.0 6 Sc_2 2 PQR 11.0 Change the name of variable to Names and you should be set. HTH, Dennis On Wed, Feb 3, 2010 at 4:09 AM, Amelia Livington <amelia_living...@yahoo.com > wrote: > Dear R helpers > > After executing the R code, where the last few lines of the code are > something like given below. > > > ## Part of my R code > > > n = 20 > > ........ > ......... > > final_output = data.frame(Numbers = numbers, ABC = data1, XYZ = data2, PQR > = data3) > > write.csv(data.frame(Scenario = paste("Sc_", 1:n, sep = ""), > final_output'), 'result.csv', row.names = FALSE) > > ## End of code > > > When I open the 'result.csv' file, my output is like > > Scenario Numbers ABC XYZ PQR > Sc_1 1 22 18 > 6 > Sc_2 2 > 24 16.5 11 > SC_3 3 38 > 41 38 > > ................................................................ > > Sc_20 20 15 > 27.5 74 > > > ## MY REQUIEMENT > > I wish to have output like given below. > > Scenario Numbers Names Values > > Sc_1 1 ABC 22 > Sc_1 1 XYZ 18 > Sc_1 1 PQR 6 > Sc_2 2 ABC 24 > Sc_2 2 XYZ 16.5 > Sc_2 2 PQR 11 > > ................................................................. > > > Sc_20 20 ABC 15 > Sc_20 20 XYZ 27.5 > Sc_20 20 PQR 74 > > > Please guide how this can be achieved? > > Regards and thanks in advance > > Amelia > > > > > > > > > [[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. > > [[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.