> -----Original Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of e-letter > Sent: Friday, April 02, 2010 9:20 AM > To: Gabor Grothendieck > Cc: r-help@r-project.org > Subject: Re: [R] Merge failure using zoo package > > On 02/04/2010, Gabor Grothendieck <ggrothendi...@gmail.com> wrote: > > The code does not run with the files. I need the requested > > information, namely a single file containing code and data > and that I > > can just copy into a session without editing and see the result you > > see. > > I don't understand how I can combine the four csv files into a single > file of data and terminal commands?
One way is to use a call to textConnection() instead of a file name. E.g., if you show a file called "data.txt" containing the lines VarA VarB 1 2 3 4 and you read that into R with data<-read.table(header=TRUE, "data.txt") then the R-helper needs to copy the file contents into an editor, save the file under the appropriate name, then copy the command into an R session. However, you can replace the file and the original read.table command with one command that an R-helper can paste into an R seesion: data <- read.table(header=TRUE, textConnection(" VarA VarB 1 2 3 4 ")) Another approach is to use dput(data) to print the dataset and stick a 'data<-' on the front of what was printed. E.g., with the above 'data' you can do > dput(data) structure(list(VarA = c(1L, 3L), VarB = c(2L, 4L)), .Names = c("VarA", "VarB"), class = "data.frame", row.names = c(NA, -2L)) and send R-help the command data <- structure(list(VarA = c(1L, 3L), VarB = c(2L, 4L)), .Names = c("VarA", "VarB"), class = "data.frame", row.names = c(NA, -2L)) You may have to insert some line breaks in sensible positions so that Outlook or Exchange doesn't break lines in nonsensical positions. Again, the R-helper can copy and paste that code into an R session and come up with a dataset identical to yours. (I've seen copy-n-pastable code in R-help that starts with remove(list=ls()) The suggestion to remove all objects really puts off R-helpers.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > Anyway, further terminal output. > > The following also occurs with correction of the commands. The data > merge is incomplete (to 1:27:30); data set 1 ends at time 1:45:30; > data set 2 1:31:59 > > > library(chron) > > library(zoo) > > z1<-read.zoo("test1.csv",header=TRUE,sep=",",FUN=times) > > z2<-read.zoo("test2.csv",header=TRUE,sep=",",FUN=times) > > z3<-(na.approx(merge(z1[,2],z2[,2]),time(z1))) > > z3 > z1[, 2] z2[, 2] > 01:01:01 0.54186455 0.17558467 > 01:01:30 0.34860813 0.20682491 > 01:01:42 0.48083615 0.23806514 > 01:02:00 0.61306418 0.49837120 > 01:02:23 0.31401158 0.75867726 > 01:02:30 0.01495898 0.75079270 > 01:03:00 0.27035612 0.74290813 > 01:03:06 0.48274755 0.73502357 > 01:03:30 0.69513898 0.83760282 > 01:03:50 0.57982828 0.94018206 > 01:04:00 0.46451758 0.83306352 > 01:04:30 0.61672569 0.72594497 > 01:04:35 0.72084346 0.61882643 > 01:05:00 0.82496122 0.65150068 > 01:05:21 0.58631138 0.68417492 > 01:05:30 0.34766154 0.47526482 > 01:06:00 0.69618714 0.26635471 > 01:06:08 0.54326964 0.05744461 > 01:06:30 0.39035214 0.19544428 > 01:06:55 0.20357679 0.33344394 > 01:07:00 0.01680143 0.45147127 > 01:07:30 0.28576967 0.56949860 > 01:07:44 0.14891191 0.68752593 > 01:08:00 0.01205416 0.51591885 > 01:08:30 0.89637254 0.34431177 > 01:08:33 0.76392454 0.17270469 > 01:09:00 0.63147653 0.49396296 > 01:09:23 0.32334896 0.81522124 > 01:09:30 0.01522139 0.77116200 > 01:10:00 0.27661960 0.72710276 > 01:10:03 0.39318042 0.68304352 > 01:10:30 0.50974124 0.53539217 > 01:10:43 0.59558051 0.38774082 > 01:11:00 0.68141977 0.61475486 > 01:11:23 0.79433915 0.84176890 > 01:11:30 0.90725854 0.59232742 > 01:12:00 0.83823443 0.34288594 > 01:12:04 0.68591842 0.09344446 > 01:12:30 0.53360241 0.11388206 > 01:12:44 0.35564718 0.13431965 > 01:13:00 0.17769196 0.52821343 > 01:13:25 0.50603906 0.92210721 > 01:13:30 0.83438616 0.72684026 > 01:14:00 0.67248807 0.53157330 > 01:14:06 0.38620370 0.33630635 > 01:14:30 0.09991933 0.45160464 > 01:14:47 0.06663450 0.56690294 > 01:15:00 0.03334966 0.33280555 > 01:15:29 0.48313660 0.09870816 > 01:15:30 0.93292355 0.32535246 > 01:16:00 0.15990837 0.55199675 > 01:16:11 0.10672443 0.77864105 > 01:16:30 0.05354050 0.69833773 > 01:16:53 0.30317627 0.61803441 > 01:17:00 0.55281203 0.44246870 > 01:17:30 0.37845690 0.26690299 > 01:17:35 0.63448528 0.09133728 > 01:18:00 0.89051365 0.09029608 > 01:18:17 0.52862829 0.08925487 > 01:18:30 0.16674292 0.49098302 > 01:19:00 0.85458626 0.89271117 > 01:19:30 0.19278550 0.72938430 > 01:19:42 0.46259477 0.56605742 > 01:20:00 0.73240405 0.77563138 > 01:20:25 0.44828965 0.98520534 > 01:20:30 0.16417524 0.87715304 > 01:21:00 0.73878212 0.76910073 > 01:21:08 0.62834165 0.66104843 > 01:21:30 0.51790118 0.81526716 > 01:21:51 0.67433278 0.96948589 > 01:22:00 0.83076438 0.66529956 > 01:22:30 0.47555504 0.36111323 > 01:22:34 0.24832072 0.05692690 > 01:23:00 0.02108640 0.38790073 > 01:23:17 0.42509847 0.71887456 > 01:23:30 0.82911053 0.43395599 > 01:24:00 0.95555646 0.14903741 > 01:24:30 0.14493657 0.50736593 > 01:24:43 0.49457995 0.86569445 > 01:25:00 0.84422332 0.57246479 > 01:25:26 0.63006153 0.27923513 > 01:25:30 0.41589974 0.51404020 > 01:26:00 0.67606367 0.74884526 > 01:26:09 0.34106401 0.98365033 > 01:26:30 0.00606434 0.53336716 > 01:26:53 0.30279212 0.08308399 > 01:27:00 0.59951991 0.34562608 > 01:27:30 0.43949260 0.60816818 > > > > ______________________________________________ > 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. > ______________________________________________ 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.