Re: [R] Loading .Rdata within an R function
Thank you for your consideration of this question. I have tried both your suggestions. However, the data is not loaded within the function. When I specify load(mydata.Rdata,.globalEnv), the data is loaded into the top level environment, and the function does access the data in the top level environment. However, I would like to load the data into the function environment, so that the data goes away when the function terminates. Cordially, Giles Crane -- View this message in context: http://r.789695.n4.nabble.com/Loading-Rdata-within-an-R-function-tp2282751p2283051.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] Appropriate tests for logistic regression with a continuous predictor variable and Bernoulli response variable
I have a data with binary response variable, repcnd (pregnant or not) and one predictor continuous variable, svl (body size) as shown below. I did Hosmer-Lemeshow test as a goodness of fit (as suggested by a kind âR-helperâ previously). To test whether the predictor (svl, or body size) has significant effect on predicting whether or not a female snake is pregnant, I used the differences between null deviance and residual deviance using a code as following:  1-pchisq(mod.fit$null.deviance - mod.fit$deviance, mod.fit$df.null - mod.fit$df.residual)  Could anyone tell me whether I did the test properly? I did this test because I thought Wald test/z score listed in the output from summary(mod.fit) is not appropriate for a kind of data I have.  Does R have automated function to run appropriate tests? I have pasted my R output below.  Thank you in advance for your time and help.  Kiyoshi              repcnd            svl 1        1                    51.5 2        1                    52.5 edited 294     0                     59.8 298     1                     60.0 300     1                     51.7 301     1                    57.4 302     1                    60.9 303     0                    56.8 304     0                    50.0 --- mod.fit - glm(formula = gb.no.M$repcnd ~ gb.no.M$svl, family = binomial(link = logit), data = gb.no.M, na.action = na.exclude, control = list(epsilon = 0.0001, maxit = 50, trace = F)) summary(mod.fit)  Call: glm(formula = gb.no.M$repcnd ~ gb.no.M$svl, family = binomial(link = logit),    data = gb.no.M, na.action = na.exclude, control = list(epsilon = 1e-04,        maxit = 50, trace = F))  Deviance Residuals:   Min     1Q Median     3Q    Max -1.757 -1.109  0.734  1.113  1.632  Coefficients:            Estimate Std. Error z value Pr(|z|)   (Intercept) -7.08565   1.84106 -3.849 0.000119 *** gb.no.M$svl 0.13529   0.03474  3.894 9.85e-05 *** --- Signif. codes: 0 â***â 0.001 â**â 0.01 â*â 0.05 â.â 0.1 â â 1  (Dispersion parameter for binomial family taken to be 1)     Null deviance: 301.92 on 217 degrees of freedom Residual deviance: 285.04 on 216 degrees of freedom  (8 observations deleted due to missingness) AIC: 289.04  Number of Fisher Scoring iterations: 3 --- Hosmer-Lemeshow test hosmerlem - function (y, yhat, g = 10) + { + cutyhat - cut(yhat, breaks = quantile(yhat, probs = seq(0, 1, 1/g)), include.lowest = T) + obs - xtabs(cbind(1 - y, y) ~ cutyhat) + expect - xtabs(cbind(1 - yhat, yhat) ~ cutyhat) + chisq - sum((obs - expect)^2/expect) + P - 1 - pchisq(chisq, g - 2) + c(X^2 = chisq, Df = g - 2, P(Chi) = P) + } mod.fit - glm(formula = no.NA$repcnd ~ no.NA$svl, family = binomial(link = logit), data = no.NA, na.action = na.exclude, control = list(epsilon = 0.0001, maxit = 50, trace = F))  hosmerlem(no.NA$repcnd, fitted(mod.fit))      X^2       Df  P(Chi) 6.8742531 8.000 0.5502587 --- list(p.value = round(1-pchisq(mod.fit$null.deviance - mod.fit$deviance, + mod.fit$df.null- mod.fit$df.residual),6), + df = mod.fit$df.null- mod.fit$df.residual, + change = mod.fit$null.deviance - mod.fit$deviance)  $p.value [1] 4e-05  $df [1] 1  $change [1] 16.87895 [[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] Aide pour faire ACM
Bonjour, Je travaille sur R et je veux faire MCA, je veux savoir comment calcules les valeurs de Contribution, cosinus carré, coordonnée et distance au centre des modalités des différentes variables. Je vous remercie beaucoup d'avance. Housseima _ Hotmail : une messagerie performante et gratuite avec une sécurité signée Microsoft [[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] Non-parametric regression
I have two data sets, each a vector of 1000 numbers, each vector representing a distribution (i.e. 1000 numbers each of which representing a frequency at one point on a scale between 1 and 1000). For similfication, here an short version with only 5 points. a - c(8,10,8,12,4) b - c(7,11,8,10,5) Leaving the obvious discussion about causality aside fro a moment, I would like to see how well i can predict b from a using a regression. Since I do not know anything about the distribution type and already discovered non-normality I cannot use parametric regression or anything GLM for that matter. How should I proceed in using non-parametric regression to model vector a and see how well it predicts b? Perhaps you could extend the given lines into a short example script to give me an idea? Are there any other options? Best, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Non-parametric regression
From reviewing the first google page result for Non-parametric regression R, I hope this link will prove useful: http://socserv.mcmaster.ca/jfox/Courses/Oxford-2005/R-nonparametric-regression.html Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 9, 2010 at 11:01 AM, Ralf B ralf.bie...@gmail.com wrote: I have two data sets, each a vector of 1000 numbers, each vector representing a distribution (i.e. 1000 numbers each of which representing a frequency at one point on a scale between 1 and 1000). For similfication, here an short version with only 5 points. a - c(8,10,8,12,4) b - c(7,11,8,10,5) Leaving the obvious discussion about causality aside fro a moment, I would like to see how well i can predict b from a using a regression. Since I do not know anything about the distribution type and already discovered non-normality I cannot use parametric regression or anything GLM for that matter. How should I proceed in using non-parametric regression to model vector a and see how well it predicts b? Perhaps you could extend the given lines into a short example script to give me an idea? Are there any other options? Best, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Kite diagrams
On 07/09/2010 07:23 AM, Graham Smith wrote: I asked the same question on R-sig-eco, and Ben Bolker provided this solution, which as I assume this should show up in a search I copy here. However, if someone can come up with a single function, that would be good. Hi Graham, library(plotrix) kiteChart(t(X)) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R^2 in loess and predict?
Parametric regression produces R^2 as a measure of how well the model predicts the sample and adjusted R^2 as a measure of how well it models the population. What is the equalvalent for non-parametric regression (e.g. loess function) ? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R^2 in loess and predict?
I do not agree with your interpretation of the adjusted R^2. The R^2 is no more than the ratio of the explained variance by the total variance, expressed in sums of squares. The adjusted R^2 is adjusted for the degrees of freedom, and can only be used for selection purposes. The interpretation towards the final model is hard, and definitely not a measure of how well it models the population. For a loess regression this can be calculated as well. But the loess is a local regression technique, highly flexible, and highly dependent on the window you use. In these cases, R^2 (or any other goodness of fit test) tells you even less. You can get an R^2 of 1 if you chose the window small enough. If you want to do inference on nonlinear regression techniques, I strongly suggest you use Generalized Additive Models, eg from the package mgcv. There you can use the framework of likelihood ratio tests for determination of goodness of fit by comparing models. Cheers Joris On Fri, Jul 9, 2010 at 10:42 AM, Ralf B ralf.bie...@gmail.com wrote: Parametric regression produces R^2 as a measure of how well the model predicts the sample and adjusted R^2 as a measure of how well it models the population. What is the equalvalent for non-parametric regression (e.g. loess function) ? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Kite diagrams
Jim, This is very good news, not so much for me, as I don't use them, but I have colleagues who do, and its an expected graphic in student assignments. So I have passed on the information. So many thanks for adding this, I a sure many people will find it useful. Graham On 9 July 2010 09:41, Jim Lemon j...@bitwrit.com.au wrote: On 07/09/2010 07:23 AM, Graham Smith wrote: I asked the same question on R-sig-eco, and Ben Bolker provided this solution, which as I assume this should show up in a search I copy here. However, if someone can come up with a single function, that would be good. Hi Graham, library(plotrix) kiteChart(t(X)) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] accessing return variables from a function
Hi, I am trying to figure out a short way to access two values output from the sort function. x - c(3,4,3,6,78,3,1,2) sort(x, index.return=T) $x [1] 1 2 3 3 3 4 6 78 $ix [1] 7 8 1 3 6 2 4 5 It would be great to do something like this (doesn't work.): c(y, indexes) - sort(x, index.return=T) But that doesn't work. I CAN grab the output of sort in a variable and then access it twice to get the values, but that seems wasteful. Any ideas? -N __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 crashes with large vectors
Good afternoon, I have been experiencing a lot of crashes working with large vectors in R. Specifically, I am using XTS of length of minimum 120k elements. My problem is that I cannot display the vector (otherwise R crashes), I cannot plot it either (otherwise R crashes). That could be solved by reducing the amount of points. However, I have been performing some statistical opreations on is and even sd(myXTS) crashes R. By crashes, I mean shuts down without any warning whatsoever. I use R 2.11.1 (64). Has anyone had the same kind of problem? Can we solve this? Best, -- Jeremie [[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] Current script name from R
Is there a way for a script to find out about its own name ? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting text in existing plot?
I would like to plot some text in a existing plot graph. Is there a very simple way to do that. It does not need to be pretty at all (just maybe a way to center it or define a position within the plot). ( ? ) Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting text in existing plot?
see ?text Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 9, 2010 at 12:52 PM, Ralf B ralf.bie...@gmail.com wrote: I would like to plot some text in a existing plot graph. Is there a very simple way to do that. It does not need to be pretty at all (just maybe a way to center it or define a position within the plot). ( ? ) Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loading .Rdata within an R function
Giles Crane wrote: Thank you for your consideration of this question. I have tried both your suggestions. However, the data is not loaded within the function. When I specify load(mydata.Rdata,.globalEnv), the data is loaded into the top level environment, and the function does access the data in the top level environment. However, I would like to load the data into the function environment, so that the data goes away when the function terminates. For the benefit of others: an offline followup showed that the data were being loaded in the right place, but a function in a contributed package wasn't looking there and didn't see it. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting text in existing plot?
On 07/09/2010 07:52 PM, Ralf B wrote: I would like to plot some text in a existing plot graph. Is there a very simple way to do that. It does not need to be pretty at all (just maybe a way to center it or define a position within the plot). ( ? ) Hi Ralf, The text function in the graphics package will place text on your plot. It centers the text by default, so that: text(3,4,my neat\ntwo liner) will place the two lines of text centered at x=3 and y=4. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] split with list
Dear List I would like to ask you something concenting a better print of the R output: I have a bit data frame which has the following structure: CFISCALE RAGSOCBANNO VAR1VAR2. 9853312 astra 2005 6 45 9853312 astra 2006 78 45 9853312 astra 2007 55 76 9653421 geox 2005 35 89 9653421 geox 200624 33 9653421 geox 2007 54 55 The first thing I did is to split my data frame for CFISCALE. The result is that R has transformed my data frame into a list. The second step was to transpose each element of my list. repo=split(rep,rep$CFISCALE) repor=lapply(repo,function(x){ t(x)}) When I print my list the format is the following $9853312 1 2 3 CFISCALE9853312 9853312 9853312 RAGSOCBastra astraastra ANNO 20052006 2007 VAR1 6 78 55 VAR2 4545 76 There is a way to remove the first row I mean 1, 2 , 3 and to have just one CFISCALE and RAGSOCB??? For the second problem I tried to use unique but it seems that it doesnt work for list. So what I would like to get is: $9853312 CFISCALE9853312 RAGSOCBastra ANNO 20052006 2007 VAR1 6 78 55 VAR2 4545 76 This is because I next run xtable on my list in order to get a table in Latex, which I woud like to be in a nice format. Thanks a lot for your attention! [[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] C module causing rounding errors?
Joseph N. Paulson wrote: Hi all! I am currently writing a C-module for a for loop in which I permute columns in a matrix (bootstrapping) and I send a couple of variables into C initially. All of it is working, except the initial values I send to R are rounded/truncated (I believe rounded). I am using a 32 bit machine to compile, I am using (I believe) 32 bit R While debugging I print the values I am sending to C, and then I print the same values using Rprintf and the number gets rounded to 10^-6, which is actually causing some errors for me. Is there any way to correct/prevent the error? sample output from R [1,] 1.000 [2,] 1.0256242 [3,] 1.1826277 [4,] -0.6937246 [5,] 1.3633604 sample output from C 1.00 1.025624 1.182628 0.693725 1.363360 It looks as though you are confusing the display of numbers with their internal values. R is printing 7 decimal places, C is printing 6. As far as we can tell, that's the only difference. Duncan Murdoch [[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] accessing return variables from a function
On Jul 9, 2010, at 5:20 AM, Noah Silverman wrote: Hi, I am trying to figure out a short way to access two values output from the sort function. x - c(3,4,3,6,78,3,1,2) sort(x, index.return=T) $x [1] 1 2 3 3 3 4 6 78 $ix [1] 7 8 1 3 6 2 4 5 It would be great to do something like this (doesn't work.): yoursort - function(x) {sx - sort(x, index.return=T); return( c(sx $x, sx$ix) )} yoursort(x) [1] 1 2 3 3 3 4 6 78 7 8 1 3 6 2 4 5 c(y, indexes) - sort(x, index.return=T) But that doesn't work. I CAN grab the output of sort in a variable and then access it twice to get the values, but that seems wasteful. Any ideas? David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Non-parametric regression
On Jul 9, 2010, at 4:01 AM, Ralf B wrote: I have two data sets, each a vector of 1000 numbers, each vector representing a distribution (i.e. 1000 numbers each of which representing a frequency at one point on a scale between 1 and 1000). For similfication, here an short version with only 5 points. a - c(8,10,8,12,4) b - c(7,11,8,10,5) Leaving the obvious discussion about causality aside fro a moment, I would like to see how well i can predict b from a using a regression. You can use density estimation,. There was a recent thread that included worked examples using MASS::kde2d and locfit::locfit for graphical display of joint distributions. Since I do not know anything about the distribution type and already discovered non-normality I cannot use parametric regression or anything GLM for that matter. How should I proceed in using non-parametric regression to model vector a and see how well it predicts b? Perhaps you could extend the given lines into a short example script to give me an idea? Are there any other options? Best, Ralf David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] KLdiv produces NA. Why?
I am trying to calculate a Kullback-Leibler divergence from two vectors with integers but get NA as a result when trying to calulate the measure. Why? x - cbind(stuff$X, morestuff$X) x[1:5,] [,1] [,2] [1,] 293 938 [2,] 293 942 [3,] 297 949 [4,] 290 956 [5,] 294 959 KLdiv(x) [,1] [,2] [1,]0 NA [2,] NA0 Best, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] accessing return variables from a function
On Fri, Jul 9, 2010 at 10:20 AM, Noah Silverman n...@smartmediacorp.com wrote: Hi, I am trying to figure out a short way to access two values output from the sort function. x - c(3,4,3,6,78,3,1,2) sort(x, index.return=T) $x [1] 1 2 3 3 3 4 6 78 $ix [1] 7 8 1 3 6 2 4 5 It would be great to do something like this (doesn't work.): c(y, indexes) - sort(x, index.return=T) But that doesn't work. I CAN grab the output of sort in a variable and then access it twice to get the values, but that seems wasteful. Care to do a little study to see how wasteful? The difference is going to be between: foo = sort(...) repeat loads of times{ f(foo$x) g(foo$ix) } and foo = sort(...) x=foo$x ix = foo$ix repeat loads of times{ f(x) g(ix) } I'd guess that for most applications the difference is less than something very close to zero. Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting text in existing plot?
On Fri, Jul 9, 2010 at 11:22 AM, Jim Lemon j...@bitwrit.com.au wrote: The text function in the graphics package will place text on your plot. It centers the text by default, so that: text(3,4,my neat\ntwo liner) will place the two lines of text centered at x=3 and y=4. BUT it only works on 'base' graphics plots, so if you're using lattice or ggplot then there's another way to do it. Perhaps. Original poster wanted a simple way to do it, but when R has three graphics systems, four OO systems, and a zillion helpful people there's never a simple way :) Barry -- blog: http://geospaced.blogspot.com/ web: http://www.maths.lancs.ac.uk/~rowlings web: http://www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] metafor and meta-analysis at arm-level
With appropriate design matrix, I mean the X matrix in the mixed-effects model y = Xb + u + e, where y is the vector of outcomes, u is a vector of (possibly correlated) random effects, and e is a vector of (possibly) random errors. The X matrix is specified via the 'mods' argument in the rma() function. If y consists of arm-level outcomes, then you need appropriate dummy variables in X to code what type of arm the outcome corresponds to. Have you read, for example: Salanti, G., Higgins, J. P. T., Ades, A. E., Ioannidis, J. P. A. (2008). Evaluation of networks of randomized trials. Statistical Methods in Medical Research, 17(3), 279-301. This article may be helpful. Best, -- Wolfgang Viechtbauerhttp://www.wvbauer.com/ Department of Methodology and StatisticsTel: +31 (0)43 388-2277 School for Public Health and Primary Care Office Location: Maastricht University, P.O. Box 616 Room B2.01 (second floor) 6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck) Original Message From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Angelo Franchini Sent: Tuesday, July 06, 2010 10:37 To: Wolfgang Viechtbauer Cc: r-help@r-project.org; Angelo Franchini Subject: Re: [R] metafor and meta-analysis at arm-level Hello Wolfgang, Thank you very much for your response. When you mentionthe appropriate design matrix, do you mean by that the 'n1i, n2i, m1i, m2i, sd1i, sd2i' arguments of the rma function, or am I missing something? I read the documentation on metafor (introduction), rma/rma.uni and escalc, and that was the only way that I could find for the package to use information at the arm-level rather than the trial one. As for the complexity of possible correlations between effects, that is something to be considered for the network analysis case, correct? Many thanks. Best regards, Angelo On Sun, July 4, 2010 6:06 am, Wolfgang Viechtbauer wrote: Hello Angelo, You can either supply the arm-level outcomes and corresponding sampling variances directly (via the yi and vi arguments) or supply the necessary information so that the escalc() or rma() functions can calculate an appropriate arm-level outcome (such as the log odds). See the documentation of the escalc() function and in particular the part about proportions and tranaformations thereof as possible outcome measures. This is the easy part. Then you need to set up an appropriate design matrix to code what arm each observed outcome corresponds to. And finally comes the tricky/problematic part. The rma() function assumes independent sampling errors and independent random effects for each observed outcome. Independent sampling errors is (usually) ok when using arm-level outcomes, but the independent random errors part may not be appropriate. This is why I am working on functions that do not make this independence assumption. With those functions, you can then carry out multivariate and network-type meta-analyses. These functions will become part of the metafor package in the future. Best, -- Wolfgang Viechtbauer http://www.wvbauer.com Angelo Franchini angelo.franch...@bristol.ac.uk wrote: Hi, I have been looking for an R package which allowed to do meta-analysis (both pairwise and network/mixed-treatment) at arm-level rather than at trial-level, the latter being the common way in which meta-analysis is done. By arm-level meta-analysis I mean one that accounts for data provided at the level of the individual arms of each trial and that does not simply derive the difference between arms and do the meta-analysis on that. I am not sure metafor can do that, but hopefully someone more experienced on it can clarify that to me. I can see that it can take data in both forms, arm and trial level, but it looks as if the arm-level information would be converted into trial one through escalc and the latter then used for the meta-analysis. Is that right? Many thanks. Angelo -- NIHR Research Methods Training Fellow, Department of Community Based Medicine University of Bristol 25 Belgrave Road Bristol BS8 2AA Tel. 0779 265-6552 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] accessing return variables from a function
which is just unlist(sort(x, index.return=T)) but I think, Noah would like to have something like srt-sort(x, index.return=T) names(srt)-c(y,indexes) attach(srt) but that is wasteful either. Am 09.07.2010 12:28, schrieb David Winsemius: On Jul 9, 2010, at 5:20 AM, Noah Silverman wrote: Hi, I am trying to figure out a short way to access two values output from the sort function. x - c(3,4,3,6,78,3,1,2) sort(x, index.return=T) $x [1] 1 2 3 3 3 4 6 78 $ix [1] 7 8 1 3 6 2 4 5 It would be great to do something like this (doesn't work.): yoursort - function(x) {sx - sort(x, index.return=T); return( c(sx$x, sx$ix) )} yoursort(x) [1] 1 2 3 3 3 4 6 78 7 8 1 3 6 2 4 5 c(y, indexes) - sort(x, index.return=T) But that doesn't work. I CAN grab the output of sort in a variable and then access it twice to get the values, but that seems wasteful. Any ideas? David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Current script name from R
I'm assuming you are using Rscript (please provide self-contained examples when posting) in which case you could look for the element in (base|R.utils)::commandArgs() that begin with the string --file= - the rest is the file name. See the asValues= parameter in help(commandArgs, package=R.utils) for a nice way to get the parameter. For an invocation of the form R foo.R you'd need to inspect your system's process table (so don't do that). Hope this helps. Allan On 09/07/10 10:48, Ralf B wrote: Is there a way for a script to find out about its own name ? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Current script name from R
I am using RGUI, the command line or the StatET Eclipse environment. Should this not all be the same? Ralf On Fri, Jul 9, 2010 at 7:11 AM, Allan Engelhardt all...@cybaea.com wrote: I'm assuming you are using Rscript (please provide self-contained examples when posting) in which case you could look for the element in (base|R.utils)::commandArgs() that begin with the string --file= - the rest is the file name. See the asValues= parameter in help(commandArgs, package=R.utils) for a nice way to get the parameter. For an invocation of the form R foo.R you'd need to inspect your system's process table (so don't do that). Hope this helps. Allan On 09/07/10 10:48, Ralf B wrote: Is there a way for a script to find out about its own name ? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] transformation of data.frame
Hello Petr, sorry for the mixed up. your example works perfectly fine. The one from Søren has shown the mentioned error. But even after reading the columns as character go - read.table(go.txt, header= TRUE, colClasses = c(character, character)) or go - read.table(go.txt, header= TRUE, as.is = 1) it didn't solve the problem. the command: gmt - lapplyBy(~GO, data = go, FUN = function(uu) {as.list(uu$GO[1], paste(uu$gen, collapse = ))}) tries to convert my first column into integers and thand add 'NA's. What I don't understand is why. Does lapplyBy can work only with integers? THX, Assa 2010/7/8 Petr PIKAL petr.pi...@precheza.cz Hi r-help-boun...@r-project.org napsal dne 08.07.2010 12:02:45: I don't understand it. When I'm doing this example it wirks fine, but when I'm adding the GO: to the beginning of the first column (as to see in my wanted result table: GO0042787 GO0016070 GO0016070 I'm getting a list of warning: Warning messages: 1: In storage.mode(xi) - a$sm : NAs introduced by coercion 2: In storage.mode(xi) - a$sm : NAs introduced by coercion ... 9: In storage.mode(xi) - a$sm : NAs introduced by coercion 10: In storage.mode(xi) - a$sm : NAs introduced by coercion Not sure what is wrong, it seems to me that your ID become factor. Having your data in dataframe test as character columns see ?str test.ag-aggregate(test$X.gen, list(test$ID), function(x) paste(x, collapse=:)) I can make aggregated data frame paste(GO,test.ag[,1], sep=) [1] GO0006417 GO0006511 GO0007409 GO0016070 GO0042787 and it is strightforward to add GO at the beginning. I leave how to add this result to your aggregated data frame as an exercise. Regards Petr What did I do wrong here? Assa On Thu, Jul 8, 2010 at 11:09, Sĸren Hĸjsgaard soren.hojsga...@agrsci.dkwrote: Like this? library(doBy) (ddd - read.table(foo.txt,header=T)) ID gen 1 42787 gen2 2 16070 gen2 3 16070 gen3 4 7409 Gen1 5 7409 gen3 6 6511 gen2 7 6417 gen3 8 16070 gen4 9 6511 gen4 aa-lapplyBy(~ID, data=ddd, + FUN=function(uu){ + list(uu$ID[1], paste(uu$gen, collapse=:)) + }) do.call(rbind,aa) [,1] [,2] 42787 42787 gen2 16070 16070 gen2:gen3:gen4 7409 7409 Gen1:gen3 6511 6511 gen2:gen4 6417 6417 gen3 Regards Sĸren -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] PÄÄ vegne af Assa Yeroslaviz Sendt: 8. juli 2010 10:45 Til: r-h...@stat.math.ethz.ch Emne: [R] transformation of data.frame Hello all R users, I have a problems transforming (or maybe better regrouping) a data.frame. I have a big data.frame, which I would like to sum up according to a specific column. This is an example of my matrix: IDgen 0042787gen2 0016070gen2 0016070gen3 0007409Gen1 0007409gen3 0006511gen2 0006417gen3 0016070gen4 0006511gen4 I want to rearrange the matrix according to column GO, so that it will look likes that: GO:0042787 gen2 GO:0016070gen2 : gen3 : gen4 GO:0007409gen1 : gen3 GO:0006511gen2 : gen4 GO:0006417gen3 I've tried it with the package doBy (lapplyBy and paste) but it just doesn't work out. I will be very happy for any suggestions you might have to help me. Thanks Assa [[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. [[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] sarima.Sim function
Does anyone have some a nice simple example of how this function is used? Thanks, Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mirror axis on hist2d plot - how?
The following code produces a heatmap based on normalized data. I would like to mirror x and y axis for this plot. Any idea how to do that? require(gplots) x - rnorm(500) y - rnorm(500) hist2d(x, y, freq=TRUE, nbins=50, col = c(white,heat.colors(256))) Best, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 not to print '\\' as '\\'
On Tue, 2010-07-06 at 19:08 -0700, Joshua Wiley wrote: Try cat(), for instance: cat(\\\n) \ The extra \n is needed for a proper line break. Or writeLines(\\) Which handles the newline for you. ?writeLines. HTH G HTH, Josh On Tue, Jul 6, 2010 at 7:01 PM, thmsfuller...@gmail.com thmsfuller...@gmail.com wrote: Hello All, '\\' is printed as '\\', but it is actually only one character. Sometimes, I'd rather print it as a single '\'. Is there a function to do so in R? nchar('\\') [1] 1 print('\\') [1] \\ -- Tom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
Re: [R] Appropriate tests for logistic regression with a continuous predictor variable and Bernoulli response variable
Have a look at ?anova or rather ?anova.glm hth Am 09.07.2010 04:46, schrieb Kiyoshi Sasaki: I have a data with binary response variable, repcnd (pregnant or not) and one predictor continuous variable, svl (body size) as shown below. I did Hosmer-Lemeshow test as a goodness of fit (as suggested by a kind “R-helper” previously). To test whether the predictor (svl, or body size) has significant effect on predicting whether or not a female snake is pregnant, I used the differences between null deviance and residual deviance using a code as following: 1-pchisq(mod.fit$null.deviance - mod.fit$deviance, mod.fit$df.null - mod.fit$df.residual) Could anyone tell me whether I did the test properly? I did this test because I thought Wald test/z score listed in the output from summary(mod.fit) is not appropriate for a kind of data I have. Does R have automated function to run appropriate tests? I have pasted my R output below. Thank you in advance for your time and help. Kiyoshi repcnd svl 1 1 51.5 2 1 52.5 edited 294 0 59.8 298 1 60.0 300 1 51.7 301 1 57.4 302 1 60.9 303 0 56.8 304 0 50.0 --- mod.fit - glm(formula = gb.no.M$repcnd ~ gb.no.M$svl, family = binomial(link = logit), data = gb.no.M, na.action = na.exclude, control = list(epsilon = 0.0001, maxit = 50, trace = F)) summary(mod.fit) Call: glm(formula = gb.no.M$repcnd ~ gb.no.M$svl, family = binomial(link = logit), data = gb.no.M, na.action = na.exclude, control = list(epsilon = 1e-04, maxit = 50, trace = F)) Deviance Residuals: Min 1Q Median 3Q Max -1.757 -1.109 0.734 1.113 1.632 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) -7.085651.84106 -3.849 0.000119 *** gb.no.M$svl 0.135290.03474 3.894 9.85e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 301.92 on 217 degrees of freedom Residual deviance: 285.04 on 216 degrees of freedom (8 observations deleted due to missingness) AIC: 289.04 Number of Fisher Scoring iterations: 3 --- Hosmer-Lemeshow test hosmerlem - function (y, yhat, g = 10) + { + cutyhat - cut(yhat, breaks = quantile(yhat, probs = seq(0, 1, 1/g)), include.lowest = T) + obs - xtabs(cbind(1 - y, y) ~ cutyhat) + expect - xtabs(cbind(1 - yhat, yhat) ~ cutyhat) + chisq - sum((obs - expect)^2/expect) + P - 1 - pchisq(chisq, g - 2) + c(X^2 = chisq, Df = g - 2, P(Chi) = P) + } mod.fit - glm(formula = no.NA$repcnd ~ no.NA$svl, family = binomial(link = logit), data = no.NA, na.action = na.exclude, control = list(epsilon = 0.0001, maxit = 50, trace = F)) hosmerlem(no.NA$repcnd, fitted(mod.fit)) X^2Df P(Chi) 6.8742531 8.000 0.5502587 --- list(p.value = round(1-pchisq(mod.fit$null.deviance - mod.fit$deviance, + mod.fit$df.null- mod.fit$df.residual),6), + df = mod.fit$df.null- mod.fit$df.residual, + change = mod.fit$null.deviance - mod.fit$deviance) $p.value [1] 4e-05 $df [1] 1 $change [1] 16.87895 [[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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Data format question for triangle.plot package ade4
hello, I am trying to develop a triangle plot but am having difficultly assigning the row.names to the 3 columns in the data.frame Here is what I've done, attach(SoilVegHydro) dim(SoilVegHydro) 129239 # now take 3 variables from main data.frame for plotting dat - cbind.data.frame(TP, meanAnnualDepthAve, BulkDensity) # These are variables held in the data frame SoilVegHydro row.names(dat) - paste(row.names(SoilVegHydro$Physiogomy), rep(c(1,2,3), rep(1292, 3)), sep = ) # following the syntax from the help triangle.plot page this is returned when the last line is submitted. row.names(dat) - paste(row.names(SoilVegHydro$Physiogomy), rep(c(1,2,3), rep(1292,3)), sep=) Error in `row.names-.data.frame`(`*tmp*`, value = c(1, 1, 1, 1, : invalid 'row.names' length I'm not certain how to define the row.names . If anyone can help I'd appreciate it. I'm using R 2.11.1 (2010-5-31) on Windows XP Thanks Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] random sample from arrays
Hi Joris, I guess i did it wrong again. but your example didn't work either. I still get the error massage. but replicate function just fine. I can even replicate the whole array lines. THX Assa On Thu, Jul 8, 2010 at 15:20, Joris Meys jorism...@gmail.com wrote: Don't know what exactly you're trying to do, but you make a matrix with 11 columns and 50 rows, then treat it as a vector. On top of that, you try to fill 50 rows/columns with 50 values. Off course that doesn't work. Did you check the warning messages when running the code? Either do : for(i in c(1:11)){ set[,i] -sample(x,50) print(c(i,-, set), quote = FALSE) } or for(i in c(1:50)){ set[i,] -sample(x,11) print(c(i,-, set), quote = FALSE) } Or just forget about the loop altogether and do : set - replicate(11,sample(x,50)) or set - t(replicate(50,sample(x,11))) cheers On Thu, Jul 8, 2010 at 8:04 AM, Assa Yeroslaviz fry...@gmail.com wrote: Hello R users, I'm trying to extract random samples from a big array I have. I have a data frame of over 40k lines and would like to produce around 50 random sample of around 200 lines each from this array. this is the matrix ID xxx_1c xxx__2c xxx__3c xxx__4c xxx__5T xxx__6T xxx__7T xxx__8T yyy_1c yyy_1c _2c 1 A_512 2.150295 2.681759 2.177138 2.142790 2.115344 2.013047 2.115634 2.189372 1.643328 1.563523 2 A_134 12.832488 12.596373 12.882581 12.987091 11.956149 11.994779 11.650336 11.995504 13.024494 12.776322 3 A_152 2.063276 2.160961 2.067549 2.059732 2.656416 2.075775 2.033982 2.111937 1.606340 1.548940 4 A_163 9.570761 10.448615 9.432859 9.732615 10.354234 10.993279 9.160038 9.104121 10.079177 9.828757 5 A_184 3.574271 4.680859 4.517047 4.047096 3.623668 3.021356 3.559434 3.156093 4.308437 4.045098 6 A_199 7.593952 7.454087 7.513013 7.449552 7.345718 7.367068 7.410085 7.022582 7.668616 7.953706 ... I tried to do it with a for loop: genelist - read.delim(/user/R/raw_data.txt) rownames(genelist) - genelist[,1] genes - rownames(genelist) x - 1:4 set - matrix(nrow = 50, ncol = 11) for(i in c(1:50)){ set[i] -sample(x,50) print(c(i,-, set), quote = FALSE) } which basically do the trick, but I just can't save the results outside the loop. After having the random sets of lines it wasn't a problem to extract the line from the arrays using subset. genSet1 -sample(x,50) random1 - genes %in% genSet1 subsetGenelist - subset(genelist, random1) is there a different way of creating these random vectors or saving the loop results outside tjhe loop so I cn work with them? Thanks a lot Assa [[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. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C module causing rounding errors?
Sorry for not including enough information everyone. I have quite a bit of code, so I will just enter relevant pieces... This is how I call C from R: The tstats are tstatistics (difference of mean, divided by sqrt of S1+S2) from an unpermuted matrix. The c code is below... dyn.load(testp.so) obj-.C(testp,ptests=as.array(permuted_ttests),as.integer(B),permuted1=as.array(permuted),matrix=as.array(Imatrix), as.integer(ncols), as.integer(nrows),as.integer(g)*,as.array(abs(tstats)* ),pvalues=as.array(ps)) to test, I decided not to permute my matrix and just send it the original matrix, Imatrix. Everything in C is a double, or if I use an integer, I cast it to a double (to divide and get mean, etc). I then compare the values of the tstats that I sent into C and the tsats I calculate within C... The following is my C code: void testp(double *permuted_ttests,int *B,double *permuted,double *Imatrix,int *nc,int *nr,int *g,*double *Tinitial*,double *ps) { after which, using the variable above I take the mean of certain elements (currently the unpermuted matrix to test) via other functions using the same double and pointers and I store them in C1 and C2 and solve for an absolute T statistic - and print it (I erased the Ts earlier). for (i=0; i*nr; i++){ xbardiff = C1[i][0]-C2[i][0]; denom = sqrt(C1[i][2]+C2[i][2]); * Ts[i]=fabs(xbardiff/denom);* * Rprintf(%f Ts\n,Ts[i]);* * if (fabs(Ts[i])fabs(Tinitial[i])){ //summing of permueted_ttests counter[i]++; Rprintf(ts %f and tinitial %f \n, Ts[i],Tinitial[i]); } * etc... The issue here - is that I get a few that when printed it appears that they were rounded up - causing my counter[i] to ++ in some cases. Should I send more code? Sorry and thank you very much, On Fri, Jul 9, 2010 at 6:18 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: Joseph N. Paulson wrote: Hi all! I am currently writing a C-module for a for loop in which I permute columns in a matrix (bootstrapping) and I send a couple of variables into C initially. All of it is working, except the initial values I send to R are rounded/truncated (I believe rounded). I am using a 32 bit machine to compile, I am using (I believe) 32 bit R While debugging I print the values I am sending to C, and then I print the same values using Rprintf and the number gets rounded to 10^-6, which is actually causing some errors for me. Is there any way to correct/prevent the error? sample output from R [1,] 1.000 [2,] 1.0256242 [3,] 1.1826277 [4,] -0.6937246 [5,] 1.3633604 sample output from C 1.00 1.025624 1.182628 0.693725 1.363360 It looks as though you are confusing the display of numbers with their internal values. R is printing 7 decimal places, C is printing 6. As far as we can tell, that's the only difference. Duncan Murdoch [[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. -- - Joseph N. Paulson [[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] Data format question for triangle.plot package ade4
On Jul 8, 2010, at 4:41 PM, steve_fried...@nps.gov wrote: hello, I am trying to develop a triangle plot but am having difficultly assigning the row.names to the 3 columns in the data.frame Here is what I've done, attach(SoilVegHydro) dim(SoilVegHydro) 129239 # now take 3 variables from main data.frame for plotting dat - cbind.data.frame(TP, meanAnnualDepthAve, BulkDensity) # These are variables held in the data frame SoilVegHydro Did that dat object have what you wanted? The function call did not make any reference to SoilVegHydro. What does str(dat) return? Oh, never mind, I now see you use attach. row.names(dat) - paste(row.names(SoilVegHydro$Physiogomy), Generally row.names is used on a dataframe rather than on a column vector. dat - data.frame(1:3, LETTERS[1:3]) row.names(dat$X1) row.names(dat) [1] 1 2 3 length(row.names(dat$X1)) [1] 0 rep(c(1,2,3), rep(1292, 3)), sep = ) # following the syntax from the help triangle.plot page this is returned when the last line is submitted. row.names(dat) - paste(row.names(SoilVegHydro$Physiogomy), rep(c(1,2,3), rep(1292,3)), sep=) Error in `row.names-.data.frame`(`*tmp*`, value = c(1, 1, 1, 1, : invalid 'row.names' length I'm not certain how to define the row.names . If anyone can help I'd appreciate it. I'm using R 2.11.1 (2010-5-31) on Windows XP Thanks Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to plot two histograms overlapped in the same plane coordinate
Dear R-help listers, I am new. I just want to get helps on how to plot two histograms overlapped in the same plane coordinate. What I did is very ugly. Could you please help me to improve it? I want to got a plot with semi- transparent overlapping region. And, I want to know how to specify the filled colors of the different histograms. I also prefer other solutions other than ggplot2. Many thanks to you. What I have done: library(ggplot2) age-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1)) sex-c(rep(F,100), rep(M, 100)) mydata-cbind(age, sex) mydata-as.data.frame(mydata) head(mydata) qplot(age, data=mydata, geom=histogram, fill=sex, xlab=age, ylab=count, alpha=I(0.5)) Best, Mao J-F __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] KLdiv produces NA. Why?
On 2010-07-09 4:31, Ralf B wrote: I am trying to calculate a Kullback-Leibler divergence from two vectors with integers but get NA as a result when trying to calulate the measure. Why? x- cbind(stuff$X, morestuff$X) x[1:5,] [,1] [,2] [1,] 293 938 [2,] 293 942 [3,] 297 949 [4,] 290 956 [5,] 294 959 KLdiv(x) [,1] [,2] [1,]0 NA [2,] NA0 I assume that you're using KLdiv() from pkg flexmix. (You should always indicate any add-on packages used.) I have no problem with KLdiv on the above 5-by-2 matrix (R 2.11.1pat, flexmix 2.2-7). Perhaps one of the following may be the case: 1. your R and/or flexmix is outdated; 2. dependencies were not installed (modeltools?) 3. there's something weird about your x[,] -Peter Ehlers Best, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] distributing a value for a given month across the number of weeks in that month
Hello! Any hint would be greatly appreciated. I have a data frame that contains (a) monthly dates and (b) a value that corresponds to each month - see the data frame monthly below: monthly-data.frame(month=c(20100301,20100401,20100501),monthly.value=c(100,200,300)) monthly$month-as.character(monthly$month) monthly$month-as.Date(monthly$month,%Y%m%d) (monthly) I need to split each month into weeks, e.g., weeks that start on Monday (it could as well be Sunday - it does not really matter) and distribute the monthly value evenly across weeks. So, if a month has 5 Mondays, then the monthly value should be dividied by 5, but if a month has only 4 weeks, then the monthly value should be divided by 4. The output I need is like this: week weekly.value 2010-03-01 20 2010-03-08 20 2010-03-15 20 2010-03-22 20 2010-03-29 20 2010-04-05 50 2010-04-12 50 2010-04-19 50 2010-04-26 50 2010-05-03 60 2010-05-10 60 2010-05-17 60 2010-05-24 60 2010-05-31 60 Thanks a lot for your advice! -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] Function on columns of a dataframe
Hi, I would like to assign the largest value of a column to a specific category and repeat this for each column (v1 - v4). x=c(1:12) cat=c(cat1,cat5,cat2,cat2,cat1,cat5,cat3,cat4,cat5,cat2,cat3,cat6) v1=rnorm(12,0.5,0.1) v2=rnorm(12,0.3,0.2) v3=rnorm(12,0.4,0.1) v4=rnorm(12,0.6,0.3) bla=data.frame(x,cat,v1,v2,v3,v4) bla x catv1 v2v3 v4 1 1 cat1 0.4013144 0.54839317 0.3946393 0.8679266 2 2 cat5 0.4595873 0.45788906 0.4030078 0.5919596 3 3 cat2 0.4542865 0.21516928 0.2777649 0.6112099 4 4 cat2 0.4787950 0.06252512 0.5095611 0.6450795 5 5 cat1 0.4910746 0.56591049 0.5151813 0.8465181 6 6 cat5 0.4194397 0.16592579 0.4361643 0.6415192 7 7 cat3 0.6148564 0.32240342 0.2690108 0.7114133 8 8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284 9 9 cat5 0.4775395 0.28611768 0.4660210 0.4634120 10 10 cat2 0.4802962 0.03715569 0.4506361 1.0063235 11 11 cat3 0.6495094 0.33303172 0.3352933 1.4390324 12 12 cat6 0.4891481 0.45355589 0.3880739 0.7831656 I can assign this by the sqldf() command for each column but I would like to automate this as I have many columns. select=sqldf(select cat, max(v1) FROM bla GROUP BY cat) select cat max(v1) 1 cat1 0.4910746 2 cat2 0.4802962 3 cat3 0.6495094 4 cat4 0.6174652 5 cat5 0.4775395 6 cat6 0.4891481 Finally, I would like to have a dataframe where where the cat is followed by each column maximum. Thanks for your help! -- View this message in context: http://r.789695.n4.nabble.com/Function-on-columns-of-a-dataframe-tp2283217p2283217.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] Function on columns of a dataframe
Hi Nils, have a look at ?tapply hth. Am 09.07.2010 15:37, schrieb LogLord: Hi, I would like to assign the largest value of a column to a specific category and repeat this for each column (v1 - v4). x=c(1:12) cat=c(cat1,cat5,cat2,cat2,cat1,cat5,cat3,cat4,cat5,cat2,cat3,cat6) v1=rnorm(12,0.5,0.1) v2=rnorm(12,0.3,0.2) v3=rnorm(12,0.4,0.1) v4=rnorm(12,0.6,0.3) bla=data.frame(x,cat,v1,v2,v3,v4) bla x catv1 v2v3 v4 1 1 cat1 0.4013144 0.54839317 0.3946393 0.8679266 2 2 cat5 0.4595873 0.45788906 0.4030078 0.5919596 3 3 cat2 0.4542865 0.21516928 0.2777649 0.6112099 4 4 cat2 0.4787950 0.06252512 0.5095611 0.6450795 5 5 cat1 0.4910746 0.56591049 0.5151813 0.8465181 6 6 cat5 0.4194397 0.16592579 0.4361643 0.6415192 7 7 cat3 0.6148564 0.32240342 0.2690108 0.7114133 8 8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284 9 9 cat5 0.4775395 0.28611768 0.4660210 0.4634120 10 10 cat2 0.4802962 0.03715569 0.4506361 1.0063235 11 11 cat3 0.6495094 0.33303172 0.3352933 1.4390324 12 12 cat6 0.4891481 0.45355589 0.3880739 0.7831656 I can assign this by the sqldf() command for each column but I would like to automate this as I have many columns. select=sqldf(select cat, max(v1) FROM bla GROUP BY cat) select cat max(v1) 1 cat1 0.4910746 2 cat2 0.4802962 3 cat3 0.6495094 4 cat4 0.6174652 5 cat5 0.4775395 6 cat6 0.4891481 Finally, I would like to have a dataframe where where the cat is followed by each column maximum. Thanks for your help! -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding
Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? And how can I end up with the right answer? Thanks a lot everybody for your help. Trafim [[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] strange floor rounding
You too have fallen victim to floating point error (see FAQ 7.31). (100*.58) == 58 [1] FALSE (100*.58) 58 [1] TRUE On Fri, Jul 9, 2010 at 9:46 AM, Trafim Vanishek rdapam...@gmail.com wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? And how can I end up with the right answer? Thanks a lot everybody for your help. Trafim -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding
On Jul 9, 2010, at 8:46 AM, Trafim Vanishek wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? And how can I end up with the right answer? Thanks a lot everybody for your help. Trafim sprintf(%.20f, 100 * .58) [1] 57.99289457 See R FAQ 7.31 HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Function on columns of a dataframe
On Jul 9, 2010, at 9:46 AM, Eik Vettorazzi wrote: Hi Nils, have a look at ?tapply hth. Perhaps this will be part way there (I couldn't really figure out the desired structure of the final object): lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) ) $v1 cat1 cat2 cat3 cat4 cat5 cat6 0.4634519 0.4062700 0.4816403 0.6354560 0.6663811 0.5260832 $v2 cat1 cat2 cat3 cat4 cat5 cat6 0.5274645 0.4282639 0.4996033 0.3558259 0.2154201 0.3934063 $v3 cat1 cat2 cat3 cat4 cat5 cat6 0.6051479 0.4443707 0.3538144 0.3646292 0.5059900 0.3545962 $v4 cat1 cat2 cat3 cat4 cat5 cat6 0.7586322 0.8419526 0.9456385 0.1907295 0.7573575 0.6412563 Am 09.07.2010 15:37, schrieb LogLord: Hi, I would like to assign the largest value of a column to a specific category and repeat this for each column (v1 - v4). x=c(1:12) cat = c (cat1 ,cat5 ,cat2 ,cat2,cat1,cat5,cat3,cat4,cat5,cat2,cat3,cat6) v1=rnorm(12,0.5,0.1) v2=rnorm(12,0.3,0.2) v3=rnorm(12,0.4,0.1) v4=rnorm(12,0.6,0.3) bla=data.frame(x,cat,v1,v2,v3,v4) bla x catv1 v2v3 v4 1 1 cat1 0.4013144 0.54839317 0.3946393 0.8679266 2 2 cat5 0.4595873 0.45788906 0.4030078 0.5919596 3 3 cat2 0.4542865 0.21516928 0.2777649 0.6112099 4 4 cat2 0.4787950 0.06252512 0.5095611 0.6450795 5 5 cat1 0.4910746 0.56591049 0.5151813 0.8465181 6 6 cat5 0.4194397 0.16592579 0.4361643 0.6415192 7 7 cat3 0.6148564 0.32240342 0.2690108 0.7114133 8 8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284 9 9 cat5 0.4775395 0.28611768 0.4660210 0.4634120 10 10 cat2 0.4802962 0.03715569 0.4506361 1.0063235 11 11 cat3 0.6495094 0.33303172 0.3352933 1.4390324 12 12 cat6 0.4891481 0.45355589 0.3880739 0.7831656 I can assign this by the sqldf() command for each column but I would like to automate this as I have many columns. select=sqldf(select cat, max(v1) FROM bla GROUP BY cat) select cat max(v1) 1 cat1 0.4910746 2 cat2 0.4802962 3 cat3 0.6495094 4 cat4 0.6174652 5 cat5 0.4775395 6 cat6 0.4891481 Finally, I would like to have a dataframe where where the cat is followed by each column maximum. Thanks for your help! -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange floor rounding
On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? FAQ 7.31 And how can I end up with the right answer? Define right, please. (There have been several questions in the last week for which FAQ 7.31 was the answer and some of the responses had useful links.) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help for mca
Good eveninig, I work on R and i want to do an MCA but, i find difficulty in calculating the contribution (CTR), cosine(CO2), coord(CORD) and distancefrom the center of the modalities of variables. Please help me how to calculate these values. In fact, when i enter the variables it writes variable not found Thank you Housseima _ Hotmail : un service de messagerie gratuit, fiable et complet [[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] Non-parametric regression
Just to be correct : gam is mentioned on the page Tal linked to, but is a semi-parametric approach using maximum likelihood. It stays valid though. Another thing : you detect non-normality. But can you use a Poisson distribution for example? The framework of generalized linear models and generalized additive models allows you to deal with non-normality of your data. In any case, I suggest you contact a statistician nearby for guidance. Cheers Joris On Fri, Jul 9, 2010 at 10:26 AM, Tal Galili tal.gal...@gmail.com wrote: From reviewing the first google page result for Non-parametric regression R, I hope this link will prove useful: http://socserv.mcmaster.ca/jfox/Courses/Oxford-2005/R-nonparametric-regression.html Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 9, 2010 at 11:01 AM, Ralf B ralf.bie...@gmail.com wrote: I have two data sets, each a vector of 1000 numbers, each vector representing a distribution (i.e. 1000 numbers each of which representing a frequency at one point on a scale between 1 and 1000). For similfication, here an short version with only 5 points. a - c(8,10,8,12,4) b - c(7,11,8,10,5) Leaving the obvious discussion about causality aside fro a moment, I would like to see how well i can predict b from a using a regression. Since I do not know anything about the distribution type and already discovered non-normality I cannot use parametric regression or anything GLM for that matter. How should I proceed in using non-parametric regression to model vector a and see how well it predicts b? Perhaps you could extend the given lines into a short example script to give me an idea? Are there any other options? Best, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] split with list
One solution is to put these unwanted entries to repor$9853312 [1:2,2:3] - Cheers Joris On Fri, Jul 9, 2010 at 12:18 PM, n.via...@libero.it n.via...@libero.it wrote: Dear List I would like to ask you something concenting a better print of the R output: I have a bit data frame which has the following structure: CFISCALE RAGSOCB ANNO VAR1 VAR2. 9853312 astra 2005 6 45 9853312 astra 2006 78 45 9853312 astra 2007 55 76 9653421 geox 2005 35 89 9653421 geox 2006 24 33 9653421 geox 2007 54 55 The first thing I did is to split my data frame for CFISCALE. The result is that R has transformed my data frame into a list. The second step was to transpose each element of my list. repo=split(rep,rep$CFISCALE) repor=lapply(repo,function(x){ t(x)}) When I print my list the format is the following $9853312 1 2 3 CFISCALE 9853312 9853312 9853312 RAGSOCB astra astra astra ANNO 2005 2006 2007 VAR1 6 78 55 VAR2 45 45 76 There is a way to remove the first row I mean 1, 2 , 3 and to have just one CFISCALE and RAGSOCB??? For the second problem I tried to use unique but it seems that it doesnt work for list. So what I would like to get is: $9853312 CFISCALE 9853312 RAGSOCB astra ANNO 2005 2006 2007 VAR1 6 78 55 VAR2 45 45 76 This is because I next run xtable on my list in order to get a table in Latex, which I woud like to be in a nice format. Thanks a lot for your attention! [[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. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 can achive step by step execution of the script
-- View this message in context: http://r.789695.n4.nabble.com/how-can-achive-step-by-step-execution-of-the-script-tp2283207p2283207.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How can i draw a graph with high and low data points
Hi Tal, Thanks for your help. I've had a look at the site, and what i wanted to do was to plot X and Y where X is a characters and Y is numeric. The problem I'm having now is that the X axis isn't characters but just numbers from 1 onwards and when i plot it, the data i have is in descending order which isn't shown on the graph. I have this at the moment: plot(1:nrow(dat),dat$Mean,type=b,xaxt=n, ylim=c(min(dat$lci),max(dat$uci)), xlab=,ylab=HR,) It gives me sort of what I want. It has the Y values in descending order, but it doesn't give me the text on the x axis and I was also thinking of plotting the upper and lower confidence intervals with a line connecting the two. I can add in the upper and lower CI values separately, but I don't know how to join the two together. -- View this message in context: http://r.789695.n4.nabble.com/How-can-i-draw-a-graph-with-high-and-low-data-points-tp2282524p2283194.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] installing packages over ssh without X forwarding
Hi, Is it possible to install packages without the testing if installed package can be loaded? I need to install bunch of packages on multiple computers over ssh. Some packages witch interact with X11 display cannot be installed in this way. for example after: install.packages('cairoDevice',dep=T) I get (...) *** installing help indices ** building package indices ... ** testing if installed package can be loaded Error : .onLoad failed in loadNamespace() for 'cairoDevice', details: call: fun(...) error: GDK display not found - please make sure X11 is running ERROR: loading failed * removing #8216;/usr/local/lib64/R/library/cairoDevice#8217; * restoring previous #8216;/usr/local/lib64/R/library/cairoDevice#8217; The downloaded packages are in #8216;/tmp/Rtmpk1XxTl/downloaded_packages#8217; Updating HTML index of packages in '.Library' Warning message: In install.packages(cairoDevice, dep = T) : installation of package 'cairoDevice' had non-zero exit status When I connect with remote computer using ssh -X r...@nod1 to enable X11 forwarding then installation works without problems. This would however require manually connect with each administred computer a do the installation. cssh which I use now to install packages on multiple computers does not enable X11 forwarding. I have also tested installation using R CMD INSTALL with --no-test-load options but the packages are loaded unsuccesfully anyway. So is it possible to turn of package testing? 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] distributing a value for a given month across the number of weeks in that month
On Fri, Jul 9, 2010 at 9:35 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! Any hint would be greatly appreciated. I have a data frame that contains (a) monthly dates and (b) a value that corresponds to each month - see the data frame monthly below: monthly-data.frame(month=c(20100301,20100401,20100501),monthly.value=c(100,200,300)) monthly$month-as.character(monthly$month) monthly$month-as.Date(monthly$month,%Y%m%d) (monthly) I need to split each month into weeks, e.g., weeks that start on Monday (it could as well be Sunday - it does not really matter) and distribute the monthly value evenly across weeks. So, if a month has 5 Mondays, then the monthly value should be dividied by 5, but if a month has only 4 weeks, then the monthly value should be divided by 4. The output I need is like this: week weekly.value 2010-03-01 20 2010-03-08 20 2010-03-15 20 2010-03-22 20 2010-03-29 20 2010-04-05 50 2010-04-12 50 2010-04-19 50 2010-04-26 50 2010-05-03 60 2010-05-10 60 2010-05-17 60 2010-05-24 60 2010-05-31 60 There is new functionality in na.locf in the development version of zoo that makes it particularly convenient to do this. First create a zoo object z from monthly and get a vector of all the mondays. Then use na.locf to place the monthly value in each monday and ave to distribute them out. library(zoo) # pull in development version of na.locf.zoo source(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/na.locf.R?revision=725root=zoo;) # convert to zoo z - with(monthly, zoo(monthly.value, month)) # get sequence of all dates and from that get mondays all.dates - seq(start(z), as.Date(as.yearmon(end(z)), frac = 1), by = day) mondays - all.dates[weekdays(all.dates) == Monday] # use na.locf to fill in mondays and ave to distribute them weeks - na.locf(z, xout = mondays) weeks[] - ave(weeks, as.yearmon(mondays), FUN = function(x) x[1]/length(x)) # show output in a few different formats weeks as.data.frame(weeks) data.frame(Monday = as.Date(time(weeks)), value = weeks) data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL) plot(weeks) The output looks like this: weeks 2010-03-01 2010-03-08 2010-03-15 2010-03-22 2010-03-29 2010-04-05 2010-04-12 20 20 20 20 20 50 50 2010-04-19 2010-04-26 2010-05-03 2010-05-10 2010-05-17 2010-05-24 2010-05-31 50 50 60 60 60 60 60 as.data.frame(weeks) weeks 2010-03-0120 2010-03-0820 2010-03-1520 2010-03-2220 2010-03-2920 2010-04-0550 2010-04-1250 2010-04-1950 2010-04-2650 2010-05-0360 2010-05-1060 2010-05-1760 2010-05-2460 2010-05-3160 data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL) Monday value 1 2010-03-0120 2 2010-03-0820 3 2010-03-1520 4 2010-03-2220 5 2010-03-2920 6 2010-04-0550 7 2010-04-1250 8 2010-04-1950 9 2010-04-2650 10 2010-05-0360 11 2010-05-1060 12 2010-05-1760 13 2010-05-2460 14 2010-05-3160 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ttrTests issue in cReturns
cr-cReturns(spData,ttr=MACD) Error in ind[t - k] - pos[t - k + 1] - pos[t - k] : replacement has length zero cr-cReturns(spData,ttr=macd4) Why is the above error coming? macd4 works alright ( which is a custom function built by the ttrTests author) while MACD doesnt work. Thanks -- 'Raghu' [[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 can achive step by step execution of the script
Hi R Experts, I have certain code ,i want to achive interactive execution . For ex: 1. as part of input ,it should ask file name or table name as input. 2.in script so many graphs i need to draw,it should wait till certain key is pressed . 3:i am using windows R,rscript scriptname is not working. Please some one help me. Thanks Experts in advance -- View this message in context: http://r.789695.n4.nabble.com/how-can-achive-step-by-step-execution-of-the-script-tp2283207p2283209.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] Function on columns of a dataframe
you are right. But maybe aggregate is close to the desired result? aggregate(bla, list(bla$cat), max) Am 09.07.2010 16:01, schrieb David Winsemius: On Jul 9, 2010, at 9:46 AM, Eik Vettorazzi wrote: Hi Nils, have a look at ?tapply hth. Perhaps this will be part way there (I couldn't really figure out the desired structure of the final object): lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) ) $v1 cat1 cat2 cat3 cat4 cat5 cat6 0.4634519 0.4062700 0.4816403 0.6354560 0.6663811 0.5260832 $v2 cat1 cat2 cat3 cat4 cat5 cat6 0.5274645 0.4282639 0.4996033 0.3558259 0.2154201 0.3934063 $v3 cat1 cat2 cat3 cat4 cat5 cat6 0.6051479 0.4443707 0.3538144 0.3646292 0.5059900 0.3545962 $v4 cat1 cat2 cat3 cat4 cat5 cat6 0.7586322 0.8419526 0.9456385 0.1907295 0.7573575 0.6412563 Am 09.07.2010 15:37, schrieb LogLord: Hi, I would like to assign the largest value of a column to a specific category and repeat this for each column (v1 - v4). x=c(1:12) cat=c(cat1,cat5,cat2,cat2,cat1,cat5,cat3,cat4,cat5,cat2,cat3,cat6) v1=rnorm(12,0.5,0.1) v2=rnorm(12,0.3,0.2) v3=rnorm(12,0.4,0.1) v4=rnorm(12,0.6,0.3) bla=data.frame(x,cat,v1,v2,v3,v4) bla x catv1 v2v3 v4 1 1 cat1 0.4013144 0.54839317 0.3946393 0.8679266 2 2 cat5 0.4595873 0.45788906 0.4030078 0.5919596 3 3 cat2 0.4542865 0.21516928 0.2777649 0.6112099 4 4 cat2 0.4787950 0.06252512 0.5095611 0.6450795 5 5 cat1 0.4910746 0.56591049 0.5151813 0.8465181 6 6 cat5 0.4194397 0.16592579 0.4361643 0.6415192 7 7 cat3 0.6148564 0.32240342 0.2690108 0.7114133 8 8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284 9 9 cat5 0.4775395 0.28611768 0.4660210 0.4634120 10 10 cat2 0.4802962 0.03715569 0.4506361 1.0063235 11 11 cat3 0.6495094 0.33303172 0.3352933 1.4390324 12 12 cat6 0.4891481 0.45355589 0.3880739 0.7831656 I can assign this by the sqldf() command for each column but I would like to automate this as I have many columns. select=sqldf(select cat, max(v1) FROM bla GROUP BY cat) select cat max(v1) 1 cat1 0.4910746 2 cat2 0.4802962 3 cat3 0.6495094 4 cat4 0.6174652 5 cat5 0.4775395 6 cat6 0.4891481 Finally, I would like to have a dataframe where where the cat is followed by each column maximum. Thanks for your help! -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding
Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve it. I am giving a concrete number and I need to get 58 not 57. Seems, there is no way? On Fri, Jul 9, 2010 at 4:05 PM, David Winsemius dwinsem...@comcast.netwrote: On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? FAQ 7.31 And how can I end up with the right answer? Define right, please. (There have been several questions in the last week for which FAQ 7.31 was the answer and some of the responses had useful links.) -- David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] print.trellis draw.in
I am attempting to plot a trellis object on a grid. vplayout = viewport(layout.pos.row=x, layout.pos.col=y) grid.newpage() pushViewport(viewport(layout=grid.layout(2,2))) g1 = ggplot() ... g2 = ggplot() ... g3 = ggplot() ... p = xyplot() ... # works as expected print(g1, vp=vplayout(1,1)) print(g2, vp=vplayout(1,2)) print(g3, vp=vplayout(2,1)) # does not work print( p, newpage=FALSE, draw.in=vplayout(2,2)$name) Error in grid.Call.graphics(L_downviewport, name$name, strict) : Viewport 'GRID.VP.112' was not found What am I doing wrong? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] installing packages over ssh without X forwarding
On 09/07/2010 7:37 AM, p...@orbit.umbr.cas.cz wrote: Hi, Is it possible to install packages without the testing if installed package can be loaded? I need to install bunch of packages on multiple computers over ssh. Some packages witch interact with X11 display cannot be installed in this way. for example after: install.packages('cairoDevice',dep=T) I get (...) *** installing help indices ** building package indices ... ** testing if installed package can be loaded Error : .onLoad failed in loadNamespace() for 'cairoDevice', details: call: fun(...) error: GDK display not found - please make sure X11 is running ERROR: loading failed * removing #8216;/usr/local/lib64/R/library/cairoDevice#8217; * restoring previous #8216;/usr/local/lib64/R/library/cairoDevice#8217; The downloaded packages are in #8216;/tmp/Rtmpk1XxTl/downloaded_packages#8217; Updating HTML index of packages in '.Library' Warning message: In install.packages(cairoDevice, dep = T) : installation of package 'cairoDevice' had non-zero exit status When I connect with remote computer using ssh -X r...@nod1 to enable X11 forwarding then installation works without problems. This would however require manually connect with each administred computer a do the installation. cssh which I use now to install packages on multiple computers does not enable X11 forwarding. I have also tested installation using R CMD INSTALL with --no-test-load options but the packages are loaded unsuccesfully anyway. So is it possible to turn of package testing? Petr Yes, use the --no-test-load option to R CMD INSTALL, which you can pass through the INSTALL_opts argument to install.packages(). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange floor rounding
On Jul 9, 2010, at 10:27 AM, Trafim Vanishek wrote: Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve it. I am giving a concrete number and I need to get 58 not 57. Seems, there is no way? Building on an example on the help page for as.integer, this seems to be working: trnc2 - function(x) trunc(x) + (trunc(x) x)*sign(x)*(abs(x - trunc(x)) .Machine$double.eps^0.5) trnc2(0.01*100) [1] 1 trnc2(seq(0, 1, by=0.01)*100) [1] 0 1 2 3 4 5 6 8 8 9 10 11 12 13 15 15 16 17 18 19 [21] 20 21 22 23 24 25 26 27 29 28 30 31 32 33 34 35 36 37 38 39 [41] 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 57 59 [61] 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 [81] 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 [101] 100 trnc2(-seq(0, 1, by=0.01)*100) [1]0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 [17] -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -28 -30 -31 [33] -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 [49] -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -57 -59 -60 -61 -62 -63 [65] -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 [81] -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 [97] -96 -97 -98 -99 -100 And after looking at that a bit I came up with a shorter alternate that seems to work as well: trnc3 - function(x) trunc(x+sign(x)* .Machine$double.eps^0.5) See also ?all.equal -- David. On Fri, Jul 9, 2010 at 4:05 PM, David Winsemius dwinsem...@comcast.net wrote: On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? FAQ 7.31 And how can I end up with the right answer? Define right, please. (There have been several questions in the last week for which FAQ 7.31 was the answer and some of the responses had useful links.) -- David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Current script name from R
On 09/07/10 12:18, Ralf B wrote: I am using RGUI, the command line or the StatET Eclipse environment. Should this not all be the same? No, there is no particular reason why they should. Allan Ralf On Fri, Jul 9, 2010 at 7:11 AM, Allan Engelhardtall...@cybaea.com wrote: I'm assuming you are using Rscript (please provide self-contained examples when posting) in which case you could look for the element in (base|R.utils)::commandArgs() that begin with the string --file= - the rest is the file name. See the asValues= parameter in help(commandArgs, package=R.utils) for a nice way to get the parameter. For an invocation of the form R foo.R you'd need to inspect your system's process table (so don't do that). Hope this helps. Allan On 09/07/10 10:48, Ralf B wrote: Is there a way for a script to find out about its own name ? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strange floor rounding
On 2010-07-09 8:27, Trafim Vanishek wrote: Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve it. I am giving a concrete number and I need to get 58 not 57. Seems, there is no way? Sure there is: round(100*0.58). -Peter Ehlers On Fri, Jul 9, 2010 at 4:05 PM, David Winsemiusdwinsem...@comcast.netwrote: On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? FAQ 7.31 And how can I end up with the right answer? Define right, please. (There have been several questions in the last week for which FAQ 7.31 was the answer and some of the responses had useful links.) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange floor rounding
On 09/07/2010 10:27 AM, Trafim Vanishek wrote: Thanks everybody for referring me to FAQ 7.31 but I don't see how to solve it. I am giving a concrete number and I need to get 58 not 57. Seems, there is no way? You aren't giving a concrete number. You're giving a string of three characters, which R interprets as a number that's a little bit less than 0.58, because there is no way to represent the number 0.58 in the floating point format that R uses. So it is calculating the right answer. If you want to work with exact 2 decimal place values, you should not use floating point storage. One alternative is to work with integers equal to 100 times the value you want, and then divide by 100 at the very end of the operation for printing. Duncan Murdoch On Fri, Jul 9, 2010 at 4:05 PM, David Winsemius dwinsem...@comcast.netwrote: On Jul 9, 2010, at 9:46 AM, Trafim Vanishek wrote: Dear all, might seem and easy question but I cannot figure it out. floor(100*(.58)) [1] 57 where is the trick here? FAQ 7.31 And how can I end up with the right answer? Define right, please. (There have been several questions in the last week for which FAQ 7.31 was the answer and some of the responses had useful links.) -- David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 on columns of a dataframe
On Jul 9, 2010, at 10:26 AM, Eik Vettorazzi wrote: you are right. But maybe aggregate is close to the desired result? aggregate(bla, list(bla$cat), max) Right. I couldn't get it to work until I removed the first two columns: aggregate(bla[,-(1:2)], list(bla$cat), max) Then I got pretty much the same dataframe as I would have with : as.data.frame(lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) )) v1v2v3v4 cat1 0.4634519 0.5274645 0.6051479 0.7586322 cat2 0.4062700 0.4282639 0.4443707 0.8419526 cat3 0.4816403 0.4996033 0.3538144 0.9456385 cat4 0.6354560 0.3558259 0.3646292 0.1907295 cat5 0.6663811 0.2154201 0.5059900 0.7573575 cat6 0.5260832 0.3934063 0.3545962 0.6412563 Except that aggregate version returns it with a Group.1 column of cats while the other version returned it with the cat names in the rownames. A matter of taste? -- David. Am 09.07.2010 16:01, schrieb David Winsemius: On Jul 9, 2010, at 9:46 AM, Eik Vettorazzi wrote: Hi Nils, have a look at ?tapply hth. Perhaps this will be part way there (I couldn't really figure out the desired structure of the final object): lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) ) $v1 cat1 cat2 cat3 cat4 cat5 cat6 0.4634519 0.4062700 0.4816403 0.6354560 0.6663811 0.5260832 $v2 cat1 cat2 cat3 cat4 cat5 cat6 0.5274645 0.4282639 0.4996033 0.3558259 0.2154201 0.3934063 $v3 cat1 cat2 cat3 cat4 cat5 cat6 0.6051479 0.4443707 0.3538144 0.3646292 0.5059900 0.3545962 $v4 cat1 cat2 cat3 cat4 cat5 cat6 0.7586322 0.8419526 0.9456385 0.1907295 0.7573575 0.6412563 Am 09.07.2010 15:37, schrieb LogLord: Hi, I would like to assign the largest value of a column to a specific category and repeat this for each column (v1 - v4). x=c(1:12) cat = c (cat1 ,cat5 ,cat2 ,cat2,cat1,cat5,cat3,cat4,cat5,cat2,cat3,cat6) v1=rnorm(12,0.5,0.1) v2=rnorm(12,0.3,0.2) v3=rnorm(12,0.4,0.1) v4=rnorm(12,0.6,0.3) bla=data.frame(x,cat,v1,v2,v3,v4) bla x catv1 v2v3 v4 1 1 cat1 0.4013144 0.54839317 0.3946393 0.8679266 2 2 cat5 0.4595873 0.45788906 0.4030078 0.5919596 3 3 cat2 0.4542865 0.21516928 0.2777649 0.6112099 4 4 cat2 0.4787950 0.06252512 0.5095611 0.6450795 5 5 cat1 0.4910746 0.56591049 0.5151813 0.8465181 6 6 cat5 0.4194397 0.16592579 0.4361643 0.6415192 7 7 cat3 0.6148564 0.32240342 0.2690108 0.7114133 8 8 cat4 0.6174652 0.28076152 0.4577064 -0.2567284 9 9 cat5 0.4775395 0.28611768 0.4660210 0.4634120 10 10 cat2 0.4802962 0.03715569 0.4506361 1.0063235 11 11 cat3 0.6495094 0.33303172 0.3352933 1.4390324 12 12 cat6 0.4891481 0.45355589 0.3880739 0.7831656 I can assign this by the sqldf() command for each column but I would like to automate this as I have many columns. select=sqldf(select cat, max(v1) FROM bla GROUP BY cat) select cat max(v1) 1 cat1 0.4910746 2 cat2 0.4802962 3 cat3 0.6495094 4 cat4 0.6174652 5 cat5 0.4775395 6 cat6 0.4891481 Finally, I would like to have a dataframe where where the cat is followed by each column maximum. Thanks for your help! -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] print.trellis draw.in - plaintext (gmail mishap)
I am attempting to plot a trellis object on a grid. vplayout = viewport(layout.pos.row=x, layout.pos.col=y) grid.newpage() pushViewport(viewport(layout=grid.layout(2,2))) g1 = ggplot() ... g2 = ggplot() ... g3 = ggplot() ... p = xyplot() ... # works as expected print(g1, vp=vplayout(1,1)) print(g2, vp=vplayout(1,2)) print(g3, vp=vplayout(2,1)) # does not work print( p, newpage=FALSE, draw.in=vplayout(2,2)$name) Error in grid.Call.graphics(L_downviewport, name$name, strict) : Viewport 'GRID.VP.112' was not found What am I doing wrong? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] distributing a value for a given month across the number of weeks in that month
Wow, Gabor - that's amazing - thank you so much! Dimitri On Fri, Jul 9, 2010 at 10:22 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Fri, Jul 9, 2010 at 9:35 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! Any hint would be greatly appreciated. I have a data frame that contains (a) monthly dates and (b) a value that corresponds to each month - see the data frame monthly below: monthly-data.frame(month=c(20100301,20100401,20100501),monthly.value=c(100,200,300)) monthly$month-as.character(monthly$month) monthly$month-as.Date(monthly$month,%Y%m%d) (monthly) I need to split each month into weeks, e.g., weeks that start on Monday (it could as well be Sunday - it does not really matter) and distribute the monthly value evenly across weeks. So, if a month has 5 Mondays, then the monthly value should be dividied by 5, but if a month has only 4 weeks, then the monthly value should be divided by 4. The output I need is like this: week weekly.value 2010-03-01 20 2010-03-08 20 2010-03-15 20 2010-03-22 20 2010-03-29 20 2010-04-05 50 2010-04-12 50 2010-04-19 50 2010-04-26 50 2010-05-03 60 2010-05-10 60 2010-05-17 60 2010-05-24 60 2010-05-31 60 There is new functionality in na.locf in the development version of zoo that makes it particularly convenient to do this. First create a zoo object z from monthly and get a vector of all the mondays. Then use na.locf to place the monthly value in each monday and ave to distribute them out. library(zoo) # pull in development version of na.locf.zoo source(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/na.locf.R?revision=725root=zoo;) # convert to zoo z - with(monthly, zoo(monthly.value, month)) # get sequence of all dates and from that get mondays all.dates - seq(start(z), as.Date(as.yearmon(end(z)), frac = 1), by = day) mondays - all.dates[weekdays(all.dates) == Monday] # use na.locf to fill in mondays and ave to distribute them weeks - na.locf(z, xout = mondays) weeks[] - ave(weeks, as.yearmon(mondays), FUN = function(x) x[1]/length(x)) # show output in a few different formats weeks as.data.frame(weeks) data.frame(Monday = as.Date(time(weeks)), value = weeks) data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL) plot(weeks) The output looks like this: weeks 2010-03-01 2010-03-08 2010-03-15 2010-03-22 2010-03-29 2010-04-05 2010-04-12 20 20 20 20 20 50 50 2010-04-19 2010-04-26 2010-05-03 2010-05-10 2010-05-17 2010-05-24 2010-05-31 50 50 60 60 60 60 60 as.data.frame(weeks) weeks 2010-03-01 20 2010-03-08 20 2010-03-15 20 2010-03-22 20 2010-03-29 20 2010-04-05 50 2010-04-12 50 2010-04-19 50 2010-04-26 50 2010-05-03 60 2010-05-10 60 2010-05-17 60 2010-05-24 60 2010-05-31 60 data.frame(Monday = as.Date(time(weeks)), value = weeks, row.names = NULL) Monday value 1 2010-03-01 20 2 2010-03-08 20 3 2010-03-15 20 4 2010-03-22 20 5 2010-03-29 20 6 2010-04-05 50 7 2010-04-12 50 8 2010-04-19 50 9 2010-04-26 50 10 2010-05-03 60 11 2010-05-10 60 12 2010-05-17 60 13 2010-05-24 60 14 2010-05-31 60 -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] Data Frame Manipulation using function
Hi, Thanks a lot. The Vectorize method worked and its much faster than looping through the data frame. Regards, Harsh Yadav On Thu, Jul 8, 2010 at 11:06 PM, David Winsemius dwinsem...@comcast.netwrote: On Jul 8, 2010, at 10:33 PM, Erik Iverson wrote: I have a data frame: id url urlType 1 1 www.yahoo.com http://www.yahoo.com 1 2 2 www.google.com/?search= http://www.google.com/?search= 2 3 3 www.google.com http://www.google.com 1 4 4 www.yahoo.com/?query= http://www.yahoo.com/?query= 2 5 5 www.gmail.com http://www.gmail.com 1 This is not output from ?dput, which means more work to read it in. Yeah it was kind of pain, but ... dta - read.table(textConnection(' id url urlType 1 1 www.yahoo.com http://www.yahoo.com 1 2 2 www.google.com/?search= http://www.google.com/?search= 2 3 3 www.google.com http://www.google.com 1 4 4 www.yahoo.com/?query= http://www.yahoo.com/?query= 2 5 5 www.gmail.com http://www.gmail.com 1') ) Here is the definition for WHITELIST:- WHITELIST = [?]query=, [?]search= WHITELIST - unlist(trim(strsplit(trim(WHITELIST), ,))) What is the 'trim' function? I do not have that defined. Perhaps David's answer will work for you... Seems to ... after I fixed my incorrect cmd-V paste of the function name and guessing that trim was the one in gdata: require(gdata) checkBaseLine - function(s){ + for (listItem in WHITELIST){ + if(regexpr(as.character(listItem), s)[1] -1){ + return(TRUE) + } + } + return(FALSE) + } #Here is the definition for WHITELIST:- WHITELIST = [?]query=, [?]search= WHITELIST - unlist(trim(strsplit(trim(WHITELIST), ,))) vcheck - Vectorize(checkBaseLine) vcheck - Vectorize(checkBaseLine) dta[ dta$urlType != 1 vcheck(dta$url) , url ] [1] www.google.com/?search= http://www.google.com/?search= www.yahoo.com/?query= http://www.yahoo.com/?query= 5 Levels: www.gmail.com http://www.gmail.com www.google.com http://www.google.com ... www.yahoo.com/?query= http://www.yahoo.com/?query= -- David. [[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] random sample from arrays
Could you elaborate? Both x - 1:4 set - matrix(nrow = 50, ncol = 11) for(i in c(1:11)){ set[,i] -sample(x,50) print(c(i,-, set), quote = FALSE) } and x - 1:4 set - matrix(nrow = 50, ncol = 11) for(i in c(1:50)){ set[i,] -sample(x,11) print(c(i,-, set), quote = FALSE) } run perfectly fine on my computer. Cheers On Fri, Jul 9, 2010 at 3:10 PM, Assa Yeroslaviz fry...@gmail.com wrote: Hi Joris, I guess i did it wrong again. but your example didn't work either. I still get the error massage. but replicate function just fine. I can even replicate the whole array lines. THX Assa On Thu, Jul 8, 2010 at 15:20, Joris Meys jorism...@gmail.com wrote: Don't know what exactly you're trying to do, but you make a matrix with 11 columns and 50 rows, then treat it as a vector. On top of that, you try to fill 50 rows/columns with 50 values. Off course that doesn't work. Did you check the warning messages when running the code? Either do : for(i in c(1:11)){ set[,i] -sample(x,50) print(c(i,-, set), quote = FALSE) } or for(i in c(1:50)){ set[i,] -sample(x,11) print(c(i,-, set), quote = FALSE) } Or just forget about the loop altogether and do : set - replicate(11,sample(x,50)) or set - t(replicate(50,sample(x,11))) cheers On Thu, Jul 8, 2010 at 8:04 AM, Assa Yeroslaviz fry...@gmail.com wrote: Hello R users, I'm trying to extract random samples from a big array I have. I have a data frame of over 40k lines and would like to produce around 50 random sample of around 200 lines each from this array. this is the matrix ID xxx_1c xxx__2c xxx__3c xxx__4c xxx__5T xxx__6T xxx__7T xxx__8T yyy_1c yyy_1c _2c 1 A_512 2.150295 2.681759 2.177138 2.142790 2.115344 2.013047 2.115634 2.189372 1.643328 1.563523 2 A_134 12.832488 12.596373 12.882581 12.987091 11.956149 11.994779 11.650336 11.995504 13.024494 12.776322 3 A_152 2.063276 2.160961 2.067549 2.059732 2.656416 2.075775 2.033982 2.111937 1.606340 1.548940 4 A_163 9.570761 10.448615 9.432859 9.732615 10.354234 10.993279 9.160038 9.104121 10.079177 9.828757 5 A_184 3.574271 4.680859 4.517047 4.047096 3.623668 3.021356 3.559434 3.156093 4.308437 4.045098 6 A_199 7.593952 7.454087 7.513013 7.449552 7.345718 7.367068 7.410085 7.022582 7.668616 7.953706 ... I tried to do it with a for loop: genelist - read.delim(/user/R/raw_data.txt) rownames(genelist) - genelist[,1] genes - rownames(genelist) x - 1:4 set - matrix(nrow = 50, ncol = 11) for(i in c(1:50)){ set[i] -sample(x,50) print(c(i,-, set), quote = FALSE) } which basically do the trick, but I just can't save the results outside the loop. After having the random sets of lines it wasn't a problem to extract the line from the arrays using subset. genSet1 -sample(x,50) random1 - genes %in% genSet1 subsetGenelist - subset(genelist, random1) is there a different way of creating these random vectors or saving the loop results outside tjhe loop so I cn work with them? Thanks a lot Assa [[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. -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 on columns of a dataframe
just to satisfy my curiousity, aggregate(bla, list(bla$cat), max) works for me and resulted in Group.1 x catv1v2v3v4 1cat1 5 cat1 0.6337076 0.2887081 0.3629962 0.5328683 2cat2 10 cat2 0.5519426 0.6076447 0.4593770 0.9632341 3cat3 11 cat3 0.6094089 0.6152059 0.5670835 0.9084917 4cat4 8 cat4 0.4772603 0.2149017 0.4534723 0.7824375 5cat5 9 cat5 0.6582466 0.3150096 0.5512863 1.3524582 6cat6 12 cat6 0.4632893 0.4498425 0.3926193 0.8023014 so, what didn't work for you, except for the extra columns? (taking for granted, that random numbers aren't the same) Am 09.07.2010 16:47, schrieb David Winsemius: On Jul 9, 2010, at 10:26 AM, Eik Vettorazzi wrote: you are right. But maybe aggregate is close to the desired result? aggregate(bla, list(bla$cat), max) Right. I couldn't get it to work until I removed the first two columns: aggregate(bla[,-(1:2)], list(bla$cat), max) Then I got pretty much the same dataframe as I would have with : as.data.frame(lapply( bla[, -(1:2)], function(x) tapply(x, bla$cat, max) )) v1v2v3v4 cat1 0.4634519 0.5274645 0.6051479 0.7586322 cat2 0.4062700 0.4282639 0.4443707 0.8419526 cat3 0.4816403 0.4996033 0.3538144 0.9456385 cat4 0.6354560 0.3558259 0.3646292 0.1907295 cat5 0.6663811 0.2154201 0.5059900 0.7573575 cat6 0.5260832 0.3934063 0.3545962 0.6412563 Except that aggregate version returns it with a Group.1 column of cats while the other version returned it with the cat names in the rownames. A matter of taste? -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.xtable suppress my row.names
Dear list, someone knows why the print.xtable doesnt print row.names? I dident do anything with the options.may depends on the size of my table??? This is my code: \documentclass[a4paper]{article} \title{SCHEMA DI BILANCIO PER SINGOLE AZIENDE} \begin{document} \maketitle \hline echo=F= library(xtable) library(plyr) rep=Bilanci rep$SPA-as.numeric(NA) rep$SPP-as.numeric(NA) rep$CE-as.numeric(NA) rep$IN-as.numeric(NA) rep$VA-as.numeric(NA) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,PROD=EC01+EC02+EC03) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,VP=rev(rev(PROD)*c(rev(PROD ^ (-1)),0)[-1])) rep$CTOT-Bilanci$AA01+Bilanci$AA03+Bilanci$AA04 rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,CIRCOL=c(NA,rev(rev(AA03)*0. 5+c(rev(AA03)*0.5,NA)[-1])[-1])+c(NA,rev(rev(AA04)*0.5+c(rev(AA04)*0.5,NA)[-1]) [-1])+c(NA,rev(rev(AL04)*0.5+c(rev(AL04)*0.5,NA)[-1])[-1])) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IE01=(EC04-EC05)/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IE02=EC06/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IE03=EC07/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IE07=(EC11A+EC11C)/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,MOL=100+IE07-IE01-IE02-IE03) rep$IR-as.numeric(NA) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,ROI=((PROD-EC04+EC05-EC06- EC07+EC11C+EC11A-EC08)*c(NA,(rev(rev(CTOT)*0.5+c(rev(CTOT)*0.5,NA)[-1])^(-1)) [-1])*100)) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,RNC=((EC12)*c(NA,(rev(rev (CTOT)*0.5+c(rev(CTOT)*0.5,NA)[-1])^(-1))[-1])*100)) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,EBIT=ROI+RNC) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,RF=((EC10-EC09)*c(NA,(rev(rev (CTOT)*0.5+c(rev(CTOT)*0.5,NA)[-1])^(-1))[-1])*100)) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,ROE=((EC14)*c(NA,(rev(rev (AL01)*0.5+c(rev(AL01)*0.5,NA)[-1])^(-1))[-1])*100)) rep$CC-as.numeric(NA) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IC01=(CIRCOL/PROD)*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IC02=c(NA,rev(rev(AA03)*0.5+c (rev(AA03)*0.5,NA)[-1])[-1])/PROD*365) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IC03=c(NA,rev(rev(AA04)*0.5+c (rev(AA04)*0.5,NA)[-1])[-1])/EC01*365) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IC04=c(NA,rev(rev(AL04)*0.5+c (rev(AL04)*0.5,NA)[-1])[-1])/(EC04+EC06)*365) rep$ES-as.numeric(NA) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IF04=(EC14+EC08)/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN03=c(NA,rev(rev(AA01)*0.5+c (rev(AA01)*0.5,NA)[-1])[-1])/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN04=c(NA,rev(rev(CTOT)*0.5+c (rev(CTOT)*0.5,NA)[-1])[-1])/PROD*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN05=AA02/AA07*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN07=AL01/AL06*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN08=AL05/AL06*100) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN09=IN08/IN07) rep-ddply(rep,c(CFISCALE,RAGSOCB),transform,IN10=((EC09)*c(NA,(rev(rev (AL05)*0.5+c(rev(AL05)*0.5,NA)[-1])^(-1))[-1])*100)) rep1=subset(rep,select=c(RAGSOCB,CFISCALE,ANNO,SPA,AA01,AA01I,AA01M,AA02,AA02B, AA02L,AA03,AA04,AA05,AA06,AA07,SPP,AL01,AL02,AL03,AL04,AL04A,AL04B,AL05,AL05B, AL05L,AL99,AL06,CE,EC01,EC02,EC03,EC04,EC05,EC06,EC07,EC08,EC08A,EC08B,EC09, EC10,EC11,EC11A,EC11C,EC12,EC13,EC14,EC15,EC16,IN,VA,PROD,CTOT,CIRCOL,MOL,IR, ROI,RNC,EBIT,RF,ROE,CC,IC01,IC02,IC03,IC04,ES,IF04,IN03,IN04,IN05,IN07,IN08, IN09,IN10)) mynames-names(rep1) mynames[mynames==SPA]-STATO_PATRIMONIALE_ATTIVO mynames[mynames==AA01]-Immobilizzazioni_tecniche_nette mynames[mynames==AA01I]-Immobilizzazioni_imm_nette mynames[mynames==AA01M]-Immobilizzazioni_mat_nette mynames[mynames==AA02]-Partecipazioni e crediti fin mynames[mynames==AA02B]-Attivita fin a breve mynames[mynames==AA02L]-Immobilizzazioni finan mynames[mynames==AA03]-Magazzino mynames[mynames==AA04]-Crediti commerciali mynames[mynames==AA05]-Liquidita mynames[mynames==AA06]-Altre attivita mynames[mynames==AA07]-Tot attivita mynames[mynames==SPP]-STATO PATRIMONIALE PASSIVO mynames[mynames==AL01]-Capitale netto mynames[mynames==AL02]-Fondo tfr mynames[mynames==AL03]-Altri fondi mynames[mynames==AL04]-Debiti commerciali mynames[mynames==AL04A]-Anticipi di clienti mynames[mynames==AL04B]-Debiti vs fornitori mynames[mynames==AL05]-Debiti fin tot mynames[mynames==AL05B]-Debiti fin a breve mynames[mynames==AL05L]-Debiti fin a medio lungo mynames[mynames==AL99]-Altre passivita mynames[mynames==AL06]-Tot passivita mynames[mynames==CE]-CONTO ECONOMICO mynames[mynames==EC01]-Ricavi netti mynames[mynames==EC02]-Produzione int capitalizzate mynames[mynames==EC03]-Variazione scorte prod finiti mynames[mynames==EC04]-Acquisti mynames[mynames==EC05]-Variazioni scorte mat prime mynames[mynames==EC06]-Costi per servizi god beni terzi mynames[mynames==EC07]-Costo del lavoro tot mynames[mynames==EC08]-Ammortamenti e accantonamenti mynames[mynames==EC08A]-Ammortamenti mynames[mynames==EC08B]-Accantonamenti e utilizzi di riserve mynames[mynames==EC09]-Oneri fin mynames[mynames==EC10]-Proventi fin
Re: [R] Plotting text in existing plot?
Original poster wanted a simple way to do it, but when R has three graphics systems, four OO systems, and a zillion helpful people there's never a simple way :) -- Rather, I'd say it has a zillion simple ways. :) Bert Barry -- blog: http://geospaced.blogspot.com/ web: http://www.maths.lancs.ac.uk/~rowlings web: http://www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Data Frame Manipulation using function
Really? I don't usually think of Vectorize as a performance enhancement, probably because my use of with a complex function then gets applied to 4.5 million records. I need to go out, get a cup of coffee, and leave it alone for about half an hour. I tried recently to figure out how I can do the matrix look-up and function application without the Vectorize route but gave up after a couple of hours after realizing that I had a method that worked and I had spent way more time on it than just doing it would have. Glad it helped. David. On Jul 9, 2010, at 11:01 AM, harsh yadav wrote: Hi, Thanks a lot. The Vectorize method worked and its much faster than looping through the data frame. Regards, Harsh Yadav On Thu, Jul 8, 2010 at 11:06 PM, David Winsemius dwinsem...@comcast.net wrote: On Jul 8, 2010, at 10:33 PM, Erik Iverson wrote: I have a data frame: id url urlType 1 1 www.yahoo.com http:// www.yahoo.com1 2 2 www.google.com/?search= http://www.google.com/? search= 2 3 3 www.google.com http:// www.google.com 1 4 4 www.yahoo.com/?query= http://www.yahoo.com/? query= 2 5 5 www.gmail.com http:// www.gmail.com 1 This is not output from ?dput, which means more work to read it in. Yeah it was kind of pain, but ... dta - read.table(textConnection(' id url urlType 1 1 www.yahoo.com http://www.yahoo.com 1 2 2 www.google.com/?search= http://www.google.com/? search= 2 3 3 www.google.com http://www.google.com 1 4 4 www.yahoo.com/?query= http://www.yahoo.com/? query= 2 5 5 www.gmail.com http://www.gmail.com 1') ) Here is the definition for WHITELIST:- WHITELIST = [?]query=, [?]search= WHITELIST - unlist(trim(strsplit(trim(WHITELIST), ,))) What is the 'trim' function? I do not have that defined. Perhaps David's answer will work for you... Seems to ... after I fixed my incorrect cmd-V paste of the function name and guessing that trim was the one in gdata: require(gdata) checkBaseLine - function(s){ + for (listItem in WHITELIST){ + if(regexpr(as.character(listItem), s)[1] -1){ + return(TRUE) + } + } + return(FALSE) + } #Here is the definition for WHITELIST:- WHITELIST = [?]query=, [?]search= WHITELIST - unlist(trim(strsplit(trim(WHITELIST), ,))) vcheck - Vectorize(checkBaseLine) vcheck - Vectorize(checkBaseLine) dta[ dta$urlType != 1 vcheck(dta$url) , url ] [1] www.google.com/?search= http://www.google.com/?search= www.yahoo.com/?query= http://www.yahoo.com/?query= 5 Levels: www.gmail.com http://www.gmail.com www.google.com http://www.google.com ... www.yahoo.com/?query= http://www.yahoo.com/?query= -- David. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how can achive step by step execution of the script
Sounds like you want devAskNewPage(TRUE) or the related options(device.ask.default). See help(devAskNewPage, package=grDevices). Hope this helps. Allan On 09/07/10 13:54, vijaysheegi wrote: Hi R Experts, I have certain code ,i want to achive interactive execution . For ex: 1. as part of input ,it should ask file name or table name as input. 2.in script so many graphs i need to draw,it should wait till certain key is pressed . 3:i am using windows R,rscriptscriptname is not working. Please some one help me. Thanks Experts in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting text in existing plot?
Possible fortune. :) Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 9, 2010 at 6:22 PM, Bert Gunter gunter.ber...@gene.com wrote: Original poster wanted a simple way to do it, but when R has three graphics systems, four OO systems, and a zillion helpful people there's never a simple way :) -- Rather, I'd say it has a zillion simple ways. :) Bert Barry -- blog: http://geospaced.blogspot.com/ web: http://www.maths.lancs.ac.uk/~rowlings web: http://www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
Re: [R] How can i draw a graph with high and low data points
Hi Nathaniel , Could you give us a simple example of your data using the ?dput Function? Basically you might want to draw the axis yourself, and connect the lines is possible through using points(..., type = l) But I'd rather try and answer this with simple example data to be sure I understand what you mean. Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 9, 2010 at 1:39 PM, Nathaniel Saxe nathaniels...@hotmail.comwrote: Hi Tal, Thanks for your help. I've had a look at the site, and what i wanted to do was to plot X and Y where X is a characters and Y is numeric. The problem I'm having now is that the X axis isn't characters but just numbers from 1 onwards and when i plot it, the data i have is in descending order which isn't shown on the graph. I have this at the moment: plot(1:nrow(dat),dat$Mean,type=b,xaxt=n, ylim=c(min(dat$lci),max(dat$uci)), xlab=,ylab=HR,) It gives me sort of what I want. It has the Y values in descending order, but it doesn't give me the text on the x axis and I was also thinking of plotting the upper and lower confidence intervals with a line connecting the two. I can add in the upper and lower CI values separately, but I don't know how to join the two together. -- View this message in context: http://r.789695.n4.nabble.com/How-can-i-draw-a-graph-with-high-and-low-data-points-tp2282524p2283194.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. [[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] interpretation of svm models with the e1071 package
Dear all, after having calibrated a svm model through the svm() command of the e1071 package, is there a way to i) represent the modeled relationships between the y and X variables (response variable vs. predictors)? ii) rank the influence of the predictors used in the model? Right now I am more interested in regression models, but I guess this would be useful for classification too. Thank you in advance, manuel -- INRA - InfoSol Centre de recherche d'Orléans 2163 Avenue de la Pomme de Pin CS 40001 ARDON 45075 ORLEANS Cedex 2 tel : (33) (0)2 38 41 48 21 fax : (33) (0)2 38 41 78 69 http://www.gissol.fr http://bdat.orleans.inra.fr 00-- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 can achive step by step execution of the script
No - devAskNewPage is not what the OP asked for. 1. The following are, but probably only work when R is in interactive mode (?interactive), e.g. in the GUI: 2. ?winDialog ?file.choose ?choose.files ?select.list ?readline and friends and for keyboard: ?getGraphicsEvent Bert Gunter Genentech Nonclinical Biostatistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Allan Engelhardt Sent: Friday, July 09, 2010 8:43 AM To: vijaysheegi Cc: r-help@r-project.org Subject: Re: [R] how can achive step by step execution of the script Sounds like you want devAskNewPage(TRUE) or the related options(device.ask.default). See help(devAskNewPage, package=grDevices). Hope this helps. Allan On 09/07/10 13:54, vijaysheegi wrote: Hi R Experts, I have certain code ,i want to achive interactive execution . For ex: 1. as part of input ,it should ask file name or table name as input. 2.in script so many graphs i need to draw,it should wait till certain key is pressed . 3:i am using windows R,rscriptscriptname is not working. Please some one help me. Thanks Experts in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 plot two histograms overlapped in the same plane coordinate
I'm not sure what you are trying to do. Do you want one histogram for males and one for females on the same graph? If so, the simplest way to put two histograms together is to simply use the add parameter: age.males=age[which(sex==M)] age.females=age[which(sex==F)] hist(age.males, col=blue) hist(age.females, add=T) The only problem is that the hist() function does not do semi- transparency. I am not sure if other packages do. The code above will give you a blue histogram for males, and clear histogram for females on top of it. You'll probably have to manually alter the axes of the histogram to give the histograms for males and females the same break points (i.e. where one bar stops and another begins). See ?hist for more information about that. Andrew Miles Department of Sociology Duke University On Jul 9, 2010, at 9:29 AM, Mao Jianfeng wrote: Dear R-help listers, I am new. I just want to get helps on how to plot two histograms overlapped in the same plane coordinate. What I did is very ugly. Could you please help me to improve it? I want to got a plot with semi- transparent overlapping region. And, I want to know how to specify the filled colors of the different histograms. I also prefer other solutions other than ggplot2. Many thanks to you. What I have done: library(ggplot2) age-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1)) sex-c(rep(F,100), rep(M, 100)) mydata-cbind(age, sex) mydata-as.data.frame(mydata) head(mydata) qplot(age, data=mydata, geom=histogram, fill=sex, xlab=age, ylab=count, alpha=I(0.5)) Best, Mao J-F __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 plot two histograms overlapped in the same plane coordinate
Empirical CDFs are much better for this purpose, and allow superpositioning (see e.g. the Ecdf function in the Hmisc package). Otherwise look at histbackback in Hmisc. Frank On 07/09/2010 11:40 AM, Andrew Miles wrote: I'm not sure what you are trying to do. Do you want one histogram for males and one for females on the same graph? If so, the simplest way to put two histograms together is to simply use the add parameter: age.males=age[which(sex==M)] age.females=age[which(sex==F)] hist(age.males, col=blue) hist(age.females, add=T) The only problem is that the hist() function does not do semi-transparency. I am not sure if other packages do. The code above will give you a blue histogram for males, and clear histogram for females on top of it. You'll probably have to manually alter the axes of the histogram to give the histograms for males and females the same break points (i.e. where one bar stops and another begins). See ?hist for more information about that. Andrew Miles Department of Sociology Duke University On Jul 9, 2010, at 9:29 AM, Mao Jianfeng wrote: Dear R-help listers, I am new. I just want to get helps on how to plot two histograms overlapped in the same plane coordinate. What I did is very ugly. Could you please help me to improve it? I want to got a plot with semi- transparent overlapping region. And, I want to know how to specify the filled colors of the different histograms. I also prefer other solutions other than ggplot2. Many thanks to you. What I have done: library(ggplot2) age-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1)) sex-c(rep(F,100), rep(M, 100)) mydata-cbind(age, sex) mydata-as.data.frame(mydata) head(mydata) qplot(age, data=mydata, geom=histogram, fill=sex, xlab=age, ylab=count, alpha=I(0.5)) Best, Mao J-F __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Frank E Harrell Jr Professor and ChairmanSchool 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.
Re: [R] how to plot two histograms overlapped in the same plane coordinate
On Fri, Jul 9, 2010 at 2:29 PM, Mao Jianfeng jianfeng@gmail.com wrote: Dear R-help listers, I am new. I just want to get helps on how to plot two histograms overlapped in the same plane coordinate. What I did is very ugly. Could you please help me to improve it? I want to got a plot with semi- transparent overlapping region. And, I want to know how to specify the filled colors of the different histograms. I also prefer other solutions other than ggplot2. Many thanks to you. What I have done: library(ggplot2) age-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1)) sex-c(rep(F,100), rep(M, 100)) mydata-cbind(age, sex) mydata-as.data.frame(mydata) head(mydata) Tried setting xlim with hist? par(mfrow=c(2,1)) hist(age[sex==M],xlim=range(age)) hist(age[sex==F],xlim=range(age)) Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Query about using timestamps returned by SQL as 'factor' forsplit
Hi Ted, Well since you mentioned data.table (!) ... If risk_input is a data.table consisting of 3 columns (m_id, sale_date, return_date) where the dates are of class IDate (recently added to data.table by Tom) then try : risk_input[, fitdistr(return_date-sale_date,normal), by=list(m_id, year(sale_date), week(sale_date))] Notice that the 'by' can contain expressions of columns, and lets you group by more than one expression. You don't have to repeat the 'group by' expressions in the select, as you would do in SQL. data.table returns those group columns automatically in the result, alongside the result of the j expression applied to each group. If you need to aggregate by m_id, year and month rather than week another way is : risk_input[, fitdistr(return_date-sale_date,normal), by=list(m_id, round(sale_date,month))] plyr and sqldf can do this task too by the way, and I'd highly recommend you take a look at those packages. There are also many excellent datetime classes around which you could also consider. The reason we need IDate in data.table is because data.table uses radix sorting, see ?sort.list. That is ultra fast for integers. Again radix is something Tom added to data.table. The radix algorithm (see wikipedia) is specifically designed to sort integers only. We would use Date, but that is stored as numeric. IDate is the same as Date but stored as integer. HTH, Matthew Ted Byers r.ted.by...@gmail.com wrote in message news:aanlktinchf3tfzkndcwolrwsxekgpfpjes3f8m5tq...@mail.gmail.com... I have a simple query as follows: SELECT m_id,sale_date,YEAR(sale_date),WEEK(sale_date),return_type,DATEDIFF(return_date,sale_date) AS elapsed_time FROM risk_input I can get, and view, all the data that that query returns. The question is, sale_date is a timestamp, and I need to call split to group this data by m_id and the week in which the sale occurred. Obviously, I would normally need both YEAR and WEEK so that data from April this year is not combined with that from last year (the system is non-autonomous). And then I need to use lapply to apply fitdistr to each subsample. Obviously, I can handle all this data in either a data.frame or in a data.table. There are two aspects of the question. 1) Is there a function (or package) that will let me group (or regroup) time series data into the week in which the data apply, properly taking into account the year that applies, in a single call passing sale_date as the argument? If I can, then I can reduce the amount of data I draw from my MySQL server and the computational load it bears. 2) The example provided for split splits only according to a single variable (*g - airquality$Month;l - split(airquality, g)*). How would that example be changed if there were two or more columns in the data.frame that are needed to define the groups? I.E. in my example, I'd need to group by m_id, and the year and week values that can be computed from sale_date. Thanks Ted [[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] Calling Gnuplot from R
There is a basic interface between R and gnuplot in the TeachingDemos package, see ?gp.open Not much interest has been shown in this, so it is still pretty alpha level, but you can send your R data to gnuplot and have it create a basic plot. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Christopher Desjardins Sent: Thursday, July 08, 2010 9:22 AM To: r-help@r-project.org Subject: [R] Calling Gnuplot from R Hi, I am wondering if there is a way to call Gnuplot from R and/or if anyone can recommend a package on CRAN capable of doing this? Thanks, Chris PS - Please cc me on the response. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Ctree Question
Hello, I've been using ctree and have developed a 55 node - 28 terminal solution. As can be imagined, the plot is difficult to travel down each of the major branches. I've read the help files for ctree I saw where terminal nodes can be color coded. plot(airct, type = simple) plot(airct, terminal_panel = node_boxplot(airct, col = blue, + fill = hsv(2/3, 0.5, 1))) Here is my question: Since my model has 55 nodes and 28 terminal nodes,(ie many branches) is it feasible to color code the each of the major branches and track the paths down the decision tree? R 2.11.1, Windox XP Thanks Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting text in existing plot?
Others pointed you to the text function for the base graphics system. But if what you want to do is use text, but have a simple way of specifying the center of the plot without computing the user coordinates by hand of the center, then look at the grconvertX and grconvertY functions. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Ralf B Sent: Friday, July 09, 2010 3:52 AM To: r-help@r-project.org Subject: [R] Plotting text in existing plot? I would like to plot some text in a existing plot graph. Is there a very simple way to do that. It does not need to be pretty at all (just maybe a way to center it or define a position within the plot). ( ? ) Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 plot two histograms overlapped in the same planecoordinate
Don't do this. The overlapping will confuse. Plot them in a lattice display with one group above the other on the same horizontal scale. See ?histogram. Bert Gunter Genentech Nonclinical Biostatistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Barry Rowlingson Sent: Friday, July 09, 2010 9:47 AM To: Mao Jianfeng Cc: r-help@r-project.org Subject: Re: [R] how to plot two histograms overlapped in the same planecoordinate On Fri, Jul 9, 2010 at 2:29 PM, Mao Jianfeng jianfeng@gmail.com wrote: Dear R-help listers, I am new. I just want to get helps on how to plot two histograms overlapped in the same plane coordinate. What I did is very ugly. Could you please help me to improve it? I want to got a plot with semi- transparent overlapping region. And, I want to know how to specify the filled colors of the different histograms. I also prefer other solutions other than ggplot2. Many thanks to you. What I have done: library(ggplot2) age-c(rnorm(100, 1.5, 1), rnorm(100, 5, 1)) sex-c(rep(F,100), rep(M, 100)) mydata-cbind(age, sex) mydata-as.data.frame(mydata) head(mydata) Tried setting xlim with hist? par(mfrow=c(2,1)) hist(age[sex==M],xlim=range(age)) hist(age[sex==F],xlim=range(age)) Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] nls error regarding numerics vs logicals
I am trying to perform an nls for a valid negative exponential function: zz=nls(y~constant+a.est*2.7183^(b.est*x),start=list(constant=4.0,a.est=-4,b.est = -.005),trace=T) and am getting a number of different error messages, the most problematic of which is Error in nls(ring.area ~ constant + a.est * 2.7183^(b.est * ba.beg), start = list(constant = 4, : REAL() can only be applied to a 'numeric', not a 'logical' I can't see where there are any logicals in this equation to cause this problem. Any help appreciated. Thank you. Jim Bouldin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R crashes with large vectors
Hi Jeremie, Maybe you can take a look at the bigmemory package. If you have multi core or have access to clusters, you may want to use any parallel computing strategy. For plotting of large data, if you are using basic R graphics, first try to use line instead of using 'point', if this still doesn't working, you may want to try an alternative way by using qtinterface (R-forge project), install qtbase and qtpaint, they are still under development, but painting in QT interface is a lot faster for large data set. Best Tengfei On Fri, Jul 9, 2010 at 2:42 AM, Jeremie Smaga jere...@4ecap.com wrote: Good afternoon, I have been experiencing a lot of crashes working with large vectors in R. Specifically, I am using XTS of length of minimum 120k elements. My problem is that I cannot display the vector (otherwise R crashes), I cannot plot it either (otherwise R crashes). That could be solved by reducing the amount of points. However, I have been performing some statistical opreations on is and even sd(myXTS) crashes R. By crashes, I mean shuts down without any warning whatsoever. I use R 2.11.1 (64). Has anyone had the same kind of problem? Can we solve this? Best, -- Jeremie [[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. -- Tengfei Yin MCDB PhD student 1620 Howe Hall, 2274, Iowa State University Ames, IA,50011-2274 Homepage: www.tengfei.name [[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] nls error regarding numerics vs logicals
On 09/07/2010 1:51 PM, Jim Bouldin wrote: I am trying to perform an nls for a valid negative exponential function: zz=nls(y~constant+a.est*2.7183^(b.est*x),start=list(constant=4.0,a.est=-4,b.est = -.005),trace=T) and am getting a number of different error messages, the most problematic of which is Error in nls(ring.area ~ constant + a.est * 2.7183^(b.est * ba.beg), start = list(constant = 4, : REAL() can only be applied to a 'numeric', not a 'logical' I can't see where there are any logicals in this equation to cause this problem. Any help appreciated. Thank you. 1. The expression you gave us is clearly not the one that produced the error: it involved ring.area and ba.beg. 2. You don't tell us what x and y are, so we can't reproduce anything. We can't help you if you don't tell us what the problem is. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] select columns from vector of column names
Hi I want to extract columns from a data frame using a vector with the desired column names. This short example uses the select argument in the subset function to accomplish what I am trying to do. Is there a better solution? #names of desired columns colnames - c(col1,col3) #my data data - data.frame(col1=c(1,2,3),col2=c(A,B,C),col3=c(4,5,6)) fun - function(colname,dframe){ nframe - subset(dframe,select=colname) vec - nframe[,1] return(vec) } fun(colnames[1],data) fun(colnames[2],data) [[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] Calling Gnuplot from R
Dear Greg, I keep on being amazed at the abundance of functions you have packed into the TeachingDemos package - thank you! Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 9, 2010 at 8:18 PM, Greg Snow greg.s...@imail.org wrote: There is a basic interface between R and gnuplot in the TeachingDemos package, see ?gp.open Not much interest has been shown in this, so it is still pretty alpha level, but you can send your R data to gnuplot and have it create a basic plot. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Christopher Desjardins Sent: Thursday, July 08, 2010 9:22 AM To: r-help@r-project.org Subject: [R] Calling Gnuplot from R Hi, I am wondering if there is a way to call Gnuplot from R and/or if anyone can recommend a package on CRAN capable of doing this? Thanks, Chris PS - Please cc me on the response. [[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. [[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] select columns from dataframe
Hi, I would like to extract columns from a dataframe using a vector of desired column names. The following working example uses the select argument in the subset function to accomplish what I am trying to do. Is there a better solution? Thanks. #my data data - data.frame(col1=c(1,2,3),col2=c(A,B,C),col3=c(4,5,6)) #names of desired columns colnames - c(col1,col3) fun - function(colname,dframe){ nframe - subset(dframe,select=colname) vec - nframe[,1] return(vec) } fun(colnames[1],data) fun(colnames[2],data) [[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] Ctree Question
Steve, I'm not sure if your task could be accomplished with a ready-made function in party. But, if you could manage to convert your tree structure to a dendrogram, then it's straightforward using dendrapply. In fact, there is an example in dendrapply help page showing how leaves are colored. ?dendrapply HTH. H -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of steve_fried...@nps.gov Sent: Friday, July 09, 2010 10:22 AM To: r-help@r-project.org Subject: [R] Ctree Question Hello, I've been using ctree and have developed a 55 node - 28 terminal solution. As can be imagined, the plot is difficult to travel down each of the major branches. I've read the help files for ctree I saw where terminal nodes can be color coded. plot(airct, type = simple) plot(airct, terminal_panel = node_boxplot(airct, col = blue, + fill = hsv(2/3, 0.5, 1))) Here is my question: Since my model has 55 nodes and 28 terminal nodes,(ie many branches) is it feasible to color code the each of the major branches and track the paths down the decision tree? R 2.11.1, Windox XP Thanks Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] select columns from vector of column names
How about data[,colnames(data)%in%colnames] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Flowers Sent: Friday, July 09, 2010 11:27 AM To: r-help@r-project.org Subject: [R] select columns from vector of column names Hi I want to extract columns from a data frame using a vector with the desired column names. This short example uses the select argument in the subset function to accomplish what I am trying to do. Is there a better solution? #names of desired columns colnames - c(col1,col3) #my data data - data.frame(col1=c(1,2,3),col2=c(A,B,C),col3=c(4,5,6)) fun - function(colname,dframe){ nframe - subset(dframe,select=colname) vec - nframe[,1] return(vec) } fun(colnames[1],data) fun(colnames[2],data) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
nlminb( obj = function(x) x, start=1, lower=-Inf, upper=Inf ) $par [1] 0 $objective [1] 0 $convergence [1] 0 $message [1] absolute function convergence (6) $iterations [1] 1 $evaluations function gradient 22 [[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] split with list
n.via...@libero.it n.via...@libero.it writes: Hi, Dear List I would like to ask you something concenting a better print of the R output: I have a bit data frame which has the following structure: CFISCALE RAGSOCBANNO VAR1VAR2. 9853312 astra 2005 6 45 9853312 astra 2006 78 45 9853312 astra 2007 55 76 9653421 geox 2005 35 89 9653421 geox 200624 33 9653421 geox 2007 54 55 The first thing I did is to split my data frame for CFISCALE. The result is that R has transformed my data frame into a list. The second step was to transpose each element of my list. repo=split(rep,rep$CFISCALE) repor=lapply(repo,function(x){ t(x)}) When I print my list the format is the following $9853312 1 2 3 CFISCALE9853312 9853312 9853312 RAGSOCBastra astraastra ANNO 20052006 2007 VAR1 6 78 55 VAR2 4545 76 So far so good. There is a way to remove the first row I mean 1, 2 , 3 and to have just one CFISCALE and RAGSOCB??? For the second problem I tried to use unique but it seems that it doesnt work for list. So what I would like to get is: Well I'm not sure what the first problem is. But if I understand the second problem, you can do something like this: dup.null - function(mat) { mat[CFISCALE, duplicated(mat[CFISCALE,])] - NA mat[RAGSOCB, duplicated(mat[RAGSOCB,])] - NA return(mat) } repor - lapply(repor, dup.null) Best, Ista $9853312 CFISCALE9853312 RAGSOCBastra ANNO 20052006 2007 VAR1 6 78 55 VAR2 4545 76 This is because I next run xtable on my list in order to get a table in Latex, which I woud like to be in a nice format. Thanks a lot for your attention! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] eval and assign in loop problem
deaR useRs, I am trying to assign different values to different objects in a for loop. The following is a toy example of the part that has been giving me a hard time. The first for loop generates four objects, b0, b1, b2, b3 with random numbers. And, the second for loop is equivalent to b1 = b0 b2 = b1 b3 = b2 b4 = b3 But, when I run this code, the result is equivalent to b1 = b0 b2 = b0 b3 = b0 b4 = b0 So, the increment does not seem to be properly working for the second part of the assign function. Why would this be? for (i in 0:3) { r = runif(1) assign(paste('b',i,sep=''),r) } for (i in 1:4) { assign(paste('b',i,sep=''),eval(parse(text=paste('b',i-1,sep='' } Thank you. Nic [[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] July BaselR Meeting
BaselR meeting July 2010 Thank you to everyone who supported our inaugural BaselR meeting on April 28th; we were fortunate to have three excellent presentations which prompted lively discussion - our thanks go to Andreas Krause, Yann Abraham and Charles Roosen for their presentations, details of which are available here The next BaselR meeting is Wednesday 28th July 2010 Venue: transBARent Viaduktstrasse 3 CH-4051 Basel Tel. 061 222 21 31 Fax 061 222 21 32 i...@transbarent.ch http://transbarent.sv-group.ch/de.html Agenda: * Introduction - Charles Roosen, Mango Solutions AG * Desktop Publishing with Sweave - Andrew Ellis, ETH Zurich * Professional Reporting with RExcel - Dominik Locher, THETA AG * R Generator Tool for Google Motion Charts - Sebastian Pérez Saaibi, ETH Zurich If you would like to join the BaselR mailing list and receive details of all BaselR meetings please email us at bas...@mango-solutions.com What is BaselR? Similar to the well-known LondonR, this informal meeting is intended to serve as a platform for all local (and regional) R users to present and exchange their experiences and ideas around the usage of R. Mango Solutions aims to host such meetings about every quarter. A typical BaselR meeting will consist of 3-4 talks of about 20-25 min to give plenty of room for sharing your R experiences, discussions and exchange of ideas. How to contribute? We are always looking for volunteers to present at subsequent meetings. If you think you have something interesting to present or know of someone who has, please contact us. For ideas on presentations, take a look at previous presentations given at LondonR (here). For more information about Mango Solutions please contact us or visit our website www.mango-solutions.ch Sarah Lewis Hadley Wickham, Creator of ggplot2 - first time teaching in the UK. 1st - 2nd November 2010. To book your seat please go to http://mango-solutions.com/news.html T: +44 (0)1249 767700 Ext: 200 F: +44 (0)1249 767707 M: +44 (0)7746 224226 www.mango-solutions.com Unit 2 Greenways Business Park Bellinger Close Chippenham Wilts SN15 1BN UK LEGAL NOTICE\ This message is intended for the use of th...{{dropped:22}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] syntax for highlighting table rows and columns using R plugin for spss
I am using the R plug-in for spss 18, and would like to know if there is any R code that will highlight and bold rows (particularly the Totals row) within an spss table. The current option that spss has is to use a python plug-in which doesn't seem to work on my windows 7 machine. Chris Anderson Data Analyst Medical Affairs wk: 925-677-4870 cell: 707-315-8486 Fax:925-677-4670 /prebrThis electronic message transmission, including any attachments, contains brinformation which may be confidential, privileged and/or otherwise exempt brfrom disclosure under applicable law. The information is intended to be for the bruse of the individual(s) or entity named above. If you are not the intended brrecipient or the employee or agent responsible for delivering the message brto the intended recipient, you are hereby notified that any disclosure, copying, brdistribution or use of the contents of this information is strictly prohibited. If bryou have received this electronic transmission in error, please notify the sender brimmediately by telephone (800-676-6777) or by a reply to sender only brmessage and destroy all electronic and hard copies of the communication, brincluding attachments. Thank you.brbrFor more information on Paradigm Management Services, LLC, please visit brhttp://www.paradigmcorp.com br [[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] Compress string memCompress/Decompress
Hello, I would like to compress a long string (character vector), store the compressed string in the text field of a SQLite database (using RSQLite), and then load the text back into memory and decompress it back into the the original string. My character vector can be compressed considerably using standard gzip/bzip2 compression. In theory it should be much faster for me to compress/decompress a long string than to write the whole string to the hard drive and then read it back (not to mention the saved hard drive space). I have tried accomplishing this task using memCompress() and memDecompress() without success. It seems memCompress can only convert a character vector to raw type which cannot be treated as a string. Does anyone have ideas on how I can go about doing this, especially using the standard base packages? Thanks!, Erik sessionInfo() R version 2.11.0 (2010-04-22) x86_64-apple-darwin9.8.0 locale: [1] 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 loaded via a namespace (and not attached): [1] tools_2.11.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 finding valid permutations
So I have an array A of length n with multiple attributes and for a selected attribute y I need to list all valid permutations where a valid permutation is of the form: A[1,y] != A[n,y] A[i,y] != A[i+1,y] I've tried using the 'combinat' package, but with the vector lengths I'm using the permn function fails with the vector(list, gamma(n + 1)) assignment. For example: 13 cards from a standard 52 card deck. attributes facevalue and suit. A = (9C, 9H, 9D, 8C, 7C, 6C, 6S, 5C, 4C, 4H, 3C, 2C, 2D) And I want to find all possible arrangements where the facevalue of each consecutive card is different but the orders are unique because of the suit. Also, I need to consider the case where the suit of each consecutive case is different but the orders are unique because of the facevalue. For A above, note that there are 8 clubs out of 13 cards so 3 of the clubs must be dropped from the draw an all valid of ten of the cards must be found (5 same suit, 5 off suit) I hope this is clear. Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.