Hallo all Various suggestion were made but with this simple task I immediatelly thought about reshape2 melt function.
x <- "Time_stamp P1A0B0D P190-90D 'Jun-10 10:34' -0.000208 -0.000195 'Jun-10 10:51' -0.000228 -0.000188 'Jun-10 11:02' -0.000234 -0.000204 'Jun-10 11:17' -0.00022 -0.000205 'Jun-10 11:25' -0.000238 -0.000195" df1 <- read.table(textConnection(x), header = TRUE, check.names = FALSE) library(reshape2) melt(df1) Using Time_stamp as id variables Time_stamp variable value 1 Jun-10 10:34 P1A0B0D -0.000208 2 Jun-10 10:51 P1A0B0D -0.000228 3 Jun-10 11:02 P1A0B0D -0.000234 4 Jun-10 11:17 P1A0B0D -0.000220 5 Jun-10 11:25 P1A0B0D -0.000238 6 Jun-10 10:34 P190-90D -0.000195 7 Jun-10 10:51 P190-90D -0.000188 8 Jun-10 11:02 P190-90D -0.000204 9 Jun-10 11:17 P190-90D -0.000205 10 Jun-10 11:25 P190-90D -0.000195 You need only rename columns if necessary. Cheers Petr > -----Original Message----- > From: R-help <r-help-boun...@r-project.org> On Behalf Of Richard O'Keefe > Sent: Thursday, June 23, 2022 2:29 AM > To: Thomas Subia <thomas.su...@fmindustries.com> > Cc: r-help@r-project.org > Subject: Re: [R] Dplyr question > > Why do you want to use dplyr? > It's easy using base R. > > original <- ... > a <- cbind(original[,-3], Location=colnames(original)[2]) colnames(a)[2] <- > "Measurement" > b <- cbind(original[,-2], Location=colnames(original)[3]) colnames(b)[2] <- > "Measurement" > result <- rbind(a, b)[,c(1,3,2)] > > > > > On Wed, 22 Jun 2022 at 04:23, Thomas Subia > <thomas.su...@fmindustries.com> > wrote: > > > Colleagues: > > > > The header of my data set is: > > Time_stamp P1A0B0D P190-90D > > Jun-10 10:34 -0.000208 -0.000195 > > Jun-10 10:51 -0.000228 -0.000188 > > Jun-10 11:02 -0.000234 -0.000204 > > Jun-10 11:17 -0.00022 -0.000205 > > Jun-10 11:25 -0.000238 -0.000195 > > > > I want my data set to resemble: > > > > Time_stamp Location Measurement > > Jun-10 10:34 P1A0B0D -0.000208 > > Jun-10 10:51 P1A0B0D -0.000228 > > Jun-10 11:02 P1A0B0D -0.000234 > > Jun-10 11:17 P1A0B0D -0.00022 > > Jun-10 11:25 P1A0B0D -0.000238 > > Jun-10 10:34 P190-90D -0.000195 > > Jun-10 10:51 P190-90D -0.000188 > > Jun-10 11:02 P190-90D -0.000204 > > Jun-10 11:17 P190-90D -0.000205 > > Jun-10 11:25 P190-90D -0.000195 > > > > I need some advice on how to do this using dplyr. > > > > V/R > > Thomas Subia > > > > FM Industries, Inc. - NGK Electronics, USA | www.fmindustries.com > > 221 Warren Ave, Fremont, CA 94539 > > > > "En Dieu nous avons confiance, tous les autres doivent apporter des > > donnees" > > > > ______________________________________________ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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 -- To UNSUBSCRIBE and more, see > 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.
______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.