Hi all, I have a couple of questions. 1) Is there a more effective way to remove the following pattern (patternrm) from the station_id_Timeseries (see below) patternrm <- c(_2000_4_OND, _2001_1_JFM, _2001_2_AMJ, _2001_3_JAS, _2001_4_OND, _2002_1_JFM, _2002_2_AMJ, _2002_3_JAS, _2002_4_OND, _2003_1_JFM, _2003_2_AMJ, _2003_3_JAS, _2003_4_OND, _2004_1_JFM, _2004_2_AMJ, _2004_3_JAS, _2000_4_OND) # This is the pattern to remove I am currently using this to remove the pattern: sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x, perl=TRUE) 2) I am attempting to make graphs of the station_id_Timeseries (x) in chronological order from 2000_4_OND to 2004_2_AMJ (there may be as as few as 2 or as many as 16) versus the load_00600_W (y1) and the load_00600_F (y2). There will be 2 plots for each x (x versus y1 & x versus y2). The data used here comes from a .csv file where there are about 100 sites and each site has it own unique station_id. In the end there should be a .pdf plot for each site. This is the full R code that I have written to process the data from the .csv file in order to plot it: trytablecompare <- read.csv("calibset_fluxmasterandWRTDS_20130226.csv", sep = ",", stringsAsFactors = FALSE) x = trytablecompare[-c(1:2, 2193:2196), 1] sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x, perl=TRUE) columnsneed <- trytablecompare[-c(1:2, 2193:2196), c(1, 16, 18)] sites <- columnsneed[1] for(i in sites) { pdf(paste0("output for ", sites,".pdf")) xrange <- range("station_id_Timeseries:endofsubset$i") yrange <- range("load_00600_W$endofsubset") plot(x, y1, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y1) par(new=T) xrange <- range("station_id_Timeseries:endofsubset$i") yrange <- range("load_00600_F$endofsubset") plot(x, y2, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y2) dev.off() } I have attempted to create reproducible code below, but I know that it is not complete. For example: x = c(02143500_2000_4_OND, 02143500_2001_1_JFM, 02143500_2001_2_AMJ, 02143500_2001_3_JAS, 02143500_2001_4_OND, 02143500_2002_1_JFM, 02143500_2002_2_AMJ, 02143500_2002_3_JAS, 02143500_2002_4_OND, 02143500_2003_1_JFM, 02143500_2003_2_AMJ, 02143500_2003_3_JAS, 02143500_2003_4_OND, 02143500_2004_1_JFM, 02143500_2004_2_AMJ, 02143500_2004_3_JAS, 21W43.5000_2000_4_OND, 21W43.5000_2001_1_JFM, 21W43.5000_2001_2_AMJ, 21W43.5000_2001_3_JAS, 21W43.5000_2001_4_OND, 21W43.5000_2002_1_JFM, 21W43.5000_2002_2_AMJ, 21W43.5000_2002_3_JAS, 21W43.5000_2002_4_OND, 21W43.5000_2003_1_JFM, 21W43.5000_2003_2_AMJ, 21W43.5000_2003_3_JAS, 21W43.5000_2003_4_OND, 21W43.5000_2004_1_JFM, 21W43.5000_2004_2_AMJ, 21W43.5000_2004_3_JAS) # station_id_Timeseries y1 = c(rnorm(16), rnorm(16)) # load_00600_W y2 = c(rnorm(16), rnorm(16)) # load_00600_F for(i in x) { pdf(paste0("output for ", sites,".pdf")) xrange <- range("x1$i") # This would be the first set of sites for the specified seasons yrange <- range("y1") plot(x, y1, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y1) par(new=T) xrange <- range(""x1$i"") # This would be the first set of sites for the specified seasons yrange <- range("y2") plot(x, y2, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y2)) dev.off() } Thank-you. Irucka Embry This is a small sampling of the data that I'm extracting to plot from the .csv file: station_id_Timeseries (as the x axis) 02143500_2000_4_OND 02143500_2001_1_JFM 02143500_2001_2_AMJ 02143500_2001_3_JAS 02143500_2001_4_OND 02143500_2002_1_JFM 02143500_2002_2_AMJ 02143500_2002_3_JAS 02143500_2002_4_OND 02143500_2003_1_JFM 02143500_2003_2_AMJ 02143500_2003_3_JAS 02143500_2003_4_OND 02143500_2004_1_JFM 02143500_2004_2_AMJ 02143500_2004_3_JAS 02169000_2000_4_OND 02169000_2001_1_JFM 02169000_2001_2_AMJ 02169000_2001_3_JAS 02169000_2001_4_OND 02169000_2002_1_JFM 02169000_2002_2_AMJ 02169000_2002_3_JAS 02169000_2002_4_OND 02169000_2003_1_JFM 02169000_2003_2_AMJ 02169000_2003_3_JAS 02169000_2003_4_OND 02169000_2004_1_JFM 02169000_2004_2_AMJ 02169000_2004_3_JAS 21GAEPD .01021001_2003_3_JAS 21GAEPD .01025001_2000_4_OND 21GAEPD .01025001_2001_1_JFM 21GAEPD .01025001_2001_2_AMJ 21GAEPD .01025001_2001_3_JAS 21GAEPD .01025001_2001_4_OND 21GAEPD .01025001_2002_1_JFM 21GAEPD .01025001_2002_2_AMJ 21GAEPD .01025001_2002_3_JAS 21GAEPD .01025001_2002_4_OND 21GAEPD .01025001_2003_1_JFM 21GAEPD .01025001_2003_2_AMJ 21GAEPD .01025001_2003_3_JAS 21NC02WQ.A2700000_2000_4_OND 21NC02WQ.A2700000_2001_1_JFM 21NC02WQ.A2700000_2001_2_AMJ 21NC02WQ.A2700000_2001_3_JAS 21NC02WQ.A2700000_2001_4_OND 21NC02WQ.A2700000_2002_1_JFM 21NC02WQ.A2700000_2002_2_AMJ 21NC02WQ.A2700000_2002_3_JAS 21NC02WQ.A2700000_2002_4_OND 21NC02WQ.A2700000_2003_1_JFM 21NC02WQ.A2700000_2003_2_AMJ 21NC02WQ.A2700000_2003_3_JAS 21NC02WQ.A2700000_2003_4_OND 21NC02WQ.A2700000_2004_1_JFM 21NC02WQ.A2700000_2004_2_AMJ 21NC02WQ.A2700000_2004_3_JAS 21NC02WQ.A4700000_2000_4_OND 21NC02WQ.A4700000_2001_1_JFM 21NC02WQ.A4700000_2001_2_AMJ 21NC02WQ.A4700000_2001_3_JAS 21NC02WQ.A4700000_2001_4_OND 21NC02WQ.A4700000_2002_1_JFM 21NC02WQ.A4700000_2002_2_AMJ 21NC02WQ.A4700000_2002_3_JAS 21NC02WQ.A4700000_2002_4_OND 21NC02WQ.A4700000_2003_1_JFM 21NC02WQ.A4700000_2003_2_AMJ 21NC02WQ.A4700000_2003_3_JAS 21NC02WQ.A4700000_2003_4_OND 21NC02WQ.A4700000_2004_1_JFM 21NC02WQ.A4700000_2004_2_AMJ 21NC02WQ.A4700000_2004_3_JAS 21NC02WQ.C0250000_2000_4_OND 21NC02WQ.C0250000_2001_1_JFM 21NC02WQ.C0250000_2001_2_AMJ 21NC02WQ.C0250000_2001_3_JAS 21NC02WQ.C0250000_2001_4_OND 21NC02WQ.C0250000_2002_1_JFM 21NC02WQ.C0250000_2002_2_AMJ 21NC02WQ.C0250000_2002_3_JAS 21NC02WQ.C0250000_2002_4_OND 21NC02WQ.C0250000_2003_1_JFM 21NC02WQ.C0250000_2003_2_AMJ 21NC02WQ.C0250000_2003_3_JAS 21NC02WQ.C0250000_2003_4_OND 21NC02WQ.C0250000_2004_1_JFM 21NC02WQ.C0250000_2004_2_AMJ 21NC02WQ.C0250000_2004_3_JAS ... load_00600_W (one set of data for the y-axis) 2897.7904362491 7551.0945112213 4062.3936560196 4386.3935825817 2148.4803413963 5887.5158386817 4551.7100620272 5159.0706830313 10946.0644621646 20223.5133431946 14275.7834627695 16653.6617307993 13900.8965496484 13396.5350817754 10918.1025781657 37343.1840220667 61152.4563009734 3087159.69237187 83271.1072869206 78182.9098615795 10344.3815353876 2246.4450929669 989.220241325 2318.3488271707 24134.6766402373 34350.75952138 39041.6413152116 28188.925323908 2281.7849286464 1756.7094755792 357.3578073865 238.1185010405 182793.701052689 2338378.58622751 333158.050834378 135771.559284203 62988.8462340411 95409.5922031234 66045.2304429448 76782.5224502097 368902.001090301 717285.957906831 1189440.79489471 1077732.29658141 263564.368874354 372894.028862293 209856.865708756 250149.67080147 ... load_00600_F (one set of data for the y-axis) 4202.7437226 4202.7437226 16214.840538 7371.9290209 3114.1090754 2464.1114951 9380.6352081 3859.2809055 901.86146915 22377.413599 53563.26564 148264.35049 103538.36278 18142.045363 14672.031667 18796.93618 75313.330193 227675.73764 92777.682029 84827.680295 193298.65669 170799.05034 103666.8759 107485.71333 213765.87505 472307.65662 799500.99994 754868.43185 454078.02653 171521.77777 265827.90007 120401.25989 194000.26057 414312.49534 617213.70273 434832.6564 388556.44724 349308.46381 633838.70254 384887.09244 303766.12561 1065566.5203 2156874.9757 2521072.5523 1377743.9361 683078.62134 936362.89268 625201.60587 1094215.7135 ... <span id=m2wTl><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Get the Free email that has everyone talking at <a href=http://www.mail2world.com target=new>http://www.mail2world.com</a><br> <font color=#999999>Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!</font></font></span> [[alternative HTML version deleted]]
Hi, May be you can try: res1<- gsub("\\_.*\\_.*\\_.*","",x) ?res2<-sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x,perl=TRUE) ?identical(res1,res2) #[1] TRUE A.K. ----- Original Message ----- From: Irucka Embry <iruckaE at mail2world.com> To: r-help at r-project.org Cc: Sent: Monday, March 4, 2013 9:51 PM Subject: [R] multiple plots and looping assistance requested Hi all, I have a couple of questions. 1) Is there a more effective way to remove the following pattern (patternrm) from the station_id_Timeseries (see below) patternrm <- c(_2000_4_OND, _2001_1_JFM, _2001_2_AMJ, _2001_3_JAS, _2001_4_OND, _2002_1_JFM, _2002_2_AMJ, _2002_3_JAS, _2002_4_OND, _2003_1_JFM, _2003_2_AMJ, _2003_3_JAS, _2003_4_OND, _2004_1_JFM, _2004_2_AMJ, _2004_3_JAS, _2000_4_OND) # This is the pattern to remove I am currently using this to remove the pattern: sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x, perl=TRUE) 2) I am attempting to make graphs of the station_id_Timeseries (x) in chronological order from 2000_4_OND to 2004_2_AMJ (there may be as as few as 2 or as many as 16) versus the load_00600_W (y1) and the load_00600_F (y2). There will be 2 plots for each x (x versus y1 & x versus y2). The data used here comes from a .csv file where there are about 100 sites and each site has it own unique station_id. In the end there should be a .pdf plot for each site. This is the full R code that I have written to process the data from the .csv file in order to plot it: trytablecompare <- read.csv("calibset_fluxmasterandWRTDS_20130226.csv", sep = ",", stringsAsFactors = FALSE) x = trytablecompare[-c(1:2, 2193:2196), 1] sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x, perl=TRUE) columnsneed <- trytablecompare[-c(1:2, 2193:2196), c(1, 16, 18)] sites <- columnsneed[1] for(i in sites) { pdf(paste0("output for ", sites,".pdf")) xrange <- range("station_id_Timeseries:endofsubset$i") yrange <- range("load_00600_W$endofsubset") plot(x, y1, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y1) par(new=T) xrange <- range("station_id_Timeseries:endofsubset$i") yrange <- range("load_00600_F$endofsubset") plot(x, y2, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y2) dev.off() } I have attempted to create reproducible code below, but I know that it is not complete. For example: x = c(02143500_2000_4_OND, 02143500_2001_1_JFM, 02143500_2001_2_AMJ, 02143500_2001_3_JAS, 02143500_2001_4_OND, 02143500_2002_1_JFM, 02143500_2002_2_AMJ, 02143500_2002_3_JAS, 02143500_2002_4_OND, 02143500_2003_1_JFM, 02143500_2003_2_AMJ, 02143500_2003_3_JAS, 02143500_2003_4_OND, 02143500_2004_1_JFM, 02143500_2004_2_AMJ, 02143500_2004_3_JAS, 21W43.5000_2000_4_OND, 21W43.5000_2001_1_JFM, 21W43.5000_2001_2_AMJ, 21W43.5000_2001_3_JAS, 21W43.5000_2001_4_OND, 21W43.5000_2002_1_JFM, 21W43.5000_2002_2_AMJ, 21W43.5000_2002_3_JAS, 21W43.5000_2002_4_OND, 21W43.5000_2003_1_JFM, 21W43.5000_2003_2_AMJ, 21W43.5000_2003_3_JAS, 21W43.5000_2003_4_OND, 21W43.5000_2004_1_JFM, 21W43.5000_2004_2_AMJ, 21W43.5000_2004_3_JAS) # station_id_Timeseries y1 = c(rnorm(16), rnorm(16)) # load_00600_W y2 = c(rnorm(16), rnorm(16)) # load_00600_F for(i in x) { pdf(paste0("output for ", sites,".pdf")) xrange <- range("x1$i") # This would be the first set of sites for the specified seasons yrange <- range("y1") plot(x, y1, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y1) par(new=T) xrange <- range(""x1$i"") # This would be the first set of sites for the specified seasons yrange <- range("y2") plot(x, y2, xlab="Year, Season", ylab="Total Flux (kg/season)") lines(x, y2)) dev.off() } Thank-you. Irucka Embry This is a small sampling of the data that I'm extracting to plot from the .csv file: station_id_Timeseries (as the x axis) 02143500_2000_4_OND 02143500_2001_1_JFM 02143500_2001_2_AMJ 02143500_2001_3_JAS 02143500_2001_4_OND 02143500_2002_1_JFM 02143500_2002_2_AMJ 02143500_2002_3_JAS 02143500_2002_4_OND 02143500_2003_1_JFM 02143500_2003_2_AMJ 02143500_2003_3_JAS 02143500_2003_4_OND 02143500_2004_1_JFM 02143500_2004_2_AMJ 02143500_2004_3_JAS 02169000_2000_4_OND 02169000_2001_1_JFM 02169000_2001_2_AMJ 02169000_2001_3_JAS 02169000_2001_4_OND 02169000_2002_1_JFM 02169000_2002_2_AMJ 02169000_2002_3_JAS 02169000_2002_4_OND 02169000_2003_1_JFM 02169000_2003_2_AMJ 02169000_2003_3_JAS 02169000_2003_4_OND 02169000_2004_1_JFM 02169000_2004_2_AMJ 02169000_2004_3_JAS 21GAEPD .01021001_2003_3_JAS 21GAEPD .01025001_2000_4_OND 21GAEPD .01025001_2001_1_JFM 21GAEPD .01025001_2001_2_AMJ 21GAEPD .01025001_2001_3_JAS 21GAEPD .01025001_2001_4_OND 21GAEPD .01025001_2002_1_JFM 21GAEPD .01025001_2002_2_AMJ 21GAEPD .01025001_2002_3_JAS 21GAEPD .01025001_2002_4_OND 21GAEPD .01025001_2003_1_JFM 21GAEPD .01025001_2003_2_AMJ 21GAEPD .01025001_2003_3_JAS 21NC02WQ.A2700000_2000_4_OND 21NC02WQ.A2700000_2001_1_JFM 21NC02WQ.A2700000_2001_2_AMJ 21NC02WQ.A2700000_2001_3_JAS 21NC02WQ.A2700000_2001_4_OND 21NC02WQ.A2700000_2002_1_JFM 21NC02WQ.A2700000_2002_2_AMJ 21NC02WQ.A2700000_2002_3_JAS 21NC02WQ.A2700000_2002_4_OND 21NC02WQ.A2700000_2003_1_JFM 21NC02WQ.A2700000_2003_2_AMJ 21NC02WQ.A2700000_2003_3_JAS 21NC02WQ.A2700000_2003_4_OND 21NC02WQ.A2700000_2004_1_JFM 21NC02WQ.A2700000_2004_2_AMJ 21NC02WQ.A2700000_2004_3_JAS 21NC02WQ.A4700000_2000_4_OND 21NC02WQ.A4700000_2001_1_JFM 21NC02WQ.A4700000_2001_2_AMJ 21NC02WQ.A4700000_2001_3_JAS 21NC02WQ.A4700000_2001_4_OND 21NC02WQ.A4700000_2002_1_JFM 21NC02WQ.A4700000_2002_2_AMJ 21NC02WQ.A4700000_2002_3_JAS 21NC02WQ.A4700000_2002_4_OND 21NC02WQ.A4700000_2003_1_JFM 21NC02WQ.A4700000_2003_2_AMJ 21NC02WQ.A4700000_2003_3_JAS 21NC02WQ.A4700000_2003_4_OND 21NC02WQ.A4700000_2004_1_JFM 21NC02WQ.A4700000_2004_2_AMJ 21NC02WQ.A4700000_2004_3_JAS 21NC02WQ.C0250000_2000_4_OND 21NC02WQ.C0250000_2001_1_JFM 21NC02WQ.C0250000_2001_2_AMJ 21NC02WQ.C0250000_2001_3_JAS 21NC02WQ.C0250000_2001_4_OND 21NC02WQ.C0250000_2002_1_JFM 21NC02WQ.C0250000_2002_2_AMJ 21NC02WQ.C0250000_2002_3_JAS 21NC02WQ.C0250000_2002_4_OND 21NC02WQ.C0250000_2003_1_JFM 21NC02WQ.C0250000_2003_2_AMJ 21NC02WQ.C0250000_2003_3_JAS 21NC02WQ.C0250000_2003_4_OND 21NC02WQ.C0250000_2004_1_JFM 21NC02WQ.C0250000_2004_2_AMJ 21NC02WQ.C0250000_2004_3_JAS ... load_00600_W (one set of data for the y-axis) 2897.7904362491 7551.0945112213 4062.3936560196 4386.3935825817 2148.4803413963 5887.5158386817 4551.7100620272 5159.0706830313 10946.0644621646 20223.5133431946 14275.7834627695 16653.6617307993 13900.8965496484 13396.5350817754 10918.1025781657 37343.1840220667 61152.4563009734 3087159.69237187 83271.1072869206 78182.9098615795 10344.3815353876 2246.4450929669 989.220241325 2318.3488271707 24134.6766402373 34350.75952138 39041.6413152116 28188.925323908 2281.7849286464 1756.7094755792 357.3578073865 238.1185010405 182793.701052689 2338378.58622751 333158.050834378 135771.559284203 62988.8462340411 95409.5922031234 66045.2304429448 76782.5224502097 368902.001090301 717285.957906831 1189440.79489471 1077732.29658141 263564.368874354 372894.028862293 209856.865708756 250149.67080147 ... load_00600_F (one set of data for the y-axis) 4202.7437226 4202.7437226 16214.840538 7371.9290209 3114.1090754 2464.1114951 9380.6352081 3859.2809055 901.86146915 22377.413599 53563.26564 148264.35049 103538.36278 18142.045363 14672.031667 18796.93618 75313.330193 227675.73764 92777.682029 84827.680295 193298.65669 170799.05034 103666.8759 107485.71333 213765.87505 472307.65662 799500.99994 754868.43185 454078.02653 171521.77777 265827.90007 120401.25989 194000.26057 414312.49534 617213.70273 434832.6564 388556.44724 349308.46381 633838.70254 384887.09244 303766.12561 1065566.5203 2156874.9757 2521072.5523 1377743.9361 683078.62134 936362.89268 625201.60587 1094215.7135 ... <span id=m2wTl><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Get the Free email that has everyone talking at <a href=http://www.mail2world.com target=new>http://www.mail2world.com</a><br>? <font color=#999999>Unlimited Email Storage ? POP3 ? Calendar ? SMS ? Translator ? Much More!</font></font></span> ??? [[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.
Hi Arun, thank you for your assistance. The code for part 1 worked perfectly. I am including here a list of all of the site names for part 2. Due to the nature of the station ids it has been difficult for me to find a good pattern to use with regular expressions. Thank you all in advance for your assistance. Irucka (02143500, 02169000, 02169500, 02169570, 02172300, 02174250, 02175000, 02177000, 02192000, 02197065, 02198500, 02198920, 21GAEPD.01001001, 21GAEPD .01008001, 21GAEPD .01011001, 21GAEPD .01011801, 21GAEPD .01013001, 21GAEPD .01014001, 21GAEPD .01014501, 21GAEPD .01015001, 21GAEPD .01018001, 21GAEPD .01021001, 21GAEPD .01025001, 21NC02WQ.A2700000, 21NC02WQ.A4700000, 21NC02WQ.C0250000, 21NC02WQ.C1000000, 21NC02WQ.C4370000, 21NC02WQ.C5900000, 21NC02WQ.C6500000, 21NC02WQ.C8660000, 21NC02WQ.C9050000, 21NC02WQ.C9210000, 21NC02WQ.C9370000, 21NC02WQ.C9680000, 21NC02WQ.C9819500, 21NC02WQ.I2090000, 21NC02WQ.I2610000, 21NC02WQ.I5690000, 21NC02WQ.I8970000, 21NC02WQ.I9350000, 21NC02WQ.Q0220000, 21NC02WQ.Q5930000, 21NC02WQ.Q5970000, 21NC02WQ.Q9120000, 21NC02WQ.Q9160000, 21NC02WQ.Q9200000, 21SC60WQ.B-005, 21SC60WQ.B-014, 21SC60WQ.B-028, 21SC60WQ.B-040, 21SC60WQ.B-041, 21SC60WQ.B-042, 21SC60WQ.B-044, 21SC60WQ.B-046, 21SC60WQ.B-047, 21SC60WQ.B-051, 21SC60WQ.B-053, 21SC60WQ.B-097, 21SC60WQ.B-126, 21SC60WQ.B-163A, 21SC60WQ.B-221, 21SC60WQ.B-236, 21SC60WQ.B-331, 21SC60WQ.B-337, 21SC60WQ.C-001, 21SC60WQ.C-007, 21SC60WQ.C-017, 21SC60WQ.C-074, 21SC60WQ.CSB-001L, 21SC60WQ.CSB-001R, 21SC60WQ.CSTL-006, 21SC60WQ.CSTL-104, 21SC60WQ.CW-014, 21SC60WQ.CW-016, 21SC60WQ.CW-019, 21SC60WQ.CW-023, 21SC60WQ.CW-064, 21SC60WQ.CW-152, 21SC60WQ.CW-174, 21SC60WQ.CW-175, 21SC60WQ.CW-206, 21SC60WQ.CW-226, 21SC60WQ.CW-236, 21SC60WQ.E-007, 21SC60WQ.E-007A, 21SC60WQ.E-007B, 21SC60WQ.E-007C, 21SC60WQ.E-008, 21SC60WQ.E-008A, 21SC60WQ.E-012, 21SC60WQ.E-015, 21SC60WQ.E-099, 21SC60WQ.MD-110, 21SC60WQ.MD-111, 21SC60WQ.MD-119, 21SC60WQ.MD-124, 21SC60WQ.MD-145, 21SC60WQ.PD-012, 21SC60WQ.PD-015, 21SC60WQ.PD-021, 21SC60WQ.PD-028, 21SC60WQ.PD-041, 21SC60WQ.PD-042, 21SC60WQ.PD-044, 21SC60WQ.PD-045, 21SC60WQ.PD-060, 21SC60WQ.PD-076, 21SC60WQ.PD-170, 21SC60WQ.PD-189, 21SC60WQ.PD-281, 21SC60WQ.PD-330, 21SC60WQ.PD-337, 21SC60WQ.PD-350, 21SC60WQ.PD-355, 21SC60WQ.PD-359, 21SC60WQ.S-007, 21SC60WQ.S-013, 21SC60WQ.S-021, 21SC60WQ.S-047, 21SC60WQ.S- 050, 21SC60WQ.S-072, 21SC60WQ.S-102, 21SC60WQ.S-119, 21SC60WQ.S-123, 21SC60WQ.S-125, 21SC60WQ.S-150, 21SC60WQ.S-171, 21SC60WQ.S-186, 21SC60WQ.S-250, 21SC60WQ.S-295, 21SC60WQ.S-298, 21SC60WQ.S-305, 21SC60WQ.S-322, 21SC60WQ.SV-004, 21SC60WQ.SV-015, 21SC60WQ.SV-118, 21SC60WQ.SV-135, 21SC60WQ.SV-137, 21SC60WQ.SV-199, 21SC60WQ.SV-251, 21SC60WQ.SV-252, 21SC60WQ.SV-325, 21SC60WQ.SV-326, 21SC60WQ.SV-328, 21SC60WQ.SV-346, 21SC60WQ.SV-354, 21SCSANT.SC-001, 21SCSANT.SC-002) <-----Original Message----->>From: arun [smartpink111@yahoo.com] >Sent: 3/4/2013 9:43:24 PM >To: iruckaE@mail2world.com >Cc: r-help@r-project.org >Subject: Re: [R] multiple plots and looping assistance requested > >Hi, > >May be you can try: >res1<- gsub("\\_.*\\_.*\\_.*","",x) > res2<-sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$","",>x,perl=TRUE) > identical(res1,res2) >#[1] TRUE >A.K. > > > >----- Original Message ----- >From: Irucka Embry <iruckaE@mail2world.com> >To: r-help@r-project.org >Cc: >Sent: Monday, March 4, 2013 9:51 PM >Subject: [R] multiple plots and looping assistance requested > >Hi all, I have a couple of questions. > >1) Is there a more effective way to remove the following pattern >(patternrm) from the station_id_Timeseries (see below) > >patternrm <- c(_2000_4_OND, _2001_1_JFM, _2001_2_AMJ, _2001_3_JAS, >_2001_4_OND, _2002_1_JFM, _2002_2_AMJ, _2002_3_JAS, _2002_4_OND, >_2003_1_JFM, _2003_2_AMJ, _2003_3_JAS, _2003_4_OND, _2004_1_JFM, >_2004_2_AMJ, _2004_3_JAS, _2000_4_OND) # This is the pattern to remove > >I am currently using this to remove the pattern: >sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x, >perl=TRUE) > > >2) I am attempting to make graphs of the station_id_Timeseries (x) in >chronological order from 2000_4_OND to 2004_2_AMJ (there may be as as >few as 2 or as many as 16) versus the load_00600_W (y1) and the >load_00600_F (y2). There will be 2 plots for each x (x versus y1 & x >versus y2). The data used here comes from a .csv file where there are >about 100 sites and each site has it own unique station_id. In the end >there should be a .pdf plot for each site. > > >This is the full R code that I have written to process the data fromthe>.csv file in order to plot it: > >trytablecompare <- read.csv("calibset_fluxmasterandWRTDS_20130226.csv", >sep = ",", stringsAsFactors = FALSE) >x = trytablecompare[-c(1:2, 2193:2196), 1] >sub("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)$", "", x, >perl=TRUE) > >columnsneed <- trytablecompare[-c(1:2, 2193:2196), c(1, 16, 18)] >sites <- columnsneed[1] > >for(i in sites) { >pdf(paste0("output for ", sites,".pdf")) >xrange <- range("station_id_Timeseries:endofsubset$i") >yrange <- range("load_00600_W$endofsubset") >plot(x, y1, xlab="Year, Season", ylab="Total Flux (kg/season)") >lines(x, y1) >par(new=T) >xrange <- range("station_id_Timeseries:endofsubset$i") >yrange <- range("load_00600_F$endofsubset") >plot(x, y2, xlab="Year, Season", ylab="Total Flux (kg/season)") >lines(x, y2) >dev.off() >} > > >I have attempted to create reproducible code below, but I know that it >is not complete. >For example: >x = c(02143500_2000_4_OND, 02143500_2001_1_JFM, 02143500_2001_2_AMJ, >02143500_2001_3_JAS, 02143500_2001_4_OND, 02143500_2002_1_JFM, >02143500_2002_2_AMJ, 02143500_2002_3_JAS, 02143500_2002_4_OND, >02143500_2003_1_JFM, 02143500_2003_2_AMJ, 02143500_2003_3_JAS, >02143500_2003_4_OND, 02143500_2004_1_JFM, 02143500_2004_2_AMJ, >02143500_2004_3_JAS, 21W43.5000_2000_4_OND, 21W43.5000_2001_1_JFM, >21W43.5000_2001_2_AMJ, 21W43.5000_2001_3_JAS, 21W43.5000_2001_4_OND, >21W43.5000_2002_1_JFM, 21W43.5000_2002_2_AMJ, 21W43.5000_2002_3_JAS, >21W43.5000_2002_4_OND, 21W43.5000_2003_1_JFM, 21W43.5000_2003_2_AMJ, >21W43.5000_2003_3_JAS, 21W43.5000_2003_4_OND, 21W43.5000_2004_1_JFM, >21W43.5000_2004_2_AMJ, 21W43.5000_2004_3_JAS) # station_id_Timeseries > >y1 = c(rnorm(16), rnorm(16)) # load_00600_W >y2 = c(rnorm(16), rnorm(16)) # load_00600_F > > >for(i in x) { >pdf(paste0("output for ", sites,".pdf")) >xrange <- range("x1$i") # This would be the first set of sites for the >specified seasons >yrange <- range("y1") >plot(x, y1, xlab="Year, Season", ylab="Total Flux (kg/season)") >lines(x, y1) >par(new=T) >xrange <- range(""x1$i"") # This would be the first set of sites forthe>specified seasons >yrange <- range("y2") >plot(x, y2, xlab="Year, Season", ylab="Total Flux (kg/season)") >lines(x, y2)) >dev.off() >} > > > > > > > >Thank-you. > >Irucka Embry > > > >This is a small sampling of the data that I'm extracting to plot from >the .csv file: >station_id_Timeseries (as the x axis) >02143500_2000_4_OND >02143500_2001_1_JFM >02143500_2001_2_AMJ >02143500_2001_3_JAS >02143500_2001_4_OND >02143500_2002_1_JFM >02143500_2002_2_AMJ >02143500_2002_3_JAS >02143500_2002_4_OND >02143500_2003_1_JFM >02143500_2003_2_AMJ >02143500_2003_3_JAS >02143500_2003_4_OND >02143500_2004_1_JFM >02143500_2004_2_AMJ >02143500_2004_3_JAS >02169000_2000_4_OND >02169000_2001_1_JFM >02169000_2001_2_AMJ >02169000_2001_3_JAS >02169000_2001_4_OND >02169000_2002_1_JFM >02169000_2002_2_AMJ >02169000_2002_3_JAS >02169000_2002_4_OND >02169000_2003_1_JFM >02169000_2003_2_AMJ >02169000_2003_3_JAS >02169000_2003_4_OND >02169000_2004_1_JFM >02169000_2004_2_AMJ >02169000_2004_3_JAS >21GAEPD .01021001_2003_3_JAS >21GAEPD .01025001_2000_4_OND >21GAEPD .01025001_2001_1_JFM >21GAEPD .01025001_2001_2_AMJ >21GAEPD .01025001_2001_3_JAS >21GAEPD .01025001_2001_4_OND >21GAEPD .01025001_2002_1_JFM >21GAEPD .01025001_2002_2_AMJ >21GAEPD .01025001_2002_3_JAS >21GAEPD .01025001_2002_4_OND >21GAEPD .01025001_2003_1_JFM >21GAEPD .01025001_2003_2_AMJ >21GAEPD .01025001_2003_3_JAS >21NC02WQ.A2700000_2000_4_OND >21NC02WQ.A2700000_2001_1_JFM >21NC02WQ.A2700000_2001_2_AMJ >21NC02WQ.A2700000_2001_3_JAS >21NC02WQ.A2700000_2001_4_OND >21NC02WQ.A2700000_2002_1_JFM >21NC02WQ.A2700000_2002_2_AMJ >21NC02WQ.A2700000_2002_3_JAS >21NC02WQ..A2700000_2002_4_OND >21NC02WQ.A2700000_2003_1_JFM >21NC02WQ.A2700000_2003_2_AMJ >21NC02WQ.A2700000_2003_3_JAS >21NC02WQ.A2700000_2003_4_OND >21NC02WQ.A2700000_2004_1_JFM >21NC02WQ.A2700000_2004_2_AMJ >21NC02WQ.A2700000_2004_3_JAS >21NC02WQ.A4700000_2000_4_OND >21NC02WQ.A4700000_2001_1_JFM >21NC02WQ.A4700000_2001_2_AMJ >21NC02WQ.A4700000_2001_3_JAS >21NC02WQ.A4700000_2001_4_OND >21NC02WQ.A4700000_2002_1_JFM >21NC02WQ.A4700000_2002_2_AMJ >21NC02WQ.A4700000_2002_3_JAS >21NC02WQ.A4700000_2002_4_OND >21NC02WQ.A4700000_2003_1_JFM >21NC02WQ.A4700000_2003_2_AMJ >21NC02WQ.A4700000_2003_3_JAS >21NC02WQ.A4700000_2003_4_OND >21NC02WQ.A4700000_2004_1_JFM >21NC02WQ.A4700000_2004_2_AMJ >21NC02WQ.A4700000_2004_3_JAS >21NC02WQ.C0250000_2000_4_OND >21NC02WQ.C0250000_2001_1_JFM >21NC02WQ.C0250000_2001_2_AMJ >21NC02WQ.C0250000_2001_3_JAS >21NC02WQ.C0250000_2001_4_OND >21NC02WQ..C0250000_2002_1_JFM >21NC02WQ.C0250000_2002_2_AMJ >21NC02WQ.C0250000_2002_3_JAS >21NC02WQ.C0250000_2002_4_OND >21NC02WQ.C0250000_2003_1_JFM >21NC02WQ.C0250000_2003_2_AMJ >21NC02WQ.C0250000_2003_3_JAS >21NC02WQ.C0250000_2003_4_OND >21NC02WQ.C0250000_2004_1_JFM >21NC02WQ.C0250000_2004_2_AMJ >21NC02WQ.C0250000_2004_3_JAS >... > >load_00600_W (one set of data for the y-axis) >2897.7904362491 >7551.0945112213 >4062.3936560196 >4386.3935825817 >2148.4803413963 >5887.5158386817 >4551.7100620272 >5159.0706830313 >10946.0644621646 >20223.5133431946 >14275.7834627695 >16653.6617307993 >13900.8965496484 >13396.5350817754 >10918.1025781657 >37343.1840220667 >61152.4563009734 >3087159.69237187 >83271.1072869206 >78182.9098615795 >10344.3815353876 >2246.4450929669 >989.220241325 >2318.3488271707 >24134.6766402373 >34350.75952138 >39041.6413152116 >28188.925323908 >2281.7849286464 >1756.7094755792 >357.3578073865 >238.1185010405 >182793.701052689 >2338378.58622751 >333158.050834378 >135771.559284203 >62988.8462340411 >95409.5922031234 >66045.2304429448 >76782.5224502097 >368902.001090301 >717285.957906831 >1189440.79489471 >1077732.29658141 >263564.368874354 >372894.028862293 >209856.865708756 >250149.67080147 >... > > > >load_00600_F (one set of data for the y-axis) >4202.7437226 >4202.7437226 >16214.840538 >7371.9290209 >3114.1090754 >2464.1114951 >9380.6352081 >3859.2809055 >901.86146915 >22377.413599 >53563.26564 >148264.35049 >103538.36278 >18142.045363 >14672.031667 >18796.93618 >75313.330193 >227675.73764 >92777.682029 >84827.680295 >193298.65669 >170799.05034 >103666.8759 >107485.71333 >213765.87505 >472307.65662 >799500.99994 >754868.43185 >454078.02653 >171521.77777 >265827.90007 >120401.25989 >194000.26057 >414312.49534 >617213.70273 >434832.6564 >388556.44724 >349308.46381 >633838.70254 >384887.09244 >303766.12561 >1065566.5203 >2156874.9757 >2521072.5523 >1377743.9361 >683078.62134 >936362.89268 >625201.60587 >1094215.7135 >...>______________________________________________ >R-help@r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html>and provide commented, minimal, self-contained, reproducible code.<span id=m2wTl><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Get the Free email that has everyone talking at <a href=http://www.mail2world.com target=new>http://www.mail2world.com</a><br> <font color=#999999>Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!</font></font></span> [[alternative HTML version deleted]]