[R] retrieving object names passed indirectly to a function
Hi folks, I'm stuck with a problem that I suspect has a trivial solution... I have a function, call it foo, that takes a number of arguments which it uses as parameters for a simulation. For later analysis, foo stores the names of the objects passed to it along with the simulation results in its output (written to a database). The objects names are accessed with deparse(substitute(argname)). A second function, call it foo.driver, takes as input a data.frame with cols corresponding to foo arguments containing the character names of objects. For each row of the data.frame in turn, it retrieves the required objects from the global environment and passes them to function foo. Where I am stuck is in how foo.driver should pass an object to foo such that calling deparse(substitute(argname)) in foo will retrieve the correct name (ie. that specified in foo.driver's input data.frame). Hopefully, the following toy code example illustrates what I'm trying to do... # some objects in the global environment to provide param values to foo p1.1 - 1 p1.2 - 2 p2.1 - 3 p2.2 - 4 # controlling table arg.table - data.frame(p1=c(p1.1, p2.2), p2=c(p2.1, p2.2), replicates=c(100, 100)) foo.driver - function( arg.table ) { for (i in 1:nrow(arg.table)) { for (j in 1:arg.table$replicates[i]) { # somehow retrieve objects named in cols p1 and p2 and # pass them to foo with their original names # (e.g. some clever use of get and assign ?) } } } foo - function(p1, p2) { # retrieve and store arg names p1name - deparse(substitute(p1)) p2name - deparse(substitute(p2)) # run simulation with values of p1 and p2 then # store results together with names of objects # passed as args to output database } My actual simulation function involves a large number of arguments of various classes and if at all possible I prefer to avoid hacking it (e.g to accept object names rather than objects). Any tips much appreciated. Michael __ 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] HDP and 99% contour lines
Dear all, I have a very simple question about how I can include HPD confidence lines in a Marginal posterior distribution scatterplot I have the following code to draw the scatterplot(s) from an output table; par(mfrow=c(2,2)) plot(temp1[,5], temp1[,6], xlab=log10(r), ylab=log10(tf), pch=46) plot(temp2[,5], temp2[,6], xlab=log10(r), ylab=log10(tf), pch=46) plot(temp3[,5], temp3[,6], xlab=log10(r), ylab=log10(tf), pch=46) plot(temp4[,5], temp4[,6], xlab=log10(r), ylab=log10(tf), pch=46) dev.print(device=pdf, height=12, width=10, file=Marginal.pdf) I would very much like to include say 0.1, 0.5 and 0.99 contours onto the graphs, but I can't figure it out using any examples of how to do it. Can someone offer any suggestions? Many thanks Peter [[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.
Re: [R] Using McNemar's test to detect shifts in response from pre- topost-treatment
On 09/14/2010 08:58 PM, Robert Baer wrote: McNemar is good for paired data. See ?mcnemar.test You need to get your data into the form of a matrix (e.g., help example), and you will need data organized by concordant and discordant pairing. This means that you will need to organize your data differently than you show us: # pairs YES YES pre-post # pairs YES NO pre-post # pairs NO-YES pre-post # pairs NO-NO pre-post0 Finally, you will need to decide whether to apply the usual continuity correction with your sample size (TRUE by default). Also notice that this is a group A vs. group B situation, whereas McNemar is for whether there is a pre-post difference within a single group. Curiously, there appears to be two different schools on how to handle this sort of data: (A) In cancer epidemiology you would say that this is like a matched case-control study and that in a model with logit-additive effects of pair and that the pre-post odds ratio is estimated by the ratio of the off-diagonal terms. To compare two such ORs between two tables, it is a fairly obvious idea to form the 2x2 table of the two sets of off-diagonal terms and test for independence. Rather nicely, you can use Fisher's exact test in small-sample situations, and its OR estimate is really the ORR - the ratio of the two ORs. (B) However, in clinical trial literature, people focus on the probability _difference_ and correct that for correlations within pairs. One advantage of this is that estimates have the same interpretation whether the experiment was paired or unpaired. Technically, what you do is little different from scoring +/-1 for increase, and 0 for no change, and then compare the average scores with a t-test or a permutation test. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ 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.
Re: [R] extracting objects from lists
You can explore the structure of the list with str(). If you use Eclipse, a list of available options will be created for you as you type (see http://imagepaste.nullnetwork.net/viewimage.php?id=1293). Cheers, Roman -- View this message in context: http://r.789695.n4.nabble.com/extracting-objects-from-lists-tp2539412p2540051.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Multiple CPU HowTo in Linux?
Hello all, Thanks for your input, and helping to clear things up on where to go. I will try out the multicore package and see if there are further bottlenecks. It looks like some loops might need special treatment with parallelization. I have been pampered with the excellent walk-through vignettes of the packages I have used so far. The HPC package guides lacked something in the practical aspects of their usage. lapply - mclapply at the beginning of my script? Well, I never would have thought of such a thing. Thanks! I might be back on the list when I run out of physical RAM ;-) Edwin -- On Tue, 14 Sep 2010 12:11:17 -0700 Martin Morgan mtmor...@fhcrc.org wrote: On 09/14/2010 08:36 AM, Christian Raschke wrote: Edwin, I'm not sure what you mean by adapting; other than installing multicore, there is nothing else to set up. How and whether you could then parallelise your code strongly depends on the specific problem you are facing. What have done in the past was to look at the source of the functions from whatever package I was using that produced the bottleneck. If what is taking the longest time is actually embarrassingly parallel, mclapply() from package multicore can help. In the simplest case you could simply replace lapply() in the with an appropriate mclapply(). Check out ?mclapply. But then again you might have to get a little more creative, depending on exactly what in the code is taking so long to run. If your problem is inherently sequential then even multicore won't help. Christian On 09/14/2010 09:35 AM, Edwin Groot wrote: Hello Cedrick, Ah, yes, that looks like it would apply to my situation. I was previously reading on snow, which is tailored for clusters, rather than a single desktop computer. Anyone with experience adapting multicore to an R-script? I have to admit I know little about parallel processing, multiprocessing and cluster processing. Edwin On Tue, 14 Sep 2010 10:15:42 -0400 Johnson, Cedrick W.cedr...@cedrickjohnson.com wrote: ?multicore perhaps On 09/14/2010 10:01 AM, Edwin Groot wrote: Hello all, I upgraded my R workstation, and to my dismay, only one core appears to be used during intensive computation of a bioconductor function. Hi Edwin -- Since you have a Bioconductor package, you might ask on the Bioconductor list, as the authors of some computationally intensive tasks have provided facilities for relatively transparent use of, e.g., multicore or Rmpi. In ShortRead, for instance, loading multicore is enough to distribute some tasks across cores, and the srapply function can help (or not; things might be as easy as lapply - mclapply at the top of your script) with your own lapply-like code. http://bioconductor.org/help/mailing-list/ Martin What I have now is two dual-core Xeon 5160 CPUs and 10 GB RAM. When I fully load it, top reports about 25% user, 75% idle and 0.98 short-term load. The archives gave nothing helpful besides mention of snow. I thought of posting to HPC, but this system is fairly modest WRT processing power. Any pointers of where to start? --- #Not running anything at the moment sessionInfo() R version 2.11.1 (2010-05-31) x86_64-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_GB.UTF-8LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.1 --- $ uname -a Linux laux29 2.6.26-2-amd64 #1 SMP Sun Jun 20 20:16:30 UTC 2010 x86_64 GNU/Linux --- Thanks for your help, Edwin __ 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. Dr. Edwin Groot, postdoctoral associate AG Laux Institut fuer Biologie III Schaenzlestr. 1 79104 Freiburg, Deutschland +49 761-2032945 __ 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
Re: [R] Problem with cat() == A related question
William Revelle li...@revelle.net on Tue, 14 Sep 2010 14:52:32 -0500 writes: At 3:45 PM -0400 9/14/10, jim holtman wrote: The problem is the 'cat' enclosing the 'print'; just get rid of the 'cat' -- that is what is causing the extra output On Tue, Sep 14, 2010 at 3:34 PM, Peng, C cpeng@gmail.com wrote: It is still visible even it is set invisible(NULL): fn1 - function(n = 5){ + mat - matrix(rnorm(5*5), 5, 5) + cat(print(mat)) + invisible(NULL)} fn1() [,1][,2] [,3][,4] [,5] [1,] -1.22767085 -1.41468587 -2.0156231 0.29732942 0.5755600 [2,] -0.16775996 -0.03780596 -0.9461079 0.91289175 0.1254273 [3,] 0.09696032 -0.75522210 -0.7494442 -0.21341669 1.7088194 [4,] 0.13535505 -1.09011005 -0.6074198 0.05342614 -1.1996344 [5,] 0.66474083 -2.62206248 0.1329972 0.06132865 0.5124778 -1.227671 -0.1677600 0.09696032 0.1353550 0.6647408 -1.414686 -0.03780596 -0.7552221 -1.09011 -2.622062 -2.015623 -0.9461079 -0.7494442 -0.6074198 0.1329972 0.2973294 0.9128917 -0.2134167 0.05342614 0.06132865 0.57556 0.1254273 1.708819 -1.199634 0.5124778 -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2539551.html Sent from the R help mailing list archive at Nabble.com. I think that what Peng was trying to do was print it without the column and row names mat - matrix(1:25,5,5) colnames(mat) - rownames(mat) - rep(,5) print(mat) 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25 Yes. A (slightly more general and efficient) version is sfsmisc::empty.dimnames( matrix(1:40, 5,8) ) 1 6 11 16 21 26 31 36 2 7 12 17 22 27 32 37 3 8 13 18 23 28 33 38 4 9 14 19 24 29 34 39 5 10 15 20 25 30 35 40 --- where the empty.dimnames() function is just one small reason to get the sfsmisc package ;-) Martin Maechler, ETH Zurich __ 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.
Re: [R] Problems with pdf device using plot glht function on multcomp library.
Dear Ken, it works for me on Linux. However, the print() commands around plot() are not necessary. Torsten __ 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] difftime problems with daylight saving time?
Hi, I seem to be having problems in calculating the period between two times, one with and the other without daylight saving time. Consider the following command : as.numeric(difftime(as.POSIXct(2010-04-01 06:00:00 CEST),as.POSIXct(2010-03-03 08:27:00 CET),units=hours)) [1] 692.55 No problem here. Strangely enough, I seem to be having problems in using the same command when applied to a data frame. Let me explain with the following code : df-structure(list(d1 = structure(c(1263279420, 1263885000, 1264492200, 1265094120, 1265784900, 1266391860, 1266908220, 1267515240, 1268117220, 1268722020, 1269327240, 1269841740, 1270532400, 1271138400, 1271833380, 1272349740, 1272953820, 1273470060, 1274075640, 1274768100, 1275285060, 1275976500, 1276494480, 1277100300, 1277703480, 1278309420, 1278913620, NA, NA, NA, NA, 1282198020, 1282630920, 1283149380), class = c(POSIXt, POSIXct), tzone = ), d2 = structure(c(1263367500, 1263972540, 1264578600, 1265182740, 1265872260, 1266479460, 1266996720, 1267601220, 1268204100, 1268811960, 1269415200, 1269929340, 1270620300, 1271224800, 1271918520, 1272436020, 1273045800, 1273558740, 1274163720, 1274854140, 1275373620, 1276062900, 1276583400, 1277187060, 1277792100, 1278397800, 1279002840, NA, NA, NA, NA, 1282285380, 1282718460, 1283237940 ), class = c(POSIXt, POSIXct), tzone = )), .Names = c(d1, d2), class = data.frame, row.names = c(NA, -34L)) # get the first of corresponding month for d1 g1-as.POSIXlt(df$d1,format=%Y-%m-%d %H:%M:%S) g1$mday-1;g1$hour-6;g1$min-0; df$m1-as.POSIXct(g1) # period between d1 and m1 df$nh1-with(df,round(as.numeric(difftime(d1,m1,units=hours)),1)) # get the first of next month for d2 g1$mon-g1$mon+1 df$m2-g1 #period between m2 and d2 df$nh2-with(df,round(as.numeric(difftime(m2,d2,units=hours)),1)) str(df) I get the following result : df d1 d2 m1 nh1 m2 nh2 1 2010-01-12 07:57:00 2010-01-13 08:25:00 2010-01-01 06:00:00 265.9 2010-02-01 06:00:00 453.6 2 2010-01-19 08:10:00 2010-01-20 08:29:00 2010-01-01 06:00:00 434.2 2010-02-01 06:00:00 285.5 3 2010-01-26 08:50:00 2010-01-27 08:50:00 2010-01-01 06:00:00 602.8 2010-02-01 06:00:00 117.2 4 2010-02-02 08:02:00 2010-02-03 08:39:00 2010-02-01 06:00:00 26.0 2010-03-01 06:00:00 621.4 5 2010-02-10 07:55:00 2010-02-11 08:11:00 2010-02-01 06:00:00 217.9 2010-03-01 06:00:00 429.8 6 2010-02-17 08:31:00 2010-02-18 08:51:00 2010-02-01 06:00:00 386.5 2010-03-01 06:00:00 261.1 7 2010-02-23 07:57:00 2010-02-24 08:32:00 2010-02-01 06:00:00 530.0 2010-03-01 06:00:00 117.5 8 2010-03-02 08:34:00 2010-03-03 08:27:00 2010-03-01 06:00:00 26.6 2010-04-01 06:00:00 NA 9 2010-03-09 07:47:00 2010-03-10 07:55:00 2010-03-01 06:00:00 193.8 2010-04-01 06:00:00 NA 10 2010-03-16 07:47:00 2010-03-17 08:46:00 2010-03-01 06:00:00 361.8 2010-04-01 06:00:00 NA 11 2010-03-23 07:54:00 2010-03-24 08:20:00 2010-03-01 06:00:00 529.9 2010-04-01 06:00:00 NA 12 2010-03-29 07:49:00 2010-03-30 08:09:00 NA NA 2010-04-01 06:00:00 45.9 13 2010-04-06 07:40:00 2010-04-07 08:05:00 2010-04-01 06:00:00 121.7 2010-05-01 06:00:00 573.9 14 2010-04-13 08:00:00 2010-04-14 08:00:00 2010-04-01 06:00:00 290.0 2010-05-01 06:00:00 406.0 15 2010-04-21 09:03:00 2010-04-22 08:42:00 2010-04-01 06:00:00 483.1 2010-05-01 06:00:00 213.3 16 2010-04-27 08:29:00 2010-04-28 08:27:00 2010-04-01 06:00:00 626.5 2010-05-01 06:00:00 69.5 17 2010-05-04 08:17:00 2010-05-05 09:50:00 2010-05-01 06:00:00 74.3 2010-06-01 06:00:00 644.2 18 2010-05-10 07:41:00 2010-05-11 08:19:00 2010-05-01 06:00:00 217.7 2010-06-01 06:00:00 501.7 19 2010-05-17 07:54:00 2010-05-18 08:22:00 2010-05-01 06:00:00 385.9 2010-06-01 06:00:00 333.6 20 2010-05-25 08:15:00 2010-05-26 08:09:00 2010-05-01 06:00:00 578.2 2010-06-01 06:00:00 141.8 21 2010-05-31 07:51:00 2010-06-01 08:27:00 2010-05-01 06:00:00 721.9 2010-06-01 06:00:00 -2.5 22 2010-06-08 07:55:00 2010-06-09 07:55:00 2010-06-01 06:00:00 169.9 2010-07-01 06:00:00 526.1 23 2010-06-14 07:48:00 2010-06-15 08:30:00 2010-06-01 06:00:00 313.8 2010-07-01 06:00:00 381.5 24 2010-06-21 08:05:00 2010-06-22 08:11:00 2010-06-01 06:00:00 482.1 2010-07-01 06:00:00 213.8 25 2010-06-28 07:38:00 2010-06-29 08:15:00 2010-06-01 06:00:00 649.6 2010-07-01 06:00:00 45.8 26 2010-07-05 07:57:00 2010-07-06 08:30:00 2010-07-01 06:00:00 98.0 2010-08-01 06:00:00 621.5 27 2010-07-12 07:47:00 2010-07-13 08:34:00 2010-07-01 06:00:00 265.8 2010-08-01 06:00:00 453.4 28 NA NA NA NA NA NA 29 NA NA NA NA NA NA 30 NA NA NA NA NA NA 31 NA NA NA NA NA NA 32 2010-08-19 08:07:00 2010-08-20 08:23:00 2010-08-01 06:00:00 434.1 2010-09-01 06:00:00 285.6 33 2010-08-24 08:22:00
Re: [R] Package build and install under Windows
On 14.09.2010 21:05, Tao wrote: Any other method besides using RTOOLS? I am using R 2.10.1, which version of Rtools should I use? The most recent one that supports R-2.10.1? According to the webpage this is Rtools211.exe. It seems that there are two versions on the website. The commands like R CMD build should be used in the CMD window, right? Thanks. Actually on your OS's command shell. Uwe Ligges __ 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] Get File Names in Folder, Read Files, Update, and Write
Dear All, Could you please recommend how I can do this? I have several text files in one folder. Let's name them A0801.RSK, A0802.RSK, I would like R to 1) Know all file names in this folder 2) Update value in one column of these files 3) Write results in another text file with _xval in the file names Below is R code for read, update, and write one file Import-C:/A0810.RSK Table-read.table(file= Import, sep = ,, head=TRUE, na.strings = NA) Table$VALUE -0 Export-C:/A_XVal0810.RSK write.table(Table, file= Export, sep = ,, col.names = TRUE) Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities Public Company Limited Tel: +662-305-9179 Email: supha...@phatrasecurities.com [[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.
Re: [R] multiple cores/building fails
On 14.09.2010 21:50, Gregory Ryslik wrote: Hi Everyone, I have written debugged and tested my code and it works (yay!). I recently tried to parallelize it (1 core/per tree) and when I run the code I get an error saying the object control was not found. I do have an object control in my code but it always works fine as long as I am not running it on multiple cores (which I am doing via the help of sleigh and the 'nws' package). Think that this could be an error in my source statements, I tried to build my package (with the hope of replace source with library()) and I get the following (where XXX is my package name that I've removed for privacy reasons): * creating vignettes ... ERROR Error: processing vignette '.Rnw' failed with diagnostics: chunk 4 Error : object control not found Again it gives me that this control object is not found. Does anyone have an idea how I can isolate what's going on. It's slightly tough to do because it all works fine in the single processor case! Perhaps you forgot to populate the object to the client nodes? Hard to say without any reproducible example code. Uwe Ligges Thanks! Kind regards, Greg __ 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.
Re: [R] Get File Names in Folder, Read Files, Update, and Write
On 15.09.2010 10:55, Suphajak Ngamlak wrote: Dear All, Could you please recommend how I can do this? I have several text files in one folder. Let's name them A0801.RSK, A0802.RSK, I would like R to 1) Know all file names in this folder ?list.files 2) Update value in one column of these files 3) Write results in another text file with _xval in the file names ?paste Uwe Ligges Below is R code for read, update, and write one file Import-C:/A0810.RSK Table-read.table(file= Import, sep = ,, head=TRUE, na.strings = NA) Table$VALUE-0 Export-C:/A_XVal0810.RSK write.table(Table, file= Export, sep = ,, col.names = TRUE) Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities Public Company Limited Tel: +662-305-9179 Email: supha...@phatrasecurities.com [[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. __ 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.
Re: [R] converting string vector to integer/numeric vector
On 05.09.2010 14:48, rajesh j wrote: Hi, Is it possible to convert a string vector to integer or numeric vector? In my situation I receive data in a string vector and have to convert it based on a given type. ?as.interger ?as.numeric Uwe Ligges __ 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.
Re: [R] assignment by value or reference
See the R Language Definition manual. Since R knows about lazy evaluation, it is sometimes neither by reference nor by value. If you want to think binary, then by value fits better than by reference. Uwe Ligges On 05.09.2010 17:19, Xiaobo Gu wrote: Hi Team, Can you please tell me the rules of assignment in R, by value or by reference. From my about 3 months of experience of part time job of R, it seems most times it is by value, especially in function parameter and return values assignment; and it is by reference when referencing container sub-objects of container objects, such as elements of List objects and row/column objects of DataFrame objectes; but it is by value when referencing the smallest unit of element of a container object, such as cell of data frame objects. Xiaobo.Gu [[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. __ 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.
Re: [R] CRAN Mirror definition error.
You may have a proxy in your network that has to be used. Since this seems to be Windows: Please see the R for Windows FAQs for more information. Best wishes, Uwe On 01.09.2010 19:43, Lenart, Joseph wrote: Hello, I was wondering if anyone has run across this problem in the past and might be able to suggest a solution. I did a review of the FAQ's link trying to find a topic that closely related to the experience I was having, however I didn't see anything that might help in diagnosing the problem. While invoking the options under the package menu I get the following errors: chooseCRANmirror() Warning message: In open.connection(con, r) : cannot open: HTTP status was '0 (nil)' setRepositories() update.packages(ask='graphics') Warning: unable to access index for repository http://www.ibiblio.org/pub/languages/R/CRAN/bin/windows/contrib/2.11 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.11 utils:::menuInstallPkgs() Warning: unable to access index for repository http://www.ibiblio.org/pub/languages/R/CRAN/bin/windows/contrib/2.11 Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.11 Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) : no packages were specified setRepositories() Does anyone have any insights into what might cause this issue, and how I might fix the problem? Any thoughts you may have would be greatly appreciated. Thanks in advance - Joe Lenart p.s. - I have confirmed that I can access the mirror sites using a regular browser, so I do not believe this to be a security or firewall-related issue. Ad Astra... Joseph P. Lenart Capacity Management Unit - Non Mainframe THE AETNA 151 Farmington Ave. Mailstop: ASA1 Hartford, CT 06156 Phone - 860-273-7085 Fax - 860-273-5053 If you hear a voice within you say, 'You cannot paint,' then by all means paint and that voice will be silenced. - Vincent van Gogh This e-mail may contain confidential or privileged information. If you think you have received this e-mail in error, please advise the sender by reply e-mail and then delete this e-mail immediately. Thank you. Aetna [[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. __ 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.
Re: [R] Using feather.plot to try and generate a stick plot of current velocity data (and having issues)
On 09/15/2010 01:29 PM, Hughes, Ed wrote: Hello All, I am attempting to use the feather.plot function from the plotrix package to graph current velocity data as I have speed and direction. I let r be the first 10 rows of current speed data and theta be the first 10 rows of directional data in radians. I had tried this with 10 measurements, but keep getting the following error message: feather.plot(r,theta,1:10,yref=0,use.arrows=FALSE, fp.type=m) Error in segments(xpos, yref, xpos + x, y, ...) : invalid third argument My goal was to trouble shoot this smaller data set and see if I could ramp up to few thousand entries to basically generate a stick plot of current flow data. Curious if I was doing anything obviously wrong with my arguments or if I should be using an entirely different function. Hi Eddie, I think the problem is with the format of your data. I tried a whole bunch of variants of vectors, matrices and data frames and couldn't reproduce your error. Could you post a sample data set that causes this problem? Thanks. Jim __ 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.
Re: [R] ggplot: stat_smooth() and nls method
great help, thanks a lot Le 14/09/2010 21:44, Brian Diggs a écrit : On 9/11/2010 7:52 AM, Benoit Boulinguiez wrote: Hi all, Does one of you know if there is any way to combine a nls method in the stat_smooth of ggplot? Regards According to the documentation for predict.nls, it is unable to create standard errors for the predictions, so that has to be turned off in the stat_smooth call. Also, the default formula isn't valid for nls and has to be overridden, and the start values can be passed. I used geom_smooth rather than stat_smooth, but either work. library(ggplot2) DF - data.frame(x=1:20, y=rnorm(20)) ggplot(DF, aes(x=x, y=y)) + geom_smooth(method=nls, formula=y~b*x+c, se=FALSE, start=list(b=0,c=1)) + geom_point() ggplot(DF, aes(x=x, y=y)) + geom_smooth(method=nls, formula=y~sin(b*x), se=FALSE, start=list(b=1)) + geom_point() __ 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] Programming: loop versus vector oriented
Dear all, I am new to R and to it's programming philosophy. The following function is supposed to work on a vector, but I can't figure out how to do that without looping through every element of it. Is there a more elegant way? Note: I have shortened it, so it is NOT correct from the pipe hydraulics point of view # Calculate wall friction factor # reynolds: Reynolds number # dk: relative roughness of pipe lambda_wall - function (reynolds, dk) { z - 1 result - 0 for (Re in reynolds) { if (Re = 2320) { # Laminar flow lambda - 64/Re } else if (Re 65 * dk[z]) { # Turbulent flow if (Re 1e+5) { lambda - 0.3164 / sqrt(sqrt(Re)) } else { lambda - 0.309/(log10(Re/7))^2 } } else { # Intermediate area lambdanew - 1 / (2 * log10(3.71 * dk[z]))^2 # Start value iter - 0 repeat { lambda - lambdanew lambdanew - 1 / (2 * log10(2.51/(Re * sqrt(lambda)) + 0.27/dk[z]))^2 iter - iter + 1 if ((abs(lambdanew - lambda) 0.001) || (iter 100)) break } lambda = lambdanew } result[z] - lambda z - z + 1 } result } # lambda_wall() __ 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] Interpolate? a line
Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? I would like to thank you for your feedback. Best Regards Alex [[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.
[R] R install in Fedora
Dear All As you suggested I tried to install was trying to install R-2.11.1-3.fc13.1686 in Fedora-13-i386 but it also shows error. I wrote yum install R-2.11.1-3fc13.i686 Errors Cannot retrieve repository metadata (repond.xml) for repository: fedora. Please verify its path and try again. Could you please help me to solve this problem. Thanks in advance Kind Regards Wesley C Mathew [[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.
[R] cochran-grubbs tests results
Hello, I'm new in this R world and I don't know much about statistics, but now I have to analize some data and I've got some first queries yet: I have 5 sets of area mesures and each set has 5 repetitions. My first step is to check data looking for outliers. I've used the outliers package. I have to use the cochran test and the grubbs test in case I find any outlier. The problem is that I don't know how to interpret the results. Cochran test finds an outlier among variances. Grubbs test finds an outlier within the set of measures wich corresponds to the variance that is an outlier. I repeat the Cochran test discarding that measure. And it finds a new outlier and so on. This is what I've done first: - varianza [1] 9.979937e-07 1.131360e-07 4.140418e-06 2.184604e-07 3.662077e-07 data1-c(rep(4,5)) cochran.test(varianza, data1, inlying = FALSE) Cochran test for outlying variance data: varianza C = 0.7094, df = 4, k = 5, p-value = 0.007645 alternative hypothesis: Group 3 has outlying variance sample estimates: 12345 9.979937e-07 1.131360e-07 4.140418e-06 2.184604e-07 3.662077e-07 It would be really helpful if someone could tell me what C, df, K and p-value mean. Besides, I don't know if alternative hypothesis (in the grubbs test) means that the highest value is an outlier to be discarded or just the worst value, but not necessarily to be discarded. grubbs.test(serie3, type = 10, opposite = FALSE, two.sided = FALSE) Grubbs test for one outlier data: serie3 G = 1.3384, U = 0.2039, p-value = 0.2155 alternative hypothesis: highest value 0.238877332 is an outlier - As you see I'm quite lost. Thank you in advance and I'll keep trying. Gracias -- View this message in context: http://r.789695.n4.nabble.com/cochran-grubbs-tests-results-tp2540295p2540295.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Interpolate? a line
Hello Alex, Here is one way to do it. It works but it's not pretty :) interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison Michael __ 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.
Re: [R] Package build and install under Windows
Tao wrote: Any other method besides using RTOOLS? I am using R 2.10.1, which version of Rtools should I use? It seems that there are two versions on the website. What website are you talking about? The Rtools website http://www.murdoch-sutherland.com/Rtools/ has 7 different versions of the tools, and clearly labels which versions of R are supported by each. Duncan Murdoch The commands like R CMD build should be used in the CMD window, right? Thanks. __ 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.
Re: [R] Interpolate? a line
Thank you very much. I am trying to execute it line by line to get some understanding how this works. Could you please explain me what these two lines do? tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] I would like to thank you in advance for your help Best Regards Alex From: Michael Bedward michael.bedw...@gmail.com Cc: Rhelp r-help@r-project.org Sent: Wed, September 15, 2010 12:52:45 PM Subject: Re: [R] Interpolate? a line Hello Alex, Here is one way to do it. It works but it's not pretty :) interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison Michael [[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.
Re: [R] Model averaging with (and without) interaction terms
Leslie Young leslie.young101 at gmail.com writes: I’ve used logistic regression to create models to assess the effect of 3 variables on the presence or absence of a species, including the interaction terms between variables and model averaging using MuMI: model.avg The top models (delta4) include several models with interaction terms and some models without; model weights are quite low for all models (0.25). My problem is that the models with interactions have negative coefficients on the variables with a positive interaction term whereas the same model without an interaction has positive coefficients. MuMIn: model.avg averages all these models together, so the relationship is washed out (CI overlaps 0). Eg. mod1-glm(presence ~ x1*x2, family=”binomial”) coefficients: -0.661 x1, -0.043 x2, 0.02 x1:x2 mod2 - glm(presence ~ x1 + x2, family=”binomial”) coefficients: 0.245 x1, 0.021 x2 I’ve read that it is difficult to compare models with and without interaction terms, but nothing regarding how one might go about doing so. Should interaction models be averaged differently or separately than models without interaction terms? Is there another way to approach this? The tricky aspect of comparing models with and without interaction terms is that the main effect parameters have different meanings when the interactions are included. It looks like your parameters are both continuous, so I'll discuss things in this context. In the interaction model, the x1 parameter gives the expected change in log-odds (logit probability) for a 1-unit increase in the corresponding predictor variable **when x2 is equal to 0**. In the non-interaction model, the x1 parameter gives the *average* expected change in log-odds across the distribution of x2 values observed in the data sets. It will help a bit if you follow Schielzeth [Schielzeth, Holger. 2010. Simple means to improve the interpretability of regression coefficients. Methods in Ecology and Evolution , no. . doi:10./j.2041-210X.2010.00012.x.] and mean-correct your predictors before fitting the model. I have a bigger problem (which perhaps luckily for you is not shared with much of the ecological community), which is that usually people who are model-averaging *parameters* (rather than *predictions*) are essentially trying to use information-theoretic approaches to test hypotheses ... __ 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.
Re: [R] HDP and 99% contour lines
Peter Spencer P.Spencer at murdoch.edu.au writes: Dear all, I have a very simple question about how I can include HPD confidence lines in a Marginal posterior distribution scatterplot I have the following code to draw the scatterplot(s) from an output table; I think the code in HPDregionplot in the emdbook package might help. __ 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.
Re: [R] Interpolate? a line
Ah, now that you ask that I realize I was making an assumption assumption about what you want to achieve. Those two lines remove coords where the y value is equal to that of the preceding coord. That may or may not be what you want to do. To visualize what is happening, type plot(m) before doing those two lines (you'll see most points arranged in horizontal pairs), the execute the two lines and do plot(m) again. Michael On 15 September 2010 21:05, Alaios ala...@yahoo.com wrote: Thank you very much. I am trying to execute it line by line to get some understanding how this works. Could you please explain me what these two lines do? tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] __ 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.
Re: [R] Interpolate? a line
Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? I would like to thank you for your feedback. Best Regards Alex On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote: Hello Alex, Here is one way to do it. It works but it's not pretty :) If you want an alternative, consider that produces the Y cell indices (since the x cell indices are already 2:62): linefn - function(x) 3+((34-3)/(62-2)) *(x-2) findInterval(linefn(2:62), 3:34) [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 [55] 28 29 29 30 30 31 32 # that seems off by two linefn(62) [1] 34 linefn(2) [1] 3 # but that checks out and I realized those were just indices for the 3:34 findInterval vector (3:34)[findInterval(linefn(2:62), 3:34)] [1] 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 [55] 30 31 31 32 32 33 34 ( no rounding and I think the logic is clearer.) -- David. interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison you can add a grid with abline(v=2:62, h=3:34) Michael __ 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. David Winsemius, MD West Hartford, CT __ 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] A question on modelling binary response data using factors
Dear all, A question on modelling proportional data in R. I have a test experiment that was designed in a particular way, and which I can analyse by hand to an extent. I am really struggling to get R to give me sensible results in modelling it properly, so must be doing something wrong here. As background, I conduct a series of experiments and count the hits and misses - I believe this could be modelled using a glm. The experiments are done under a range of conditions, altering three different factors, lets call them A, B, and C. Factors A and B each have 2 levels (A1,A2,B1,B2) while factor C has 5 levels (C1,C2,C3,C4,C5). The experiment has only partial coverage, that is not every A is tested with every B and every C. However, I was careful in the experimental design to ensure that every A and every B was tested against at least one C. Here is my experimental data: FactorA FactorB FactorCHit Miss A1 B1 C1 17 83 A1 B1 C2 17 83 A1 B1 C3 18 82 A1 B1 C4 NA NA A1 B1 C5 NA NA A1 B2 C1 11 89 A1 B2 C2 17 83 A1 B2 C3 17 83 A1 B2 C4 NA NA A1 B2 C5 NA NA A2 B1 C1 NA NA A2 B1 C2 NA NA A2 B1 C3 23 77 A2 B1 C4 19 81 A2 B1 C5 29 71 A2 B2 C1 NA NA A2 B2 C2 NA NA A2 B2 C3 13 87 A2 B2 C4 20 80 A2 B2 C5 24 76 I to compare individual rates against the overall rate, and look at difference across pooled rate for each factor Doing hand calculations, it is possible to calculate the individual hit rates, the overall hit rate of the pool, and the standard errors on these using hitrate = hits/(hits+misses) and hitrateerror = sqrt((hits+misses)*(hits/(hits+misses))*(misses/(hits+misses)))/(hits+misses) Again doing hand calculations, it is possible to extract the influence of each variant of each factor, by producing a pool and comparing the influence of each variant to the pool. For the overall pool, there were 225 hits from 1200 trials, for a pooled hitrate of 18.8%. For factor C the analysis is relatively straightforward, in that we calculate the hitrate for each C1 (28 hits from 200 trials = 14.0%), C2, ... etc. We then calculate the influence of a given factor compared to the pool - for example C1 has a hitrate of 14.0% compared to a pooled hitrate of 18.8%, so has an influence of (14.0%/18.8%)-100% = -25%. For factor A, the analysis is slightly complicated by the fact that factor C3 is the only variant that fairly tests factor A (none of factors C1,C2,C4,C5 do not have experiments for both factors A1 and A2). Therefore, just taking the factor C3 data, we can show that the pool of 400 trials had 71 hits, for a hitrate of 17.8%. We can then calculate the hitrate for A1 and A2 as 17.5% and 18.0% respectively. From this we can say that the effect of A1 and A2 was -1.4% and +1.4%, that is to say (17.5%/17.8%)-100% and (18.0/17.8%)-100%. The trick here is that the pooled hitrate for factor A is 17.8%, i.e. the hitrate for factor C3 alone, not 18.8% which is the overall pooled hitrate. However we have taken out the influence of C3 by normalising to the C3 hitrate, i.e. we could calculate the expected hitrate of the combination A2 B2 C1, which was never tested, by combining the influence of A2, B2 and C1 on the overall pool hitrate of 18.8%. It should be possible to model this using e.g. a glm with appropriate contrasts and model, however for the life of me I cannot work out how to get this to work. Getting R to provide a sensible intercept to the model, i.e. the overall hitrate of 18.8%, and also get sensible indications of the importance or otherwise of each factor. In particular, I am really struggling to get R to test the relevance of factor A - this is because when tested using all factor C, not just C3, there is a huge bias in that C1 and C2 have comparitively low hit rates, and were only tested against A1, whereas C4 and C5 have comparitively high hitrates, but were only tested against A2. That means that it appears, unless you look at the C3 data only, that factor A is highly important - whereas it clearly is not. The reason for using R to model this correctly, rather than just doing the hand
[R] barplot: space between axis and bars
Hi all, I have a problem with a rather simple plot (which I have used several times) - barplot. I want to create a barplot, where no space is between the axis and the bars. Example: barplot(rnorm(10), space=0) creates a vertical axis at the left and bars. I want to skip the space between both. Thank you for your help. Daniel __ 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.
Re: [R] Interpolate? a line
On Sep 15, 2010, at 7:24 AM, David Winsemius wrote: Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? I would like to thank you for your feedback. Best Regards Alex On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote: Hello Alex, Here is one way to do it. It works but it's not pretty :) If you want an alternative, consider that produces the Y cell indices (since the x cell indices are already 2:62): linefn - function(x) 3+((34-3)/(62-2)) *(x-2) findInterval(linefn(2:62), 3:34) [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 [55] 28 29 29 30 30 31 32 # that seems off by two linefn(62) [1] 34 linefn(2) [1] 3 # but that checks out and I realized those were just indices for the 3:34 findInterval vector (3:34)[findInterval(linefn(2:62), 3:34)] [1] 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 [55] 30 31 31 32 32 33 34 ( no rounding and I think the logic is clearer.) But I also realized it didn't enumerate all the the cells were crossed either, only indicating which cell was associated with an integer value of x. Also would have even more serious problems if the slope were greater than unity. To enumerate the cell indices that were crossed, try: unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) ) ) [,1] [,2] [1,]23 [2,]33 [3,]44 [4,]54 [5,]55 [6,]65 [7,]75 [8,]76 snipping interior results [83,] 58 32 [84,] 59 32 [85,] 60 32 [86,] 60 33 [87,] 61 33 [88,] 62 34 That could probably be passed to rect() to illustrate (and check logic): rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) #redraw line : lines(2:62, 3+(34-3)/(62-2)*(0:60)) -- David. interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison you can add a grid with abline(v=2:62, h=3:34) Michael __ 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. David Winsemius, MD West Hartford, CT __ 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. David Winsemius, MD West Hartford, CT __ 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.
Re: [R] content analysis
Christian, Have you looked at TM? There is also Quantitative Corpus Linguistics with R by Stefan Gries, which you may find of interest. Tau, Readme and rattle might be worth looking into. See also: http://ses.telecom-paristech.fr/lebart/ regards Bob __ 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.
Re: [R] barplot: space between axis and bars
Try par(xaxs=i) barplot(rnorm(10), space=0) -tgs On Wed, Sep 15, 2010 at 7:54 AM, Daniel Stepputtis daniel.stepput...@vti.bund.de wrote: Hi all, I have a problem with a rather simple plot (which I have used several times) - barplot. I want to create a barplot, where no space is between the axis and the bars. Example: barplot(rnorm(10), space=0) creates a vertical axis at the left and bars. I want to skip the space between both. Thank you for your help. Daniel __ 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.
Re: [R] retrieving object names passed indirectly to a function
Answering my own question (in case it's of use to anyone else) here is the example code again but now using call and eval to accomplish the desired output: foo - function(p1, p2) { p1name - deparse(substitute(p1)) p2name - deparse(substitute(p2)) # The real function runs a simulation, but # here we just confirm the object names # and values passed as args cat(passed, p1name, with value, p1, \n) cat(passed, p2name, with value, p2, \n) } foo.driver - function(param.table) { for (i in 1:nrow(param.table)) { foo.call - call(foo, as.name(param.table$p1[i]), as.name(param.table$p2[i]) ) for (rep in 1:param.table$repl[i]) { eval(foo.call) } } } # some objects in the global env which will be used as args to foo p1a - 1.1 p1b - 1.2 p2a - 2.1 p2b - 2.2 # the controlling table for foo.driver param.table - data.frame(p1=c(p1a, p1b), p2=c(p2a,p2b), replicates=c(1,1), stringsAsFactors=FALSE) # Now run foo.driver with param.table... foo.driver(param.table) The code above produces the following output: passed p1a with value 1.1 passed p2a with value 2.1 passed p1b with value 1.2 passed p2b with value 2.2 Happy :) Michael On 15 September 2010 16:07, Michael Bedward michael.bedw...@gmail.com wrote: Hi folks, I'm stuck with a problem that I suspect has a trivial solution... I have a function, call it foo, that takes a number of arguments which it uses as parameters for a simulation. For later analysis, foo stores the names of the objects passed to it along with the simulation results in its output (written to a database). The objects names are accessed with deparse(substitute(argname)). A second function, call it foo.driver, takes as input a data.frame with cols corresponding to foo arguments containing the character names of objects. For each row of the data.frame in turn, it retrieves the required objects from the global environment and passes them to function foo. Where I am stuck is in how foo.driver should pass an object to foo such that calling deparse(substitute(argname)) in foo will retrieve the correct name (ie. that specified in foo.driver's input data.frame). Hopefully, the following toy code example illustrates what I'm trying to do... # some objects in the global environment to provide param values to foo p1.1 - 1 p1.2 - 2 p2.1 - 3 p2.2 - 4 # controlling table arg.table - data.frame(p1=c(p1.1, p2.2), p2=c(p2.1, p2.2), replicates=c(100, 100)) foo.driver - function( arg.table ) { for (i in 1:nrow(arg.table)) { for (j in 1:arg.table$replicates[i]) { # somehow retrieve objects named in cols p1 and p2 and # pass them to foo with their original names # (e.g. some clever use of get and assign ?) } } } foo - function(p1, p2) { # retrieve and store arg names p1name - deparse(substitute(p1)) p2name - deparse(substitute(p2)) # run simulation with values of p1 and p2 then # store results together with names of objects # passed as args to output database } My actual simulation function involves a large number of arguments of various classes and if at all possible I prefer to avoid hacking it (e.g to accept object names rather than objects). Any tips much appreciated. Michael __ 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.
Re: [R] barplot: space between axis and bars
On 09/15/2010 09:54 PM, Daniel Stepputtis wrote: Hi all, I have a problem with a rather simple plot (which I have used several times) - barplot. I want to create a barplot, where no space is between the axis and the bars. Example: barplot(rnorm(10), space=0) creates a vertical axis at the left and bars. I want to skip the space between both. Hi Daniel, Try the barp function in the plotrix package. Jim __ 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] Enumerating unit cell traversals Re: Interpolate? a line
On Sep 15, 2010, at 7:55 AM, David Winsemius wrote: On Sep 15, 2010, at 7:24 AM, David Winsemius wrote: Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? I would like to thank you for your feedback. Best Regards Alex On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote: Hello Alex, Here is one way to do it. It works but it's not pretty :) If you want an alternative, consider that produces the Y cell indices (since the x cell indices are already 2:62): linefn - function(x) 3+((34-3)/(62-2)) *(x-2) findInterval(linefn(2:62), 3:34) [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 [55] 28 29 29 30 30 31 32 # that seems off by two linefn(62) [1] 34 linefn(2) [1] 3 # but that checks out and I realized those were just indices for the 3:34 findInterval vector (3:34)[findInterval(linefn(2:62), 3:34)] [1] 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 [55] 30 31 31 32 32 33 34 ( no rounding and I think the logic is clearer.) But I also realized it didn't enumerate all the the cells were crossed either, only indicating which cell was associated with an integer value of x. Also would have even more serious problems if the slope were greater than unity. To enumerate the cell indices that were crossed, try: unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) ) ) [,1] [,2] [1,]23 [2,]33 [3,]44 [4,]54 [5,]55 [6,]65 [7,]75 [8,]76 snipping interior results [83,] 58 32 [84,] 59 32 [85,] 60 32 [86,] 60 33 [87,] 61 33 [88,] 62 34 That could probably be passed to rect() to illustrate (and check logic): rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) #redraw line : lines(2:62, 3+(34-3)/(62-2)*(0:60)) And then I got to wondering if every 0.1 was sufficient to catch all the corners and discovered I could identify 3 more cell traversals with by=0.01 cellid2 -unique( floor(cbind(seq(2,62, by=0.01), linefn(seq(2,62, by=0.01) )) ) ) NROW(cellid2) # 91 cells rect(cellid2[,1], cellid2[,2], cellid2[,1]+1, cellid2[,2]+1, col=blue) rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) lines(2:62, 3+(34-3)/(62-2)*(0:60)) (Trying by=0.001 did not change the count, but did take longer) -- David. - David. interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison you can add a grid with abline(v=2:62, h=3:34) Michael David Winsemius, MD West Hartford, CT __ 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.
Re: [R] Enumerating unit cell traversals Re: Interpolate? a line
Nice posts David. I like the way that 'simple' problems such as this one give rise to an interesting assortment of approaches and gotchas :) Michael On 15 September 2010 22:41, David Winsemius dwinsem...@comcast.net wrote: On Sep 15, 2010, at 7:55 AM, David Winsemius wrote: On Sep 15, 2010, at 7:24 AM, David Winsemius wrote: Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? I would like to thank you for your feedback. Best Regards Alex On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote: Hello Alex, Here is one way to do it. It works but it's not pretty :) If you want an alternative, consider that produces the Y cell indices (since the x cell indices are already 2:62): linefn - function(x) 3+((34-3)/(62-2)) *(x-2) findInterval(linefn(2:62), 3:34) [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 [55] 28 29 29 30 30 31 32 # that seems off by two linefn(62) [1] 34 linefn(2) [1] 3 # but that checks out and I realized those were just indices for the 3:34 findInterval vector (3:34)[findInterval(linefn(2:62), 3:34)] [1] 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 [55] 30 31 31 32 32 33 34 ( no rounding and I think the logic is clearer.) But I also realized it didn't enumerate all the the cells were crossed either, only indicating which cell was associated with an integer value of x. Also would have even more serious problems if the slope were greater than unity. To enumerate the cell indices that were crossed, try: unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) ) ) [,1] [,2] [1,] 2 3 [2,] 3 3 [3,] 4 4 [4,] 5 4 [5,] 5 5 [6,] 6 5 [7,] 7 5 [8,] 7 6 snipping interior results [83,] 58 32 [84,] 59 32 [85,] 60 32 [86,] 60 33 [87,] 61 33 [88,] 62 34 That could probably be passed to rect() to illustrate (and check logic): rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) #redraw line : lines(2:62, 3+(34-3)/(62-2)*(0:60)) And then I got to wondering if every 0.1 was sufficient to catch all the corners and discovered I could identify 3 more cell traversals with by=0.01 cellid2 -unique( floor(cbind(seq(2,62, by=0.01), linefn(seq(2,62, by=0.01) )) ) ) NROW(cellid2) # 91 cells rect(cellid2[,1], cellid2[,2], cellid2[,1]+1, cellid2[,2]+1, col=blue) rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) lines(2:62, 3+(34-3)/(62-2)*(0:60)) (Trying by=0.001 did not change the count, but did take longer) -- David. - David. interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison you can add a grid with abline(v=2:62, h=3:34) Michael David Winsemius, MD West Hartford, CT __ 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.
Re: [R] Enumerating unit cell traversals Re: Interpolate? a line
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 15/09/10 14:46, Michael Bedward wrote: Nice posts David. I like the way that 'simple' problems such as this one give rise to an interesting assortment of approaches and gotchas :) Michael On 15 September 2010 22:41, David Winsemius dwinsem...@comcast.net wrote: On Sep 15, 2010, at 7:55 AM, David Winsemius wrote: On Sep 15, 2010, at 7:24 AM, David Winsemius wrote: Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? This is a known problem in computer graphics and the algorythm used to identify these cells is the Bresenham's Line Drawing Algorithm You can check out one version at http://www.falloutsoftware.com/tutorials/dd/dd4.htm or http://en.wikipedia.org/wiki/Bresenham's_line_algorithm Cheers, Rainer I would like to thank you for your feedback. Best Regards Alex On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote: Hello Alex, Here is one way to do it. It works but it's not pretty :) If you want an alternative, consider that produces the Y cell indices (since the x cell indices are already 2:62): linefn - function(x) 3+((34-3)/(62-2)) *(x-2) findInterval(linefn(2:62), 3:34) [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 [55] 28 29 29 30 30 31 32 # that seems off by two linefn(62) [1] 34 linefn(2) [1] 3 # but that checks out and I realized those were just indices for the 3:34 findInterval vector (3:34)[findInterval(linefn(2:62), 3:34)] [1] 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 [55] 30 31 31 32 32 33 34 ( no rounding and I think the logic is clearer.) But I also realized it didn't enumerate all the the cells were crossed either, only indicating which cell was associated with an integer value of x. Also would have even more serious problems if the slope were greater than unity. To enumerate the cell indices that were crossed, try: unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) ) ) [,1] [,2] [1,]23 [2,]33 [3,]44 [4,]54 [5,]55 [6,]65 [7,]75 [8,]76 snipping interior results [83,] 58 32 [84,] 59 32 [85,] 60 32 [86,] 60 33 [87,] 61 33 [88,] 62 34 That could probably be passed to rect() to illustrate (and check logic): rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) #redraw line : lines(2:62, 3+(34-3)/(62-2)*(0:60)) And then I got to wondering if every 0.1 was sufficient to catch all the corners and discovered I could identify 3 more cell traversals with by=0.01 cellid2 -unique( floor(cbind(seq(2,62, by=0.01), linefn(seq(2,62, by=0.01) )) ) ) NROW(cellid2) # 91 cells rect(cellid2[,1], cellid2[,2], cellid2[,1]+1, cellid2[,2]+1, col=blue) rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) lines(2:62, 3+(34-3)/(62-2)*(0:60)) (Trying by=0.001 did not change the count, but did take longer) -- David. - David. interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison you can add a grid with abline(v=2:62, h=3:34) Michael David Winsemius, MD West Hartford, CT __ 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. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP
Re: [R] R install in Fedora
On Sep 15, 2010, at 5:14 AM, wesley mathew wrote: Dear All As you suggested I tried to install was trying to install R-2.11.1-3.fc13.1686 in Fedora-13-i386 but it also shows error. I wrote yum install R-2.11.1-3fc13.i686 Errors Cannot retrieve repository metadata (repond.xml) for repository: fedora. Please verify its path and try again. Could you please help me to solve this problem. Thanks in advance Kind Regards Wesley C Mathew The command that I told you to use was: yum install R to be used as root. Note that there is nothing after the R. You have to have root privileges to use yum and to install the R RPMs. So you either need to use: su - then enter the root password and then use the command above, or if you have set up sudo, you can use: sudo yum install R after which you will need to enter the root password. If you still get the error, you have a configuration problem with your yum repo setup, which means that you really need to be looking to the Fedora (not R) lists for assistance, since it is not an R issue. That being said, as I also noted, if you post to the R-SIG-Fedora list, there are folks there who can offer Fedora specific assistance for R, as this thread is getting to be OT for R-Help. Marc Schwartz __ 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.
Re: [R] decision tree display
If you are talking about an rpart object you are going to plot, see ?plot.rpart and ?text.rpart Uwe Ligges On 19.08.2010 23:10, Olga Shaganova wrote: I am using plot and text commands to display the decision tree I built, here is the code: plot(fit, compress=TRUE) text(fit, use.n=TRUE) but the the result of this code is not readable. Text doesn't get fully displayed (missing on the margines and overlapping in the middle). Where can I get info on how to adjust the tree display and text size display? Please help. Thank you! Olga [[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. __ 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.
Re: [R] About choosing file
On 26.08.2010 09:50, Stephen Liu wrote: Hi folks, Following command only works on Windows Test01=read.table(file.choose(), header=TRUE) It popup open a dialog box for choosing file. But it doesn't work on Linux (Ubuntu); Test01=read.table(file.choose(), header=TRUE) Enter file name: Entering file name doesn't work. Please advise. TIA (assuming R-2.11.1) Why not? What happens? What is the error message? Which file did you specify and does list.files() lists the file? Please show the output. Best, Uwe Ligges B.R. Stephen L __ 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.
Re: [R] binary package build error:target 'xf-' is not a directory
You have to build a *source* package under Linux in order to install it under Windows afterwards. A Linux binary package cannot be used under Windows. Best, Uwe Ligges On 31.08.2010 09:59, raje...@cse.iitm.ac.in wrote: Hi, I built a package in linux and generated its binary using R CMD build --binary testpack. This generated testpack.tar.gz. I tried to install this package in windows using R CMD INSTALL package.tar.gz and I got the error *installing to library 'H:/R-2.11.1/library' *installing *binary* package 'testpack' ... /cygdrive/RTools/bin/cp: target 'xf-' is not a directory ERROR: installing binary package failed can someone help me out. what does this mean? ~Aks [[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. __ 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.
Re: [R] Enumerating unit cell traversals Re: Interpolate? a line
On Sep 15, 2010, at 8:58 AM, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 15/09/10 14:46, Michael Bedward wrote: Nice posts David. I like the way that 'simple' problems such as this one give rise to an interesting assortment of approaches and gotchas :) Michael On 15 September 2010 22:41, David Winsemius dwinsem...@comcast.net wrote: On Sep 15, 2010, at 7:55 AM, David Winsemius wrote: On Sep 15, 2010, at 7:24 AM, David Winsemius wrote: Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? This is a known problem in computer graphics and the algorythm used to identify these cells is the Bresenham's Line Drawing Algorithm You can check out one version at http://www.falloutsoftware.com/tutorials/dd/dd4.htm or http://en.wikipedia.org/wiki/Bresenham's_line_algorithm After viewing the Wikipedia description and the illustration I think that may not be the same problem. Note that the cells traversed only at their very outer corners do not get chosen. The goal is to approximate a line rather than to enumerate traversals. -- David. Cheers, Rainer I would like to thank you for your feedback. Best Regards Alex On Sep 15, 2010, at 6:52 AM, Michael Bedward wrote: Hello Alex, Here is one way to do it. It works but it's not pretty :) If you want an alternative, consider that produces the Y cell indices (since the x cell indices are already 2:62): linefn - function(x) 3+((34-3)/(62-2)) *(x-2) findInterval(linefn(2:62), 3:34) [1] 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 [28] 14 15 15 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 [55] 28 29 29 30 30 31 32 # that seems off by two linefn(62) [1] 34 linefn(2) [1] 3 # but that checks out and I realized those were just indices for the 3:34 findInterval vector (3:34)[findInterval(linefn(2:62), 3:34)] [1] 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 [28] 16 17 17 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 [55] 30 31 31 32 32 33 34 ( no rounding and I think the logic is clearer.) But I also realized it didn't enumerate all the the cells were crossed either, only indicating which cell was associated with an integer value of x. Also would have even more serious problems if the slope were greater than unity. To enumerate the cell indices that were crossed, try: unique( floor( cbind( seq(2,62, by=0.1), linefn(seq(2,62, by=0.1)) ) ) ) [,1] [,2] [1,]23 [2,]33 [3,]44 [4,]54 [5,]55 [6,]65 [7,]75 [8,]76 snipping interior results [83,] 58 32 [84,] 59 32 [85,] 60 32 [86,] 60 33 [87,] 61 33 [88,] 62 34 That could probably be passed to rect() to illustrate (and check logic): rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) #redraw line : lines(2:62, 3+(34-3)/(62-2)*(0:60)) And then I got to wondering if every 0.1 was sufficient to catch all the corners and discovered I could identify 3 more cell traversals with by=0.01 cellid2 -unique( floor(cbind(seq(2,62, by=0.01), linefn(seq(2,62, by=0.01) )) ) ) NROW(cellid2) # 91 cells rect(cellid2[,1], cellid2[,2], cellid2[,1]+1, cellid2[,2]+1, col=blue) rect(cellidxs[,1], cellidxs[,2], cellidxs[,1]+1, cellidxs[,2]+1, col=red) lines(2:62, 3+(34-3)/(62-2)*(0:60)) (Trying by=0.001 did not change the count, but did take longer) -- David. - David. interp - approx(c(2, 62), c(3, 34), method=linear, xout=2:62) m - matrix(c(interp$x, round(interp$y)), ncol=2) tie - m[,2] == c(-Inf, m[-nrow(m),2]) m - m[ !tie, ] You might want to examine the result like this... plot(m) # plots points lines(c(2,26), c(3, 34)) # overlay line for comparison you can add a grid with abline(v=2:62, h=3:34) Michael David Winsemius, MD West Hartford, CT __ 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. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main
Re: [R] Error: cannot allocate vector of size X.0 Mb
Thank you all for the suggestions. We do intend to get more RAM space. Meanwhile I shall have a look at the ShortRead package features. -- View this message in context: http://r.789695.n4.nabble.com/Error-cannot-allocate-vector-of-size-X-0-Mb-tp2539031p2540518.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] how to convert a unix R package to windows installable zip file?
On 24.08.2010 17:35, Jack Luo wrote: Hi, I downloaded a package with .gz extension, which presumably works for Unix, when I installed it directly on windows, it has the error msg: Error in gzfile(file, r) : cannot open the connection In addition: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In gzfile(file, r) : cannot open compressed file 'CustomCDF_1.1.0.tar.gz/DESCRIPTION', probable reason 'No such file or directory' Does anyone know how to convert the package into a windows installable zip file? Please see the R Installation and Administration manual in order to learn how to install source packages (such as the tar.gz file you got) under Windows. Best, Uwe Ligges Thanks a bunch, -Jack [[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. __ 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] Keyword to clear the screen
Hi all, can anyone please tell me what is the key-word to clear the screen? I am aware of the cont+L, however I need some R-syntax, that can be typed into the console to clear the screen. Thanks [[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.
[R] Fwd: R install in Fedora
Dear Sir Actually I tried in both ways : yum install R and sudo yum install R , but the error is same. I have root privilege, means I used the command su - and enter the password. May be its problem from Fedora. Thanks for your valuable help. I will post this issue in R-SIG-Fedora list. Kind Regards Wesley -- Forwarded message -- From: Marc Schwartz marc_schwa...@me.com Date: Wed, Sep 15, 2010 at 2:02 PM Subject: Re: [R] R install in Fedora To: wesley mathew wesleycmat...@gmail.com Cc: r-help@r-project.org On Sep 15, 2010, at 5:14 AM, wesley mathew wrote: Dear All As you suggested I tried to install was trying to install R-2.11.1-3.fc13.1686 in Fedora-13-i386 but it also shows error. I wrote yum install R-2.11.1-3fc13.i686 Errors Cannot retrieve repository metadata (repond.xml) for repository: fedora. Please verify its path and try again. Could you please help me to solve this problem. Thanks in advance Kind Regards Wesley C Mathew The command that I told you to use was: yum install R to be used as root. Note that there is nothing after the R. You have to have root privileges to use yum and to install the R RPMs. So you either need to use: su - then enter the root password and then use the command above, or if you have set up sudo, you can use: sudo yum install R after which you will need to enter the root password. If you still get the error, you have a configuration problem with your yum repo setup, which means that you really need to be looking to the Fedora (not R) lists for assistance, since it is not an R issue. That being said, as I also noted, if you post to the R-SIG-Fedora list, there are folks there who can offer Fedora specific assistance for R, as this thread is getting to be OT for R-Help. Marc Schwartz -- Wesley C Mathew [[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.
Re: [R] Enumerating unit cell traversals Re: Interpolate? a line
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 15/09/10 15:23, David Winsemius wrote: On Sep 15, 2010, at 8:58 AM, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 15/09/10 14:46, Michael Bedward wrote: Nice posts David. I like the way that 'simple' problems such as this one give rise to an interesting assortment of approaches and gotchas :) Michael On 15 September 2010 22:41, David Winsemius dwinsem...@comcast.net wrote: On Sep 15, 2010, at 7:55 AM, David Winsemius wrote: On Sep 15, 2010, at 7:24 AM, David Winsemius wrote: Replacing context: Hello everyone. I have created a 100*100 matrix in R. Let's now say that I have a line that starts from (2,3) point and ends to the (62,34) point. In other words this line starts at cell (2,3) and ends at cell (62,34). Is it possible to get by some R function all the matrix's cells that this line transverses? This is a known problem in computer graphics and the algorythm used to identify these cells is the Bresenham's Line Drawing Algorithm You can check out one version at http://www.falloutsoftware.com/tutorials/dd/dd4.htm or http://en.wikipedia.org/wiki/Bresenham's_line_algorithm After viewing the Wikipedia description and the illustration I think that may not be the same problem. Note that the cells traversed only at their very outer corners do not get chosen. The goal is to approximate a line rather than to enumerate traversals. You might actually be right. Cheers, Rainer - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyQyl8ACgkQoYgNqgF2egpdnACfS3zQX3MUAPraxIm5ExbFcnQu bdYAn0vpYs3Gy2XmutNoJQKaVVZ+hnYH =ByN/ -END PGP SIGNATURE- __ 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.
Re: [R] Keyword to clear the screen
The first result of RSiteSearch(clear console) gives PBSmodelling::clearRcon() Ivan Le 9/15/2010 15:27, Ron Michael a écrit : Hi all, can anyone please tell me what is the key-word to clear the screen? I am aware of the cont+L, however I need some R-syntax, that can be typed into the console to clear the screen. Thanks [[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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php [[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.
Re: [R] relative risk regression with survey data
Dear Thomas, You said, the log-binomial model is very non-robust when the fitted values get close to 1, and there is some controversy over the best approach. Could you please point me to a paper that discusses the issues? I have written some code to do maximum likelihood estimation for relative, additive, and mixed risk regression models with binomial model. I have been able to obtain good convergence. I have used bootstrap to get standard errors. However, I am not sure if these standard errors are valid when fitted values were close to 0 or 1. It seems to me that when the fitted probabilities are close to 0 or 1, there is not a good way to estimate standard errors. Thanks, Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Thomas Lumley Sent: Monday, September 13, 2010 10:41 PM To: Daniel Nordlund Cc: r-help@r-project.org Subject: Re: [R] relative risk regression with survey data On Mon, 13 Sep 2010, Daniel Nordlund wrote: I have been asked to look at options for doing relative risk regression on some survey data. I have a binary DV and several predictor / adjustment variables. In R, would this be as simple as using the survey package to set up an appropriate design object and then running svyglm with family=binomial(log) ? Any other suggestions for covariate adjustment of relative risk estimates? Any and all suggestions welcomed. If the fitted values don't get too close to 1 then svyglm( ,family=quasibinomial(log)) will do it. The log-binomial model is very non-robust when the fitted values get close to 1, and there is some controversy over the best approach. You can still use svyglm( ,family=quasibinomial(log)) but you will probably need to set the number of iterations much higher (perhaps 200). Alternatively, you can use nonlinear least squares [svyglm(, family=gaussian(log))] or other quasilikelihood approaches, such as family=quasipoisson(log). These are all consistent for the same parameter if the model is correctly specified and are much more robust to x-outliers. I rather like nonlinear least squares, because it's easy to explain. -thomas Thomas Lumley Professor of Biostatistics University of Washington, Seattle __ 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.
Re: [R] Keyword to clear the screen
Try this (for windows): clear - function() { library(RDCOMClient) ws - COMCreate(WScript.Shell) invisible(ws$SendKeys('^L')) } On Wed, Sep 15, 2010 at 10:27 AM, Ron Michael ron_michae...@yahoo.comwrote: Hi all, can anyone please tell me what is the key-word to clear the screen? I am aware of the cont+L, however I need some R-syntax, that can be typed into the console to clear the screen. Thanks [[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]] __ 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 for shift.down
Hi all, I created a matrix by parsing a csv file when I shift rows I am getting the wrong output as below my matrix has single column with multiple rows but it is splitting into multiple columns and not shifting row wise also can you please resolve this issue CMA1-function() { PMA3- read.csv(c:/myfile2.csv, strip.white = TRUE,head=TRUE,sep=,) PMA1-as.matrix(PMA3) shift.down(PMA1,rows=47,fill=0) } CMA1() [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26] [1,]000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,]000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50] [,51] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62] [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] [,74] [,75] [,76] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] [,86] [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] [,98] [,99] [,100] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,101] [,102] [,103] [,104] [,105] [,106] [,107] [,108] [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117] [,118] [,119] [,120] [,121] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,122] [,123] [,124] [,125] [,126] [,127] [,128] [,129] [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137] [,138] [,139] [,140] [,141] [,142] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,143] [,144] [,145] [,146] [,147] [,148] [,149] [,150] [,151] [,152] [,153] [,154] [,155] [,156] [,157] [,158] [,159] [,160] [,161] [,162] [,163] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,164] [,165] [,166] [,167] [,168] [,169] [,170] [,171] [,172] [,173] [,174] [,175] [,176] [,177] [,178] [,179] [,180] [,181] [,182] [,183] [,184] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,185] [,186] [,187] [,188] [,189] [,190] [,191] [,192] [,193] [,194] [,195] [,196] [,197] [,198] [,199] [,200] [,201] [,202] [,203] [,204] [,205] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [,206] [,207] [,208] [,209] [,210] [,211] [,212] [,213] [,214] [,215] [,216] [,217] [,218] [,219] [,220] [,221] [,222] [,223] [,224] [,225] [,226] [1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Re: [R] Keyword to clear the screen
Thanks everyone who have looked into my problem. In the mean time I already found one tip here http://onertipaday.blogspot.com/2007/05/how-to-clear-screen-in-r.html to do that. I am yet to try it...perhaps it would solve me problem :) Thanks, --- On Wed, 15/9/10, Ron Michael ron_michae...@yahoo.com wrote: From: Ron Michael ron_michae...@yahoo.com Subject: [R] Keyword to clear the screen To: r-h...@stat.math.ethz.ch Date: Wednesday, 15 September, 2010, 8:27 PM Hi all, can anyone please tell me what is the key-word to clear the screen? I am aware of the cont+L, however I need some R-syntax, that can be typed into the console to clear the screen. Thanks [[alternative HTML version deleted]] -Inline Attachment Follows- __ 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.
[R] Re : content analysis
Bob, Thank you very much for your help. I found TM and Readme. I am going to look into Tau and rattle right now. Thanks, Christian De : Bob Green bgr...@dyson.brisnet.org.au À : r-help@r-project.org Cc : Sametrie Neurones neuro...@ymail.com Envoyé le : Mer 15 septembre 2010, 21h 00min 29s Objet : Re: content analysis Christian, Have you looked at TM? There is also Quantitative Corpus Linguistics with R by Stefan Gries, which you may find of interest. Tau, Readme and rattle might be worth looking into. See also: http://ses.telecom-paristech.fr/lebart/ regards Bob [[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.
Re: [R] About choosing file
Hi Uwe, (assuming R-2.11.1) Yes Test01=read.table(file.choose(), header=TRUE) Enter file name: My problem here is ; the file is NOT on /home/user directory. I need to browse for it. list.files() [1] boxplot.pdf Desktop FourPlots01.png hist.png [5] jranke_cran.asc M-x R M-x R~ B.R. Stephen L - Original Message From: Uwe Ligges lig...@statistik.tu-dortmund.de To: Stephen Liu sati...@yahoo.com Cc: R-help@r-project.org Sent: Wed, September 15, 2010 9:20:48 PM Subject: Re: [R] About choosing file On 26.08.2010 09:50, Stephen Liu wrote: Hi folks, Following command only works on Windows Test01=read.table(file.choose(), header=TRUE) It popup open a dialog box for choosing file. But it doesn't work on Linux (Ubuntu); Test01=read.table(file.choose(), header=TRUE) Enter file name: Entering file name doesn't work. Please advise. TIA (assuming R-2.11.1) Why not? What happens? What is the error message? Which file did you specify and does list.files() lists the file? Please show the output. Best, Uwe Ligges B.R. Stephen L __ 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.
Re: [R] assignment by value or reference
Thanks. Xiaobo.Gu -Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: Wednesday, September 15, 2010 5:06 PM To: Xiaobo Gu Cc: r-help@r-project.org; '顾小波' Subject: Re: [R] assignment by value or reference See the R Language Definition manual. Since R knows about lazy evaluation, it is sometimes neither by reference nor by value. If you want to think binary, then by value fits better than by reference. Uwe Ligges On 05.09.2010 17:19, Xiaobo Gu wrote: Hi Team, Can you please tell me the rules of assignment in R, by value or by reference. From my about 3 months of experience of part time job of R, it seems most times it is by value, especially in function parameter and return values assignment; and it is by reference when referencing container sub-objects of container objects, such as elements of List objects and row/column objects of DataFrame objectes; but it is by value when referencing the smallest unit of element of a container object, such as cell of data frame objects. Xiaobo.Gu [[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. __ 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.
Re: [R] About choosing file
You can specify an absolute or relative path (relative to the current directory) of course. Uwe On 15.09.2010 16:03, Stephen Liu wrote: Hi Uwe, (assuming R-2.11.1) Yes Test01=read.table(file.choose(), header=TRUE) Enter file name: My problem here is ; the file is NOT on /home/user directory. I need to browse for it. list.files() [1] boxplot.pdf Desktop FourPlots01.png hist.png [5] jranke_cran.asc M-x R M-x R~ B.R. Stephen L - Original Message From: Uwe Liggeslig...@statistik.tu-dortmund.de To: Stephen Liusati...@yahoo.com Cc: R-help@r-project.org Sent: Wed, September 15, 2010 9:20:48 PM Subject: Re: [R] About choosing file On 26.08.2010 09:50, Stephen Liu wrote: Hi folks, Following command only works on Windows Test01=read.table(file.choose(), header=TRUE) It popup open a dialog box for choosing file. But it doesn't work on Linux (Ubuntu); Test01=read.table(file.choose(), header=TRUE) Enter file name: Entering file name doesn't work. Please advise. TIA (assuming R-2.11.1) Why not? What happens? What is the error message? Which file did you specify and does list.files() lists the file? Please show the output. Best, Uwe Ligges B.R. Stephen L __ 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. __ 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.
Re: [R] About choosing file
You can try tcltk: library(tcltk) tk_choose.files() On Wed, Sep 15, 2010 at 11:03 AM, Stephen Liu sati...@yahoo.com wrote: Hi Uwe, (assuming R-2.11.1) Yes Test01=read.table(file.choose(), header=TRUE) Enter file name: My problem here is ; the file is NOT on /home/user directory. I need to browse for it. list.files() [1] boxplot.pdf Desktop FourPlots01.png hist.png [5] jranke_cran.asc M-x R M-x R~ B.R. Stephen L - Original Message From: Uwe Ligges lig...@statistik.tu-dortmund.de To: Stephen Liu sati...@yahoo.com Cc: R-help@r-project.org Sent: Wed, September 15, 2010 9:20:48 PM Subject: Re: [R] About choosing file On 26.08.2010 09:50, Stephen Liu wrote: Hi folks, Following command only works on Windows Test01=read.table(file.choose(), header=TRUE) It popup open a dialog box for choosing file. But it doesn't work on Linux (Ubuntu); Test01=read.table(file.choose(), header=TRUE) Enter file name: Entering file name doesn't work. Please advise. TIA (assuming R-2.11.1) Why not? What happens? What is the error message? Which file did you specify and does list.files() lists the file? Please show the output. Best, Uwe Ligges B.R. Stephen L __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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.
[R] Odp: Programming: loop versus vector oriented
Hi I do not want to go too much deep to internals of your function. What do you suppose to get as the result. If you want to get results of your function for a vector of reynolds and dk you can use function outer and probably get rid of for cycle in the function. outer(c(100, 530,2410), c(10, 150,200),lambda_wall) [,1] [,2] [,3] [1,] 0.640 0.6400 0.6400 [2,] 0.1207547 0.12075472 0.12075472 [3,] 0.1081338 0.04515774 0.04515774 If you want to feed vector(s) to your function it would not be so easy as you need to check some predefined conditions for laminar or turbulent or any other flow. In this case you cold check function ?switch together with separate function definitions for each type of flow. But three if's could be as good as switch. Basically your function probably works for vectors but only in certain conditions. Laminar OK lambda_wall(10:20) [1] 6.40 5.818182 5.33 4.923077 4.571429 4.27 4.00 3.764706 [9] 3.56 3.368421 3.20 Turbulent needs dk lambda_wall(2400:2410) Error: argument dk is missing, with no default But not any dk lambda_wall(2400:2410, 10) Error in if (Re 65 * dk[z]) { : missing value where TRUE/FALSE needed only a vector of the same length as reynolds lambda_wall(2400:2410, 10:21) [1] 0.10815993 0.10325278 0.09912072 0.09558754 0.09252750 0.08984834 [7] 0.08748069 0.08537137 0.08347884 0.08177018 0.08021892 So before trying to elaborate your function further what shall be inputs and what is desired output? Regards Petr r-help-boun...@r-project.org napsal dne 15.09.2010 11:57:28: Dear all, I am new to R and to it's programming philosophy. The following function is supposed to work on a vector, but I can't figure out how to do that without looping through every element of it. Is there a more elegant way? Note: I have shortened it, so it is NOT correct from the pipe hydraulics point of view # Calculate wall friction factor # reynolds: Reynolds number # dk: relative roughness of pipe lambda_wall - function (reynolds, dk) { z - 1 result - 0 for (Re in reynolds) { if (Re = 2320) { # Laminar flow lambda - 64/Re } else if (Re 65 * dk[z]) { # Turbulent flow if (Re 1e+5) { lambda - 0.3164 / sqrt(sqrt(Re)) } else { lambda - 0.309/(log10(Re/7))^2 } } else { # Intermediate area lambdanew - 1 / (2 * log10(3.71 * dk[z]))^2 # Start value iter - 0 repeat { lambda - lambdanew lambdanew - 1 / (2 * log10(2.51/(Re * sqrt(lambda)) + 0.27/dk[z]))^2 iter - iter + 1 if ((abs(lambdanew - lambda) 0.001) || (iter 100)) break } lambda = lambdanew } result[z] - lambda z - z + 1 } result } # lambda_wall() __ 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.
[R] Creating publication-quality plots for use in Microsoft Word
Hi everyone, I am trying to make some publication-quality plots for use in Microsoft Word, but I am having trouble creating high-quality plots that are supported by Microsoft Word. If I use the R plot function to create the figure, the lines are jagged, and the picture is not of high quality (same with JPEG(), TIFF(), and PNG() functions). I have tried using the Cairo package, but it distorts my dashed lines, and the win.metafile results in a picture of terrible quality. The only way I have succeeded in getting a high quality picture in a file is by using the pdf() function to save the plot as a pdf file, but all my attempts to convert the image in the pdf file to a TIFF or other file type accepted by Word result in considerably degraded quality. Do you have any suggestions for creating publication-quality plots in R that can be placed in Word documents? What packages, functions (along with options), and/or conversions would you use? Thanks so much for your help! -- View this message in context: http://r.789695.n4.nabble.com/Creating-publication-quality-plots-for-use-in-Microsoft-Word-tp2540676p2540676.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
There's many ways to solve this, but you are close to one already: Make the pdf, put the cursor where you want it in the document, then on the menu bar Insert -- Picture -- From File... And navigate to the file. This works on the Mac, and seems to store the picture internally in a different way that selecting the graphic in a viewer and cutting and pasting. Quality is top-notch and the graphic is clickable to be resized (and retains it's quality). HTH. Bryan * Bryan Hanson Professor of Chemistry Biochemistry DePauw University, Greencastle IN USA On 9/15/10 10:38 AM, dadrivr dadr...@gmail.com wrote: Hi everyone, I am trying to make some publication-quality plots for use in Microsoft Word, but I am having trouble creating high-quality plots that are supported by Microsoft Word. If I use the R plot function to create the figure, the lines are jagged, and the picture is not of high quality (same with JPEG(), TIFF(), and PNG() functions). I have tried using the Cairo package, but it distorts my dashed lines, and the win.metafile results in a picture of terrible quality. The only way I have succeeded in getting a high quality picture in a file is by using the pdf() function to save the plot as a pdf file, but all my attempts to convert the image in the pdf file to a TIFF or other file type accepted by Word result in considerably degraded quality. Do you have any suggestions for creating publication-quality plots in R that can be placed in Word documents? What packages, functions (along with options), and/or conversions would you use? Thanks so much for your help! __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
On Wed, Sep 15, 2010 at 10:38 AM, dadrivr dadr...@gmail.com wrote: Hi everyone, I am trying to make some publication-quality plots for use in Microsoft Word, but I am having trouble creating high-quality plots that are supported by Microsoft Word. If I use the R plot function to create the figure, the lines are jagged, and the picture is not of high quality (same with JPEG(), TIFF(), and PNG() functions). I have tried using the Cairo package, but it distorts my dashed lines, and the win.metafile results in a picture of terrible quality. The only way I have succeeded in getting a high quality picture in a file is by using the pdf() function to save the plot as a pdf file, but all my attempts to convert the image in the pdf file to a TIFF or other file type accepted by Word result in considerably degraded quality. Do you have any suggestions for creating publication-quality plots in R that can be placed in Word documents? What packages, functions (along with options), and/or conversions would you use? Thanks so much for your help! Those are all bitmapped formats. For best quality you want a vector-based format. This link here discusses the difference: http://web.archive.org/web/20070221152152/http://www.stc-saz.org/resources/0203_graphics.pdf Microsoft's metafile formats are vector formats that work well in Word. Try savePlot with type = wmf or type = emf as the argument or right click a graphic in R and choose one of the metafile options. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
That approach will be unique to OSX, upon which PDF is a default format. You can copy and paste from a PDF document using Preview into Office or iWork or similar apps. However, when subsequently displaying that content on a non-OSX system, the content will be shown as a bitmap not as the vector based PDF. You would have to save the new document to a new PDF file via the printer dialogs, in order to retain the full high quality PDF content. The ultimate question for the OP is what do you intend to do with the Word document relative to displaying/printing the content in the Word document? Using EMF/WMF is one way to get vector based images from R into other Windows apps and typically that provides suitable quality. However, if you truly want publication quality, then you would need to use encapsulated postscript (EPS) for which you can see ?postscript and pay attention to the Details section for proper creation. However, after importing an EPS image into Word on Windows, you will not see the EPS based image, but a bitmapped preview. You would then have to print the document to a PS compatible printer to see the vector based content in the imported image in the output. So it all depends upon how you plan to use the document. HTH, Marc Schwartz On Sep 15, 2010, at 9:50 AM, Bryan Hanson wrote: There's many ways to solve this, but you are close to one already: Make the pdf, put the cursor where you want it in the document, then on the menu bar Insert -- Picture -- From File... And navigate to the file. This works on the Mac, and seems to store the picture internally in a different way that selecting the graphic in a viewer and cutting and pasting. Quality is top-notch and the graphic is clickable to be resized (and retains it's quality). HTH. Bryan * On 9/15/10 10:38 AM, dadrivr dadr...@gmail.com wrote: Hi everyone, I am trying to make some publication-quality plots for use in Microsoft Word, but I am having trouble creating high-quality plots that are supported by Microsoft Word. If I use the R plot function to create the figure, the lines are jagged, and the picture is not of high quality (same with JPEG(), TIFF(), and PNG() functions). I have tried using the Cairo package, but it distorts my dashed lines, and the win.metafile results in a picture of terrible quality. The only way I have succeeded in getting a high quality picture in a file is by using the pdf() function to save the plot as a pdf file, but all my attempts to convert the image in the pdf file to a TIFF or other file type accepted by Word result in considerably degraded quality. Do you have any suggestions for creating publication-quality plots in R that can be placed in Word documents? What packages, functions (along with options), and/or conversions would you use? Thanks so much for your help! __ 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] Contour line coordinates
Hi all, I used contour() to add contour lines to a plot. Now I’m wondering if there is a way to get an output of the calculated x- and y- coordinates of the contour lines? Tonja __ 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.
Re: [R] About choosing file
Hi Henrique, Thanks for your advice which works for me. B.R. Stephen L From: Henrique Dallazuanna www...@gmail.com Cc: R-help@r-project.org Sent: Wed, September 15, 2010 10:24:01 PM Subject: Re: [R] About choosing file You can try tcltk: library(tcltk) tk_choose.files() Hi Uwe, (assuming R-2.11.1) Yes Test01=read.table(file.choose(), header=TRUE) Enter file name: My problem here is ; the file is NOT on /home/user directory. I need to browse for it. list.files() [1] boxplot.pdf Desktop FourPlots01.png hist.png [5] jranke_cran.asc M-x R M-x R~ B.R. Stephen L - Original Message From: Uwe Ligges lig...@statistik.tu-dortmund.de Cc: R-help@r-project.org Sent: Wed, September 15, 2010 9:20:48 PM Subject: Re: [R] About choosing file On 26.08.2010 09:50, Stephen Liu wrote: Hi folks, Following command only works on Windows Test01=read.table(file.choose(), header=TRUE) It popup open a dialog box for choosing file. But it doesn't work on Linux (Ubuntu); Test01=read.table(file.choose(), header=TRUE) Enter file name: Entering file name doesn't work. Please advise. TIA (assuming R-2.11.1) Why not? What happens? What is the error message? Which file did you specify and does list.files() lists the file? Please show the output. Best, Uwe Ligges B.R. Stephen L __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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.
Re: [R] Package build and install under Windows
Thanks. It seems that both Rtools210.exe and Rtools211.exe support R 1.10.x, which one is better for R 2.10.1. -- View this message in context: http://r.789695.n4.nabble.com/Package-build-and-install-under-Windows-tp2539509p2540713.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Contour line coordinates
On Sep 15, 2010, at 11:13 AM, Tonja Krueger wrote: Hi all, I used contour() to add contour lines to a plot. Now I’m wondering if there is a way to get an output of the calculated x- and y- coordinates of the contour lines? ?contourLines # as was suggested to be the first See(n) Also in contour. Tonja __ 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. David Winsemius, MD West Hartford, CT __ 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] characters in a string
Hi, I need to check if a string rha,b,c,drh is delimited by two rh 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique? [[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.
Re: [R] Contour line coordinates
On 15/09/2010 11:13 AM, Tonja Krueger wrote: Hi all, I used contour() to add contour lines to a plot. Now I’m wondering if there is a way to get an output of the calculated x- and y- coordinates of the contour lines? ?contourLines Duncan Murdoch __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
Thanks for your help, guys. I'm looking to produce a high-quality plot (no jagged lines or other distortions) with a filetype that is accepted by Microsoft Word on a PC and that most journals will accept. That's why I'd prefer to stick with JPEG, TIFF, PNG, or the like. I'm not sure EPS would fly. I tried inserting the PDF directly into Word, but I am on a PC and there is a loss of quality in the transfer. I'm not sure I know how to use the approach that Marc suggested in reference to saving a new PDF for use in Word. I also tried Gabor's suggestion to save in Microsoft's metafile format (savePlot with type = wmf and emf), but the images contain lines that are as jagged as those created from the regular R plot output. Is there a way to enable anti-aliasing on all regular R plot output to clean up the jaggies and then save it in another format? Or should I try something else? Thanks again! -- View this message in context: http://r.789695.n4.nabble.com/Creating-publication-quality-plots-for-use-in-Microsoft-Word-tp2540676p2540744.html Sent from the R help mailing list archive at Nabble.com. __ 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] symmetric dotplot? (Wilkinson 1999, Am Stat 53 (3) 276-281
DeaR all, The stripchart function (graphics) is provides jittered and stacked univariate scatterplots, but I wonder if anyone has implemented a *symmetric* version of this - as in the lower panel of Wilkinson's paper: http://www.jstor.org/stable/2686111 I have looked through several functions in contributed packages that do similar things, but not found one that can do this. What am I missing? Thanks! Paul -- View this message in context: http://r.789695.n4.nabble.com/symmetric-dotplot-Wilkinson-1999-Am-Stat-53-3-276-281-tp2540757p2540757.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] multiple cores/building fails
Hi, That seems to be the case. Is there a way that I can put an object in some global place where all the workers can access it? Doing the following at the start (before I make multiple workers) does not work: Assign('global.control', control, globalenv()) Thanks for your help! Kind regards, Greg Sent via BlackBerry by ATT -Original Message- From: Uwe Ligges lig...@statistik.tu-dortmund.de Date: Wed, 15 Sep 2010 10:56:54 To: Gregory Ryslikrsa...@comcast.net Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] multiple cores/building fails On 14.09.2010 21:50, Gregory Ryslik wrote: Hi Everyone, I have written debugged and tested my code and it works (yay!). I recently tried to parallelize it (1 core/per tree) and when I run the code I get an error saying the object control was not found. I do have an object control in my code but it always works fine as long as I am not running it on multiple cores (which I am doing via the help of sleigh and the 'nws' package). Think that this could be an error in my source statements, I tried to build my package (with the hope of replace source with library()) and I get the following (where XXX is my package name that I've removed for privacy reasons): * creating vignettes ... ERROR Error: processing vignette '.Rnw' failed with diagnostics: chunk 4 Error : object control not found Again it gives me that this control object is not found. Does anyone have an idea how I can isolate what's going on. It's slightly tough to do because it all works fine in the single processor case! Perhaps you forgot to populate the object to the client nodes? Hard to say without any reproducible example code. Uwe Ligges Thanks! Kind regards, Greg __ 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.
Re: [R] characters in a string
On Sep 15, 2010, at 10:16 AM, raje...@cse.iitm.ac.in wrote: Hi, I need to check if a string rha,b,c,drh is delimited by two rh 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique? See ?grep and ?regex grepl(^rh.*rh$, rha,b,c,drh) [1] TRUE You can pass the entire source vector to grepl(): Vec - c(rha,b,c,drh, 1, 2, 3, 4, a, b, c, drh, rh1, 2, 3, 4rh) grepl(^rh.*rh$, Vec) [1] TRUE FALSE FALSE TRUE HTH, Marc Schwartz __ 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.
Re: [R] characters in a string
Le 15/09/10 17:16, raje...@cse.iitm.ac.in a écrit : Hi, I need to check if a string rha,b,c,drh is delimited by tworh 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique? Hi Rajesh, f - function( x ) grepl( ^rh.*rh$, x ) f( rha,b,c,drh ) [1] TRUE See ?grepl for details. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
On Wed, Sep 15, 2010 at 11:25 AM, dadrivr dadr...@gmail.com wrote: Thanks for your help, guys. I'm looking to produce a high-quality plot (no jagged lines or other distortions) with a filetype that is accepted by Microsoft Word on a PC and that most journals will accept. That's why I'd prefer to stick with JPEG, TIFF, PNG, or the like. I'm not sure EPS would fly. I tried inserting the PDF directly into Word, but I am on a PC and there is a loss of quality in the transfer. I'm not sure I know how to use the approach that Marc suggested in reference to saving a new PDF for use in Word. I also tried Gabor's suggestion to save in Microsoft's metafile format (savePlot with type = wmf and emf), but the images contain lines that are as jagged as those created from the regular R plot output. You may simply be viewing the document at such a small resolution that the resolution is not there to display smooth lines regardless of the approach. Try viewing the document at increased zoom. With vector based images they automatically adapt to the resolution available. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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.
Re: [R] characters in a string
On Sep 15, 2010, at 11:16 AM, raje...@cse.iitm.ac.in wrote: Hi, I need to check if a string rha,b,c,drh is delimited by two rh 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique? txt - rha,b,c,drh grep(^rh.+rh$, txt) [1] 1 [[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. David Winsemius, MD West Hartford, CT __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
On Sep 15, 2010, at 10:25 AM, dadrivr wrote: Thanks for your help, guys. I'm looking to produce a high-quality plot (no jagged lines or other distortions) with a filetype that is accepted by Microsoft Word on a PC and that most journals will accept. That's why I'd prefer to stick with JPEG, TIFF, PNG, or the like. I'm not sure EPS would fly. I tried inserting the PDF directly into Word, but I am on a PC and there is a loss of quality in the transfer. I'm not sure I know how to use the approach that Marc suggested in reference to saving a new PDF for use in Word. I also tried Gabor's suggestion to save in Microsoft's metafile format (savePlot with type = wmf and emf), but the images contain lines that are as jagged as those created from the regular R plot output. Is there a way to enable anti-aliasing on all regular R plot output to clean up the jaggies and then save it in another format? Or should I try something else? Thanks again! The comments that I had vis-a-vis saving to PDF were specific to operating on an OSX platform. They won't apply to Windows/Linux. The issue is that the notion of most journals is problematic. Many journals will have requirements for specific formats, including plot/graphic output, which I would note includes the use of LaTeX/EPS/PDF as the source content, not Word or similar word processing formats. If you need to stick with bitmapped formats, then you need to generate the plot file with a specific size/dpi in mind, so that the content will not be resized during editing. It is the resizing of plots and images that gets you into trouble with bitmapped formats, resulting in the oft seen pixelation. I would recommend that you check specifically with the journal(s) that you are targeting to find out exactly what they want. They typically publish guidelines for authors, which you should seek out. Once you know exactly what the specific journals require, then you can target the content creation accordingly. You can also search the archives via rseek.org (using publication quality plots) to review past discussions on this same topic. HTH, Marc __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
On Wed, 15 Sep 2010, dadrivr wrote: Thanks for your help, guys. I'm looking to produce a high-quality plot (no jagged lines or other distortions) with a filetype that is accepted by Microsoft Word on a PC and that most journals will accept. That's why I'd prefer to stick with JPEG, TIFF, PNG, or the like. I'm not sure EPS would fly. One simple approach, which I use when I have to create graphics for MS Office while on a non-Windows platform is to use PNG and set the resolution and file size large enough. At 300dpi or so the physics of ink on paper does all the antialiasing you need. Work out how big you want the graph to be, and use PNG with enough pixels to get at least 300dpi at that final size. You'll need to set the pointsize argument and it will help to set the resolution argument. -thomas Thomas Lumley Professor of Biostatistics University of Washington, Seattle __ 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.
Re: [R] relative risk regression with survey data
On Wed, 15 Sep 2010, Ravi Varadhan wrote: Dear Thomas, You said, the log-binomial model is very non-robust when the fitted values get close to 1, and there is some controversy over the best approach. Could you please point me to a paper that discusses the issues? I have written some code to do maximum likelihood estimation for relative, additive, and mixed risk regression models with binomial model. I have been able to obtain good convergence. I have used bootstrap to get standard errors. However, I am not sure if these standard errors are valid when fitted values were close to 0 or 1. It seems to me that when the fitted probabilities are close to 0 or 1, there is not a good way to estimate standard errors. There's a technical report at http://www.bepress.com/uwbiostat/paper293/ with simulations, some theory, and references. It's under review at the moment, after being forgotten for a few years. The distribution of the parameter estimates when the true parameter is on the boundary of the parameter space is a separate mess. Theoretically it is the intersection of the the multivariate Normal with the parameter space, and if the parameter space has a piecewise linear boundary the log likelihood ratio has a chi-squared mixture distribution. In practice, if there isn't a hard edge to the covariate distribution it's not going to be easy to get a good approximation to the distribution of parameter estimates. As an example of the complications, the sampling distributions for fixed and random design matrices can be very different, because a random design matrix means that the estimated edge of the parameter space moves from one realization to another. -thomas Thomas Lumley Professor of Biostatistics University of Washington, Seattle __ 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] Difficulty creating Julian day in data frame
Hi, I'm attempting to add a Julian Day column to a data frame. Here is my code and the resulting data frame: vic.data - read.table(C:/VIC/data/vic.data.csv, header=F) names(vic.data) - c(year, month, day, precip, evap, runoff, baseflow, Tsup, SM1, SM2, SM3, SWE) vic.data$temp.date - as.Date(paste(vic.data$year, /, vic.data$month, /, vic.data$day, sep=)) vic.data$julian.day - julian(vic.data$temp.date, origin = as.Date(1900-01-01))[1] head(vic.data) year month day precip evap runoff baseflow Tsup SM1 SM2 SM3 SWE temp.date julian.day 1 1916 1 1 0.00 0.0789 0 0.5037 -15.9907 20.2285 63.4011 296.9437 214.7537 1916-01-01 5843 2 1916 1 2 0.00 0.1135 0 0.5030 -14.1946 20.1619 63.3425 296.5659 214.7009 1916-01-02 5843 3 1916 1 3 29.74 0.1584 0 0.5024 -11.1894 20.0998 63.2817 296.1864 244.0971 1916-01-03 5843 4 1916 1 4 11.37 0.2056 0 0.5017 -12.9745 20.0416 63.2194 295.8052 255.3145 1916-01-04 5843 5 1916 1 5 0.00 0.1467 0 0.5011 -15.1542 19.9866 63.1561 295.4224 255.2361 1916-01-05 5843 6 1916 1 6 0.00 0.0939 0 0.5004 -12.5409 19.9345 63.0922 295.0379 255.2084 1916-01-06 5843 As you can see, the temp.date column behaves as expected, but the julian.day column is populated with the Julian day value from 1/1/1916. Please help me out if you have some ideas. Thanks, Sean * Sean Parks Ecologist | Geospatial Analyst Aldo Leopold Wilderness Research Institute Rocky Mountain Research Station (406) 542-4182 http://leopold.wilderness.net/ * [[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.
[R] Scripting help
Dear all, I am new to R and this group. I have good experience in S scripts. I need some orientation on data imports, general plotting functions. Can you please direct me? Regards,Ayyappa Chaturvedula __ 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.
Re: [R] Difficulty creating Julian day in data frame
On Sep 15, 2010, at 12:05 PM, Sean Parks wrote: Hi, I'm attempting to add a Julian Day column to a data frame. Here is my code and the resulting data frame: vic.data - read.table(C:/VIC/data/vic.data.csv, header=F) names(vic.data) - c(year, month, day, precip, evap, runoff, baseflow, Tsup, SM1, SM2, SM3, SWE) vic.data$julian.day - julian(vic.data$temp.date, origin = as.Date(1900-01-01))[1] There's one problem. Why are you appending the [1]? to the as.Date function. It's just going to give you the first date. -- David. head(vic.data) year month day precip evap runoff baseflow Tsup SM1 SM2 SM3 SWE temp.date julian.day 1 1916 1 1 0.00 0.0789 0 0.5037 -15.9907 20.2285 63.4011 296.9437 214.7537 1916-01-01 5843 2 1916 1 2 0.00 0.1135 0 0.5030 -14.1946 20.1619 63.3425 296.5659 214.7009 1916-01-02 5843 3 1916 1 3 29.74 0.1584 0 0.5024 -11.1894 20.0998 63.2817 296.1864 244.0971 1916-01-03 5843 4 1916 1 4 11.37 0.2056 0 0.5017 -12.9745 20.0416 63.2194 295.8052 255.3145 1916-01-04 5843 5 1916 1 5 0.00 0.1467 0 0.5011 -15.1542 19.9866 63.1561 295.4224 255.2361 1916-01-05 5843 6 1916 1 6 0.00 0.0939 0 0.5004 -12.5409 19.9345 63.0922 295.0379 255.2084 1916-01-06 5843 As you can see, the temp.date column behaves as expected, but the julian.day column is populated with the Julian day value from 1/1/1916. Please help me out if you have some ideas. Thanks, Sean * Sean Parks Ecologist | Geospatial Analyst Aldo Leopold Wilderness Research Institute Rocky Mountain Research Station (406) 542-4182 http://leopold.wilderness.net/ * [[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. David Winsemius, MD West Hartford, CT __ 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.
Re: [R] characters in a string
great! Thanks - Original Message - From: David Winsemius dwinsem...@comcast.net To: raje...@cse.iitm.ac.in Cc: r-help r-help@r-project.org Sent: Wed, 15 Sep 2010 21:12:27 +0530 (IST) Subject: Re: [R] characters in a string On Sep 15, 2010, at 11:16 AM, raje...@cse.iitm.ac.in wrote: Hi, I need to check if a string a,b,c,d is delimited by two 's as efficiently as possible(I need to do this a lot of times) and return TRUE. Can someone suggest a good technique? txt - a,b,c,d grep(^.+$, txt) [1] 1 [[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. David Winsemius, MD West Hartford, CT [[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.
[R] Computing effect sizes based on mixed models
In an intervention study with subjects randomly allocated to two treatments (treat A and B) and three time points (time) plus an additional baseline measurement (dv_base), I've set up the following model to test for differences in temporal courses of treatments for the outcome (dv), thereby allowing for individual intercepts and slopes: lmer(dv ~ dv_base+treat*time+(1+time|subject)) Fixed effects: Estimate Std. Error DF t value (Intercept)-1.080041 0.126665 58 -8.527 dv_base-0.888656 0.090617 53 -9.807 treatB 0.645455 0.190541 53 3.387 time -0.001726 0.163044 58 -0.011 treatB:time 0.377888 0.271972 58 1.389 I'm interested now in comparing estimated treatment means for let's say the last time point and I've centered 'time' accordingly. The term 'treatB' shows the difference which is relatively high and significantly different from 0 (t(53)=3.387). Now I want to compute the effect size of this difference, based on the model, not on the observed values. From my understanding I could obtain raw effect sizes by simply reporting the value of the term 'treatB' (=0.645). When it comes to standardized effect sizes (comparable to Cohen's d) I could simply take the t-value and the degrees of freedom and use the formula 2*t/sqrt(DF)=0.930. My question: Is this a correct procedure? I'm somewhat unsure as I've never encountered it in the literature. And help on this is greatly appreciated. Andrea [[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.
Re: [R] Difficulty creating Julian day in data frame
On Sep 15, 2010, at 12:23 PM, David Winsemius wrote: On Sep 15, 2010, at 12:05 PM, Sean Parks wrote: Hi, I'm attempting to add a Julian Day column to a data frame. Here is my code and the resulting data frame: vic.data - read.table(C:/VIC/data/vic.data.csv, header=F) names(vic.data) - c(year, month, day, precip, evap, runoff, baseflow, Tsup, SM1, SM2, SM3, SWE) vic.data$julian.day - julian(vic.data$temp.date, origin = as.Date(1900-01-01))[1] There's one problem. Why are you appending the [1]? to the as.Date function. Er, ... that would be the julian function. (But same import.) -- David It's just going to give you the first date. -- David. head(vic.data) year month day precip evap runoff baseflow Tsup SM1 SM2 SM3 SWE temp.date julian.day 1 1916 1 1 0.00 0.0789 0 0.5037 -15.9907 20.2285 63.4011 296.9437 214.7537 1916-01-01 5843 2 1916 1 2 0.00 0.1135 0 0.5030 -14.1946 20.1619 63.3425 296.5659 214.7009 1916-01-02 5843 3 1916 1 3 29.74 0.1584 0 0.5024 -11.1894 20.0998 63.2817 296.1864 244.0971 1916-01-03 5843 4 1916 1 4 11.37 0.2056 0 0.5017 -12.9745 20.0416 63.2194 295.8052 255.3145 1916-01-04 5843 5 1916 1 5 0.00 0.1467 0 0.5011 -15.1542 19.9866 63.1561 295.4224 255.2361 1916-01-05 5843 6 1916 1 6 0.00 0.0939 0 0.5004 -12.5409 19.9345 63.0922 295.0379 255.2084 1916-01-06 5843 As you can see, the temp.date column behaves as expected, but the julian.day column is populated with the Julian day value from 1/1/1916. Please help me out if you have some ideas. Thanks, Sean * Sean Parks Ecologist | Geospatial Analyst Aldo Leopold Wilderness Research Institute Rocky Mountain Research Station (406) 542-4182 http://leopold.wilderness.net/ * [[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. David Winsemius, MD West Hartford, CT __ 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. David Winsemius, MD West Hartford, CT __ 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.
Re: [R] How to uncompress a gz file in R
Dear Henrik, Thank you so much for your kind help. Unfortunately, I could not find out any function such as 'gunzip' in R.utils package. Instead, I could be successful by using the following command. system(gunzip filename) On the other hand, the function 'gzfile' supports the compression as gz format, but I still do not know how to decompress gz file by using the function 'gzfile'. Best Regards, Wonsang On 14 September 2010 15:23, Henrik Bengtsson h...@stat.berkeley.edu wrote: To uncompress an *.gz file into another file on disk, see also ?gunzip in the R.utils package. /Henrik 2010/9/14 Uwe Ligges lig...@statistik.tu-dortmund.de: See ?gzfile Uwe Ligges On 14.09.2010 11:02, Wonsang You wrote: Dear Fellows, I would like to know how to uncompress a gz file at the R console. I could not find out any help from the R-help archive. Thanks for your great help. Best Regards, Wonsang You - -- Wonsang You Special Lab Non-Invasive Brain Imaging Leibniz Institute for Neurobiology http://www.ifn-magdeburg.de __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
You might want to check out the Reproducible Research task view: http://cran.r-project.org/web/views/ReproducibleResearch.html There is a section on Microsoft formats, as well as other formats that can be converted. Max On Wed, Sep 15, 2010 at 11:49 AM, Thomas Lumley tlum...@u.washington.edu wrote: On Wed, 15 Sep 2010, dadrivr wrote: Thanks for your help, guys. I'm looking to produce a high-quality plot (no jagged lines or other distortions) with a filetype that is accepted by Microsoft Word on a PC and that most journals will accept. That's why I'd prefer to stick with JPEG, TIFF, PNG, or the like. I'm not sure EPS would fly. One simple approach, which I use when I have to create graphics for MS Office while on a non-Windows platform is to use PNG and set the resolution and file size large enough. At 300dpi or so the physics of ink on paper does all the antialiasing you need. Work out how big you want the graph to be, and use PNG with enough pixels to get at least 300dpi at that final size. You'll need to set the pointsize argument and it will help to set the resolution argument. -thomas Thomas Lumley Professor of Biostatistics University of Washington, Seattle __ 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. -- Max __ 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.
Re: [R] Creating publication-quality plots for use in Microsoft Word
I'd prefer to stick with JPEG, TIFF, PNG, or the like. I'm not sure EPS would fly. Preferring to stick with bitmap formats (like JPEG, TIFF, PNG) is likely to give you the jagged lines and other distortions you profess to want to avoid. EPS (encapsulated postscript, which handles vector+bitmap) is one of the graphic file formats preferred by most quality journals. Surprisingly, not too many people seem to be aware of the fact that PDF really is a crippled form of postscript. Regards, Mark. -- View this message in context: http://r.789695.n4.nabble.com/Creating-publication-quality-plots-for-use-in-Microsoft-Word-tp2540676p2540858.html Sent from the R help mailing list archive at Nabble.com. __ 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] Format Data Issue??
R Users, I am new to R and have tried to figure out how to automate this process instead of using excel. I have read in this dataframe into r with read.table. I need to reshape the data from the first table into the format of the second table. TractID StandID Species CruiseDate DBHClassTreesPerAcre Carbon Stand 1 Loblolly Pine 5/20/201010 1.2 Carbon Stand 1 Loblolly Pine 5/20/201012 1.2 Carbon Stand 1 Loblolly Pine 5/20/201014 0.61 Carbon Stand 1 Loblolly Pine 5/20/201016 0.75 Carbon Stand 1 Hard Hardwoods 5/20/2010 6 27.4 Carbon Stand 1 Hard Hardwoods 5/20/2010 8 16.4 Carbon Stand 1 Hard Hardwoods 5/20/2010 10 16.1 Carbon Stand 1 Hard Hardwoods 5/20/2010 12 18.3 Carbon Stand 1 Hard Hardwoods 5/20/2010 14 9.9 I want the TreesPerAcre number to be divided evenly (1.2/20) over the tenth inch DBHClasses. For example, A 10 inch DBHClass would range from 9.1 to 11.0, the 12 inch class would be from 11.1 to 13.0, etc. Any help will be greatly appreciated. TractID StandID Species CruiseDate DBHClassTreesPerAcre Carbon Stand 1 Loblolly Pine 5/20/2010 9.1 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.2 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.3 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.4 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.5 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.6 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.7 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.8 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.9 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.00.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.10.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.20.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.30.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.40.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.50.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.60.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.70.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.80.06 Carbon Stand 1 Loblolly Pine 5/20/2010 10.90.06 Carbon Stand 1 Loblolly Pine 5/20/2010 11.00.06 etc. Information: R 2.11.1 Windows 7 Thanks in advance, Randy __ 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.
Re: [R] How to uncompress a gz file in R
Hi. On Wed, Sep 15, 2010 at 9:30 AM, Wonsang You y...@ifn-magdeburg.de wrote: Dear Henrik, Thank you so much for your kind help. Unfortunately, I could not find out any function such as 'gunzip' in R.utils package. Hmm... it's been there since at least 2005. library(R.utils); help(gunzip) See the example. gzip() and gunzip() works on any OS. /H Instead, I could be successful by using the following command. system(gunzip filename) On the other hand, the function 'gzfile' supports the compression as gz format, but I still do not know how to decompress gz file by using the function 'gzfile'. Best Regards, Wonsang On 14 September 2010 15:23, Henrik Bengtsson h...@stat.berkeley.edu wrote: To uncompress an *.gz file into another file on disk, see also ?gunzip in the R.utils package. /Henrik 2010/9/14 Uwe Ligges lig...@statistik.tu-dortmund.de: See ?gzfile Uwe Ligges On 14.09.2010 11:02, Wonsang You wrote: Dear Fellows, I would like to know how to uncompress a gz file at the R console. I could not find out any help from the R-help archive. Thanks for your great help. Best Regards, Wonsang You - -- Wonsang You Special Lab Non-Invasive Brain Imaging Leibniz Institute for Neurobiology http://www.ifn-magdeburg.de __ 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.
[R] Sas to R
Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x 'D:\Program Files\R\R-2.9.2\bin\Rgui.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah -- --- Sarah Jilani (317) 979 2830 [[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.
Re: [R] Scripting help
On Wed, Sep 15, 2010 at 12:22:15PM -0400, Ayyappa Chaturvedula wrote: Dear all, I am new to R and this group. I have good experience in S scripts. I need some orientation on data imports, general plotting functions. Can you please direct me? Welcome to R. Coming from an S background you should have no problems to adjust quickly. For data import have a look at the R Data Import/Export manual: http://cran.r-project.org/doc/manuals/R-data.html Plotting is not to different from S-Plus. As far as my knowledge goes there are 3 differnet plotting frameworsk in R: 1) Basic plot functions like plot or hist some of which are covered in the Introduction to R 2) lattice (the R aequivalent of trellis graphics covered in many manual pages, many tutorials and talks google will quickly find and last but not least the book Lattice: Multivariate Data Visualization with R by Deepayan Sarkar who implemented lattice 3) ggplot2 See http://had.co.nz/ggplot2/ for documentation and consider the book ggplot2: Elegant Graphics for Data Analysis by Hadley Wickham (the author of ggplot2) I use all three frameworks on a regular basis - choosing the respective functions depending on the complexity of the task. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/ __ 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.
Re: [R] Sas to R
Sarah, This is a SAS question, not R. However, it seems clear that it has something to do with the fact that there are spaces in the command that you're sending to Windows. Maybe try calling with the 'short directory name' notation, I forget what that's called in Windows. Or else follow-up on a SAS list? Sarah Jilani wrote: Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x 'D:\Program Files\R\R-2.9.2\bin\Rgui.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah __ 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.
Re: [R] Sas to R
David Winsemius wrote: On Sep 15, 2010, at 1:44 PM, Sarah Jilani wrote: Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says I went searching for a worked example and found this: http://www.nesug.org/proceedings/nesug08/sa/sa07.pdf Those of us with a preference for R are likely to be either amused (or mildly offended) by statements like ...Data manipulation is much easier in SAS... Which is just another way of saying, I am used to manipulating data in SAS or I've never been taught to manipulate data in R. __ 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.
Re: [R] Sas to R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Sarah Jilani Sent: Wednesday, September 15, 2010 10:44 AM To: r-help@r-project.org Subject: [R] Sas to R Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x 'D:\Program Files\R\R-2.9.2\bin\Rgui.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah Sarah, I have found that making sure the command you wish to run will actually run at the command line is a big help. I suspect that the command, as you have specified it, will not run at the command line. Try copying everything inside the single quotes, open a command prompt, then paste the command and run it. I don't think it will do what you expect or want. That being said, try something like x 'D:\Program Files\R\R-2.9.2\bin\R.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; You don't want to run Rgui.exe, use R.exe. In addition, you don't want to double your double-quotes, because they are inside single-quotes. Doubling them will cause problems. If this doesn't work, then the R-help related issue is figuring out how to run R from the command line with input and output redirection. The syntax I provide above should run just fine in Windows XP/Vista/7. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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.
Re: [R] Sas to R
Hi Sarah, Just a couple additional notes to what's been said: 1) It seems like R CMD BATCH might be easier 2) If the space in Program Files is causing issues, you can use the Windows environment variable %PROGRAMFILES% (which also means you do not need the drive letter. 3) I find it handy to define a new Windows environment variable with the path to R, then I can just reference that rather than the entire path (a google search will show you lots of ways to do this via the GUI and the command prompt). For instance: %R%/Rterm.exe starts R in the command prompt for me. Here is an example run from the Windows command prompt: %PROGRAMFILES%/R/R-2.11.1/bin/R.exe CMD BATCH C:/myscript.R C:/results.txt Cheers, Josh On Wed, Sep 15, 2010 at 10:44 AM, Sarah Jilani sarahjil...@gmail.com wrote: Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x 'D:\Program Files\R\R-2.9.2\bin\Rgui.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah -- --- Sarah Jilani (317) 979 2830 [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ 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.
Re: [R] Sas to R
Thanks Josh and Dan! I got it to work using the following code that Dan had suggested. x D:\Program Files\R\R-2.9.2\bin\R.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log; Thanks for your help!! :) Sarah On Wed, Sep 15, 2010 at 2:58 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: Hi Sarah, Just a couple additional notes to what's been said: 1) It seems like R CMD BATCH might be easier 2) If the space in Program Files is causing issues, you can use the Windows environment variable %PROGRAMFILES% (which also means you do not need the drive letter. 3) I find it handy to define a new Windows environment variable with the path to R, then I can just reference that rather than the entire path (a google search will show you lots of ways to do this via the GUI and the command prompt). For instance: %R%/Rterm.exe starts R in the command prompt for me. Here is an example run from the Windows command prompt: %PROGRAMFILES%/R/R-2.11.1/bin/R.exe CMD BATCH C:/myscript.R C:/results.txt Cheers, Josh On Wed, Sep 15, 2010 at 10:44 AM, Sarah Jilani sarahjil...@gmail.com wrote: Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x 'D:\Program Files\R\R-2.9.2\bin\Rgui.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah -- --- Sarah Jilani (317) 979 2830 [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ -- --- Sarah Jilani (317) 979 2830 [[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.
Re: [R] Homogeneity of regression slopes
That's good insight, and gives me some good ideas for what direction to this. Thanks everyone ! Doug P.S. - I guess if you have a significant interaction, that implies the slopes of the individual regression lines are significantly different anyway, doesn't it... On Tue, Sep 14, 2010 at 11:33 AM, Thomas Stewart tgstew...@gmail.com wrote: If you are interested in exploring the homogeneity of variance assumption, I would suggest you model the variance explicitly. Doing so allows you to compare the homogeneous variance model to the heterogeneous variance model within a nested model framework. In that framework, you'll have likelihood ratio tests, etc. This is why I suggested the nlme package and the gls function. The gls function allows you to model the variance. -tgs P.S. WLS is a type of GLS. P.P.S It isn't clear to me how a variance stabilizing transformation would help in this case. On Tue, Sep 14, 2010 at 6:53 AM, Clifford Long gnolff...@gmail.com wrote: Hi Thomas, Thanks for the additional information. Just wondering, and hoping to learn ... would any lack of homogeneity of variance (which is what I believe you mean by different stddev estimates) be found when performing standard regression diagnostics, such as residual plots, Levene's test (or equivalent), etc.? If so, then would a WLS routine or some type of variance stabilizing transformation be useful? Again, hoping to learn. I'll check out the gls() routine in the nlme package, as you mentioned. Thanks. Cliff On Mon, Sep 13, 2010 at 10:02 PM, Thomas Stewart tgstew...@gmail.com wrote: Allow me to add to Michael's and Clifford's responses. If you fit the same regression model for each group, then you are also fitting a standard deviation parameter for each model. The solution proposed by Michael and Clifford is a good one, but the solution assumes that the standard deviation parameter is the same for all three models. You may want to consider the degree by which the standard deviation estimates differ for the three separate models. If they differ wildly, the method described by Michael and Clifford may not be the best. Rather, you may want to consider gls() in the nlme package to explicitly allow the variance parameters to vary. -tgs On Mon, Sep 13, 2010 at 4:52 PM, Doug Adams f...@gmx.com wrote: Hello, We've got a dataset with several variables, one of which we're using to split the data into 3 smaller subsets. (as the variable takes 1 of 3 possible values). There are several more variables too, many of which we're using to fit regression models using lm. So I have 3 models fitted (one for each subset of course), each having slope estimates for the predictor variables. What we want to find out, though, is whether or not the overall slopes for the 3 regression lines are significantly different from each other. Is there a way, in R, to calculate the overall slope of each line, and test whether there's homogeneity of regression slopes? (Am I using that phrase in the right context -- comparing the slopes of more than one regression line rather than the slopes of the predictors within the same fit.) I hope that makes sense. We really wanted to see if the predicted values at the ends of the 3 regression lines are significantly different... But I'm not sure how to do the Johnson-Neyman procedure in R, so I think testing for slope differences will suffice! Thanks to any who may be able to help! Doug Adams __ 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. __ 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] test to see if a s4 property is assigned?
Class(person,representation(age=numeric,weight=numeric)) [1] person bob - new(person,age=30) is.null(b...@weight) [1] FALSE b...@weight numeric(0) b...@weight == numeric(0) logical(0) How can i test to see if a s4 property is assigned? -- View this message in context: http://r.789695.n4.nabble.com/test-to-see-if-a-s4-property-is-assigned-tp2541044p2541044.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Format Data Issue??
Hi: This isn't the most elegant way, I'm sure, but here's one approach. library(reshape) # read in your data...I had to surround the text strings with quotes because of the spaces df - read.table(textConnection( TractID StandID Species CruiseDate DBHClassTreesPerAcre 'Carbon Stand' 1 'Loblolly Pine' 5/20/201010 1.2 'Carbon Stand' 1 'Loblolly Pine' 5/20/201012 1.2 'Carbon Stand' 1 'Loblolly Pine' 5/20/201014 0.61 'Carbon Stand' 1 'Loblolly Pine' 5/20/201016 0.75 'Carbon Stand' 1 'Hard Hardwoods' 5/20/2010 6 27.4 'Carbon Stand' 1 'Hard Hardwoods' 5/20/2010 8 16.4 'Carbon Stand' 1 'Hard Hardwoods' 5/20/2010 10 16.1 'Carbon Stand' 1 'Hard Hardwoods' 5/20/2010 12 18.3 'Carbon Stand' 1 'Hard Hardwoods' 5/20/2010 14 9.9), header = TRUE) # Generate a matrix that expands the DBHs in each row and column concatenate DBH - t(apply(df, 1, function(x) as.numeric(x[5]) + seq(-0.9, 1, by = 0.1))) df2 - cbind(df, DBH) # Divide the TreesPerAcre by 20 df2$TreesPerAcre - df2$TreesPerAcre/20 # reshape from wide to long using the reshape function melt() df3 - melt(df2, id = 1:6) # a 180 x 8 data frame df3 - df3[order(df3$DBHClass, df3$value), ] head(df3) TractID StandIDSpecies CruiseDate DBHClass TreesPerAcre 5 Carbon Stand 1 Hard Hardwoods 5/20/20106 1.37 14 Carbon Stand 1 Hard Hardwoods 5/20/20106 1.37 23 Carbon Stand 1 Hard Hardwoods 5/20/20106 1.37 32 Carbon Stand 1 Hard Hardwoods 5/20/20106 1.37 41 Carbon Stand 1 Hard Hardwoods 5/20/20106 1.37 50 Carbon Stand 1 Hard Hardwoods 5/20/20106 1.37 variable value 5 1 5.1 142 5.2 233 5.3 324 5.4 415 5.5 506 5.6 You'll likely need to convert the CruiseDate to a date variable at some point; see ?as.Date, especially the format argument. If you need this as a function to be applied multiple times, DBHspread - function(df) { # Function to spread out the DBHClass values over an interval of # length 2 in increments of 0.1, and divide TreesPerAcre by 20 to # compensate for change in class width. require(reshape) # Generate a matrix that expands the DBHs in each row and column concatenate # Since DBHClass (variable 5) is integer, it needs to be converted to numeric # In this context, x is the i-th row of the data frame. DBH - t(apply(df, 1, function(x) as.numeric(x[5]) + seq(-0.9, 1, by = 0.1))) # Concatenate new DBHClass values to existing data frame df2 - cbind(df, DBH) # Divide the TreesPerAcre by 20 df2$TreesPerAcre - df2$TreesPerAcre/20 # reshape from wide to long using the reshape function melt() df3 - melt(df2, id = 1:6) # Sort by DBHClass and value within it, output with(df3, df3[order(DBHClass, value), ]) } HTH, Dennis On Wed, Sep 15, 2010 at 10:17 AM, Randy Cass randynewru...@gmail.comwrote: R Users, I am new to R and have tried to figure out how to automate this process instead of using excel. I have read in this dataframe into r with read.table. I need to reshape the data from the first table into the format of the second table. TractID StandID Species CruiseDate DBHClassTreesPerAcre Carbon Stand 1 Loblolly Pine 5/20/201010 1.2 Carbon Stand 1 Loblolly Pine 5/20/201012 1.2 Carbon Stand 1 Loblolly Pine 5/20/201014 0.61 Carbon Stand 1 Loblolly Pine 5/20/201016 0.75 Carbon Stand 1 Hard Hardwoods 5/20/2010 6 27.4 Carbon Stand 1 Hard Hardwoods 5/20/2010 8 16.4 Carbon Stand 1 Hard Hardwoods 5/20/2010 10 16.1 Carbon Stand 1 Hard Hardwoods 5/20/2010 12 18.3 Carbon Stand 1 Hard Hardwoods 5/20/2010 14 9.9 I want the TreesPerAcre number to be divided evenly (1.2/20) over the tenth inch DBHClasses. For example, A 10 inch DBHClass would range from 9.1 to 11.0, the 12 inch class would be from 11.1 to 13.0, etc. Any help will be greatly appreciated. TractID StandID Species CruiseDate DBHClassTreesPerAcre Carbon Stand 1 Loblolly Pine 5/20/2010 9.1 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.2 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.3 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.4 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.5 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.6 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.7 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.8 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010 9.9 0.06 Carbon Stand 1 Loblolly Pine 5/20/2010