Re: [R] scale or not to scale that is the question - prcomp
OIS Thank you both for pointing me to it. I did not notice this as the unscaled position of points was quite clear and strightforward according to my knowledge of data. The scaled plot is slightly more distorted and the relationships are not so obvious. Thank you both Petr Pikal petr.pi...@precheza.cz 724008364, 581 252 256, 581 252 140, 581 252 257 Kevin Wright kw.s...@gmail.com napsal dne 19.08.2009 18:33:12: If you mentally rotate the second biplot by 90 degrees, the plots are not so different. This just indicates that the 2nd and 3rd principal components have switched roles. Kevin Wright On Wed, Aug 19, 2009 at 10:09 AM, Petr PIKAL petr.pi...@precheza.cz wrote: Ok Thank you for your time. Best regards Petr Pikal Duncan Murdoch murd...@stats.uwo.ca napsal dne 19.08.2009 16:29:07: On 8/19/2009 10:14 AM, Petr PIKAL wrote: Duncan Murdoch murd...@stats.uwo.ca napsal dne 19.08.2009 15:25:00: On 19/08/2009 9:02 AM, Petr PIKAL wrote: Thank you Duncan Murdoch murd...@stats.uwo.ca napsal dne 19.08.2009 14:49:52: On 19/08/2009 8:31 AM, Petr PIKAL wrote: Dear all snip I would say the answer depends on the meaning of the variables. In the unusual case that they are measured in dimensionless units, it might make sense not to scale. But if you are using arbitrary units of measurement, do you want your answer to depend on them? For example, if you change from Kg to mg, the numbers will become much larger, the variable will contribute much more variance, and it will become a more important part of the largest principal component. Is that sensible? Basically variables are in percentages (all between 0 and 6%) except dus which is present or not present (for the purpose of prcomp transformed to 0/1 by as.numeric:). The only variable which is not such is iep which is basically in range 5-8. So ranges of all variables are quite similar. What surprises me is that biplot without scaling I can interpret by used variables while biplot with scaling is totally different and those two pictures does not match at all. This is what surprised me as I would expected just a small difference between results from those two settings as all numbers are quite comparable and does not differ much. If you look at the standard deviations in the two cases, I think you can see why this happens: Scaled: Standard deviations: [1] 1.3335175 1.2311551 1.0583667 0.7258295 0.2429397 Not Scaled: Standard deviations: [1] 1.0030048 0.8400923 0.5679976 0.3845088 0.1531582 The first two sds are close, so small changes to the data will affect I see. But I would expect that changes to data made by scaling would not change it in such a way that unscaled and scaled results are completely different. their direction a lot. Your biplots look at the 2nd and 3rd components. Yes because grouping in 2nd and 3rd component biplot can be easily explained by values of some variables (without scaling). I must admit that I do not use prcomp much often and usually scaling can give me explainable result, especially if I use it to variable reduction. Therefore I am reluctant to use it in this case. when I try more standard way fit-lm(iep~sio2+al2o3+p2o5+as.numeric(dus), data=rglp) summary(fit) Call: lm(formula = iep ~ sio2 + al2o3 + p2o5 + as.numeric(dus), data = rglp) Residuals: Min 1Q Median 3Q Max -0.41751 -0.15568 -0.03613 0.20124 0.43046 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 7.120850.62257 11.438 8.24e-08 *** sio2-0.672500.20953 -3.210 0.007498 ** al2o30.405340.08641 4.691 0.000522 *** p2o5-0.769090.11103 -6.927 1.59e-05 *** as.numeric(dus) -0.640200.18101 -3.537 0.004094 ** I get quite plausible result which can be interpreted without problems. My data is a result of designed experiment (more or less :) and therefore all variables are significant. Is that the reason why scaling may bye inappropriate in this case? No, I think it's just that the cloud of points is approximately spherical in the first 2 or 3 principal components, so the principal component directions are somewhat arbitrary. You just got lucky that the 2nd and 3rd components are interpretable: I wouldn't put too much faith in being able to repeat that if you went out and collected a new set of data using the same design. 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
[R] Unable to load RHtestV2
Dear All, I am not being able to load RHtestV2 or rhtest_gui.r for homogeneity test of climatic data. I have 2 user manual RHTest (0.95) and RHtestV2. Though, I load source code for RHtestV2 no any other window pops up. However, I am unable to find source code rhtest_gui.r. Regards, Binaya Pasakhala __ 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] Embedding lists in matrices and matrices in lists
Hi Michael Kogan michael.ko...@gmx.net napsal dne 19.08.2009 17:22:04: Thanks, that was the solution! But in fact I didn't want to have this list of lists layer at all. And now I'm having trouble writing matrices into the database. It's really really strange... If I write a matrix into the database manually everything works, but if I create a function which adds a matrix into the database and then run the function it fails... Look at this (sorry for the long code block, in fact you can skip the sums and test_sums functions): ##test matrix### m1=matrix(c( 1,0, 0,1 ),nrow=2, byrow=TRUE) #sums### sums=function(matrix) { c(sort(colSums(matrix)),sort(rowSums(matrix))) } ##test_sums# test_sums=function(matrix) { liste=database[[nrow(matrix),ncol(matrix)]][[1]] w=1 if(length(liste)0){ for(i in 1:length(liste)){ if(all(sums(matrix)==sums(liste[[i]]))){ w0=0 }else{ w0=1} w=w*w0} }else{ w=2} w } #write to db write_to_db=function(matrix){ en=nrow(matrix) fn=ncol(matrix) if(test_sums(matrix)==1){ print(matrix isn't in the DB yet) database[en,fn][[1]]=list(database[en,fn][[1]], matrix) }else if(test_sums(matrix)==2){ print(matrix isn't in the DB entry yet and DB is empty) database[en,fn][[1]][[1]]=list(matrix) }else{ print(matrix already exists in the DB) } } ##create database## database=matrix(list(),2,2) ##trying to write a matrix into db using the function## write_to_db(m1) database ###writing a matrix into db without using a function### en=nrow(m1) fn=ncol(m1) if(test_sums(m1)==1){ print(matrix isn't in the DB yet) database[en,fn][[1]]=list(database[en,fn][[1]], m1) }else if(test_sums(m1)==2){ print(matrix isn't in the DB entry yet and DB is empty) database[en,fn][[1]][[1]]=list(m1) }else{ print(matrix already exists in the DB) } database ###test whether matrix already is in db## write_to_db(m1) And the output is: [1] matrix isn't in the DB entry yet and DB is empty [,1] [,2] [1,] NULL NULL [2,] NULL NULL [1] matrix isn't in the DB entry yet and DB is empty [,1] [,2] [1,] NULL NULL [2,] NULL List,1 [1] matrix already exists in the DB So writing the matrix into the database using the function fails while writing it using the same commands but not through a function works! Maybe it's a problem with all these layers in the database matrix? No. It is the problem of scoping. AFAIK functions create their own environment and everything what is assigned inside the function does not affect outside objects unless you use - assignment operator. i-100 ff-function(x) i-x ff(10) i [1] 100 fff-function(x) i-x fff(200) i [1] 200 However I would distract you from this practice. Personally I used such assignment only when I started with S/R about 10 years ago. Why do you want a database to be a matrix? It seems to be that list structure is in that case more flexible and there are *apply functions for manipulation with lists. E.g. structure lm(...) results in list and summary(lm(...)) is again a list with quite complicated structure. If I understand it correctly, during your computation you will have as a result matrices with arbitrary dimensions. I would make a list lll-vector(list, 1) and in simple loop for (i in 1:n) { do any computation here together with sophisticated and complicated functions and assign results to your list lll[[1]] - result of functions which itself can have quite complicated structure } If you want nested list just add another cycle and use lll[[i]][[j]] -some other result. With choosing appropriate structure of your date you can save yourself much problems. Regards Petr Petr PIKAL schrieb: Hi r-help-boun...@r-project.org napsal dne 19.08.2009 13:04:39: Strange, it doesn't work for me: Error in database[4, 4][[1]][1, ] : incorrect number of dimensions Execution halted R version 2.9.0 (2009-04-17) on Arch Linux, no additional packages installed. database[4,4][[1]][,1] does not work for me either but it is result of your complicated structure of nested lists This works database[4,4][[1]][[1]][,1] [1] 0 1 1 1 See the structure Matrix of lists database [,1] [,2] [,3] [,4] [,5] [1,] NULL NULL NULL NULL NULL [2,] NULL NULL NULL NULL NULL [3,] NULL NULL NULL NULL NULL [4,] NULL NULL NULL List,1 NULL [5,] NULL NULL NULL NULL NULL List of lists database[4,4] [[1]] [[1]][[1]] [,1] [,2] [,3] [,4] [1,]0111 [2,]1011 [3,]1
Re: [R] [Hmisc] latex() with ctable=T inserting unwanted empty line in .tex file when used on summary.formula(method=reverse) object
Vincent Chouraki wrote: When I'm using Hmisc's latex() function with ctable=TRUE on a summary.formula with method=reverse object and saving in a .tex file, the latter contains an unwanted empty line which makes compilation fail. ... Example removed Vincent, I checked it and think it is a bug. I have forwarded this to the maintainer, Thomas Dupong, with a cc to Frank Harrell. Dieter -- View this message in context: http://www.nabble.com/-Hmisc--latex%28%29-with-ctable%3DT-inserting-unwanted-empty-line-in-.tex-file-when-used-on-summary.formula%28method%3D%22reverse%22%29-object-tp25051531p25056786.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] ggsave to .png bug in ggplot2 (?)
Chris Friedl wrote: Text is really small and legend boxes are huge in this plot when saved to .png with ggsave. Plot is correct (i.e. looks the same as the screen) when saved with dev.print. Saving to .pdf with ggsave give the correct output. You are not alone. Things like this always happen the day before the deadline, when you want to make minor changes. It is not limited to ggplot, but looking at the variant require(ggplot2) x - data.frame(value=rnorm(5000, mean=0), case=A) y - data.frame(value=rnorm(5000, mean=3), case=B) xy - rbind(x, y) p - ggplot(xy, aes(x=value, colour=case, group=case)) + geom_density() p ggsave(p, width=4,height=4,filename = xy_ggsave.png) makes me believe that this function should be banned. You might also check the output of the ggsave documentation page to learn what scaling means in R. (Slightly modified below). ratings - qplot(rating, data=movies, geom=histogram) qplot(length, data=movies, geom=histogram) ggsave(file=length-hist.pdf) ggsave(file=length-hist.png) ggsave(ratings, file=ratingsA.pdf) ggsave(ratings, file=ratingsB.pdf, width=4, height=4) # make twice as big as on screen ggsave(ratings, file=ratingsC.pdf, scale=2) I never use these functions in final production, be it in standard graphics or lattice, but always open a device and close it after all plots have been produced. Dieter -- View this message in context: http://www.nabble.com/ggsave-to-.png-bug-in-ggplot2-%28-%29-tp25055170p25057074.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] expanding 1:12 months to Jan:Dec
Dear R users I would like to do some spreadsheet style expansion of dates. For example, I would need to obtain a vector of months. I approached in an obviously wrong way: paste(01:12) [1] 1 2 3 4 5 6 7 8 9 10 11 12 as.Date(paste(01:12), %m) [1] NA NA NA NA NA NA NA NA NA NA NA NA to subsequently format(.., %b). Other than writing the months manually, could anyone suggest an easier way to obtain such a list? Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] mild and extreme outliers in boxplot
Hi Jimmy, please be reassured that I did not intend to offend you nor any other in the list. Rnewbie ha scritto: I read the boxplot() help file and googled before making the post, and with my little knowledge on R I was not able to plot in the way I wanted. If I'm allowed, this was not evident from your post. Probably due to its conciseness, I thought it was in the style I have a problem, I do not want to study to solve it, need someone to do it for me I realize now it was not the case. I apologize for this. Ottorino That’s why I made the post. Whether I can eventually solve the problem or not, I appreciate very much any help. I’m a very beginner of R, and found the R help forum a couple of weeks ago. Since I thought I’m not among the major players of the forum and that the post per se rather than poster is of concern like in any other public online forum, I just registered with an arbitrarily chosen ID and kept using it. I’m not making use of R help for any commercial purposes whatsoever. I’m a master’s student working on my thesis. Thanks all for your help. Jimmy __ 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] mild and extreme outliers in boxplot
Hi Rolf, On Thu, 2009-08-20 at 12:31 +1200, Rolf Turner wrote: I despair. Why do you keep insisting that black is white? The OP wanted to be able to specify an argument to boxplot() that would cause it to plot mild and extreme outliers with different symbols. Then you and I were reading different emails Rolf. I quote: [Sorry I don't have the original email, so this from Gmane: http://article.gmane.org/gmane.comp.lang.r.general/159957 ] dear all, could somebody tell me how I can plot mild outliers as a circle(°) and extreme outliers as an asterisk(*) in a box-whisker plot? Thanks very much in advance The OP wants to use a different pch for the points that are plotted at the extremes of the distribution of points. It is up to him, as I pointed out, to define what extreme means in this context... THIS CAN'T BE DONE!!! ...but the plotting he wanted to do, can be done! I showed one way it could be done. Why do you insist he can't do what he wants? There is no such argument specification. Agreed (if you discount 'coef' of boxplot.stats() ), but the OP didn't ask specifically for an argument. You appear to have taken a very narrow view of what the OP wanted and then objected that someone had the temerity to suggest the OP read the help pages which, as Bert pointed out, do show you how to alter the plotting characters. The whole point of R, for me at least, is that R Core and the wonderful community of developeRs we are blessed with, provide me with the base tools to do general statistical computing and add-on functionality for specific tasks respectively, but because everything is open and R is a programming language, I *can* do things, with a bit of extra effort, by resorting to writing a few lines of extra code to build on what /is/ provided. The response to which I objected implied that it *could* be done and would have had the OP tearing his hair out reading and re-reading the help pages and wondering what he was missing. OF COURSE it ``can be done'' with some hacking. You can do anything in R. But it can't be done simply by specifying an argument to the given function. Which only you seem to think the OP was requesting. When I said that the appropriate response was ``it can't be done'' I was being stylistically terse. What I would actually have said is something like ``It can't be done directly; you'll need to do some coding to get the effect you want. I'm not sure what coding, or how difficult it might be.'' Then somebody else could follow up with suggestions as to appropriate code, if they felt like it. As to whether the hacking/coding is ``substantial'', that is indeed subjective. What is a simple task for you would very likely be pretty daunting to the OP. Agreed, which is why I felt it instructive and not a waste of my time to provide /a/ solution when I responded to this thread. If he could do it, he probably wouldn't have asked the question in the first place. The response to which I objected was SERIOUSLY MISLEADING. And therefore objectionable. Full stop. In your humble opinion, Rolf? Are you open to the possibility, however remote that othes may have a different opinion to yours? Regardless of whether you thought the original response was way of base or not, you have publicly admonished the responder for providing an answer on a public list to a rather vague question. You are entitled to your views, of course, but you could have emailed the responder off-list, in a polite and diplomatic manner and pointed out why you thought their response was SERIOUSLY MISLEADING, but instead, you wade in with the public criticism. That is what I thought was off base, and why I replied. We've both had our says now and clearly we have different opinions on what was asked, said, etc. I'd be happy to continue this off-list, but for now I'm going to spare the inboxes of the other thousands of R-HelpeRs and get on with the day job. All the best, G cheers, Rolf Turner On 20/08/2009, at 10:53 AM, Gavin Simpson wrote: On Thu, 2009-08-20 at 09:58 +1200, Rolf Turner wrote: On 20/08/2009, at 9:39 AM, Gavin Simpson wrote: snip Criticising correct, if cryptic or highlevel, responses to a list where people give their time for free, *and* not provide a more complete solution is unfair, Rolf. The OP is free to respond and ask for additional help once they've given it a go if they are still having trouble.. When the ``correct response'' is seriously misleading, as this one was --- the implication of the response was that the specified task *could* be done (if one looked hard enough at the help files), when in fact the specified task can't be done (at least not without substantial hacking) Hardly substantial hacking Rolf, and somewhat educational in regards of the underlying functions used by boxplot. My suggestion is 9 lines of code, and it only
Re: [R] mild and extreme outliers in boxplot
I'm very sorry for all this, but still serene. I'm (trying) to use R since may be 5 or 6 years now. What I learned from this list is that you have to show some code to let others to help you out, a thing that Rnewbye did not in this particular case. I had a look myself at the help pages and see that something was there that could help Rnewbye. In particular outlty, outlwd, outpch, outcex, outcol, outbg: outlier line type, line width, point character, point size expansion, color, and background color. The default 'outlty= blank' suppresses the lines and 'outpch=NA' suppresses points. My answer was somehow provocative, but I was ready to help, not to patronize (as many times I saw on this list). I tried myself to change the appearance of the circles and other aspect of the plot, uncorrectly assuming that it could be extended to the problem of Rnewbye. I surely made a mistake, and I apologize for this. This is is my only fault. BUT PLEASE do not forget that if Rnewbye answered to my post (with a piece of code for example) I would have helped him. As I was always helped, harshly or not. Ottorino This is the sort of response that gives R-help a bad name. I did not know that R-help had a bad name. I myself received sometimes some harsh answers, but never lamented about. Gabor Grothendieck ha scritto: I agree its not completely obvious from that answer but that does not mean the responder deserves to be attacked. The circle part is actually the default and albeit with difficulty the help files do give the info we need to produce this: bp - boxplot(c(1:50, 80, 100, 200), outpch = NA) with(bp, points(group, out, pch = c(1, 1, 8))) which can be suitably generalized for other situations. On Wed, Aug 19, 2009 at 8:31 PM, Rolf Turnerr.tur...@auckland.ac.nz wrote: I despair. .. -- Ottorino-Luca Pantani, Università di Firenze Dip. Scienza del Suolo e Nutrizione della Pianta P.zle Cascine 28 50144 Firenze Italia Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 olpant...@unifi.it http://www4.unifi.it/dssnp/ __ 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 read large file
Dear Jim Michael the file contains 1000 lines and 1.200.000 columns, txt format and i wish to read all the file with R if possible, or read a few columns? I tried without success to turn bigmemory and colbycol packages, also scan and readLines function but It takes a long time without anything. I have windows X64 bits 8 Go In advance thanks ML jim holtman a écrit : A little more detail would be appropriate. How large is large? What is the format of the file? What do you wnat to do with the data? Do you have to have it all in memory at once? Does it exist in a data base already? What type of system are you running on? How much memory do you have? On Wed, Aug 19, 2009 at 4:51 AM, Mohamed Lajnefmohamed.laj...@inserm.fr wrote: Dear R-Users, I am looking for packages that could read large files in R? any suggestions are welcome. Regards, ML __ 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] print selected variables
Hi every one, I read one excel external file into R, in that R dataset i have 20 variables. now my querry is i want to print only selected variables (eg:10 variables) with complete data. pls send me the code it will be very helpful for us. Thanks in Advance. -- View this message in context: http://www.nabble.com/print-selected-variables-tp25057378p25057378.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] how to categorize continuous variable when useing regression
assume dependent variable y( continuous),independent variable x ( continuous),I try to categorize x with some interval,such that,those intervals would has most significant different effect on y. any one knows which method I should apply,I really need some hints,thanks so much~ [[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] expanding 1:12 months to Jan:Dec
On Thu, 2009-08-20 at 08:14 +0100, Liviu Andronic wrote: Dear R users I would like to do some spreadsheet style expansion of dates. For example, I would need to obtain a vector of months. I approached in an obviously wrong way: paste(01:12) [1] 1 2 3 4 5 6 7 8 9 10 11 12 as.Date(paste(01:12), %m) [1] NA NA NA NA NA NA NA NA NA NA NA NA to subsequently format(.., %b). Other than writing the months manually, could anyone suggest an easier way to obtain such a list? Liviu I think as.Date is probably not the best way to approach this as these aren't really dates - all you have is the month. R has some built in constants, including the abbreviated month names. See ?month.abb : mon - 01:12 mon - factor(mon, labels = month.abb) mon as.character(mon) ## it you want these as strings not a factor Notice also that starting from characters doesn't get the right answer. Compare mon above with the output from below. mon2 - as.character(01:12) mon2 - factor(mon2, labels = month.abb) mon2 With mon, using the month numbers as numerics keeps the ordering. If your data are characters, then replace the first line in the mon example with (something like): mon - as.numeric(my.months) where my.months is your vector of months. FYI, should you need the full names at any point, there is another constant 'month.name' that fulfils that requirement. See ?month.abb G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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] Several simple but hard tasks to do with R
Rakknar wrote: Hello everybody. I've been learning R for about a month to do a econometric study and now i'm stuck with some problems to make R do the things I want. Here I give the list of things I wanna do from the most simple to the more complex (for me of course): 1. Make a log. I've been using Stata and there i have a great tool to register what the program do: the log file, wich it's a simple .txt file where Stata writes every output it makes (not graphics of course). When I wanted to make the same thing with R I started to use the function sink() but it only register the results of the commands (summaries for example) and not the commands itself, witch it's really uncomfortable because it's harder to find out to witch command that results come from. Hi, I would recommend not using the command line as such too much. Making a script on your harddrive and always working from that seems a better to me. If you have some data on your harddrive (csv for example) you can write a script that takes that data and produces your results (graphs, lm's etc). This ensures that you can always later see how you have done your analysis, and redo if necessary. See also this e-mail on R-help http://www.nabble.com/PowerCut-Killed-R---is-my-code-retrievable--td25052662.html#a25052662. cheers and hope this helps, Paul 2. Saving objects in a .Rdata step by step. I want to save several regressions of interest in one .Rdata file. I want to save this results one by one. For example: make regression 1, save the result in the .Rdata file; then make the regression 2 and save the results in the same .Rdata file. I know I could make all the regressions and save the results all at once but for the kind of study I want to make It would be much useful this way. I've been using function save() but I only could save one result or all. 3. Conditional reading. I want to run regressions conditional to the existence of a .Rdata file (the one I would be making in step two). The condition would be something like If you find X.Rdata file run regression with X.Rdata data else run regression from the 0. I hope I can find help here. Thanks!! -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ 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] print selected variables
rajclinasia wrote: Hi every one, I read one excel external file into R, in that R dataset i have 20 variables. now my querry is i want to print only selected variables (eg:10 variables) with complete data. pls send me the code it will be very helpful for us. Thanks in Advance. Hi, Please read the posting guide. It is very hard for us to give good advice right now. cheers, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ 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] expanding 1:12 months to Jan:Dec
One possible (but not very elegant) solution is: aa - paste(1:12,:10:2009,sep=) dd-as.Date(aa,format=%m:%d:%Y) mon - format(dd,%b) mon [1] Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec --- On Thu, 20/8/09, Liviu Andronic landronim...@gmail.com wrote: From: Liviu Andronic landronim...@gmail.com Subject: [R] expanding 1:12 months to Jan:Dec To: r-help@r-project.org Help r-help@r-project.org Received: Thursday, 20 August, 2009, 5:14 PM Dear R users I would like to do some spreadsheet style expansion of dates. For example, I would need to obtain a vector of months. I approached in an obviously wrong way: paste(01:12) [1] 1 2 3 4 5 6 7 8 9 10 11 12 as.Date(paste(01:12), %m) [1] NA NA NA NA NA NA NA NA NA NA NA NA to subsequently format(.., %b). Other than writing the months manually, could anyone suggest an easier way to obtain such a list? Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Contrasts within ANOVA frame (Repost)
Hi Jun, I have three levels for a factor names StdLot and want to make three comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. With only three levels to your factor, the contrast matrix you are specifying is over-parametrized (i.e. over-specified): it has 3 rows and 3 columns. ## Look at the default behaviour contrasts(d3$StdLot) - NULL contrasts(d3$StdLot) contrasts(d3$StdLot) - contr.helmert contrasts(d3$StdLot) I think what you really want are linear contrasts, which you will find in package car (?linear.hypothesis), in gmodels (?estimable) [based on Frank Harrell's approach; so look at his package Design], and package multcomp, amongst others. Regards, Mark. Jun Shen-3 wrote: Would like to try my luck to see if I can catch your eyes. I was trying to do some contrasts within ANOVA. I searched the archive and found a clue posted by Steffen Katzner ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html) I have three levels for a factor names StdLot and want to make three comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. First, contrasts(d3$StdLot,3)-matrix(c(1,-1, 0,0,1,-1,1,0,-1),3,3) #d3 is the data set. set up the contrast matrix Second, aov(Bkg~StdLot,na.rm=T,data=d3,contrasts=contrasts(d3$StdLot))-mod.aov #ANOVA, Finally, summary(mod.aov,split=list(StdLot=list('1 vs 2'=1,'2 vs 3'=2,'1 vs 3'=3))) #comparison summary Here is the final result I got, the third comparison is missing. Does anyone have any idea what is wrong here? If I change the order of the comparisons it's always the third one missing. So I guess it's not due to the data. Appreciate any comment. Df Sum Sq Mean Sq F valuePr(F) StdLot 2 1.905 0.953 10.3769 3.710e-05 *** StdLot: 1 vs 2 1 0.223 0.223 2.42390.1200 StdLot: 2 vs 3 1 1.683 1.683 18.3299 2.162e-05 *** StdLot: 1 vs 3 1 Residuals601 55.173 0.092 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 2 observations deleted due to missingness -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 [[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. -- View this message in context: http://www.nabble.com/Contrasts-within-ANOVA-frame-%28Repost%29-tp25052361p25057955.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] change default measurement unit to millimetre
Readers, How do I configure R so that all units of measurement are in millimetres? For example if I want to set the width of a graph, I want to write: width=100 and R interprets this value as millimetres. Yours, rh...@conference.jabber.org r 251 mandriva 2008 __ 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] eval and evironments: call local function in a global function
Hi, in my project I want the user to be able to write hook functions that are in turn called in my main code. I'd like the user's hooks to be able to call some function that set a variable outside their running environment. The trick is that this variable is not global, but defined on runtime before calling the hooks, and I don't want to leave any trace (i.e. global variables) after the main code has finished. I thought that the following would work but it doesn't. I guess I got too messy with environment and enclosures: # global function defined by the user fun.global - function(){ message('fun.global') setVar(5) # } # my main code main - function(){ message('main') # define a function to set some local variable setVar - local({ l.var - 0 function(value){ message('setVar') l.var - value } }) .workspace - environment(setVar) environment(setVar) - new.env() eval(fun.global(), enclos=environment(setVar)) print(get('l.var', envir=.workspace, inherits=FALSE)) } main() I get the following output: main fun.global Error in fun.global() : could not find function setVar There is definitely a problem of lookup somewhere. I first tried without eval, as I thought that function setVar would then be defined in a parent environment of the call to fun.global, but it does not work either. Can anybody tell me what's the problem and how I should do my stuff? Thanks, Renaud __ 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] Fitting a logistic regression
Thank you very much, Jun. This is what I was looking for. Best! Dani On Wed, 2009-08-19 at 09:52 -0500, Jun Shen wrote: I would suggest a model with a baseline level, something like nls(AMP~E0+(Emax-E0)*Time**gamma/(EC50**gamma+Time**gamma),data=your data, start=list(EC50=50,gamma=2,E0=0.2,Emax=1.2))-mod.test AIC(mod.test) does improve. Hope this helps. Jun On Wed, Aug 19, 2009 at 5:04 AM, Dani Valverde daniel.valve...@uab.cat wrote: Hello, I have this data: Time AMP 0 0.200 10 0.1958350 20 0.2914560 40 0.6763628 60 0.8494534 90 0.9874526 120 1.0477692 where AMP is the concentration of this metabolite with time. If you plot the data, you can see that it could be fitted using a logistic regression. For this purpose, I used this code: AMP.nls - nls(AMP~SSlogis(Time,Asym, xmid, scal), data = concentrations,model=T) When plotting the fitted function, it seems that it fits quite well at the end of the time. However, at the beginning it seems that the fit is not so good. How can I achieve a better fit? Forgive me if it is a stupid question, but I am just starting with non linear regression. Thank you, Dani -- [?] __ 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. -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Tlf. +34 93 581 1910 Fax: +34 93 581 1573 __ 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] Hello
dimple thyagarajan wrote: Hello! I am trying to merge two xy-plot with different ylimits. It seems that you are using lattice graphics (which you do not mention), if so, look at the documentation of xyplot, specifically to the panel argument. cheers, Paul Can someone please give me possible way of achieving it.. Thank you Regards Dimple [[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. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ 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] postscript, options
On 18/08/2009, Stefan Grosse singularit...@gmx.net wrote: On Tue, 18 Aug 2009 16:08:36 +0100 e-letter inp...@gmail.com wrote: EL postscript(/pathto/filename.eps,horizontal=FALSE,onefile=FALSE,paper=special) EL EL This command created a small blank eps file. Its hard to say why without any example code. Does postscript(/pathto/filename.eps,width=8,height=8,horizontal=FALSE,onefile=FALSE,paper=special) hist(rnorm(100)) dev.off() work? Yes, using the following commands: postscript(/pathto/filename.eps,width=4,height=4,horizontal=FALSE,onefile=FALSE,paper=special) hist(rnorm(100)) dev.off() Command terminal response: X11 2 I opened successfully the file. Thank you. __ 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] ggsave to .png bug in ggplot2 (?)
Dear Chris, That problem is due to the fact that ggsave() and png() use different default for the resolution. ggsave() uses 300 dpi and png() 72 dpi. If you set the resolution in ggsave() to 72 then you get exactly the same output as on the screen. But the resolution is way to low for publication. I have the feeling that everything scales rather nice when using a different resolution, except for the fonts. My workaround is to always save my plots to pdf. I use them as pdf (no problem with that in LaTeX), unless the figure contains lots of points (e.g. scatterplots). In that case I convert the pdf to png outside R. The best tools I found for that are Ghostfriend (http://www.noliturbare.com/index.php) and www.zamzar.com. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Dieter Menne Verzonden: donderdag 20 augustus 2009 9:13 Aan: r-help@r-project.org Onderwerp: Re: [R] ggsave to .png bug in ggplot2 (?) Chris Friedl wrote: Text is really small and legend boxes are huge in this plot when saved to .png with ggsave. Plot is correct (i.e. looks the same as the screen) when saved with dev.print. Saving to .pdf with ggsave give the correct output. You are not alone. Things like this always happen the day before the deadline, when you want to make minor changes. It is not limited to ggplot, but looking at the variant require(ggplot2) x - data.frame(value=rnorm(5000, mean=0), case=A) y - data.frame(value=rnorm(5000, mean=3), case=B) xy - rbind(x, y) p - ggplot(xy, aes(x=value, colour=case, group=case)) + geom_density() p ggsave(p, width=4,height=4,filename = xy_ggsave.png) makes me believe that this function should be banned. You might also check the output of the ggsave documentation page to learn what scaling means in R. (Slightly modified below). ratings - qplot(rating, data=movies, geom=histogram) qplot(length, data=movies, geom=histogram) ggsave(file=length-hist.pdf) ggsave(file=length-hist.png) ggsave(ratings, file=ratingsA.pdf) ggsave(ratings, file=ratingsB.pdf, width=4, height=4) # make twice as big as on screen ggsave(ratings, file=ratingsC.pdf, scale=2) I never use these functions in final production, be it in standard graphics or lattice, but always open a device and close it after all plots have been produced. Dieter -- View this message in context: http://www.nabble.com/ggsave-to-.png-bug-in-ggplot2-%28-%29-tp25055170p2 5057074.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. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ 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] PowerCut Killed R - is my code retrievable?
On Thu, 20-Aug-2009 at 12:21AM +0100, Ted Harding wrote: [] | Again, what I routinely do (in Linux) when developing R code is to | have two terminal windows open. In one I am running R. In the | other, beside it, I am editing a file of R code. To run code in R | that has been entered in the code window, I just highlight it | with the mouse in the code window, and then paste it into the R | window. It's even easier using ESS -- highlight in your code buffer, press your designated function key and the code will be run in the *R* buffer -- or you can use another function key to run code line by line, or, etc. etc. I must admit I didn't like Emacs for the first week or so but when I saw how easy it was to manage code, I decided it was worth the effort to get used to the strange old paradigm which had been developed before the invention of the mouse. I'd also admit that I've seen people do things amazingly quickly using vi -- despite its strange jumping from command mode to insert mode. As others have indicated, whatever you use, it makes good sense to keep a file of the code that you use. Rerunning is something I do as a rule, not an exception. It's particularly useful when follow up work arrives which can reuse the same code or a slightly modified version of it. [...] -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] Problem with predict.coxph
Dear Terry, The following is an additional set of two simple examples. In these, no issue with factor levels, etc, arises. It looks like the problem consistently shows up when the number of rows of newdata differs from the number of rows in the original data set AND time and status are not part of the data frame. library(survival) rm(list = ls()) time - c(4,3,1,1,2,2,3) status - c(1,1,1,0,1,1,0) d3 - data.frame(x=c(0,2,1,1,1,0,0), u=c(0,0,0,0,1,1,1)) m3 - coxph(Surv(time, status) ~ x + u, data = d3) predict(m3) # OK predict(m3, newdata = d3) # OK predict(m3, newdata = d3[1:5, ]) # Fails predict(m3, newdata = d3[c(1:3, 1:4), ]) # OK rm(list = ls()) d1 - data.frame(time = c(4,3,1,1,2,2,3), status = c(1,1,1,0,1,1,0), x= c(0,2,1,1,1,0,0), u = c(0,0,0,0,1,1,1)) m1 - coxph(Surv(time, status) ~ x + u, data = d1) predict(m1) ## OK predict(m1, newdata = d1) ## OK predict(m1, newdata = d1[1:5, ]) ## OK predict(m1, newdata = d1[c(1:3, 1:4), ]) ## OK Best, R. On Wed, Aug 19, 2009 at 5:53 PM, Terry Therneauthern...@mayo.edu wrote: -- begin included message --- We occasionally utilize the coxph function in the survival library to fit multinomial logit models. (The breslow method produces the same likelihood function as the multinomial logit). We then utilize the predict function to create summary results for various combinations of covariates. For example: ... The problem is that under R 2.8.1 and R 2.9.1 the previous line fails with the following error: totalut-predict(mod1,newdata=newdata,type=lp) Error in model.frame.default(Terms2, newdata, xlev = object$xlevels) : variable lengths differ (found for 'Price') In addition: Warning message: 'newdata' had 25 rows but variable(s) found have 43350 rows ---end inclusion -- The coxph code was updated to use the standard R methods for prediction with factors. I even added test cases -- but obviously I've missed something. I'll look into a fix and get back to you. Can I assume that Price and Product were both factors with the 5 levels 1:5? Terry Therneau __ 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. -- Ramon Diaz-Uriarte Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz Phone: +34-91-732-8000 ext. 3019 __ 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: Re: Several simple but hard tasks to do with R]
Rakknar ha scritto: Hello everybody. I've been learning R for about a month to do a econometric study and now i'm stuck with some problems to make R do the things I want. Here I give the list of things I wanna do from the most simple to the more complex (for me of course): 1. Make a log. I've been using Stata and there i have a great tool to register what the program do: the log file, wich it's a simple .txt file where Stata writes every output it makes (not graphics of course). When I wanted to make the same thing with R I started to use the function sink() but it only register the results of the commands (summaries for example) and not the commands itself, witch it's really uncomfortable because it's harder to find out to witch command that results come from. 2. Saving objects in a .Rdata step by step. I want to save several regressions of interest in one .Rdata file. I want to save this results one by one. For example: make regression 1, save the result in the .Rdata file; then make the regression 2 and save the results in the same .Rdata file. I know I could make all the regressions and save the results all at once but for the kind of study I want to make It would be much useful this way. I've been using function save() but I only could save one result or all. As far as I can understand, you are running the commands from the command line, right ? I did this at the very beginning, but then I realize that are better way of dealing with R, that is let R do the calculations and other software do the editing of the scripts, saving data, code and so on. Consider the use of emacs + ESS + R. http://ess.r-project.org/ This will complicate things a little more, (A LOT !) but you will not regret the time spent in learning. Emacs will be useful in MANY other ways. -- Ottorino-Luca Pantani, Università di Firenze Dip. Scienza del Suolo e Nutrizione della Pianta P.zle Cascine 28 50144 Firenze Italia Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 olpant...@unifi.it http://www4.unifi.it/dssnp/ __ 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] Heckman probit ?
Is there a function to fit heckman probit model in R ? Sincerly.. Justin BEM BP 1917 Yaoundé Tél (237) 76043774 [[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] nested, repeated measure lme
Dear all, Suppose I have a nested, repeated measure lme model. Which of the following formulae is correct? (assuming data are sampled from several plots in an agricultural experiment) (1) y~explanatory.variables,random=~time|block/plot/subplot/individual (2) y~explanatory.variables,random=~time|unique.ID.of.every.individual I have read that (2) is the only approach that works. But how could I then still include the nesting information from (1)? Many thanks for your help! Best wishes Christoph (using R 2.9.0 and the nlme library on Windows XP) -- Dr. rer.nat. Christoph Scherber University of Goettingen DNPW, Agroecology Waldweg 26 D-37073 Goettingen Germany phone +49 (0)551 39 8807 fax +49 (0)551 39 8806 Homepage http://www.gwdg.de/~cscherb1 __ 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] nested, repeated measure lme
Dear Christoph, Why should (1) not work? As long as you have enough levels, it should not be a problem. You need at least 6 levels for each random effect. When you have less than six levels, then you better move those variables to the fixed effects. An example: 2 blocks with each 2 plots. Each plot has 2 subplots. A subplot contains 8 individuals. In this case you have 2 blocks, 4 plots, 8 subplots and 64 individuals. So the model will look like: y~explanatory.variables + block/plot, random=~time|subplot/individual Another example: 6 blocks with each 2 plots. Each plot has 2 subplots. A subplot contains 3 individuals. In this case you have 6 blocks, 12 plots, 24 subplots and 72 individuals. So the model will look like: y~explanatory.variables, random=~time|block/plot/subplot/individual HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Christoph Scherber Verzonden: donderdag 20 augustus 2009 11:33 Aan: r-h...@stat.math.ethz.ch Onderwerp: [R] nested, repeated measure lme Dear all, Suppose I have a nested, repeated measure lme model. Which of the following formulae is correct? (assuming data are sampled from several plots in an agricultural experiment) (1) y~explanatory.variables,random=~time|block/plot/subplot/individual (2) y~explanatory.variables,random=~time|unique.ID.of.every.individual I have read that (2) is the only approach that works. But how could I then still include the nesting information from (1)? Many thanks for your help! Best wishes Christoph (using R 2.9.0 and the nlme library on Windows XP) -- Dr. rer.nat. Christoph Scherber University of Goettingen DNPW, Agroecology Waldweg 26 D-37073 Goettingen Germany phone +49 (0)551 39 8807 fax +49 (0)551 39 8806 Homepage http://www.gwdg.de/~cscherb1 __ 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. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ 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] globally set digits=3 in Sweave
Dear all I would like to globally set options(digits = 4) in an Sweave document. I've read this thread [1] where it was suggested to set the above option and pass every printed number through format(). Aanother way to do so would be to round(expr, 4). However I would like to set the digits option once per document so that every number printed respects it, without the need to pass every time through a formatting/rounding function. Is this possible in Sweave? Thank you Liviu [1] https://stat.ethz.ch/pipermail/r-help/2003-September/039481.html -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] getting R 2.9.1 from the tar.gz file
Lazarus Mramba wrote: Dear Sir, I am almost giving up on getting the R-2.9.1 on the ubuntu 9.04 using the instructions found on the R site. I decided to use the R-2.9.1.tar.gz and untarred it. I then typed ./configure and the results are shown below. However, on typing make, I got an error, No targets specified and no makefile found stop What is the solution? lmra...@lmramba-dll-d:~$ su Password: r...@lmramba-dll-d:/home/lmramba# ./configure bash: ./configure: No such file or directory r...@lmramba-dll-d:/home/lmramba# cd R/R-2.9.1 r...@lmramba-dll-d:/home/lmramba/R/R-2.9.1# ./configure checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu loading site script './config.site' loading build specific script './config.site' checking for pwd... /bin/pwd [...] checking for ICU... no checking for X... no configure: error: --with-x=yes (default) and X11 headers/libs are not available Which tells you that you need the X11 headers and libs installed on your system (that are currently missing). Uwe Ligges r...@lmramba-dll-d:/home/lmramba/R/R-2.9.1# make make: *** No targets specified and no makefile found. Stop. Kind regards, Lazarus Mramba Junior Statistician P.O Box 986, 80108, Kilifi, Kenya Mobile No. +254721292370 Tel: +254 41 522063 Tel: +254 41 522390 (office extension : 419) Jakson Alves de Aquino jaksonaqu...@gmail.com 08/20/09 4:05 AM Lazarus Mramba wrote: I have been running R-2.9.1 on Windows without any problem. I decided to run it on my Ubuntu 9.04 where i have R-2.8.1 and I have a problem loading the package JGR because it cannot load the dependancy rJava. This is a cool editor I would wish to use while on Ubuntu. Here is a copy of the errors i get: library(JGR) Loading required package: rJava Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/usr/local/lib/R/site-library/rJava/libs/rJava.so': libjvm.so: cannot open shared object file: No such file or directory Error : .onLoad failed in 'loadNamespace' for 'rJava' Error: package 'rJava' could not be loaded This means I managed to download the rJava package '/usr/local/lib/R/site-library/rJava/libs/rJava.so': libjvm.so ... but It cannot be loaded. What do I do? After solving problem 2, open a terminal and do: sudo aptitude -y install r-base-core r-base-dev sun-java6-jdk sudo R CMD javareconf sudo R Then, in R, type: install.packages(c('JGR', 'iplots', 'rJava', JavaGD'), repos='http://www.vps.fmvz.usp.br/CRAN') library(JGR) JGR() quit(save = 'no') Problem 2: I have tried in vain to get the newer R version of 2.9.1. I keep on getting the 2.8.1. I have read the instructions from the R site but I seem not to be there. What do I do? To install R 2.9.1 in Ubuntu go to http://www.r-project.org/ on the left panel, click on CRAN Choose a mirror Click on: Linux linux ubuntu Follow the instructions. You must be able to follow the instructions because you'll have to disable the repository before upgrading Ubuntu and, then, will have to update the R's repository. This e-mail (including any attachment to it) contains information which is confidential. It is intended only for the use of the named recipient. If you have received this e-mail in error, please let us know by replying to the sender, and immediately delete it from your system. Please note, that in these circumstances, the use, disclosure, distribution or copying of this information is strictly prohibited. We apologize for any inconvenience that may have been caused to you. KEMRI-Wellcome Trust Programmecannot accept any responsibility for the accuracy or completeness of this message as it has been transmitted over a public network. KEMRI-Wellcome Trust Programme reserves the right to monitor all incoming and outgoing email traffic. Although the Programme has taken reasonable precautions to ensure no viruses are present in emails, it cannot accept responsibility for any loss or damage arising from the use of the email or attachments. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of KEMRI- Wellcome Trust Programme. __ 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] Sobol Sensitivity Analysis: Loop Problem
Dear list, I would like to calculate Sobol indices (first-order and total indices) with the sobol2002 function in the 'sensitivity' package for a hydrologic model. The input of my model consists of a parameter vector, the output of a single value (agreement between observed and simulated stream flow). I cannot run my model for a parameter matrix (each line = parameter vector); therefore, I need a loop over lines. However, sobol2002 does not seem to work for loops (see simplified code below). #parameter dataframes library(sensitivity) n - 10 X1 - data.frame(matrix(runif(2 * n), nrow = n)) X2 - data.frame(matrix(runif(2 * n), nrow = n)) #Function without loop FUN1 - function(X) { OUT - X[,1] OUT } x_FUN1 - sobol2002(model = FUN1, X1 = X1, X2 = X2, nboot = 100) ##works! #Function with loop FUN2 - function(X) { OUT - rep(NA, n) for (i in 1:n) {OUT[i] - X[i,1]} OUT } x_FUN2 - sobol2002(model = FUN2, X1 = X1, X2 = X2, nboot = 100) ##fails! I am grateful for any hints, how I can use sobol2002 for a model based on a parameter vectors! Regards, Haeru [[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] lattice xyplot strip colors and location
Hi Shankar On a slightly different note - below produces a strip to the left without the stacked strips require(latticeExtra) # NB install if not found useOuterStrips(strip=strip.custom(bg=skyblue), strip.left=strip.custom(bg=yellow), xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab=Min number of reads, ylab=Number of misjoins ) ) HTH Duncan Mackay Department of Agronomy and Soil Science Univeristy of New England ARMIDALE NSW 2351 Email: home : mac...@northnet.com.au At 12:23 20/08/2009, you wrote: Hi all, I've been trying (unsuccessfully) to modify an xyplot I created using the lattice package. I would like to change default strip colors and locations. I started with numeric data in 4 columns, which look like this: 0.252 1 32 0.252 2 30 0.252 3 27 0.252 4 23 0.252 5 17 0.253 1 30 0.253 2 29 0.253 3 26 0.253 4 21 0.253 5 15 0.5 2 1 23 0.5 2 2 23 0.5 2 3 22 0.5 2 4 18 0.5 2 5 15 0.5 3 1 22 0.5 3 2 22 0.5 3 3 21 0.5 3 4 16 0.5 3 5 13 Here's what I've done so far: library(lattice) plotdata - read.table(file=data.txt, header=FALSE) attach(plotdata) frac.f - factor(V1) stdev.f - factor(V2) levels(frac.f) - paste(f=,levels(frac.f), sep=) levels(stdev.f) - paste(s=, levels(stdev.f), sep=) xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab=Reads as evidence, ylab=Total incorrect) detach(plotdata) Conditional variable values now appear as two stacked strips at the top of each panel. I'd like to move one to the left and also change strip colors. I tried the following but it didn't produce the desired result xyplot(V4~V3|frac.f*stdev.f, aspect=3/4, xlab=Min number of reads, ylab=Number of misjoins, strip=strip.custom(which.given=1, bg=skyblue), strip.left=strip.custom(which.given=2,bg=yellow)) This changes the colors but also does the following - positions the left strips slightly away from the respective panels - all strip labels and values reflect only one conditional variable (s=2, s=3, etc.) Any help would be much appreciated Thanks, Shankar Postdoctoral Fellow National Human Genome Research Institute NIH Bethesda, MD __ 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] getting R 2.9.1 from the tar.gz file
Dear Sir, I am almost giving up on getting the R-2.9.1 on the ubuntu 9.04 using the instructions found on the R site. I decided to use the R-2.9.1.tar.gz and untarred it. I then typed ./configure and the results are shown below. However, on typing make, I got an error, No targets specified and no makefile found stop What is the solution? lmra...@lmramba-dll-d:~$ su Password: r...@lmramba-dll-d:/home/lmramba# ./configure bash: ./configure: No such file or directory r...@lmramba-dll-d:/home/lmramba# cd R/R-2.9.1 r...@lmramba-dll-d:/home/lmramba/R/R-2.9.1# ./configure checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu loading site script './config.site' loading build specific script './config.site' checking for pwd... /bin/pwd checking whether builddir is srcdir... yes checking for working aclocal... missing checking for working autoconf... missing checking for working automake... missing checking for working autoheader... missing checking for gawk... no checking for mawk... mawk checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking whether ln -s works... yes checking for bison... no checking for byacc... no checking for ar... ar checking for a BSD-compatible install... /usr/bin/install -c checking for sed... /bin/sed checking for less... /usr/bin/less checking for perl... /usr/bin/perl checking whether perl version is at least 5.8.0... yes checking for dvips... no checking for tex... no configure: WARNING: you cannot build DVI versions of the R manuals checking for latex... no configure: WARNING: you cannot build DVI versions of all the help pages checking for makeindex... no checking for pdftex... no configure: WARNING: you cannot build PDF versions of the R manuals checking for pdflatex... no configure: WARNING: you cannot build PDF versions of all the help pages checking for makeinfo... no configure: WARNING: you cannot build info or HTML versions of the R manuals checking for texi2dvi... no checking for unzip... /usr/bin/unzip checking for zip... /usr/bin/zip checking for gzip... /bin/gzip checking for firefox... /usr/bin/firefox using default browser ... /usr/bin/firefox checking for acroread... no checking for acroread4... no checking for evince... /usr/bin/evince checking for pkg-config... /usr/bin/pkg-config checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking whether gcc needs -traditional... no checking how to run the C preprocessor... gcc -E checking for gfortran... gfortran checking whether we are using the GNU Fortran 77 compiler... yes checking whether gfortran accepts -g... yes checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking how to run the C++ preprocessor... g++ -E checking whether __attribute__((visibility())) is supported... yes checking whether gcc accepts -fvisibility... yes checking whether gfortran accepts -fvisibility... yes checking for gcc... gcc checking whether we are using the GNU Objective C compiler... no checking whether gcc accepts -g... no checking for Objective C++ compiler... trying some possibilities checking whether g++ can compile ObjC++... no checking whether can compile ObjC++... no no working compiler found checking for a sed that does not truncate output... (cached) /bin/sed checking for fgrep... /bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking the maximum length of command line arguments... 1572864 checking whether the shell understands some XSI constructs... yes checking whether the shell understands +=... yes checking for /usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking whether we are using the GNU C++ compiler... (cached) yes checking whether g++ accepts -g... (cached) yes checking how to run the C++ preprocessor... g++ -E
Re: [R] ggsave to .png bug in ggplot2 (?)
ONKELINX, Thierry wrote: My workaround is to always save my plots to pdf. .. In that case I convert the pdf to png outside R. The best tools I found for that are Ghostfriend (http://www.noliturbare.com/index.php) and www.zamzar.com. Which is also my approach, but not using ggsave or similar as a go-between. Dieter -- View this message in context: http://www.nabble.com/ggsave-to-.png-bug-in-ggplot2-%28-%29-tp25055170p25059682.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] mild and extreme outliers in boxplot
Hi Ottorino, Nevermind. I'm not in a position to require answers. As I said, I appreciate any help and that people would spend time reading my post. I didn't intend to elicit debates over my post, but again I thank all for offering help. I need some time to digest the information before making further posts. best wishes to all, jimmy Dr. Ottorino-Luca Pantani wrote: Hi Jimmy, please be reassured that I did not intend to offend you nor any other in the list. Rnewbie ha scritto: I read the boxplot() help file and googled before making the post, and with my little knowledge on R I was not able to plot in the way I wanted. If I'm allowed, this was not evident from your post. Probably due to its conciseness, I thought it was in the style I have a problem, I do not want to study to solve it, need someone to do it for me I realize now it was not the case. I apologize for this. Ottorino That’s why I made the post. Whether I can eventually solve the problem or not, I appreciate very much any help. I’m a very beginner of R, and found the R help forum a couple of weeks ago. Since I thought I’m not among the major players of the forum and that the post per se rather than poster is of concern like in any other public online forum, I just registered with an arbitrarily chosen ID and kept using it. I’m not making use of R help for any commercial purposes whatsoever. I’m a master’s student working on my thesis. Thanks all for your help. Jimmy __ 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. -- View this message in context: http://www.nabble.com/mild-and-extreme-outliers-in-boxplot-tp25040545p25058523.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] Embedding lists in matrices and matrices in lists
Thanks, I was already told this solution by somebody (he just forgot to add the mailing list as CC). Well, the purpose of the whole thing is to get something like this: http://home.att.net/~numericana/data/polycount.htm where the numbers in the table cells give the number of matrices saved in the corresponding cell. The program looks like this now: http://paste.ubuntuusers.de/396117/ It even runs (though errors occur if I add th process r into the main loop, but I'm still not done with it...). Petr PIKAL schrieb: Hi No. It is the problem of scoping. AFAIK functions create their own environment and everything what is assigned inside the function does not affect outside objects unless you use - assignment operator. i-100 ff-function(x) i-x ff(10) i [1] 100 fff-function(x) i-x fff(200) i [1] 200 However I would distract you from this practice. Personally I used such assignment only when I started with S/R about 10 years ago. Why do you want a database to be a matrix? It seems to be that list structure is in that case more flexible and there are *apply functions for manipulation with lists. E.g. structure lm(...) results in list and summary(lm(...)) is again a list with quite complicated structure. If I understand it correctly, during your computation you will have as a result matrices with arbitrary dimensions. I would make a list lll-vector(list, 1) and in simple loop for (i in 1:n) { do any computation here together with sophisticated and complicated functions and assign results to your list lll[[1]] - result of functions which itself can have quite complicated structure } If you want nested list just add another cycle and use lll[[i]][[j]] -some other result. With choosing appropriate structure of your date you can save yourself much problems. Regards Petr __ 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] mild and extreme outliers in boxplot
On Thu, Aug 20, 2009 at 3:23 AM, Gavin Simpsongavin.simp...@ucl.ac.uk wrote: Hi Rolf, On Thu, 2009-08-20 at 12:31 +1200, Rolf Turner wrote: I despair. Why do you keep insisting that black is white? The OP wanted to be able to specify an argument to boxplot() that would cause it to plot mild and extreme outliers with different symbols. Then you and I were reading different emails Rolf. I quote: [Sorry I don't have the original email, so this from Gmane: http://article.gmane.org/gmane.comp.lang.r.general/159957 ] dear all, could somebody tell me how I can plot mild outliers as a circle(°) and extreme outliers as an asterisk(*) in a box-whisker plot? Thanks very much in advance The OP wants to use a different pch for the points that are plotted at the extremes of the distribution of points. It is up to him, as I pointed out, to define what extreme means in this context... THIS CAN'T BE DONE!!! ...but the plotting he wanted to do, can be done! I showed one way it could be done. Why do you insist he can't do what he wants? I think what he means is that outpch can only supply one symbol per boxplot so to get the result you need to superimpose the points on the boxplot using points() as in my post. If you supply a vector to outpch then successive values are used for successive boxplots, not for successive outliers in the same boxplot. __ 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] Insert rows in between dataframes
Hi all, Can anyone suggest me how to insert rows in between data frames and also keep the ordering of row numbers correct? Estimate Std. Errort value Pr(|t|) recmeanC2 9.275880e-176.322780e-17 1.467057e+00 0.14349903 recmeanC3 1.283534e-17 2.080644e-176.168929e-01 0.53781390 recmeanC4 - 3.079466e-172.565499e-17 -1.200338e+00 0.23103743 i15.00e-01 1.036197e-17 4.825338e+16 0. i2 -5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282 i3 4.291387e-18 1.207522e-17 3.553879e-01 0.72257050 i4 1.472662e-17 1.423051e-17 1.034863e+00 0.30163897 i5 5.00e-011.003323e-17 4.983441e+16 0. i6 5.147966e-18 1.569095e-17 3.280850e-01 0.74309614 i7 1.096044e-17 1.555829e-17 7.044760e-01 0.48173041 i8-1.166290e-181.287370e-17 -9.059482e-02 0.92788026 i9 1.627371e-17 1.540567e-17 1.056345e+00 0.29173427 i104.001692e-18 1.365740e-17 2.930053e-01 0.76973827 i12-1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000 i132.571236e-17 1.357336e-17 1.894325e+00 0.05922715 This is my coeffcients table.Here I want ti inser t rows with value NA in all columns in between and after the last row.After last row I can insert using rbind.But how will I enter row in between so that the order also doesnt change. I need this to be generated :--- Estimate Std. Errort value Pr(|t|) recmeanC2 9.275880e-176.322780e-17 1.467057e+00 0.14349903 recmeanC3 1.283534e-17 2.080644e-176.168929e-01 0.53781390 recmeanC4 - 3.079466e-172.565499e-17 -1.200338e+00 0.23103743 i15.00e-01 1.036197e-17 4.825338e+16 0. i2 -5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282 i3 4.291387e-18 1.207522e-17 3.553879e-01 0.72257050 i4 1.472662e-17 1.423051e-17 1.034863e+00 0.30163897 i5 5.00e-011.003323e-17 4.983441e+16 0. i6 5.147966e-18 1.569095e-17 3.280850e-01 0.74309614 i7 1.096044e-17 1.555829e-17 7.044760e-01 0.48173041 i8-1.166290e-181.287370e-17 -9.059482e-02 0.92788026 i9 1.627371e-17 1.540567e-17 1.056345e+00 0.29173427 i104.001692e-18 1.365740e-17 2.930053e-01 0.76973827 i11NA NA NA NA i12-1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000 i132.571236e-17 1.357336e-17 1.894325e+00 0.05922715 i14 NA NA NA NA i15 NA NA NA NA rbind after row number i10 will change row number i12 to have NA,Na,NA.Na values. -- Thanks in advance Moumita [[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] function of probability for normal distribution
Dear all, Because my last email was in html format, so it was a disaster to read. I have second thought of my question asked in my last email, and came up some solution to myself, but I found the result was a bit weird, can someone please help look at my coding and advise where I have done wrong? I need to write a function which compute the probability for standard normal distribution. The formula is P(z)= 1/2 + 1/(sqrt(2*pi)) * sum ((-1)^k*z^(2*k+1) /(2^k*k!*(2*k+1)) From series expansion for the exponential function, we know e^x= sum (x^n/n!), we can substitute x = -t^2/2, so e^(-t^2/2) = sum ((-1)^k*t^(2*k)/(2^k*k!)). Comparing with the formula above, the sum ((-1)^k*z^(2*k+1) /(2^k*k!*(2*k+1)) is very similar to e^(-t^2/2), except there is z/(2*k+1) in the formula. So I create a function for the sum ((-1)^k*z^(2*k+1) /(2^k*k!*(2*k+1)), which is expf = function (t) { neg=(t0) t = ifelse(neg,-t,t) k=0;term=1;sum=1 oldsum=0 while(any(sum!=oldsum)){ oldsum = sum k = k+1 term = term*(((-1)^1*t^2) / (2*k)) sum = sum + (t/(2*k+1))*term } ifelse(neg,1/sum,sum) } Now the sum part of the probability can be replaced by expf function, then I create the function for the probability p(z), which is prob = function(z) { 1/2+(1/sqrt(2*pi))*expf(z) } Am I doing the right thing here? However, when I test the probability function, e.g. prob(1:10), the result appear some negative value and some very large value which do not seem right to me as probability values. Can someone please guide me where I have done wrong here? Thanks a lot. Rene. __ 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] Fw: Hist kernel density estimates
Dear All, Here are the codes of a histogram a kernel density estimates that I used. For the hist estimate par(mex=1.3) dens-density(q) options(scipen=4) ylim-range(dens$y) h-hist(q,breaks=scott,freq=FALSE,probability=TRUE, + right=FALSE,xlim=c(9000,16000),ylim=ylim,main=Histogram of q(scott)) lines(dens) box() For the kernel estimateoptions(scipen=4) d - density(q, bw = nrd0,kernel=gaussian) d plot(d) In fact the variable q is a vector of 1000 simulated positive values; that is I generated 1000 samples from the pareto distribution, from each sample I calculated the value of q ( a certain fn in the sample observations), and thus I was left with 1000 values of q and I don't know the distribution of q. Hence, I used the above codes for histogram and kernel density estimation to estimate the density of q. But what I'm really intersed in is to estimate the probability that q is greater than a certain value , for ex.,P(q11000), using the density estimates I obtained. Could u help me with a fn or some document to do this? Thank u so much Maram [[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] expanding 1:12 months to Jan:Dec
month.abb [1] Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec # or random month.abb[sample(1:12)] [1] Jan Apr Sep Mar Nov May Aug Oct Dec Jul Jun Feb On Thu, Aug 20, 2009 at 3:14 AM, Liviu Androniclandronim...@gmail.com wrote: Dear R users I would like to do some spreadsheet style expansion of dates. For example, I would need to obtain a vector of months. I approached in an obviously wrong way: paste(01:12) [1] 1 2 3 4 5 6 7 8 9 10 11 12 as.Date(paste(01:12), %m) [1] NA NA NA NA NA NA NA NA NA NA NA NA to subsequently format(.., %b). Other than writing the months manually, could anyone suggest an easier way to obtain such a list? Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] eval and evironments: call local function in a global function
I am not sure what the purpose of workspace is so I have eliminated it in the following. We just use the environment within main and when main exits all its variables go too so that seems sufficient. fun.global - function() { message('fun.global'); setVar(5) } main - function() { l.var - 0 setVar - function(value) { message(set Var); l.var - value } environment(fun.global) - environment() fun.global() print(l.var) } main() We could also recognize that there is an implicit object here with methods setVar and fun.global and property l.var so using proto: library(proto) fun.global - function(obj) { message(setVar); obj$setVar(5) } main - function() { p - proto(l.var = 0, setVar = function(obj, value) { message(setVar); obj$l.var - value }, fun.global = fun.global) p$fun.global() print(p$l.var) } main() On Thu, Aug 20, 2009 at 4:27 AM, Renaud Gaujouxgeto...@gmail.com wrote: Hi, in my project I want the user to be able to write hook functions that are in turn called in my main code. I'd like the user's hooks to be able to call some function that set a variable outside their running environment. The trick is that this variable is not global, but defined on runtime before calling the hooks, and I don't want to leave any trace (i.e. global variables) after the main code has finished. I thought that the following would work but it doesn't. I guess I got too messy with environment and enclosures: # global function defined by the user fun.global - function(){ message('fun.global') setVar(5) # } # my main code main - function(){ message('main') # define a function to set some local variable setVar - local({ l.var - 0 function(value){ message('setVar') l.var - value } }) .workspace - environment(setVar) environment(setVar) - new.env() eval(fun.global(), enclos=environment(setVar)) print(get('l.var', envir=.workspace, inherits=FALSE)) } main() I get the following output: main fun.global Error in fun.global() : could not find function setVar There is definitely a problem of lookup somewhere. I first tried without eval, as I thought that function setVar would then be defined in a parent environment of the call to fun.global, but it does not work either. Can anybody tell me what's the problem and how I should do my stuff? Thanks, Renaud __ 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] expanding 1:12 months to Jan:Dec
month.abb month.name On Thu, Aug 20, 2009 at 3:14 AM, Liviu Androniclandronim...@gmail.com wrote: Dear R users I would like to do some spreadsheet style expansion of dates. For example, I would need to obtain a vector of months. I approached in an obviously wrong way: paste(01:12) [1] 1 2 3 4 5 6 7 8 9 10 11 12 as.Date(paste(01:12), %m) [1] NA NA NA NA NA NA NA NA NA NA NA NA to subsequently format(.., %b). Other than writing the months manually, could anyone suggest an easier way to obtain such a list? Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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 a list of combinations
Dear R Users, I have 120 objects stored in R's memory and I want to pass the names of these many objects to be held as just one single object. The naming convention is month, year in sequence for all months between January 1986 to December 1995 (e.g. Jan86, Feb86, Mar86... through to Dec95). I hope to pass all these names (and their data I guess) to an object called file_list, however, I'm experiencing some problems whereby only the first (and possibly last) names seem to make the list, with the remainder recorded as 'NA' values. Here is my code as it stands: index - expand.grid(month=month.abb, year=seq(from=86,to=95, by=1)) for (i in seq(nrow(index))) { file_list - paste(index$month[i], index$year[i], sep='') print(file_list[i]) } Output is as follows: [1] Jan86 [1] NA [1] NA [1] NA #[continues to row 120 as NA] file_list; file_list[i] [1] Dec95 [1] NA head(index) # this seems to be working fine month year 1 Jan 86 2 Feb 86 3 Mar 86 4 Apr 86 5 May 86 6 Jun 86 Any help on how I can populate file_list correctly with all 120 combinations of month + year (without NAs!) would be gratefully received. Thanks, Steve _ icons. __ 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] Several simple but hard tasks to do with R
Rakknar wrote: Hello everybody. I've been learning R for about a month to do a econometric study and now i'm stuck with some problems to make R do the things I want. Here I give the list of things I wanna do from the most simple to the more complex (for me of course): 1. Make a log. I've been using Stata and there i have a great tool to register what the program do: the log file, wich it's a simple .txt file where Stata writes every output it makes (not graphics of course). When I wanted to make the same thing with R I started to use the function sink() but it only register the results of the commands (summaries for example) and not the commands itself, witch it's really uncomfortable because it's harder to find out to witch command that results come from. Hi Rakknar, To echo what others have said, it is often easier to write a script (in STATA terms, a do file) of commands and then source the script. When it runs to your satisfaction, usually not the first time for me, there are several ways to store the output. Both the R2HTML and prettyR packages contain methods to store output as HTML files. You can store both the commands and output in the same file. 2. Saving objects in a .Rdata step by step. I want to save several regressions of interest in one .Rdata file. I want to save this results one by one. For example: make regression 1, save the result in the .Rdata file; then make the regression 2 and save the results in the same .Rdata file. I know I could make all the regressions and save the results all at once but for the kind of study I want to make It would be much useful this way. I've been using function save() but I only could save one result or all. You can save one object at a time if you want, and do it during a script. I usually save the primary data object after I have translated it from whatever format it came to me. You can save subsets of the data as different files and simply use load to read in the data you want. load can also signal if the data is not there, albeit in a fairly messy way. 3. Conditional reading. I want to run regressions conditional to the existence of a .Rdata file (the one I would be making in step two). The condition would be something like If you find X.Rdata file run regression with X.Rdata data else run regression from the 0. I hope I can find help here. 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] Creating a list of combinations
the short answer is to add [[i]] in your loop, file_list[[i]] - paste(index$month[i], index$year[i], sep='') yet a shorter answer would be, file_list = apply(index, 1, paste, collapse=) HTH, baptiste 2009/8/20 Steve Murray smurray...@hotmail.com: Dear R Users, I have 120 objects stored in R's memory and I want to pass the names of these many objects to be held as just one single object. The naming convention is month, year in sequence for all months between January 1986 to December 1995 (e.g. Jan86, Feb86, Mar86... through to Dec95). I hope to pass all these names (and their data I guess) to an object called file_list, however, I'm experiencing some problems whereby only the first (and possibly last) names seem to make the list, with the remainder recorded as 'NA' values. Here is my code as it stands: index - expand.grid(month=month.abb, year=seq(from=86,to=95, by=1)) for (i in seq(nrow(index))) { file_list - paste(index$month[i], index$year[i], sep='') print(file_list[i]) } Output is as follows: [1] Jan86 [1] NA [1] NA [1] NA #[continues to row 120 as NA] file_list; file_list[i] [1] Dec95 [1] NA head(index) # this seems to be working fine month year 1 Jan 86 2 Feb 86 3 Mar 86 4 Apr 86 5 May 86 6 Jun 86 Any help on how I can populate file_list correctly with all 120 combinations of month + year (without NAs!) would be gratefully received. Thanks, Steve _ icons. __ 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. -- _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK http://newton.ex.ac.uk/research/emag __ 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] change default measurement unit to millimetre
e-letter wrote: Readers, How do I configure R so that all units of measurement are in millimetres? For example if I want to set the width of a graph, I want to write: width=100 and R interprets this value as millimetres. Hi e-letter, If you just want a quick hack: mm2in-function(mm) return(mm/25.4) then width=mm2in(100) 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] PowerCut Killed R - is my code retrievable?
Also - is there a better way for the future? I know some people use IDE's but is that for serious programming or for building a small function and tweaking it? What about a version control system to (locally) save the different stages of your script files? (I use git but Subversion (SVN) may be easier and do the job). Cheers, Hans-Peter __ 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] ANCOVA with defined error terms
Thanks Richard, I tried running the analysis the way you suggested but here is the error that I get track.aov - aov(mice ~ coon+block*veget*fruit*time - block:veget:fruit:time + + Error(block/plot), data = track) Warning message: In aov(kotz.mice ~ kotz.coon + block * veget * fruit * time - block:veget:fruit:time + : Error() model is singular anova(track.aov) Error in UseMethod(anova) : no applicable method for anova I'm not sure you can use the function anova for an aov object. I tried summary and it also didn't work. Did you mean something else? Thanks Richard M. Heiberger wrote: track.aov - aov(mice ~ coon + block*veget*fruit*time - block:veget:fruit:time + Error(block/plot), data = track) anova(track.aov) I think this is what you are looking for. This model in words says, What is the effect of the four-way crossing after adjusting for the covariate coon? We don't have enough degrees of freedom for the full crossing, so remove the four-way interaction. anova() gives the sequential sums of squares of (multi-degree of freedom) effects. Be sure that the five variables (block, veget, fruit, time, plot) are factors. I am assuming time is a factor here. __ 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. -- View this message in context: http://www.nabble.com/ANCOVA-with-defined-error-terms-tp25055311p25061223.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] print selected variables
Hi there, what you means by complete data. Read the posting guide, where it is suggested a minimum reproducible code, as well as good clarification about what you have/get and what you realy want to get. bests milton On Thu, Aug 20, 2009 at 3:38 AM, rajclinasia r...@clinasia.com wrote: Hi every one, I read one excel external file into R, in that R dataset i have 20 variables. now my querry is i want to print only selected variables (eg:10 variables) with complete data. pls send me the code it will be very helpful for us. Thanks in Advance. -- View this message in context: http://www.nabble.com/print-selected-variables-tp25057378p25057378.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.htmlhttp://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] eval and evironments: call local function in a global function
Hi Gabor, thanks. Indeed I reckon implementing it using an object would be better, but I wanted to keep it as simple as possible for the end user, by hiding the object mechanism. The user would not have to define its function with an extra parameter, maybe obscure to him. My problem now is that the solution you proposed with the environment does not work if the user defined function actually calls function setVar from another function, that I can't know about. Say if function fun.global is as follows: fun.global2 - function(){ message('fun.global2') setVar(4) } fun.global - function(){ message('fun.global') fun.global2() } What I thought is that once set running environment as you proposed, the following function calls would all inherit from it. I guess I'm wrong. It looks very strange to me, as in other interpreted languages there would not be any problem with such calls. Do you know exactly how do the environments work? I might end up using the object solution to make it clean. Thanks Gabor Grothendieck wrote: I am not sure what the purpose of workspace is so I have eliminated it in the following. We just use the environment within main and when main exits all its variables go too so that seems sufficient. fun.global - function() { message('fun.global'); setVar(5) } main - function() { l.var - 0 setVar - function(value) { message(set Var); l.var - value } environment(fun.global) - environment() fun.global() print(l.var) } main() We could also recognize that there is an implicit object here with methods setVar and fun.global and property l.var so using proto: library(proto) fun.global - function(obj) { message(setVar); obj$setVar(5) } main - function() { p - proto(l.var = 0, setVar = function(obj, value) { message(setVar); obj$l.var - value }, fun.global = fun.global) p$fun.global() print(p$l.var) } main() On Thu, Aug 20, 2009 at 4:27 AM, Renaud Gaujouxgeto...@gmail.com wrote: Hi, in my project I want the user to be able to write hook functions that are in turn called in my main code. I'd like the user's hooks to be able to call some function that set a variable outside their running environment. The trick is that this variable is not global, but defined on runtime before calling the hooks, and I don't want to leave any trace (i.e. global variables) after the main code has finished. I thought that the following would work but it doesn't. I guess I got too messy with environment and enclosures: # global function defined by the user fun.global - function(){ message('fun.global') setVar(5) # } # my main code main - function(){ message('main') # define a function to set some local variable setVar - local({ l.var - 0 function(value){ message('setVar') l.var - value } }) .workspace - environment(setVar) environment(setVar) - new.env() eval(fun.global(), enclos=environment(setVar)) print(get('l.var', envir=.workspace, inherits=FALSE)) } main() I get the following output: main fun.global Error in fun.global() : could not find function setVar There is definitely a problem of lookup somewhere. I first tried without eval, as I thought that function setVar would then be defined in a parent environment of the call to fun.global, but it does not work either. Can anybody tell me what's the problem and how I should do my stuff? Thanks, Renaud __ 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] how to categorize continuous variable when useing regression
Manli Yan wrote: assume dependent variable y( continuous),independent variable x ( continuous),I try to categorize x with some interval,such that,those intervals would has most significant different effect on y. any one knows which method I should apply,I really need some hints,thanks so much~ This is a dangerous practice. Unless you have mastered the bootstrap so that you can accurately estimate the damage to the statistical significance caused by such categorization, it is best to avoid this altogether. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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] what is the meaning of this error
Error in Math.factor(c(2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, : log not meaningful for factors In addition:Warning messages: 1: In Ops.factor(LRUpBound, LRLowBound) : * not meaningful for factors 2: In Ops.factor(TransitCoefStdDev, TransitCoefMean) : / not meaningful for factors [[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] how to specify two variance effects in gls
I got the answer: weights=varComb(varFixed(~1/n),varPower(~Age)) Bond, Stephen-2 wrote: Hello everybody, I have a dataset where each row has number of subjects and that gives me natural weights for the variance function. Additionally I see that variance increases with Age, which is a regressor. So using gls I have weights=varFixed(~1/n) but don't know how to include the extra effect of the regressor. Fitted values show a quadratic curve vs. age, not sure if that helps. Thanks everybody. Stephen [[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. -- View this message in context: http://www.nabble.com/how-to-specify-two-variance-effects-in-gls-tp25044356p25061604.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] Error message when performing cointegration and causality tests
Hello, I write this message because I have a problem with cointegration and causality tests on R. I'm working with time series data. I use ucra and vars packages.To perform cointegration and Granger causality tests, I respectively write : sjv - vardata[, c(upd, nc, r, up, op, ur, expl)] sjv.vecm - ca.jo(sjv, type=eigen, K=2, spec = longrun, season =4) summary(sjv.vecm) reg1.caus - VAR(vardata[, c(upd, nc, r, up, op, ur, expl)], p = 2, type = const) causality(reg1.caus, cause = up) In both cases, I respectively obtain the following error messages: Error is solve.default(M11) : the system is numerically singular : conditionnement de la réciproque = 9.47575e-17 and Error is solve.default(crossprod(as.matrix(Z))) : the system is numerically singular : conditionnement de la réciproque = 7.87318e-22 What do these messages mean ? And how can I resolve this problem? I precise that I use quarterly data and that when I try to directly estimate VAR model using the command below I encounter no problem: reg1 - VAR(vardata[, c(upd, nc, r, up, op, ur, expl)], p = 1, type =const) reg1 Thank you in advance for answer. Axel [[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] eval and evironments: call local function in a global function
A function finds its free variables in its environment. Changing the environment of one function does not change the environment of other functions; however, if instead of messing with environments you use the proto solution already posted then that would handle this situation by passing the object from one function to another: fun.global2 - function(obj) { message(fun.global2); obj$setVar(4) } fun.global - function(obj) { message(fun.global); fun.global2(obj) } # insert main from previously posted proto solution here library(proto); main() On Thu, Aug 20, 2009 at 8:48 AM, Renaud Gaujouxren...@cbio.uct.ac.za wrote: Hi Gabor, thanks. Indeed I reckon implementing it using an object would be better, but I wanted to keep it as simple as possible for the end user, by hiding the object mechanism. The user would not have to define its function with an extra parameter, maybe obscure to him. My problem now is that the solution you proposed with the environment does not work if the user defined function actually calls function setVar from another function, that I can't know about. Say if function fun.global is as follows: fun.global2 - function(){ message('fun.global2') setVar(4) } fun.global - function(){ message('fun.global') fun.global2() } What I thought is that once set running environment as you proposed, the following function calls would all inherit from it. I guess I'm wrong. It looks very strange to me, as in other interpreted languages there would not be any problem with such calls. Do you know exactly how do the environments work? I might end up using the object solution to make it clean. Thanks Gabor Grothendieck wrote: I am not sure what the purpose of workspace is so I have eliminated it in the following. We just use the environment within main and when main exits all its variables go too so that seems sufficient. fun.global - function() { message('fun.global'); setVar(5) } main - function() { l.var - 0 setVar - function(value) { message(set Var); l.var - value } environment(fun.global) - environment() fun.global() print(l.var) } main() We could also recognize that there is an implicit object here with methods setVar and fun.global and property l.var so using proto: library(proto) fun.global - function(obj) { message(setVar); obj$setVar(5) } main - function() { p - proto(l.var = 0, setVar = function(obj, value) { message(setVar); obj$l.var - value }, fun.global = fun.global) p$fun.global() print(p$l.var) } main() On Thu, Aug 20, 2009 at 4:27 AM, Renaud Gaujouxgeto...@gmail.com wrote: Hi, in my project I want the user to be able to write hook functions that are in turn called in my main code. I'd like the user's hooks to be able to call some function that set a variable outside their running environment. The trick is that this variable is not global, but defined on runtime before calling the hooks, and I don't want to leave any trace (i.e. global variables) after the main code has finished. I thought that the following would work but it doesn't. I guess I got too messy with environment and enclosures: # global function defined by the user fun.global - function(){ message('fun.global') setVar(5) # } # my main code main - function(){ message('main') # define a function to set some local variable setVar - local({ l.var - 0 function(value){ message('setVar') l.var - value } }) .workspace - environment(setVar) environment(setVar) - new.env() eval(fun.global(), enclos=environment(setVar)) print(get('l.var', envir=.workspace, inherits=FALSE)) } main() I get the following output: main fun.global Error in fun.global() : could not find function setVar There is definitely a problem of lookup somewhere. I first tried without eval, as I thought that function setVar would then be defined in a parent environment of the call to fun.global, but it does not work either. Can anybody tell me what's the problem and how I should do my stuff? Thanks, Renaud __ 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] what is the meaning of this error
On Thu, 2009-08-20 at 12:54 +, Inchallah Yarab wrote: Error in Math.factor(c(2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, : log not meaningful for factors In addition:Warning messages: 1: In Ops.factor(LRUpBound, LRLowBound) : * not meaningful for factors 2: In Ops.factor(TransitCoefStdDev, TransitCoefMean) : / not meaningful for factors Your data are stored in a factor and you can't use the log() function on a factor. I've mentioned this several times to you; just because you think your data are numeric etc doesn't mean the R sees them that way. Always do str(DAT) [where DAT is your data object] after reading your data in to R and check that the stated formats are what you think. If you have numeric data but str() reports them to be factors, see the FAQ for how to correctly undo this conversion. One way is to: DAT$foo - as.numeric(as.character(DAT$foo)) where foo is the factor you wish to convert to numeric. And please () read *and* follow the posting guide before sending emails to this list. We need to know what you did to get the error (the error itself is not always clear without the context) so show us the commands. And to be even more helpful, show us an example with dummy or real data that you give to us so we can run it on our computers. There is no free lunch (well, not often) on R-Help. Help us to help you. HTH G [[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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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] definition of AIC and BIC in gls
Hello everybody, Please help with connecting the AIC and BIC numbers printed by summary.gls to the logLik number. 1. is the logLik number the true ML or density scaling constants have been omitted? 2. what is the formula for calculating the AIC and BIC from logLik (and how can I see it)? I tried printing summary.gls but it says object not found. Thank you very much. Stephen [[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] what is the meaning of this error
On Thu, 20 Aug 2009 12:54:33 + (GMT) Inchallah Yarab inchallahya...@yahoo.fr wrote: IY Error in Math.factor(c(2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, IY 1L, : log not meaningful for factors IY In addition:Warning messages: IY IY 1: In Ops.factor(LRUpBound, LRLowBound) : * not meaningful for IY factors 2: In Ops.factor(TransitCoefStdDev, TransitCoefMean) : IY / not meaningful for factors You are doing something with factors which is not possible. Since you haven't given any code we cannot say much more. Provide a reproductive example and maybe someone is able to help you more... Stefan __ 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] boxplot with log=y and values starting at 0
Hi, I'm working with a data.frame containing values between 0 and 22000. Most of the values are actually between 0 and 50 and the high ones are outliers. I want to generate a boxplot and since the outliers are extremely high, I need to scale the y scale logarithmically. Otherwise one wouldn't really see the boxes of the boxplot. boxplot(dat, log=y, ylim=c(0, max(dat))) Trying the above doesn't work, since the y scale has to be positive. But when I generate the boxplot with ylim=c(1, max(dat)) it doesn't properly generate the whiskers or beginning of the boxes, because some of the mins and first quantiles are 0. Can anybody help and tell me how I can generate a logarithmic y scale starting at 0? Thanks in advance, -- Anne Skoeries [[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] eval and evironments: call local function in a global function
Indeed. So is there no way to do that without passing an object as parameter, which acts as a 'global local' workspace? Isn't there a way to do say: run this function and subsequent calls within this environment? Gabor Grothendieck wrote: A function finds its free variables in its environment. Changing the environment of one function does not change the environment of other functions; however, if instead of messing with environments you use the proto solution already posted then that would handle this situation by passing the object from one function to another: fun.global2 - function(obj) { message(fun.global2); obj$setVar(4) } fun.global - function(obj) { message(fun.global); fun.global2(obj) } # insert main from previously posted proto solution here library(proto); main() On Thu, Aug 20, 2009 at 8:48 AM, Renaud Gaujouxren...@cbio.uct.ac.za wrote: Hi Gabor, thanks. Indeed I reckon implementing it using an object would be better, but I wanted to keep it as simple as possible for the end user, by hiding the object mechanism. The user would not have to define its function with an extra parameter, maybe obscure to him. My problem now is that the solution you proposed with the environment does not work if the user defined function actually calls function setVar from another function, that I can't know about. Say if function fun.global is as follows: fun.global2 - function(){ message('fun.global2') setVar(4) } fun.global - function(){ message('fun.global') fun.global2() } What I thought is that once set running environment as you proposed, the following function calls would all inherit from it. I guess I'm wrong. It looks very strange to me, as in other interpreted languages there would not be any problem with such calls. Do you know exactly how do the environments work? I might end up using the object solution to make it clean. Thanks Gabor Grothendieck wrote: I am not sure what the purpose of workspace is so I have eliminated it in the following. We just use the environment within main and when main exits all its variables go too so that seems sufficient. fun.global - function() { message('fun.global'); setVar(5) } main - function() { l.var - 0 setVar - function(value) { message(set Var); l.var - value } environment(fun.global) - environment() fun.global() print(l.var) } main() We could also recognize that there is an implicit object here with methods setVar and fun.global and property l.var so using proto: library(proto) fun.global - function(obj) { message(setVar); obj$setVar(5) } main - function() { p - proto(l.var = 0, setVar = function(obj, value) { message(setVar); obj$l.var - value }, fun.global = fun.global) p$fun.global() print(p$l.var) } main() On Thu, Aug 20, 2009 at 4:27 AM, Renaud Gaujouxgeto...@gmail.com wrote: Hi, in my project I want the user to be able to write hook functions that are in turn called in my main code. I'd like the user's hooks to be able to call some function that set a variable outside their running environment. The trick is that this variable is not global, but defined on runtime before calling the hooks, and I don't want to leave any trace (i.e. global variables) after the main code has finished. I thought that the following would work but it doesn't. I guess I got too messy with environment and enclosures: # global function defined by the user fun.global - function(){ message('fun.global') setVar(5) # } # my main code main - function(){ message('main') # define a function to set some local variable setVar - local({ l.var - 0 function(value){ message('setVar') l.var - value } }) .workspace - environment(setVar) environment(setVar) - new.env() eval(fun.global(), enclos=environment(setVar)) print(get('l.var', envir=.workspace, inherits=FALSE)) } main() I get the following output: main fun.global Error in fun.global() : could not find function setVar There is definitely a problem of lookup somewhere. I first tried without eval, as I thought that function setVar would then be defined in a parent environment of the call to fun.global, but it does not work either. Can anybody tell me what's the problem and how I should do my stuff? Thanks, Renaud __ 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] boxplot with log=y and values starting at 0
What about starting the data by adding some small amount to the 0's? Perhaps something like mysample - data.frame(aa = sample(c(A,B,C), 20, replace=TRUE), bb = sample(0:9, 20, replace=TRUE)) ifelse(mysample$bb==0,.1, mysample$bb) though you may wish to make .1 much smaller. --- On Thu, 8/20/09, Anne Skoeries h...@anne-skoeries.de wrote: From: Anne Skoeries h...@anne-skoeries.de Subject: [R] boxplot with log=y and values starting at 0 To: r-help@r-project.org Received: Thursday, August 20, 2009, 9:15 AM Hi, I'm working with a data.frame containing values between 0 and 22000. Most of the values are actually between 0 and 50 and the high ones are outliers. I want to generate a boxplot and since the outliers are extremely high, I need to scale the y scale logarithmically. Otherwise one wouldn't really see the boxes of the boxplot. boxplot(dat, log=y, ylim=c(0, max(dat))) Trying the above doesn't work, since the y scale has to be positive. But when I generate the boxplot with ylim=c(1, max(dat)) it doesn't properly generate the whiskers or beginning of the boxes, because some of the mins and first quantiles are 0. Can anybody help and tell me how I can generate a logarithmic y scale starting at 0? Thanks in advance, -- Anne Skoeries [[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. __ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ __ 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] boxplot with log=y and values starting at 0
On 20/08/09 14:15, Anne Skoeries wrote: Hi, I'm working with a data.frame containing values between 0 and 22000. Most of the values are actually between 0 and 50 and the high ones are outliers. I want to generate a boxplot and since the outliers are extremely high, I need to scale the y scale logarithmically. Otherwise one wouldn't really see the boxes of the boxplot. boxplot(dat, log=y, ylim=c(0, max(dat))) Trying the above doesn't work, since the y scale has to be positive. But when I generate the boxplot with ylim=c(1, max(dat)) it doesn't properly generate the whiskers or beginning of the boxes, because some of the mins and first quantiles are 0. Can anybody help and tell me how I can generate a logarithmic y scale starting at 0? I think that is impossible, unless you redefine mathematics and geometry. Sadly R only supports a relatively usual form of mathematics where log(0) is by convention -Inf, and the graphics is basically Euclidean so you can't draw infinities easily. You could try filing a bug report What is min(dat)? If that is zero, then you can't use a log scale. If it is small but positive, then you can use that for your ylim. But your data set is a large range and therefore intrinsically hard to visualize. Consider some other way of presenting the data. What is the reader supposed to learn from / do with the data you show? Hope this helps a little. Allan __ 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] print selected variables
If your data is in a data frame named mydata and you want to print the 3rd, 5th and 10th variables: mydata[ , c(3,5,10) ] -Don At 12:38 AM -0700 8/20/09, rajclinasia wrote: Hi every one, I read one excel external file into R, in that R dataset i have 20 variables. now my querry is i want to print only selected variables (eg:10 variables) with complete data. pls send me the code it will be very helpful for us. Thanks in Advance. -- View this message in context: http://*www.*nabble.com/print-selected-variables-tp25057378p25057378.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. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ 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 read large file
It is a big file which is going to take some time to read. How long probably depends as much on your disks as on R. On my system: system.time( y - scan(file = /tmp/dat.txt, what = integer(0)) ) Read 12 items user system elapsed 197.085 15.164 216.149 This is with a test file containing only the value 0: try that first. Try a faster disk (local, not NFS, for example). Hope this helps a little. Allan. On 20/08/09 08:30, Mohamed Lajnef wrote: Dear Jim Michael the file contains 1000 lines and 1.200.000 columns, txt format and i wish to read all the file with R if possible, or read a few columns? I tried without success to turn bigmemory and colbycol packages, also scan and readLines function but It takes a long time without anything. I have windows X64 bits 8 Go In advance thanks ML jim holtman a écrit : A little more detail would be appropriate. How large is large? What is the format of the file? What do you wnat to do with the data? Do you have to have it all in memory at once? Does it exist in a data base already? What type of system are you running on? How much memory do you have? On Wed, Aug 19, 2009 at 4:51 AM, Mohamed Lajnefmohamed.laj...@inserm.fr wrote: Dear R-Users, I am looking for packages that could read large files in R? any suggestions are welcome. Regards, ML __ 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. [[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] Histogram problem
I'm trying to create a histogram from the following code, but my data keeps adding the Num vector and plotting that. My data in the CSV file is just one vector. Does anyone know why? Thanks Conrad SPXdf = data.frame(read.csv(file = SPX.csv, header = TRUE, sep = ,, dec = ., fill = TRUE)) Max = max(SPXdf[,2]) Min = min(SPXdf[,2]) Count = length(SPXdf[,2]) sig = sd(SPXdf[,2]) BinSize = (3.5*sig)/(Count^(1/3)) BinNum = (Max - Min)/(BinSize) Bins = seq(Min,Max,by = BinSize) Count2 = length(Bins) Num = mat.or.vec(1,Count2) for (i in 1:Count){ for (j in 1:Count2){ if ((SPXdf[i,2] Bins[j])) {Num[j] = Num[j] + 1} } } barplot(Num,Bins, xlab = SPXdf, ylab = Frequency) [[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] How to extract row values?
Dear All! I'm trying to extract one specific row from a data frame without columnnames being included. I only want a 1-dimensional vector that consists of the specific data on this row. Here's an example: existing data: column names: v1v2v3 Row 1 ab cd ef Row 2 gh ij kl Row 3 mn op qr This is what I want to extract: ab cd ef I do not want: v1v2v3 ab cd ef Thank you in advance Henrik __ 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] Problems with loading 'wordnet' in a standalone pc
Hi group, I have the following error code after submitting library(wordnet) in a standalone pc. rJava is already in place. Error in .jpackage(pkgname,lib.loc=libname) unused argument(s) (lib.loc=libname) Error: .onLoad failed in 'loadNamespace' for 'wordnet' Error: package/namespace load failed for 'wordnet' My guess is I miss something from the namespace but unfortunately I can't get to the internet. Does anyone know what I'm missing (from the namespace?). Thank you very much! Kelvin -- View this message in context: http://www.nabble.com/Problems-with-loading-%27wordnet%27-in-a-standalone-pc-tp25062412p25062412.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] a bug in the offset parameter syntax in the geepack package?
I found that the syntax ahnven wrote: model=geeglm(y~covariates,offset(log(xxx)),data=data,family=poisson,id=idx) indeed fits offset(log(xxx)) as weights. -- View this message in context: http://www.nabble.com/a-bug-in-the-offset-parameter-syntax-in-the-geepack-package--tp25047143p25061988.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] re ading in array
I saved an array of dim=c(28,28,28,28) using write.table. When I try to read it in with read.table I get a data frame of dim=c(28,28^3). Of course it is very important to preserve the structure of the saved array when I read it in. Does anyone know how to read it in so that it is an array of the proper dimensions? Thanks so much -- View this message in context: http://www.nabble.com/reading-in-array-tp25062073p25062073.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] Contrasts within ANOVA frame (Repost)
Dr Shen Even though you pose 3 contrasts, there are only 2 degrees of freedom as the 3rd contrast is the sum of the first two. Your aov output states this as StdLot has only 2 df. Having used up your df, the aov has nothing to report. Joe Joseph F. Lucke Senior Statistician Research Institute on Addictions State University of New York at Buffalo 1021 Main Street Buffalo, NY 14203-1016 Office: 716-887-6807 Fax: 716-887-2510 http://www.ria.buffalo.edu/profiles/lucke.html Jun Shen jun.shen...@gmail.com Sent by: r-help-boun...@r-project.org 08/19/2009 05:33 PM To r-help@r-project.org cc Subject [R] Contrasts within ANOVA frame (Repost) Would like to try my luck to see if I can catch your eyes. I was trying to do some contrasts within ANOVA. I searched the archive and found a clue posted by Steffen Katzner ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html) I have three levels for a factor names StdLot and want to make three comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. First, contrasts(d3$StdLot,3)-matrix(c(1,-1, 0,0,1,-1,1,0,-1),3,3) #d3 is the data set. set up the contrast matrix Second, aov(Bkg~StdLot,na.rm=T,data=d3,contrasts=contrasts(d3$StdLot))-mod.aov #ANOVA, Finally, summary(mod.aov,split=list(StdLot=list('1 vs 2'=1,'2 vs 3'=2,'1 vs 3'=3))) #comparison summary Here is the final result I got, the third comparison is missing. Does anyone have any idea what is wrong here? If I change the order of the comparisons it's always the third one missing. So I guess it's not due to the data. Appreciate any comment. Df Sum Sq Mean Sq F valuePr(F) StdLot 2 1.905 0.953 10.3769 3.710e-05 *** StdLot: 1 vs 2 1 0.223 0.223 2.42390.1200 StdLot: 2 vs 3 1 1.683 1.683 18.3299 2.162e-05 *** StdLot: 1 vs 3 1 Residuals601 55.173 0.092 --- Signif. codes: 0 â***â 0.001 â**â 0.01 â*â 0.05 â.â 0.1 â â 1 2 observations deleted due to missingness -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to extract row values?
Assuming your data.frame has the name data, you would extract arbitrary row n by data[n, ] Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Henrik Kallberg Gesendet: Thursday, August 20, 2009 7:56 AM An: r-help@r-project.org Betreff: [R] How to extract row values? Dear All! I'm trying to extract one specific row from a data frame without columnnames being included. I only want a 1-dimensional vector that consists of the specific data on this row. Here's an example: existing data: column names: v1v2v3 Row 1 ab cd ef Row 2 gh ij kl Row 3 mn op qr This is what I want to extract: ab cd ef I do not want: v1v2v3 ab cd ef Thank you in advance Henrik __ 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 extract row values?
What you have is a one-dimensional vector. I think that you are up against an R default. You are going to get some names no matter what you do. You can always change them using the names() command, e.g. names(xx) - c(a,b, c) to replace the v1 v2 v3 --- On Thu, 8/20/09, Henrik Kallberg henrik.kallb...@ki.se wrote: From: Henrik Kallberg henrik.kallb...@ki.se Subject: [R] How to extract row values? To: r-help@r-project.org Received: Thursday, August 20, 2009, 7:55 AM Dear All! I'm trying to extract one specific row from a data frame without columnnames being included. I only want a 1-dimensional vector that consists of the specific data on this row. Here's an example: existing data: column names: v1v2v3 Row 1 ab cd ef Row 2 gh ij kl Row 3 mn op qr This is what I want to extract: ab cd ef I do not want: v1v2v3 ab cd ef Thank you in advance Henrik -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. __ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ __ 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] Embedding lists in matrices and matrices in lists
Hm I still suppose that you do not need matrix as a top level object. If you are sure there is only one level of nesting, e.g. in each node of the list there is only one level of saved matrices, you can get summary information from str, length and/or summary. lll-list(a=1, b=2, c=list(a=1,b=2,c=3), d=list(a=1, b=1), e=list(a=5,b=3, c=4, d=7, e=8)) lapply(lll, length) $a [1] 1 $b [1] 1 $c [1] 3 $d [1] 2 $e [1] 5 sapply(lll, length) a b c d e 1 1 3 2 5 summary(lll) Length Class Mode a 1 -none- numeric b 1 -none- numeric c 3 -none- list d 2 -none- list e 5 -none- list Michael Kogan michael.ko...@gmx.net napsal dne 20.08.2009 12:48:32: Thanks, I was already told this solution by somebody (he just forgot to add the mailing list as CC). Well, the purpose of the whole thing is to get something like this: http://home.att.net/~numericana/data/polycount.htm where the numbers in the table cells give the number of matrices saved in the corresponding cell. The program looks like this now: Do you really want the matrices saved in corresponding cell? If this 466224664031 is a number of items in one cell and if the item is only one number you would need 500 GB memory (hope I computed it correctly :-) to keep only this one cell in memory which I presume you do not have. If you want just store the number of existing variations which belong to this cell then you shall rethink your procedures. Regards Petr http://paste.ubuntuusers.de/396117/ It even runs (though errors occur if I add th process r into the main loop, but I'm still not done with it...). Petr PIKAL schrieb: Hi No. It is the problem of scoping. AFAIK functions create their own environment and everything what is assigned inside the function does not affect outside objects unless you use - assignment operator. i-100 ff-function(x) i-x ff(10) i [1] 100 fff-function(x) i-x fff(200) i [1] 200 However I would distract you from this practice. Personally I used such assignment only when I started with S/R about 10 years ago. Why do you want a database to be a matrix? It seems to be that list structure is in that case more flexible and there are *apply functions for manipulation with lists. E.g. structure lm(...) results in list and summary(lm(...)) is again a list with quite complicated structure. If I understand it correctly, during your computation you will have as a result matrices with arbitrary dimensions. I would make a list lll-vector(list, 1) and in simple loop for (i in 1:n) { do any computation here together with sophisticated and complicated functions and assign results to your list lll[[1]] - result of functions which itself can have quite complicated structure } If you want nested list just add another cycle and use lll[[i]][[j]] -some other result. With choosing appropriate structure of your date you can save yourself much problems. Regards Petr __ 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] should months be an ordered factor?
This is not a purely stats question as it depends on the implementation of mixed models in R. The help says that ordered factors are treated differently than unordered, which is not very informative. More explicitly: does ordering simply imply that February follows January or that February has got more than January of sth that they both have? Or pls recommend another way of treating monthly effects. Thank you [[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] joining two points in rgl
It gave me a the following error Error in cylinder3d(pts, radius = 0.1, e2 = rbind(c(1, 0, 0), c(1, 0, : subscript out of bounds The code I used is below for completeness. library(rgl) pts-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795), z = c(-1.8, 1.8)), .Names = c(x, y, z), class = data.frame, row.names = c(NA, -2L)) plot3d(pts, col=grey, size=2, box=FALSE, axes=TRUE, type=s, xlim=c(-5,5), ylim=c(-5,5), zlim=c(-5,5)) text3d(pts[1,],text=c(a), adj = c(0.5, -1)) text3d(pts[2,],text=c(t), adj = c(0.5, -1)) shade3d(cylinder3d(pts, radius=0.1, e2=rbind(c(1,0,0),c(1,0,0))), col=red) Thanks for adj. The rgl package is absolutely wonderful. It is extremely useful to me. Cheers../Murli From: Duncan Murdoch [murd...@stats.uwo.ca] Sent: Wednesday, August 19, 2009 9:02 PM To: Nair, Murlidharan T Cc: r-help@r-project.org Subject: Re: [R] joining two points in rgl On 19/08/2009 3:51 PM, Nair, Murlidharan T wrote: I tried the following library(rgl) pts-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795), z = c(-1.8, 1.8)), .Names = c(x, y, z), class = data.frame, row.names = c(NA, -2L)) plot3d(pts$x,pts$y,pts$z, col=grey, size=2, box=FALSE, axes=TRUE, type=s) lines3d(pts$x,pts$y,pts$z, col=black, lwd=5) x1--0.975688 y1-9.258795 z1--1.8+0.2 x2--0.975688 y2--9.258795 z2-1.8+0.2 text3d(x1,y1,z1,text=c(a)) text3d(x2,y2,z2,text=c(t)) cylinder3d(c(x1,y1,z1),c(x2,y2,z2)) The first argument should be a matrix giving all the coordinates of the centres. 1 I tried the above and could not get it to work. I did not understand how to give the Frenet coordinates. Can you give me some tip here please? There was actually a typo in the handling of e2, but with that fixed, this works: plot3d(pts, col=grey, size=2, box=FALSE, axes=TRUE, type=s, xlim=c(-5,5), ylim=c(-5,5), zlim=c(-5,5)) text3d(pts[1,],text=c(a), adj = c(0.5, -1)) text3d(pts[2,],text=c(t), adj = c(0.5, -1)) shade3d(cylinder3d(pts, radius=0.1, e2=rbind(c(1,0,0),c(1,0,0))), col=red) It's not perfect, because it draws a cylinder with a circular cross section, but the original plot has very uneven scaling. That's why I added the xlim, ylim, and zlim: to get equal coordinates in all axes. 2 Is there a better way of writing the text than what I have done above? Can I make the spheres transparent so that if I write the text at the exact same coordinate of the sphere the text is above the sphere and can be seen? You can use adj = c(0.5, -1) in the text3d calls to place the text above the point, as I did above. Duncan Murdoch Thanks ../Murli -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nair, Murlidharan T Sent: Friday, August 14, 2009 4:14 PM To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] joining two points in rgl Thanks, for lwd. I could not find rgl 0.85. The latest one I saw was 0.84. Can you tell me where I can download it from? It's on r-forge.r-project.org Also, is there a curve3d? I need to join two points in 3d smoothly. No, though par3dinterp could probably be faked into doing that. Duncan Murdoch Thanks ../Murli -Original Message- From: Duncan Murdoch [mailto:murd...@stats.uwo.ca] Sent: Thursday, August 13, 2009 8:24 PM To: Nair, Murlidharan T Cc: r-help@r-project.org Subject: Re: [R] joining two points in rgl Nair, Murlidharan T wrote: Hi!! I need to draw a cylinder/tube joining two points. I am trying to make something presentable, I have been able to do it using lines3d. But is it possible to increase the thickness of the lines? The size parameter does not work. Does any one have any suggestions? There's a new function cylinder3d (in rgl 0.85) that probably does exactly what you want, but lwd is the parameter that controls line width. Duncan Murdoch Thanks ../Murli library(rgl) pts-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795 ), z = c(-1.8, 1.8)), .Names = c(x, y, z), class = data.frame, row.names = c(NA, -2L)) plot3d(pts$x,pts$y,pts$z, col=grey, size=2, box=FALSE, axes=FALSE, type=s) lines3d(pts$x,pts$y,pts$z, col=grey, size=2) __ 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
Re: [R] Insert rows in between dataframes
There may be a much cleaner and better way but just split the data.frame into two parts, create the NA rows as another data.frame and use rbind to put them back together again. Example #=== (mydata - data.frame(aa=letters[1:5], bb=1:5)) topdata - mydata[1:3,] bottomdata - mydata[4:5,] nadata - data.frame(aa=rep(NA,2),bb=rep(NA,2)) d1 - rbind(topdata,nadata) d2 - rbind(d1, bottomdata) #=== --- On Thu, 8/20/09, Moumita Das das.moumita.onl...@gmail.com wrote: From: Moumita Das das.moumita.onl...@gmail.com Subject: [R] Insert rows in between dataframes To: r-help@r-project.org Received: Thursday, August 20, 2009, 7:18 AM Hi all, Can anyone suggest me how to insert rows in between data frames and also keep the ordering of row numbers correct? Estimate Std. Error t value Pr(|t|) recmeanC2 9.275880e-17 6.322780e-17 1.467057e+00 0.14349903 recmeanC3 1.283534e-17 2.080644e-17 6.168929e-01 0.53781390 recmeanC4 - 3.079466e-17 2.565499e-17 -1.200338e+00 0.23103743 i1 5.00e-01 1.036197e-17 4.825338e+16 0. i2 -5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282 i3 4.291387e-18 1.207522e-17 3.553879e-01 0.72257050 i4 1.472662e-17 1.423051e-17 1.034863e+00 0.30163897 i5 5.00e-01 1.003323e-17 4.983441e+16 0. i6 5.147966e-18 1.569095e-17 3.280850e-01 0.74309614 i7 1.096044e-17 1.555829e-17 7.044760e-01 0.48173041 i8 -1.166290e-18 1.287370e-17 -9.059482e-02 0.92788026 i9 1.627371e-17 1.540567e-17 1.056345e+00 0.29173427 i10 4.001692e-18 1.365740e-17 2.930053e-01 0.76973827 i12 -1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000 i13 2.571236e-17 1.357336e-17 1.894325e+00 0.05922715 This is my coeffcients table.Here I want ti inser t rows with value NA in all columns in between and after the last row.After last row I can insert using rbind.But how will I enter row in between so that the order also doesn’t change. I need this to be generated :--- Estimate Std. Error t value Pr(|t|) recmeanC2 9.275880e-17 6.322780e-17 1.467057e+00 0.14349903 recmeanC3 1.283534e-17 2.080644e-17 6.168929e-01 0.53781390 recmeanC4 - 3.079466e-17 2.565499e-17 -1.200338e+00 0.23103743 i1 5.00e-01 1.036197e-17 4.825338e+16 0. i2 -5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282 i3 4.291387e-18 1.207522e-17 3.553879e-01 0.72257050 i4 1.472662e-17 1.423051e-17 1.034863e+00 0.30163897 i5 5.00e-01 1.003323e-17 4.983441e+16 0. i6 5.147966e-18 1.569095e-17 3.280850e-01 0.74309614 i7 1.096044e-17 1.555829e-17 7.044760e-01 0.48173041 i8 -1.166290e-18 1.287370e-17 -9.059482e-02 0.92788026 i9 1.627371e-17 1.540567e-17 1.056345e+00 0.29173427 i10 4.001692e-18 1.365740e-17 2.930053e-01 0.76973827 i11 NA NA NA NA i12 -1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000 i13 2.571236e-17 1.357336e-17 1.894325e+00 0.05922715 i14 NA NA NA NA i15 NA NA NA NA rbind after row number i10 will change row number i12 to have NA,Na,NA.Na values. -- Thanks in advance Moumita [[alternative HTML version deleted]] -Inline Attachment Follows- __
[R] Odp: Histogram problem
Hi r-help-boun...@r-project.org napsal dne 20.08.2009 15:33:38: I'm trying to create a histogram from the following code, but my data keeps adding the Num vector and plotting that. My data in the CSV file is just one vector. Does anyone know why? Well, I think that only you know why CSV file is just one vector, (which I do not believe as SPXdf[,2] does not coplain). Thanks Conrad SPXdf = data.frame(read.csv(file = SPX.csv, header = TRUE, sep = ,, dec = ., fill = TRUE)) SPXdf = data.frame(read.csv(file = SPX.csv, header = TRUE, sep = ,, dec + = ., fill = TRUE)) Error in file(file, r) : cannot open the connection In addition: Warning message: In file(file, r) : cannot open file 'SPX.csv': No such file or directory Max = max(SPXdf[,2]) Error: object 'SPXdf' not found Min = min(SPXdf[,2]) E I can not retrieve the data, it throws an error. Max = max(SPXdf[,2]) Min = min(SPXdf[,2]) Count = length(SPXdf[,2]) sig = sd(SPXdf[,2]) BinSize = (3.5*sig)/(Count^(1/3)) BinNum = (Max - Min)/(BinSize) Bins = seq(Min,Max,by = BinSize) Count2 = length(Bins) Num = mat.or.vec(1,Count2) for (i in 1:Count){ for (j in 1:Count2){ if ((SPXdf[i,2] Bins[j])) {Num[j] = Num[j] + 1} } } barplot(Num,Bins, xlab = SPXdf, ylab = Frequency) R does what you require. You want barplot of Num vector with width according to Bin vector. Just as a curiosity, does hist(SPXdf[,2]) show a histogram? Regards Petr [[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] getting R 2.9.1 from the tar.gz file
On Thu, Aug 20, 2009 at 10:57:52AM +0300, Lazarus Mramba wrote: Dear Sir, I am almost giving up on getting the R-2.9.1 on the ubuntu 9.04 using the instructions found on the R site. I decided to use the R-2.9.1.tar.gz and untarred it. I then typed ./configure and the results are shown below. Please see http://cran.r-project.org/bin/linux/ubuntu to see how you can install pre-built binaries of R 2.9.1 for Ubuntu -- you do not have to build from source. Also consider the r-sig-debian list for Debian / Ubuntu questions; subscriptions are required in order to post. Dirk -- Three out of two people have difficulties with fractions. __ 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] Insert rows in between dataframes
Try this also: as.data.frame(t(sapply(append(split(mydata, row.names(mydata)), list(c('f', 6)), after = 2), as.matrix))) The after argument of append can be the line number where you want the new line. On Thu, Aug 20, 2009 at 8:18 AM, Moumita Das das.moumita.onl...@gmail.comwrote: Hi all, Can anyone suggest me how to insert rows in between data frames and also keep the ordering of row numbers correct? Estimate Std. Errort value Pr(|t|) recmeanC2 9.275880e-176.322780e-17 1.467057e+00 0.14349903 recmeanC3 1.283534e-17 2.080644e-176.168929e-01 0.53781390 recmeanC4 - 3.079466e-172.565499e-17 -1.200338e+00 0.23103743 i15.00e-01 1.036197e-17 4.825338e+16 0. i2 -5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282 i3 4.291387e-18 1.207522e-17 3.553879e-01 0.72257050 i4 1.472662e-17 1.423051e-17 1.034863e+00 0.30163897 i5 5.00e-011.003323e-17 4.983441e+16 0. i6 5.147966e-18 1.569095e-17 3.280850e-01 0.74309614 i7 1.096044e-17 1.555829e-17 7.044760e-01 0.48173041 i8-1.166290e-181.287370e-17 -9.059482e-02 0.92788026 i9 1.627371e-17 1.540567e-17 1.056345e+00 0.29173427 i104.001692e-18 1.365740e-17 2.930053e-01 0.76973827 i12-1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000 i132.571236e-17 1.357336e-17 1.894325e+00 0.05922715 This is my coeffcients table.Here I want ti inser t rows with value NA in all columns in between and after the last row.After last row I can insert using rbind.But how will I enter row in between so that the order also doesnt change. I need this to be generated :--- Estimate Std. Errort value Pr(|t|) recmeanC2 9.275880e-176.322780e-17 1.467057e+00 0.14349903 recmeanC3 1.283534e-17 2.080644e-176.168929e-01 0.53781390 recmeanC4 - 3.079466e-172.565499e-17 -1.200338e+00 0.23103743 i15.00e-01 1.036197e-17 4.825338e+16 0. i2 -5.630739e-18 1.638267e-17 -3.437010e-01 0.73133282 i3 4.291387e-18 1.207522e-17 3.553879e-01 0.72257050 i4 1.472662e-17 1.423051e-17 1.034863e+00 0.30163897 i5 5.00e-011.003323e-17 4.983441e+16 0. i6 5.147966e-18 1.569095e-17 3.280850e-01 0.74309614 i7 1.096044e-17 1.555829e-17 7.044760e-01 0.48173041 i8-1.166290e-181.287370e-17 -9.059482e-02 0.92788026 i9 1.627371e-17 1.540567e-17 1.056345e+00 0.29173427 i104.001692e-18 1.365740e-17 2.930053e-01 0.76973827 i11NA NA NA NA i12-1.052843e-17 1.324484e-17 -7.949081e-01 0.42735000 i132.571236e-17 1.357336e-17 1.894325e+00 0.05922715 i14 NA NA NA NA i15 NA NA NA NA rbind after row number i10 will change row number i12 to have NA,Na,NA.Na values. -- Thanks in advance Moumita [[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] possible problem with plot.lm
Hi, Here's one toy example that shows what I believe to be a problem with plot.lm. This was brought up by another user (Marcos Tadeu Andrade Cordeiro). I took a look at the source and the problem appears to be related to the fact that you need to reorder the data by the group means and the correct order of the labels is lost. set.seed(2) a - rnorm(50,0,2) x - rep(seq(10, 50, by=10), each=10) y - x+a f - rep(c(e,a,c,b,d), rep(10,5)) f - as.factor(f) y[1] - 200 mod1 - aov(y ~ f) par(mfrow=c(2,2)) plot(mod1) The last plot suggests that the outliers belongs to group D, when in fact it belongs to E. Does this make any sense or are we missing something? I'm reporting this with R-rc, but it is reproducible with previous versions too. Thanks a lot, b -- sessionInfo() R version 2.9.2 RC (2009-08-17 r49309) i386-apple-darwin9.8.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base __ 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] Several simple but hard tasks to do with R
Rakknar ha scritto: 1. Make a log. I've been using Stata and there i have a great tool to register what the program do: the log file, wich it's a simple .txt file where Stata writes every output it makes (not graphics of course). When I wanted to make the same thing with R I started to use the function sink() but it only register the results of the commands (summaries for example) and not the commands itself, witch it's really uncomfortable because it's harder to find out to witch command that results come from. A possible workaround could be: sink(ouputfile.txt) as.character(rnorm(5, mean = 0, sd = 1)) rnorm(5, mean = 0, sd = 1) sink() I know, it is not elegant, and a bit repetitive, but it could help. 8rino __ 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] Several simple but hard tasks to do with R
For history of both commands and output, consider running R inside emacs using the ESS package and simply saving the buffer to a file. If you save the session as an S transcript file (extension .St) it is also easy to reload and re-execute any part of it. Emacs or xemacs is available on most platforms including Windows. Rakknar wrote: 1. logs. help.search(history) and ?savehistory shows you that R does exactly what you want very easily (depending on the platform, which contrary to the posting guide's request, you did not tell us). I've already find out about the history tool but it was not useful because it only register commands, not output from the commands. The commands are already stored in scripts (I use Tinn-R, I don't know if you would recommend me other) what I want to do it's to store de commands AND the outputs from each. I use the Windows version by the way. -- View this message in context: http://www.nabble.com/Several-simple-but-hard-tasks-to-do-with-R-tp25052563p25064007.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] simple randomization question: How to perform sample in chunks
Hello dear R-help group. My task looks simple, but I can't seem to find a smart (e.g: non loop) solution to it. Task: I wish to randomize a data.frame by one column, while keeping the inner-order in the second column as is. So for example, let's say I have the following data.frame: xx -data.frame(a= c(1,2,2,3,3,3,4,4,4,4) , b = c(1,1,2,1,2,3,1,2,3,4) ) I would like to shuffle it by column a, while keeping the order in column b. Here is my not-smart way of doing it: # R example xx -data.frame(a= c(1,2,2,3,3,3,4,4,4,4) , b = c(1,1,2,1,2,3,1,2,3,4) ) randomize.by.column.a - function(xx) { new.a.order - sample(unique(xx$a)) new.xx - NULL for(i in new.a.order) { xx.subset - xx[ xx$a %in% i ,] new.xx - rbind(new.xx , xx.subset) } return(new.xx) } randomize.by.column.a(xx) # END of - R example I would love for a better, faster, way of doing it. Thanks, Tal -- -- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: http://www.r-statistics.com/ http://www.talgalili.com http://www.biostatistics.co.il [[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] globally set digits=3 in Sweave
On 8/20/2009 6:19 AM, Liviu Andronic wrote: Dear all I would like to globally set options(digits = 4) in an Sweave document. I've read this thread [1] where it was suggested to set the above option and pass every printed number through format(). Aanother way to do so would be to round(expr, 4). However I would like to set the digits option once per document so that every number printed respects it, without the need to pass every time through a formatting/rounding function. Is this possible in Sweave? Why not put echo=FALSE= options(digits=4) @ somewhere near the top of your document? Duncan Murdoch Thank you Liviu [1] https://stat.ethz.ch/pipermail/r-help/2003-September/039481.html __ 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] eval and evironments: call local function in a global function
On 8/20/2009 4:27 AM, Renaud Gaujoux wrote: Hi, in my project I want the user to be able to write hook functions that are in turn called in my main code. I'd like the user's hooks to be able to call some function that set a variable outside their running environment. The trick is that this variable is not global, but defined on runtime before calling the hooks, and I don't want to leave any trace (i.e. global variables) after the main code has finished. The best way to do this is to pass the function (setVar below) as an argument to the user's function. If it's the user's function, you have no business messing with it by changing its environment. How do you know the user didn't spend hours working out some crazy scheme of creating a nested function with a carefully crafted environment, and evaluation of his function depends on you leaving it alone? I thought that the following would work but it doesn't. I guess I got too messy with environment and enclosures: # global function defined by the user fun.global - function(){ message('fun.global') setVar(5) # } Pass setVar as an arg: fun.global - function(setVar) { message('fun.global') setVar(5) } # my main code main - function(){ message('main') # define a function to set some local variable setVar - local({ l.var - 0 function(value){ message('setVar') l.var - value } }) .workspace - environment(setVar) environment(setVar) - new.env() eval(fun.global(), enclos=environment(setVar)) print(get('l.var', envir=.workspace, inherits=FALSE)) } I wouldn't bother with the extra layer of local(), just put l.var in main's evalution frame. (Since you're the one writing setVar, you can avoid any name clashes.) That is: main - function() { message('main') l.var - 0 setVar - function(value) { message('setVar') l.var - value } fun.global(setVar) print(l.var) } Duncan Murdoch main() I get the following output: main fun.global Error in fun.global() : could not find function setVar There is definitely a problem of lookup somewhere. I first tried without eval, as I thought that function setVar would then be defined in a parent environment of the call to fun.global, but it does not work either. Can anybody tell me what's the problem and how I should do my stuff? Thanks, Renaud __ 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 with regular expressions in R
I'm having trouble achieving the results I want using a regular expression. I want to eliminate all characters that fall within square brackets as well as the brackets themselves, returning an . I'm not sure if it's R's use of double slash escapes or something else that is tripping me up. If I only use one slash I get 1: '\[' is an unrecognized escape in a character string 2: '\]' is an unrecognized escape in a character string 3: unrecognized escapes removed from \[*.\] Below is my self-contained code followed by sessionInfo(). Thanks in advance for your help. I'm going to be doing a lot of text mining in the near future. I have an excellent O'Reilly book on regex's. What is the best reference for R's special treatment of these animals? Mark myCharVec - c([the rain in spain], (the rain in spain)) gsub('\\[*.\\]', '', myCharVec) #what I get # [1] [the rain in spai (the rain in spain) #what I want [1](the rain in spain) sessionInfo() R version 2.10.0 Under development (unstable) (2009-08-12 r49193) x86_64-unknown-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] RWeka_0.3-20 tm_0.4 loaded via a namespace (and not attached): [1] grid_2.10.0 rJava_0.6-3 slam_0.1-3 Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** [[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] Several simple but hard tasks to do with R
Bert: Thanks for your help. I'll try to clarify some of your doubts 1. logs. help.search(history) and ?savehistory shows you that R does exactly what you want very easily (depending on the platform, which contrary to the posting guide's request, you did not tell us). I've already find out about the history tool but it was not useful because it only register commands, not output from the commands. The commands are already stored in scripts (I use Tinn-R, I don't know if you would recommend me other) what I want to do it's to store de commands AND the outputs from each. I use the Windows version by the way. 2. saving data. ?save would show you how this can be trivially done manually. ?addTaskCallback , an admittedly more sophisticated and less well-known approach, would show you how this can be done simply and automatically. As I said I've used the save command but, at least for now, I only could save one object in the .Rdata file or several at once but what I want to do it's to save them step by step saving them in the same .Rdata file. When trying to do this the save command overwrites the .Rdata file and stores the new object. 3. Conditional execution. R is a programming language! It is straightforward to write a little program that does exactly what you want using R's built in file system functionality. ?files will tell you what's available; I believe file.exists() is what you want in a construct like if(file.exists(yourfile.rdata))lm(...,data = read(yourfile.rdata)) Thanks. I was trying not to start making commands for R (after all making them after only a month seems a huge task for be but if there is no other option...). -- View this message in context: http://www.nabble.com/Several-simple-but-hard-tasks-to-do-with-R-tp25052563p25063630.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] predict.HoltWinters source misunderstanding.
If I look in the stats package for the 'R' source code for predict.HoltWinters I see the following lines: vars - function(h) { psi - function(j) object$alpha * (1 + j * object$beta) + (j%%f == 0) * object$gamma * (1 - object$alpha) var(residuals(object)) * if (object$seasonal == additive) sum(1, (h 1) * sapply(1L:(h - 1), function(j) crossprod(psi(j There is more source code but my question is on the call to crossprod(psi(j)). Looking at the psi function I could see no elements that are vectors (or matrices) or that result in such. In fact if I replace the call to crossprod with: sum(1, (h 1) * sapply(1L:(h - 1), function(j) { r - psi(j) r*r } )) I get the same results. If I further augment my test by printing out the length of the return value from 'psi' I can see no case where 'psi' would return anything but a single number. So my question is, why the call to crossprod when simply squaring the number will do. Am I missing a case when the members of the HoltWinters fit would be vectors and then crossprod would be appropriate or is this just an oversight? Thank you. Kevin __ 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] ANCOVA with defined error terms
Yes, I meant summary(). anova() isn't defined for aovlist objects and summary() is. Warning message: In aov(kotz.mice ~ kotz.coon + block * veget * fruit * time - block:veget:fruit:time + : Error() model is singular You will need to investigate the singular Error() model. You might want to use the simpler Error model Error(block) My guess is the plot term is redundant. What are kotz.mice? That variable isn't in the model you showed. For more detailed help you will need to provide commented, minimal, self-contained, reproducible code. Rich __ 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] Several simple but hard tasks to do with R
To echo what others have said, it is often easier to write a script (in STATA terms, a do file) of commands and then source the script. When it runs to your satisfaction, usually not the first time for me, there are several ways to store the output. Both the R2HTML and prettyR packages contain methods to store output as HTML files. You can store both the commands and output in the same file. I already using script. I'm using Tinn-R to write them. Thanks for the recommendation of the R2HTML package I'll see how to use it right now. Thanks. You can save one object at a time if you want, and do it during a script. I usually save the primary data object after I have translated it from whatever format it came to me. You can save subsets of the data as different files and simply use load to read in the data you want. load can also signal if the data is not there, albeit in a fairly messy way. Yes, I already know I can do things that way but it doesn't work for me: I want to be able to store several objects in one .Rdata file in a flexible and fast way. Writing one for each object seems too messy for me. -- View this message in context: http://www.nabble.com/Several-simple-but-hard-tasks-to-do-with-R-tp25052563p25063776.html Sent from the R help mailing list archive at Nabble.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] help with regular expressions in R
How about this: myCharVec - c([the rain in spain], (the rain in spain)) gsub('\\[.*\\]', '', myCharVec) [1] (the rain in spain) you had *. when you should have .* On Thu, Aug 20, 2009 at 11:30 AM, Mark Kimpelmwkim...@gmail.com wrote: I'm having trouble achieving the results I want using a regular expression. I want to eliminate all characters that fall within square brackets as well as the brackets themselves, returning an . I'm not sure if it's R's use of double slash escapes or something else that is tripping me up. If I only use one slash I get 1: '\[' is an unrecognized escape in a character string 2: '\]' is an unrecognized escape in a character string 3: unrecognized escapes removed from \[*.\] Below is my self-contained code followed by sessionInfo(). Thanks in advance for your help. I'm going to be doing a lot of text mining in the near future. I have an excellent O'Reilly book on regex's. What is the best reference for R's special treatment of these animals? Mark myCharVec - c([the rain in spain], (the rain in spain)) gsub('\\[*.\\]', '', myCharVec) #what I get # [1] [the rain in spai (the rain in spain) #what I want [1] (the rain in spain) sessionInfo() R version 2.10.0 Under development (unstable) (2009-08-12 r49193) x86_64-unknown-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] RWeka_0.3-20 tm_0.4 loaded via a namespace (and not attached): [1] grid_2.10.0 rJava_0.6-3 slam_0.1-3 Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] [SPAM] - help with regular expressions in R - Bayesian Filter detected spam
Possibly just a typo: gsub('\\[.*\\]', '', myCharVec) ^^ [1] (the rain in spain) HTH, -- David -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Kimpel Sent: Thursday, August 20, 2009 10:31 AM To: r-help@r-project.org Subject: [SPAM] - [R] help with regular expressions in R - Bayesian Filter detected spam I'm having trouble achieving the results I want using a regular expression. I want to eliminate all characters that fall within square brackets as well as the brackets themselves, returning an . I'm not sure if it's R's use of double slash escapes or something else that is tripping me up. If I only use one slash I get 1: '\[' is an unrecognized escape in a character string 2: '\]' is an unrecognized escape in a character string 3: unrecognized escapes removed from \[*.\] Below is my self-contained code followed by sessionInfo(). Thanks in advance for your help. I'm going to be doing a lot of text mining in the near future. I have an excellent O'Reilly book on regex's. What is the best reference for R's special treatment of these animals? Mark myCharVec - c([the rain in spain], (the rain in spain)) gsub('\\[*.\\]', '', myCharVec) #what I get # [1] [the rain in spai (the rain in spain) #what I want [1](the rain in spain) sessionInfo() R version 2.10.0 Under development (unstable) (2009-08-12 r49193) x86_64-unknown-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] RWeka_0.3-20 tm_0.4 loaded via a namespace (and not attached): [1] grid_2.10.0 rJava_0.6-3 slam_0.1-3 Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** [[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. imal, self-contained, reproducible code. This e-mail and any materials attached hereto, including, without limitation, all content hereof and thereof (collectively, Rho Content) are confidential and proprietary to Rho Trading Securities, LLC (Rho) and/or its affiliates, and are protected by intellectual property laws. Without the prior written consent of Rho, the Rho Content may not (i) be disclosed to any third party or (ii) be reproduced or otherwise used by anyone other than current employees of Rho or its affiliates, on behalf of Rho or its affiliates. THE RHO CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY KIND. TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, RHO HEREBY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE RHO CONTENT, AND NEITHER RHO NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR INABILITY TO USE, ANY RHO CONTENT, EVEN IF RHO IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE. __ 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] help with regular expressions in R
Mark, Try this: myCharVec [1] [the rain in spain] (the rain in spain) gsub(\\[.*\\], , myCharVec) [1] (the rain in spain) You need two backslashes to escape the square brackets. The regular expression \\[.\\] translates to a [ followed by 0 or more instances of any character followd by ]. Best regards, Chuck Taylor TIBCO Spotfire Seattle -Original Message- I want to eliminate all characters that fall within square brackets as well as the brackets themselves, returning an . ... #what I want [1](the rain in spain) __ 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] Several simple but hard tasks to do with R
Put the objects that you want to save in a 'list' and then 'save' the list. You can build up the contents of the list dynamically in your program and then save it at the appropriate point. On Thu, Aug 20, 2009 at 10:59 AM, Rakknaraliengene...@yahoo.com wrote: To echo what others have said, it is often easier to write a script (in STATA terms, a do file) of commands and then source the script. When it runs to your satisfaction, usually not the first time for me, there are several ways to store the output. Both the R2HTML and prettyR packages contain methods to store output as HTML files. You can store both the commands and output in the same file. I already using script. I'm using Tinn-R to write them. Thanks for the recommendation of the R2HTML package I'll see how to use it right now. Thanks. You can save one object at a time if you want, and do it during a script. I usually save the primary data object after I have translated it from whatever format it came to me. You can save subsets of the data as different files and simply use load to read in the data you want. load can also signal if the data is not there, albeit in a fairly messy way. Yes, I already know I can do things that way but it doesn't work for me: I want to be able to store several objects in one .Rdata file in a flexible and fast way. Writing one for each object seems too messy for me. -- View this message in context: http://www.nabble.com/Several-simple-but-hard-tasks-to-do-with-R-tp25052563p25063776.html Sent from the R help mailing list archive at Nabble.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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Is there a construct for conditional comment?
Why not if ( 0 ) { commented with zero } else { commented with one } Greg Snow-2 wrote: I believe that #if lines for C++ programs is handled by the preprocessor, not the compiler. So if you want the same functionality for R programs, it would make sense to just preprocess the R file. In C++, I can use the following construct to choice either of the two blocks the comment but not both. Depending on whether the number after #if is zero or not, the commented block can be chose. I'm wondering if such thing is possible in R? #if 0 commented with 0 #else commented with 1 #endif Regards, Peng -- View this message in context: http://www.nabble.com/Is-there-a-construct-for-conditional-comment--tp25034224p25064798.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] RMySQL - overwrite record, not table
Hi, Adrian- If you use overwrite=T parameter, you will overwrite the entire table, not each record. this is the essence of my problem and i still haven't found out right solution. i am thinking of writing my own MySQLwriteTable function... Thank you for your answer anyway! Adrian Dusa wrote: whizvast wrote: Hi, useR- In RMySQL, how do I overwrite records? (equivalent to replace query). For example, suppose that dat2 is a newer data.frame than dat1. con - dbConnect(MySQL()) res - dbWriteTable(con, DBname, dat1, row.names=F, append=T, replace=T) res - dbWriteTable(con, DBname, dat2, row.names=F, append=T, replace=T) This would not update/replace the dat1 records in DBname with newer records from dat2. How would you solve the problem? Thanks= In case it isn't too late (it's vacation time around), try: dbWriteTable(con, DBname, dat2, overwrite=TRUE, row.names=FALSE) I believe you are confusing DBname with the DATABASE from the MySQL which is not specified here but in dbConnect(). A correct (and complete) connection to the MySQL should specify the database as well; for example: con - dbConnect(drv, user=myusername, password=mypass, dbname=mydatabase, host=xxx.xxx.xxx.xxx) Here, the dbname argument specifies the database used, the equivalent of USE command in MySQL. If DBname refers to a table in the database used with dbConnect(), then the first command of dbWriteTable() that I indicated (without your res -, it's a pure command to the MySQL connection, which should not be saved into an object) will replace the table DBname with your dat2 table. I hope it helps, Adrian -- View this message in context: http://www.nabble.com/RMySQL---overwrite-record%2C-not-table-tp24870097p25064733.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] [R-pkgs] New package for multivariate Kalman filtering, smoothing, simulation and forecasting
Dear all, I am pleased to announce the CRAN release of a new package called 'KFAS' - Kalman filter and smoother. The package KFAS contains functions of multivariate Kalman filter, smoother, simulation smoother and forecasting. It uses univariate approach algorithm (aka sequential processing), which is faster than normal method, and it also allows mean square prediction error matrix Ft to be singular. Filtering, smoothing and simulation functions are all written in Fortran. Functions allow time-variant system matrices and missing observations. In case distributions of some or all elements of initial state vector are unknown, functions use exact diffuse initialisation. I hope that this package will be useful for people working with state space models and time series in general. Any feedback is appreciated. Yours, Jouni Lehtonen University of Jyväskylä Finland ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] globally set digits=3 in Sweave
On 8/20/09, Duncan Murdoch murd...@stats.uwo.ca wrote: Why not put echo=FALSE= options(digits=4) @ somewhere near the top of your document? I did so, but it has no practical effect on \Sexpr{} (which I'm interested in, and failed to mention in the original e-mail). With echo=FALSE= options(digits=4) @ , the following = tmp - pi tmp @ will yield tmp - pi tmp [1] 3.142 , while \Sexpr{tmp} will yield 3.14159265358979 and \Sexpr{format(tmp)} will yield 3.142 Liviu __ 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.