[R] Help with Iterator
Dear Experts, The following is my Iterator. When I try to write a new function with itel, I got error. This is what I have: supDist-function(x,y) return(max(abs(x-y))) myIterator - function(xinit,f,data=NULL,eps=1e-6,itmax=5,verbose=FALSE) { + xold-xinit + itel-0 + repeat { + xnew-f(xold,data) + if (verbose) { + cat( + Iteration: ,formatC(itel,width=3, format=d), + xold: ,formatC(xold,digits=8,width=12,format=f), + xnew: ,formatC(xnew,digits=8,width=12,format=f), + \n + ) + } + if ((supDist(xold,xnew) eps) || (itel == itmax)) { + return(xnew) + } + xold-xnew; itel-itel+1 + } + } mat-function (x, data=NULL) {return (1+x^itel)} myIterator(3, f=mat, verbose=TRUE) Error in f(xold, data) : object 'itel' not found Can anyone please help me to fix the error? -- View this message in context: http://r.789695.n4.nabble.com/Help-with-Iterator-tp3033254p3033254.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] Calculate Mean from List
Dear all, I have a list of correlation coefficient matrixes. Each matrix represents one date. For example A[[1]] A B C A 1 0.2 0.3 B 0.2 1 0.4 C 0.3 0.4 1 A[[2]] A B C A 1 0.5 0.6 B 0.5 1 0.7 C 0.6 0.7 1 A[[n]] I would like to calculate the mean of correlation coefficient from the whole time series, i.e. Average cor(A,B) = (A[[1]][2,1] + A[[2]] [2,1] + ... + A[[n]] [2,1])/n Average cor(A,C) = (A[[1]][3,1] + A[[2]] [3,1] + ... + A[[n]] [3,1])/n Average cor(B,C) = (A[[1]][3,2] + A[[2]] [3,2] + ... + A[[n]] [3,2])/n Please note that some cells are NA; so I need to remove them when calculating average. How could I get this efficiently? Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities Public Company Limited Tel: (66)2-305-9179 Email: supha...@phatrasecurities.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Row-wise recurive function call
Thanks this works. Only, I need to reference in the formula using indexes. -Original Message- From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] Sent: 09 November 2010 13:22 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Row-wise recurive function call try this: apply(data.matrix(a), 1, playFn) I hope it helps. Best, Dimitris On 11/9/2010 8:32 AM, Santosh Srinivas wrote: Dear Group, I have a following dataset: a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L, 39L, 7L, 47L), D = c(40L, 32L, 16L, 26L, 0L, 18L, 2L, 48L, 21L, 10L)), .Names = c(A, B, C, D), class = data.frame, row.names = c(NA, -10L)) I have a function that works off EVERY individual ROW to throw a result. Like playFn- function (x){ + result = ((x$A+6*x$B)/(3*x$C)+20)*x$D + return(result) + } I want to apply the function for every row can I use an apply function ... tried but not been able to ... e.g. print(rapply(a,playFn)) Please advise. Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with Iterator
I guess what you want is: - change the line : xnew-f(xold,data) into xnew-f(xold,data, itel) - change your mat function to take itel as an extra parameter: mat-function (x, data=NULL, itel) {return (1+x^itel)} That should do the trick (though I haven't checked whether the rest of your code is OK) Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of zhiji19 Sent: dinsdag 9 november 2010 9:02 To: r-help@r-project.org Subject: [R] Help with Iterator Dear Experts, The following is my Iterator. When I try to write a new function with itel, I got error. This is what I have: supDist-function(x,y) return(max(abs(x-y))) myIterator - function(xinit,f,data=NULL,eps=1e-6,itmax=5,verbose=FALSE) { + xold-xinit + itel-0 + repeat { + xnew-f(xold,data) + if (verbose) { + cat( + Iteration: ,formatC(itel,width=3, format=d), + xold: ,formatC(xold,digits=8,width=12,format=f), + xnew: ,formatC(xnew,digits=8,width=12,format=f), + \n + ) + } + if ((supDist(xold,xnew) eps) || (itel == itmax)) { + return(xnew) + } + xold-xnew; itel-itel+1 + } + } mat-function (x, data=NULL) {return (1+x^itel)} myIterator(3, f=mat, verbose=TRUE) Error in f(xold, data) : object 'itel' not found Can anyone please help me to fix the error? -- View this message in context: http://r.789695.n4.nabble.com/Help-with-Iterator-tp3033254p3033254.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do i plot this hist?
Hi casperyc, While Jim Holtman's solution is quite neat, I thought I would add a multiple histogram to the discussion in case that was what you wanted: library(plotrix) barp(t(x.m[,2:5]),names.arg=x.m[,1],col=rainbow(4)) legend(20,2500,paste(V,2:5,sep=),fill=rainbow(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.
Re: [R] Calculate Mean from List
one way is the following: A - replicate(10, cor(matrix(rnorm(30), 10, 3)), simplify = FALSE) triA - sapply(A, function (m) m[upper.tri(m)]) rowMeans(triA, na.rm = TRUE) I hope it helps. Best, Dimitris On 11/9/2010 9:23 AM, Suphajak Ngamlak wrote: Dear all, I have a list of correlation coefficient matrixes. Each matrix represents one date. For example A[[1]] A B C A 1 0.2 0.3 B 0.2 1 0.4 C 0.3 0.4 1 A[[2]] A B C A 1 0.5 0.6 B 0.5 1 0.7 C 0.6 0.7 1 A[[n]] I would like to calculate the mean of correlation coefficient from the whole time series, i.e. Average cor(A,B) = (A[[1]][2,1] + A[[2]] [2,1] + ... + A[[n]] [2,1])/n Average cor(A,C) = (A[[1]][3,1] + A[[2]] [3,1] + ... + A[[n]] [3,1])/n Average cor(B,C) = (A[[1]][3,2] + A[[2]] [3,2] + ... + A[[n]] [3,2])/n Please note that some cells are NA; so I need to remove them when calculating average. How could I get this efficiently? Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities Public Company Limited Tel: (66)2-305-9179 Email: supha...@phatrasecurities.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] : unusual combinations of categorical data
On 11/09/2010 09:25 AM, Alan Chalk wrote: Regarding unusual combinations of factors in categorical data. Are there any R packages that can be used to identify the outliers i.e. unusual combinations in categorical datasets ? Hi Alan, If your factors are dichotomous and you are looking for common patterns of intersection, try intersectDiagram. 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] Creating a list to store output objects from a recursive loop
Dear Group, I am having a function that I am running in a loop that generated two results for each loop The result1 is a zoo object The result2 is a data frame Now I want to put both of them in a list or some structure ... that I can access or output to a file after the loop is done. For e.g. for (i in 1:20){ niceFunction(x[i],i) } niceFunction (x,i) { result1 = someOperations() #zoo object result2 = someOperations() #data.frame OutputObj[i,1]=result1 OutputObj[i,2]=result2 } How can I go about this? Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] the formula of quantile regression for panel data, which is correct?
Hi,everyone I have some trouble in understanding the formula. http://r.789695.n4.nabble.com/file/n3033305/%E6%9C%AA%E5%91%BD%E5%90%8D.jpg http://r.789695.n4.nabble.com/file/n3033305/%E6%9C%AA%E5%91%BD%E5%90%8D1.jpg which is correct? best wish. thanks -- View this message in context: http://r.789695.n4.nabble.com/the-formula-of-quantile-regression-for-panel-data-which-is-correct-tp3033305p3033305.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] plot graph(quantile regression for panel data)
Hi,everyone I have two group data. x=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9) y=c(1,2,3,4,5,6,7,8,9) and the confidence interval of y [0.9,1.1],[1.9,2.1],[2.9,3.1] [3.9,4.1],[4.9,5.1],[5.9,6.1] [6.9,7.1],[7.9,8.1],[8.9,9.1] How can I get the graph? as follows http://r.789695.n4.nabble.com/file/n3033259/%E6%9C%AA%E5%91%BD%E5%90%8D.jpg -- View this message in context: http://r.789695.n4.nabble.com/plot-graph-quantile-regression-for-panel-data-tp3033259p3033259.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] convergence message SE calculation when using optim( )
Hi R-users, I am trying to estimate function parameters using optim(). My count observations follows a Poisson like distribution. The problem is that I wanna express the lambda coefficient, in the passion likelihood function, as a linear function of other covariates (and thus of other coefficients). The codes that I am using (except data frame) are the following (FYI the parameters need to be positive): myfun - function(coeff, H1, H2, p, Range) { (coeff[1]+coeff[2]*H1+coeff[3]*H2+coeff[4]*p+H1*Range*coeff[5]+H2*Range* coeff[6]+H1*H2*coeff[7])*exp((coeff[8]+coeff[9]*H1+coeff[10]*H2+coeff[11 ]*p+H1*Range*coeff[12]+H2*Range*coeff[13]+H1*H2*coeff[14])*(Range-1))+co eff[15]+coeff[16]*H1+coeff[17]*H2+coeff[18]*p+H1*Range*coeff[19]+H2*Rang e*coeff[20]+H1*H2*coeff[21] } SS - function(coeff,Range,H1,H2,p,steps) { sum((steps - myfun(coeff,Range,H1,H2,p))^2) } coeff - c(0.1,0.1,0.1,0.1,0.1,1,5,5,5,1,1,1,1,1,1,1,0.1,0.1,0.1,0.1,0.1) scale - c(0.1,0.1,0.1,0.1,0.1,1,5,5,5,1,1,1,1,1,1,1,0.1,0.1,0.1,0.1,0.1) est_coeff - optim(par=coeff, fn = SS, H1=org_results$H1, H2=org_results$H2, p=org_results$p, Range=org_results$Range, steps=org_results$no.steps, method= 'L-BFGS-B', lower = rep(0, 21), upper = rep(Inf, 21), control = list(trace=FALSE, parscale=scale), hessian=TRUE) this is the output: $par [1] 0.099794607 0.099841098 0.099896127 0.099899549 0.099856776 0.991269412 4.807153280 [8] 25.115556187 55.961674737 1.519658195 1.378913148 2.800328223 1.448902455 2.280837645 [15] 1.594648898 0.011581676 0.040651369 0.0 0.0 0.0 0.002717246 $value [1] 14535187 $counts function gradient 54 54 $convergence [1] 0 $message [1] CONVERGENCE: REL_REDUCTION_OF_F = FACTR*EPSMCH $hessian [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.00e+00 0.00e+00 0.00e+00 -0.0023283064 0.00 2.328306e-03 [2,] 0.00e+00 0.00e+00 0.00e+00 -0.0023283064 0.00 2.328306e-03 [3,] 0.00e+00 0.00e+00 0.00e+00 0.0023283064 0.00 0.00e+00 [4,] -2.328306e-03 -2.328306e-03 2.328306e-03 0.00 -0.0023283064 2.328306e-04 [5,] 0.00e+00 0.00e+00 0.00e+00 -0.0023283064 0.0046566129 -2.095476e-03 [6,] 2.328306e-03 2.328306e-03 0.00e+00 0.0002328306 -0.0020954758 0.00e+00 [7,] 9.313226e-05 9.313226e-05 4.656613e-05 0.0023748726 0.0001396984 4.656613e-05 [8,] -4.284550e-01 -4.284550e-01 -1.916196e-01 -0.2018641680 -0.3814231604 -1.689885e-01 [9,] -4.284550e-01 -4.284550e-01 -1.916196e-01 -0.2018641680 -0.3814231604 -1.689885e-01 [10,] -1.892913e-01 -1.892913e-01 -1.240987e-01 -0.0880099833 -0.1706648618 -1.098961e-01 [11,] -1.974404e-01 -1.974404e-01 -8.568168e-02 -0.1315493137 -0.1781154424 -7.823110e-02 [12,] -3.885943e-01 -3.885943e-01 -1.704320e-01 -0.1802109182 -0.3480818123 -1.513399e-01 [13,] -1.706649e-01 -1.706649e-01 -1.108274e-01 -0.0789295882 -0.1504085958 -9.872019e-02 [14,] -1.892913e-01 -1.892913e-01 -1.240987e-01 -0.0880099833 -0.1706648618 -1.098961e-01 [15,] 2.813991e+00 2.813991e+00 1.214910e+00 1.3138633221 2.5336630642 1.093373e+00 [16,] 2.814224e+00 2.814224e+00 1.212582e+00 1.3138633221 2.5336630642 1.093373e+00 [17,] 1.213048e+00 1.213048e+00 7.892959e-01 0.5634501576 1.0943040252 7.092021e-01 [18,] 1.317821e+00 1.317821e+00 5.704351e-01 0.8870847523 1.1851079762 5.112961e-01 [19,] 2.537854e+00 2.537854e+00 1.089647e+00 1.1827796698 2.2817403078 9.855721e-01 [20,] 1.094304e+00 1.094304e+00 7.101335e-01 0.5122274160 0.9802170098 6.388873e-01 [21,] 1.215376e+00 1.215376e+00 7.939525e-01 0.5657784641 1.0919757187 7.094350e-01 [,7][,8][,9] [,10] [,11] [,12] [,13] [1,] 9.313226e-05 -0.42845495 -0.42845495 -0.18929131 -0.19744039 -0.38859434 -0.17066486 [2,] 9.313226e-05 -0.42845495 -0.42845495 -0.18929131 -0.19744039 -0.38859434 -0.17066486 [3,] 4.656613e-05 -0.19161962 -0.19161962 -0.12409873 -0.08568168 -0.17043203 -0.11082739 [4,] 2.374873e-03 -0.20186417 -0.20186417 -0.08800998 -0.13154931 -0.18021092 -0.07892959 [5,] 1.396984e-04 -0.38142316 -0.38142316 -0.17066486 -0.17811544 -0.34808181 -0.15040860 [6,] 4.656613e-05 -0.16898848 -0.16898848 -0.10989606 -0.07823110 -0.15133992 -0.09872019 [7,] 9.313226e-05 -0.18775463 -0.18775463 -0.12246892 -0.08759089 -0.16880222 -0.11008233 [8,] -1.877546e-01 0.12330711 0.12330711 0.07711351 0.05806796 0.11092052 0.06952323 [9,] -1.877546e-01 0.12330711 0.12330711 0.07711351 0.05806796 0.11092052 0.06952323 [10,] -1.224689e-01 0.07711351 0.07711351 0.05681068 0.03585592 0.06938353 0.05122274 [11,] -8.759089e-02 0.05806796 0.05806796 0.03585592 0.03864989 0.05215406 0.03213063 [12,] -1.688022e-01 0.11092052 0.11092052 0.06938353 0.05215406 0.09965152 0.06286427 [13,]
[R] repeatedrepeated measures in ANOVA or mixed model
dear List I have a dataset with blood measurements at 5 points in TIME (0,30,60,90,120) taken on 3 VISITS (same subjects). the interest is to compare these measurements between Visits, overall and at the different time points. I have problems setting up repeated measures ANOVA with 2 repeated measures (VISIT and TIME) (and then doing post hoc testing) or doing it with a linear mixed model ( both VISIT and TIME are repeated). Any suggestions? Paul Prof P Rheeder School of Health Systems and Public Health Faculty of Health Sciences University of Pretoria Room 6:12 HW Snyman North Tel: 012 354 1488 Fax: 012 354 1750 Mobile: 082 779 3054 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with Iterator
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of zhiji19 Sent: Tuesday, November 09, 2010 12:02 AM To: r-help@r-project.org Subject: [R] Help with Iterator Dear Experts, The following is my Iterator. When I try to write a new function with itel, I got error. This is what I have: supDist-function(x,y) return(max(abs(x-y))) myIterator - function(xinit,f,data=NULL,eps=1e-6,itmax=5,verbose=FALSE) { + xold-xinit + itel-0 + repeat { + xnew-f(xold,data) + if (verbose) { + cat( + Iteration: ,formatC(itel,width=3, format=d), + xold: ,formatC(xold,digits=8,width=12,format=f), + xnew: ,formatC(xnew,digits=8,width=12,format=f), + \n + ) + } + if ((supDist(xold,xnew) eps) || (itel == itmax)) { + return(xnew) + } + xold-xnew; itel-itel+1 + } + } mat-function (x, data=NULL) {return (1+x^itel)} myIterator(3, f=mat, verbose=TRUE) Error in f(xold, data) : object 'itel' not found Can anyone please help me to fix the error? It appears to me that your problem is a matter of variable scope. The error message says that the function f cannot find object 'itel'. That is because itel is defined in the function iterate and is local to that function. You might want to add a third parameter to function f so you can pass in the value of itel. (I would avoid using itel for the parameter name as you will likely end up confusing yourself at some point). I haven't tried to figure out what you are doing so I don't know if that is the best solution. But the problem is that f doesn't know about object 'itel'. Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why doesn't ?match keep the original (x) data.frame order?
Hello all, Following on my question here ( http://www.mail-archive.com/r-help@r-project.org/msg116075.html), I understand now that when using sort = FALSE the order of the merged data frame is unspecified. But why was it designed this way? Why not keep the original order (when possible)? Thanks, 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) -- [[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] repeatedrepeated measures in ANOVA or mixed model
Hi Paul, Here are a bunch of tutorials on the topic: http://www.r-statistics.com/2010/04/repeated-measures-anova-with-r-tutorials/ I suggest a more specific question for people to help :) Best, 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 Tue, Nov 9, 2010 at 8:02 AM, Paul Rheeder paul.rhee...@up.ac.za wrote: dear List I have a dataset with blood measurements at 5 points in TIME (0,30,60,90,120) taken on 3 VISITS (same subjects). the interest is to compare these measurements between Visits, overall and at the different time points. I have problems setting up repeated measures ANOVA with 2 repeated measures (VISIT and TIME) (and then doing post hoc testing) or doing it with a linear mixed model ( both VISIT and TIME are repeated). Any suggestions? Paul Prof P Rheeder School of Health Systems and Public Health Faculty of Health Sciences University of Pretoria Room 6:12 HW Snyman North Tel: 012 354 1488 Fax: 012 354 1750 Mobile: 082 779 3054 [[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] Overdetermined systems
Hello, I have a simple overdetermined system coming from physical measurements. I would like to know if there is a simple way to compute the result of such a system in R. I am aware of the package chebR and the least square methods to provide an optimal solution. But I am really interested in the error propagation, I have variable uncertainty associated to my measurements and would like to propagate them to come up with a confidence interval for the optimal solutions of the system. Any way or library to do that in R? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Overdetermined-systems-tp3033353p3033353.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] Add text to a stacked barplot
Dear All, Now with data. Any suggestion how to center the text in the filling would be appreciated. Kind regards, Ashraf library(lattice) a-c(100,100,93.57,50,0,0,6.43,50) b-c(1,1,1,1,0,0,0,0) VISIT-c(1,2,3,4,1,2,3,4) VISIT-as.character(VISIT) stuffd-data.frame(FREQ=a, VISIT=VISIT, RES=b) barchart(FREQ~VISIT, data = stuffd,par.strip.text = list(cex = 0.35), groups = RES, xlab=Visit,ylab=Frequency, layout = c(1,1), par.settings=list(superpose.polygon=list(col=colors()[c(636,96,256,92,27,376)])), stack = T, auto.key = list(points = FALSE, rectangles = TRUE, space = top), scales = list(x = list(alternating=c(1,1),tck=c(1,0),abbreviate = TRUE, minlength = 5, rot = 0),y=list(alternating=c(1,1),tck=c(1,0))), panel = function(y,x,...){ panel.grid(h = -1, v = 0, col = gray, lty = 3,lwd=1) panel.barchart(x,y,...) panel.text(x,y,label = round(y,3),cex=1) } ) On Mon, Nov 8, 2010 at 4:37 PM, RICHARD M. HEIBERGER r...@temple.edu wrote: Please post some data (fake data is fine) for stuffa. The example doesn't execute as is. Rich On Mon, Nov 8, 2010 at 10:27 AM, Ashraf Yassen ashraf.yas...@gmail.comwrote: Hi All, I need some help in putting text in a stacked barplot. The barplot is filled with 5 levels and now I would like to put text to each level in the stacked barplot. However, it seems that the code that I am using is not placing the text at the correct hight (centered at each fill) in the barplot. Any suggestions to improve the code to make it work? barchart(FREQ ~ VISIT |which*as.factor(TRTN), data = stuffa,par.strip.text = list(cex = 0.35), groups = RES, xlab=Visit,ylab=Frequency, layout = c(4,2), par.settings=list(superpose.polygon=list(col=colors()[c(636,96,256,92,27,376)])), stack = T, auto.key = list(points = FALSE, rectangles = TRUE, space = top), scales = list(x = list(alternating=c(1,1),tck=c(1,0),abbreviate = TRUE, minlength = 5, rot = 0),y=list(alternating=c(1,1),tck=c(1,0))), panel = function(y,x,...){ panel.grid(h = -1, v = 0, col = gray, lty = 3,lwd=1) panel.barchart(x,y,...) panel.text(x,y,label = round(y,1),cex=0.48) } ) Kind regards, Ashraf Yassen [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a list to store output objects from a recursive loop
Figured this out this ways I think outPut - list(list(result1),list(result2)) -Original Message- From: Santosh Srinivas [mailto:santosh.srini...@gmail.com] Sent: 09 November 2010 14:21 To: 'r-help@r-project.org' Subject: Creating a list to store output objects from a recursive loop Dear Group, I am having a function that I am running in a loop that generated two results for each loop The result1 is a zoo object The result2 is a data frame Now I want to put both of them in a list or some structure ... that I can access or output to a file after the loop is done. For e.g. for (i in 1:20){ niceFunction(x[i],i) } niceFunction (x,i) { result1 = someOperations() #zoo object result2 = someOperations() #data.frame OutputObj[i,1]=result1 OutputObj[i,2]=result2 } How can I go about this? Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Row-wise recurive function call
On Tue, Nov 9, 2010 at 1:58 PM, Santosh Srinivas santosh.srini...@gmail.com wrote: Thanks this works. Only, I need to reference in the formula using indexes. In case you don't want to change references in formula try this try this library(plyr) adply(a,1,playFn) also it easy to parallelize using .parallel argument with foreach in background -Original Message- From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] Sent: 09 November 2010 13:22 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Row-wise recurive function call try this: apply(data.matrix(a), 1, playFn) I hope it helps. Best, Dimitris On 11/9/2010 8:32 AM, Santosh Srinivas wrote: Dear Group, I have a following dataset: a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L, 39L, 7L, 47L), D = c(40L, 32L, 16L, 26L, 0L, 18L, 2L, 48L, 21L, 10L)), .Names = c(A, B, C, D), class = data.frame, row.names = c(NA, -10L)) I have a function that works off EVERY individual ROW to throw a result. Like playFn- function (x){ + result = ((x$A+6*x$B)/(3*x$C)+20)*x$D + return(result) + } I want to apply the function for every row can I use an apply function ... tried but not been able to ... e.g. print(rapply(a,playFn)) Please advise. Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thanks and Regards Sayan Dasgupta [[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] Lattice: xyplot group title format
Dear all, if I plot a lattice xyplot like: library(lattice); require(stats); Depth - equal.count(quakes$depth, number=8, overlap=.1) xyplot(lat ~ long | Depth, data = quakes) How can I manipulate the group title format (here: Depth)? Like the font size, position, etc. Best Marcus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there a way to have 'comment' keep a list?
Hello all, I recently discovered the comment command. I see it can only hold a vector of characters. Is there a way (or an alternative), to make it possible to have it keep a list? (for example, to keep different pieces of information like date of creation, information of each variable and so on) The closest solution I can think of is using 'names' on the vector, like this: x - 1 comment(x) - letters names(comment(x)) - LETTERS x comment(x) Any other suggestions? (or general best practices for the comment command ?) Thanks, 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) -- [[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] Installing the latest version of BRugs
Hi, I am trying to install the latest version of the BRugs package on a 32 bit windows machine which, due to the set up, won't allow me to install it via the usual R GUI. Can anyone point me to a link from which I can download the relevant files that allow me to install it manually (most pages flagged by Google point back to a message saying it was removed from CRAN and to look in the archives) - and I've not been able to identify the correct link for the CRAN extras site. Alternatively, can I just install it via the R GUI on a different machine and copy the BRugs (and if necessary any other missing pre-requisites) directories from the R library subdirectory? Cheers Martyn The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. Th...{{dropped:4}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there a way to have 'comment' keep a list?
You can use attributes: attributes(x) - list(CreateDate = Sys.time(), User = Sys.info()['user']) On Tue, Nov 9, 2010 at 8:36 AM, Tal Galili tal.gal...@gmail.com wrote: Hello all, I recently discovered the comment command. I see it can only hold a vector of characters. Is there a way (or an alternative), to make it possible to have it keep a list? (for example, to keep different pieces of information like date of creation, information of each variable and so on) The closest solution I can think of is using 'names' on the vector, like this: x - 1 comment(x) - letters names(comment(x)) - LETTERS x comment(x) Any other suggestions? (or general best practices for the comment command ?) Thanks, 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) -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there a way to have 'comment' keep a list?
Look at the help page, the example does exactly this by putting a two element vector of strings as comment. Hope it helps mario On 09-Nov-10 11:36, Tal Galili wrote: Hello all, I recently discovered the comment command. I see it can only hold a vector of characters. Is there a way (or an alternative), to make it possible to have it keep a list? (for example, to keep different pieces of information like date of creation, information of each variable and so on) The closest solution I can think of is using 'names' on the vector, like this: x- 1 comment(x)- letters names(comment(x))- LETTERS x comment(x) Any other suggestions? (or general best practices for the comment command ?) Thanks, 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) -- [[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. -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Error: could not find function extract in package raster
In addition to the good advice given earlier, you may note for the future that the raster authors reply actively on the R-sig-geo list, often within minutes. So questions about the raster package may best be directed to that list. Roger Monica Pisica wrote: Hi, I would like to use the function extract from package raster and i get the following error: m01e - extract(marsh01, p) Error: could not find function extract marsh01 is a raster object and p is an intersectExtent object that is not null. The package is installed and loaded, i use a Windows machine 64 bit and R x64 2.11.0. Do i really need to update my R to use this function? Thanks, Monica [[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. - Roger Bivand Economic Geography Section Department of Economics Norwegian School of Economics and Business Administration Helleveien 30 N-5045 Bergen, Norway -- View this message in context: http://r.789695.n4.nabble.com/Error-could-not-find-function-extract-in-package-raster-tp3032175p3033580.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] new column from column in another df
If I have a data frame where a species occupies several rows with different phases such as (both col's ar factors): species,phase Populus tremula,1 Populus tremula,2 Populus tremula,3 Calluna vulgaris,1 Calluna vulgaris,2 Betula alba,1 Betula alba,2 Betula alba,3 Primula veris,1 Primula veris,2 and another df where each species only have one row: species,growth_form Populus tremula,tree Acer platanoides,tree Ribes rubrum,shrub Calluna vulgaris,dwarf_shrub Betula alba,tree Primula veris,herb ...how can I create a new column in the first data frame where growth form is picked up from the second data frame (also factors) and entered into all rows for a species as follows: species,phase,growth_form Populus tremula,1,tree Populus tremula,2,tree Populus tremula,3,tree Calluna vulgaris,1,dwarf_shrub Calluna vulgaris,2,dwarf_shrub Betula alba,1,tree Betula alba,2,tree Betula alba,3,tree Primula veris,1,herb Primula veris,2,herb This will be made for data frames a lot larger than this one so it needs to be automated in some way. Also, as you can see the second data frame contains more species than the first one so I need to pick them out by name not only by row number... (I tried something like: subset(dataframe2.df, dataframe2.df$species==as.character(unique(dataframe1.df$species))) in a for loop but I got an error about different factor levels which is true.) Any help is very appreciated! Jonas -- View this message in context: http://r.789695.n4.nabble.com/new-column-from-column-in-another-df-tp3033619p3033619.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] Status of the bs Package
Hi, the package bs, version 1.0, is available. Yet, I've gote some problems with it, specifically with the maximum likelihood estimation of the parameters \alpha and \beta of Birnbaum-Saunders distribution. Let the following code run: library(bs) alpha-1.5 beta-0.5 n-100 set.seed(1) x-rbs(n,alpha,beta) est1bs(x) The MLE algorithm does not converge. Not only for this pair of values and for this sample... Please have a look... -- View this message in context: http://r.789695.n4.nabble.com/Status-of-the-bs-Package-tp827806p3033442.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] Installing the latest version of BRugs
On 09.11.2010 13:37, Martyn Byng wrote: Hi, Thanks for the reply. As to my second question, I think what I am really asking is: Assuming that everything is the same (version of R, operating system etc), can you just copy the package directory (for examples BRugs) in the R library subdirectory between different machines and expect the package to work correctly (assuming that all pre-requisites are present / the same version). Yes. Best, Uwe Ligges Cheers -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 09 November 2010 12:25 To: Martyn Byng Cc: r-help@r-project.org Subject: Re: [R] Installing the latest version of BRugs On Nov 9, 2010, at 5:38 AM, Martyn Byng wrote: Hi, I am trying to install the latest version of the BRugs package on a 32 bit windows machine which, due to the set up, won't allow me to install it via the usual R GUI. Can anyone point me to a link from which I can download the relevant files that allow me to install it manually (most pages flagged by Google point back to a message saying it was removed from CRAN and to look in the archives) - and I've not been able to identify the correct link for the CRAN extras site. http://www.stats.ox.ac.uk/pub/RWin/src/contrib/ Alternatively, can I just install it via the R GUI on a different machine and copy the BRugs (and if necessary any other missing pre-requisites) directories from the R library subdirectory? Packages often have version dependencies and you have not given any details about those. Cheers Martyn David Winsemius, MD West Hartford, CT This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extending the accuracy of exp(1) in R
Hi, I want to use a more accurate value of exp(1). The value given by R is 2.718282. I want a value which has more than 15 decimal places. Can anyone let me know how can I increase the accuracy level. Actually there are some large multipliers of exp(1) in my whole expression, and I want a more accurate result at the last step of my program, and for that I need to use highly accurate value of exp(1). Can anyone help me out? Thanks. Shant [[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 the latest version of BRugs
Hi, Thanks for the reply. As to my second question, I think what I am really asking is: Assuming that everything is the same (version of R, operating system etc), can you just copy the package directory (for examples BRugs) in the R library subdirectory between different machines and expect the package to work correctly (assuming that all pre-requisites are present / the same version). Cheers -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 09 November 2010 12:25 To: Martyn Byng Cc: r-help@r-project.org Subject: Re: [R] Installing the latest version of BRugs On Nov 9, 2010, at 5:38 AM, Martyn Byng wrote: Hi, I am trying to install the latest version of the BRugs package on a 32 bit windows machine which, due to the set up, won't allow me to install it via the usual R GUI. Can anyone point me to a link from which I can download the relevant files that allow me to install it manually (most pages flagged by Google point back to a message saying it was removed from CRAN and to look in the archives) - and I've not been able to identify the correct link for the CRAN extras site. http://www.stats.ox.ac.uk/pub/RWin/src/contrib/ Alternatively, can I just install it via the R GUI on a different machine and copy the BRugs (and if necessary any other missing pre-requisites) directories from the R library subdirectory? Packages often have version dependencies and you have not given any details about those. Cheers Martyn David Winsemius, MD West Hartford, CT This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Status of the bs Package
Perhaps the problem stands on the rbs function which generates random samples from the Birnbaum-Saunders distribution: library(bs) set.seed(1) x-rbs(n=1000,alpha=0.5,beta=1.0) # sample mean mean(x) [1] 1.117749 # expected value beta*(1+alpha^2/2) [1] 2.125 # so different! -- View this message in context: http://r.789695.n4.nabble.com/Status-of-the-bs-Package-tp827806p3033546.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] new column from column in another df
fugelpitch jo...@runtimerecords.net 09-Nov-10 12:28: ...how can I create a new column in the first data frame where growth form is picked up from the second data frame (also factors) and entered into all rows for a species as follows: ?merge eg dat1 - merge(dat1,dat2) Marianne -- Marianne Promberger PhD, King's College London http://promberger.info R version 2.12.0 (2010-10-15) Ubuntu 9.04 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] tukey.1
I have been trying to do tukey's test to no avail. This is what I have and the error produced: pen.df = data.frame(blend, treatment, y) source(tukey.1.r) tukey.1(aov.pen, pen.df) Error in tukey.1(aov.pen, pen.df) : the model must be two-way This is a two-way design. Therefore I am confused. Can anyone help? Raphael pen.df blend treatment y 1 1 A 89 2 2 A 84 3 3 A 81 4 4 A 87 5 5 A 79 6 1 B 88 7 2 B 77 8 3 B 87 9 4 B 92 10 5 B 81 11 1 C 97 12 2 C 92 13 3 C 87 14 4 C 89 15 5 C 80 16 1 D 94 17 2 D 79 18 3 D 85 19 4 D 84 20 5 D 88 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Add values of rlm coefficients to xyplot
Hello again, Thanks to this forum, I found a lapply command to apply rlm to each Device of the Name column of the df1 data frame (df1 data frame is given in the previous post). I'm now looking for a nice way to create a data frame with the name of the device, the intercept and the slope. I now use a for loop (see below) but I'm sure there is a more elegant way to retrieve these coefficients, isn't it ? Thanks in advance for your help to improve this script. Ptit Bleu. # Library including rlm library(MASS) # To apply rlm to each Device of df1$Name bbb-lapply(split(df1, df1$Name), function(X)(rlm(col2 ~ col3, data=X)}) # To get Intercept and Slope for each device dfrlm1-data.frame() for (u in 1:length(names(bbb))) { dfrlm1-rbind(dfrlm1, data.frame(as.character(names(bbb)[u]), bbb[[u]][[1]][[1]], bbb[[u]][[1]][[2]])) } names(dfrlm1)-c(Name, Intercept, Slope) # To plot the graphs and display the rlm coefficients x11(15,12) xyplot(df1$col2 ~ df1$col3 | df1$Name, panel = function(x, y,...) { panel.abline(h=seq(20,30,1), col=gray) panel.abline(v=seq(20,70,5), col=gray) panel.xyplot(x, y, type=p, col=red, pch=20,...) panel.abline(rlm(y ~ x), col=blue) panel.text(40,21, paste(y =, round(dfrlm1$Intercept[panel.number()],3),+ (, round(dfrlm1$Slope[panel.number()],3),) *x)) }, scales=list(cex=1.2), xlab=list(X, cex=1.4), ylab=list(Y, cex=1.4), xlim=c(20,70), ylim=c(20,30)) -- View this message in context: http://r.789695.n4.nabble.com/Add-values-of-rlm-coefficients-to-xyplot-tp3032166p3033669.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to eliminate this for loop ?
I doubt this to be true. Try this in R: dmy-rep(1,5) dmy[2:5]-dmy[1:4]+1 This is equivalent to what you propose (even simpler), but it does not, as OP seems to have wanted, fill dmy with 1,2,3,4,5, but, as I had expected, with 1,2,2,2,2. I would be interested in knowing what exactly the difference beween my example above, and the one you suggest, is. As others have suggested: another way is to use actual recursive calls, but I seriously doubt these to be more efficient. You should probably only use it if you really hate to type the word 'for' (-: Though I would also like to see an example where they prove to be the better way to go (by any criteria, but preferably speed or perhaps other resource usage) Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: maandag 8 november 2010 15:04 To: Nick Sabbe Cc: 'PLucas'; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? On Nov 8, 2010, at 4:30 AM, Nick Sabbe wrote: Whenever you use a recursion (that cannot be expressed otherwise), you always need a (for) loop. Not necessarily true ... assuming a is of length n: a[2:n] - a[1:(n-1))]*b + cc[1:(n-1)] # might work if b and n were numeric vectors of length 1 and cc had length = n. (Never use c as a vector name.) # it won't work if there are no values for the nth element at the beginning and you are building up a element by element. And you always need to use operations that appropriate to the object type. So if a really is a list, this will always fail since arithmetic does not work on list elements. If on the other hand, the OP were incorrect in calling this a list and a were a numeric vector, there might be a chance of success if the rules of indexing were adhered to. The devil is in the details and the OP has not supplied enough code to tell what might happen. -- David. Apply and the like do not allow to use the intermediary results (i.e. a[i-1] to calculate a[i]). So: no, it cannot be avoided in your case, I guess. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of PLucas Sent: maandag 8 november 2010 10:26 To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } Is it possible ? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to-eliminate-this-for-loop-tp3031667p30316 67.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] running command before non-interactive job is exited
Dear list members, i am running some R scripts non interactively on a remote cluster. In case of an error this cluster terminates the R job and only sends me some messages. Is there any way to save the workspace before this job is terminated to retrieve some information on why the error is caused? I have tried to run this test job in a non interactive mode, but had no success (the a[b] command is added to cause the error!): .Last = function() save.image() a=1:10 a[b] The code was run by: R --vanilla test.R Any suggestions? Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] new column from column in another df
?merge df1 V1 V2 1 Populus tremula 1 2 Populus tremula 2 3 Populus tremula 3 4 Calluna vulgaris 1 5 Calluna vulgaris 2 6 Betula alba 1 7 Betula alba 2 8 Betula alba 3 9 Primula veris 1 10Primula veris 2 df2 - read.table('clipboard', sep=',') df2 V1 V2 1 Populus tremulatree 2 Acer platanoidestree 3 Ribes rubrum shrub 4 Calluna vulgaris dwarf_shrub 5 Betula albatree 6Primula verisherb merge(df1, df2, by = V1) V1 V2.xV2.y 1 Betula alba1tree 2 Betula alba2tree 3 Betula alba3tree 4 Calluna vulgaris1 dwarf_shrub 5 Calluna vulgaris2 dwarf_shrub 6 Populus tremula1tree 7 Populus tremula2tree 8 Populus tremula3tree 9 Primula veris1herb 10Primula veris2herb On Tue, Nov 9, 2010 at 7:28 AM, fugelpitch jo...@runtimerecords.net wrote: If I have a data frame where a species occupies several rows with different phases such as (both col's ar factors): species,phase Populus tremula,1 Populus tremula,2 Populus tremula,3 Calluna vulgaris,1 Calluna vulgaris,2 Betula alba,1 Betula alba,2 Betula alba,3 Primula veris,1 Primula veris,2 and another df where each species only have one row: species,growth_form Populus tremula,tree Acer platanoides,tree Ribes rubrum,shrub Calluna vulgaris,dwarf_shrub Betula alba,tree Primula veris,herb ...how can I create a new column in the first data frame where growth form is picked up from the second data frame (also factors) and entered into all rows for a species as follows: species,phase,growth_form Populus tremula,1,tree Populus tremula,2,tree Populus tremula,3,tree Calluna vulgaris,1,dwarf_shrub Calluna vulgaris,2,dwarf_shrub Betula alba,1,tree Betula alba,2,tree Betula alba,3,tree Primula veris,1,herb Primula veris,2,herb This will be made for data frames a lot larger than this one so it needs to be automated in some way. Also, as you can see the second data frame contains more species than the first one so I need to pick them out by name not only by row number... (I tried something like: subset(dataframe2.df, dataframe2.df$species==as.character(unique(dataframe1.df$species))) in a for loop but I got an error about different factor levels which is true.) Any help is very appreciated! Jonas -- View this message in context: http://r.789695.n4.nabble.com/new-column-from-column-in-another-df-tp3033619p3033619.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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there a way to have 'comment' keep a list?
I hadn't seen 'comment' before, so don't take my suggestion as authoritative. It looks useful, so I investigated a bit. This technique seems to work and is (perhaps?) easier than names: tlist - list(a=c(1:3), b=7) comment(x) - unlist(sapply(tlist, as.character)) or in one line comment(x) - unlist(sapply(list(a=c(1:3), b=7), as.character)) If at least one of the list elements is already character you could simplify to: tlist - list(a=c(1:3), b=fred) comment(x) - unlist(tlist) or in one line comment(x) - unlist(list(a=c(1:3), b=fred)) Not as nice as having a _real_ list, but I guess that would really be a case for attributes HTH Keith J Tal Galili tal.gal...@gmail.com wrote in message news:aanlktimpmma9_h1+=oj1bhrf27rlp2j5veodhjxqp...@mail.gmail.com... Hello all, I recently discovered the comment command. I see it can only hold a vector of characters. Is there a way (or an alternative), to make it possible to have it keep a list? (for example, to keep different pieces of information like date of creation, information of each variable and so on) The closest solution I can think of is using 'names' on the vector, like this: x - 1 comment(x) - letters names(comment(x)) - LETTERS x comment(x) Any other suggestions? (or general best practices for the comment command ?) Thanks, 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) -- [[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] Row-wise recurive function call
On Nov 9, 2010, at 3:28 AM, Santosh Srinivas wrote: Thanks this works. Only, I need to reference in the formula using indexes. Then you need to use the indices inside plaFn. playFn- function (x){ result = ((x[1]+6*x[2])/(3*x[3])+20)*x[4] return(result) } -Original Message- From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] Sent: 09 November 2010 13:22 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Row-wise recurive function call try this: apply(data.matrix(a), 1, playFn) I hope it helps. Best, Dimitris On 11/9/2010 8:32 AM, Santosh Srinivas wrote: Dear Group, I have a following dataset: a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L, 39L, 7L, 47L), D = c(40L, 32L, 16L, 26L, 0L, 18L, 2L, 48L, 21L, 10L)), .Names = c(A, B, C, D), class = data.frame, row.names = c(NA, -10L)) I have a function that works off EVERY individual ROW to throw a result. Like playFn- function (x){ + result = ((x$A+6*x$B)/(3*x$C)+20)*x$D + return(result) + } I want to apply the function for every row can I use an apply function ... tried but not been able to ... e.g. print(rapply(a,playFn)) Please advise. Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Implementation of Functional Link Neural Network
Dear Team I am trying to find a reference implementation of the functional link neural network in R-project. the neuralnet package does not have it. Any help in terms of a reference implementation of this variant of neural network ( without hidden layers) will be greatly appreciated. As always thanks to your proactive support. Regards Shyam [[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] Catmap package and forest plots
I am sorry to bother the group with what is probably a simple error on my behalf as I am new to R, but I have been able to find a solution looking online or in the R forums. I have just started using R so I can use the catmap package which allows a meta analysis of both case control and TDT studies. I am using the latest windows version of R (v 2.12) and the latest version of catmap (V1.6). I can perform the actual meta analysis at the heart of catmap; e.g.catmap('rs2305764.txt', 0.95, TRUE, TRUE) works fine, giving me all the expected outputs and a tabulation of the ORs and CIs for each study. But when I try to use the results of that meta analysis to generate a forest plot based on that data I get the error message 'Error in catmapobject$ci : $ operator is invalid for atomic vectors' Am I right in thinking the order should be follows: catmapobject1-catmap('rs2305764.txt', 0.95, TRUE, TRUE) catmap.forest(catmapobject1, TRUE, TRUE) I think I am failing to assign the results of the meta anlaysis - catmap('rs2305764.txt', 0.95, TRUE, TRUE)--- to an object in R, and then have catmap.forest act on that object. thanks Matthew [[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] Extending the accuracy of exp(1) in R
2010/11/9 Shant Ch sha1...@yahoo.com Can anyone let me know how can I increase the accuracy level. library(Rmpfr) exp(mpfr(1,128)) 1 'mpfr' number of precision 128 bits [1] 2.718281828459045235360287471352662497759 -- Mi³ego dnia [[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 the latest version of BRugs
On Nov 9, 2010, at 5:38 AM, Martyn Byng wrote: Hi, I am trying to install the latest version of the BRugs package on a 32 bit windows machine which, due to the set up, won't allow me to install it via the usual R GUI. Can anyone point me to a link from which I can download the relevant files that allow me to install it manually (most pages flagged by Google point back to a message saying it was removed from CRAN and to look in the archives) - and I've not been able to identify the correct link for the CRAN extras site. http://www.stats.ox.ac.uk/pub/RWin/src/contrib/ Alternatively, can I just install it via the R GUI on a different machine and copy the BRugs (and if necessary any other missing pre-requisites) directories from the R library subdirectory? Packages often have version dependencies and you have not given any details about those. Cheers Martyn 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] Add values of rlm coefficients to xyplot
On Nov 9, 2010, at 8:01 AM, PtitBleu wrote: Hello again, Thanks to this forum, I found a lapply command to apply rlm to each Device of the Name column of the df1 data frame (df1 data frame is given in the previous post). I'm now looking for a nice way to create a data frame with the name of the device, the intercept and the slope. I now use a for loop (see below) but I'm sure there is a more elegant way to retrieve these coefficients, isn't it ? Thanks in advance for your help to improve this script. Ptit Bleu. # Library including rlm library(MASS) # To apply rlm to each Device of df1$Name bbb-lapply(split(df1, df1$Name), function(X)(rlm(col2 ~ col3, data=X)}) # To get Intercept and Slope for each device dfrlm1-data.frame() for (u in 1:length(names(bbb))) { dfrlm1-rbind(dfrlm1, data.frame(as.character(names(bbb)[u]), bbb[[u]][[1]][[1]], bbb[[u]][[1]][[2]])) } names(dfrlm1)-c(Name, Intercept, Slope) That looks a bit painful. It might be easier to simple wrap the rlm call in the lapply(split(...)) step with coef() and then you would have just the coefficients in a neat bundle. Generally that list can be made into a data.frame or matrix with do.call(rbind, list- object), possibly needing as.data.frame to finish the bundling process. ?coef # which is a function that is a method for many regression fit classes methods(coef) class(rlm(stack.loss ~ ., stackloss)) [1] rlm lm Then, of course, there are the plyr and data.table packages that often make the process even beautiful. -- David # To plot the graphs and display the rlm coefficients x11(15,12) xyplot(df1$col2 ~ df1$col3 | df1$Name, panel = function(x, y,...) { panel.abline(h=seq(20,30,1), col=gray) panel.abline(v=seq(20,70,5), col=gray) panel.xyplot(x, y, type=p, col=red, pch=20,...) panel.abline(rlm(y ~ x), col=blue) panel.text(40,21, paste(y =, round(dfrlm1$Intercept[panel.number()],3),+ (, round(dfrlm1$Slope[panel.number()],3),) *x)) }, scales=list(cex=1.2), xlab=list(X, cex=1.4), ylab=list(Y, cex=1.4), xlim=c(20,70), ylim=c(20,30)) -- 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] Extending the accuracy of exp(1) in R
Where the value of exp(1) as computed by R is concerned, you have been deceived by what R displays (prints) on screen. The default is to display any number to 7 digits of accuracy, but that is not the accuracy of the number held internally by R: exp(1) # [1] 2.718282 exp(1) - 2.718282 # [1] -1.715410e-07 I encourage anyone confused about this issue to study http://en.wikipedia.org/wiki/The_Treachery_of_Images And to watch http://www.youtube.com/watch?v=ejweI0EQpX8 Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to extract Friday data from daily data.
thornbird huachang...@gmail.com 05-Nov-10 20:10: Thank you very much. It worked great with the testdata. I have one more questionto to ask. As my data is incomplete, sometimes Thu is also missing, then I have no other options but to pick Sat instead, and if Sat is also missing, then my best possible option is to pick Wed, and etc. Bascially I have to pick a day as the data for that week starting from Friday following this order: Fri-- (if no Fri) Thu-- (if no Thu) Sat-- (if no Sat) Wed -- (if no Wed) Sun -- (if no Sun) Tue --(if no Tue) Mon. In this sense, I have to write a loop if command, right? Could you please help me with that? Again thanks a lot. I don't think you need a loop. Without knowing zoo, here's what I would try: If you look at Gabor's code, # extract all Thursdays and Fridays z45 - z[format(time(z), %w) %in% 4:5,] # keep last entry in each week # and show result on R console z45[!duplicated(format(time(z45), %U), fromLast = TRUE), ] It takes Thur and Fri data and takes the latest record that is there. You could work on a solution along the same lines except have the days ordered in the order of your top choice above (or inverse), then pick the first (or last) entry that exists for that week. Of course, since your choice order is not chronologlical you probably can't use fromLast. Marianne -- Marianne Promberger PhD, King's College London http://promberger.info R version 2.12.0 (2010-10-15) Ubuntu 9.04 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extending the accuracy of exp(1) in R
On 09-Nov-10 13:21:10, Shant Ch wrote: Hi, I want to use a more accurate value of exp(1)._ The value given by R is 2.718282. I want a value which has more than 15 decimal places. Can anyone let me know how can I increase the accuracy level. Actually there are some large multipliers of exp(1) in my whole expression, and I want a more accurate result at the last step of my program, and for that I need to use highly accurate value of exp(1). Can anyone help me out? Thanks. Shant Where the value of exp(1) as computed by R is concerned, you have been deceived by what R displays (prints) on screen. The default is to display any number to 7 digits of accuracy, but that is not the accuracy of the number held internally by R: exp(1) # [1] 2.718282 exp(1) - 2.718282 # [1] -1.715410e-07 You can get a particular result to be displayed to greater accuracy by using print(..., digits=...) (and the digits argument is the one in second position, so you don;t necessarily need to use digits=. Therefore: print(exp(1),17) # [1] 2.718281828459045 (and you will not get greater precision by using more digits, e.g. 18,19,...). print(exp(1)-2.718281828459045,19) [1] 0 So 2.718281828459045 is the greatest accuracy you can get with normal 32-bit R. This is the value which will be computed by R for any instance of exp(1), and which will be stored as the value of Y in: Y - exp(1) If you want to see all computed results displayed to more than 7 digits of accuracy, you can set the global digits option: options(digits=17) exp(1) # [1] 2.718281828459045 pi # [1] 3.141592653589793 See the entry for digits in ?options. Hoping this helps, Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 09-Nov-10 Time: 13:42:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extending the accuracy of exp(1) in R
On Nov 9, 2010, at 8:21 AM, Shant Ch wrote: Hi, I want to use a more accurate value of exp(1). The value given by R is 2.718282. Well, not really. That is what is printed at the console with the default settings for digits. The internal representation is wider: format(exp(1), digits=15) [1] 2.71828182845905 I want a value which has more than 15 decimal places. Can anyone let me know how can I increase the accuracy level. You already have it. Actually there are some large multipliers of exp(1) in my whole expression, and I want a more accurate result at the last step of my program, and for that I need to use highly accurate value of exp(1). Can anyone help me out? Thanks. Shant 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] time question
I have this script which I use to get an epoch with accuracy of 1 second (based on R's inability to calculate millisecond-accurate timestamps -- at least I have not seen a straightforward solution :) ): nowInSeconds - as.numeric(Sys.time()) nowInMS - nowInSeconds * 1000 print(nowInSeconds) print(as.character(nowInMS)) when running this I get the following: nowInSeconds - as.numeric(Sys.time()) nowInMS - nowInSeconds * 1000 print(nowInSeconds) [1] 1289312002 print(as.character(nowInMS)) [1] 1289312002093 I wonder where the 93 milliseconds come from. Is this a random number? A rounding error? Can somebody explain this? 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] help to add a new column filled with value 1
Dear All, I have a data frame with 5 column and 201 row data. I want to add one more column between column 1 and 2 with value of 1. So the new column has to be the second column filled with 1. Any help will be appreciated. Thanks for your time. Thanks Rg Mohan L __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] time question
On Nov 9, 2010, at 9:18 AM, Ralf B wrote: I have this script which I use to get an epoch with accuracy of 1 second (based on R's inability to calculate millisecond-accurate timestamps -- at least I have not seen a straightforward solution :) ): From help page for Sys.time: Value Sys.time returns an object of class POSIXct (see DateTimeClasses). On almost all systems it will have sub-second accuracy: on systems conforming to POSIX 1003.1-2001 the time will be reported in microsecond increments. On Windows it increments in clock ticks (1/60 of a second) reported to millisecond accuracy. You may be misled by the output of default formats. nowInSeconds - as.numeric(Sys.time()) nowInMS - nowInSeconds * 1000 print(nowInSeconds) print(as.character(nowInMS)) when running this I get the following: nowInSeconds - as.numeric(Sys.time()) nowInMS - nowInSeconds * 1000 print(nowInSeconds) [1] 1289312002 print(as.character(nowInMS)) [1] 1289312002093 I wonder where the 93 milliseconds come from. Is this a random number? A rounding error? Can somebody explain this? 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] Qt interfaces to R/ Windows version as well as using PyQT
Is the project on creating R GUIs using QT interfaces still on? Any plans of using PyQT Regards Ajay Ohri Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Tue, Nov 9, 2010 at 8:33 PM, Kari Ruohonen kari.ruoho...@utu.fi wrote: Hi, I wonder if someone could help. I needed to transfer (copy) a workspace file that had been generated in linux (R 2.11) to windows running the same version of R 2.11 (but of course windows binary). Usually, there is no problem in doing this and all objects work as expected. I am often doing this to be able to produce wmf or emf graphic files that I need. This time I had some spectra that I have taken the first derivative of with the sav_gol function in the RTisean package. I know RTisean is just an interface to the Tisean executables. The trouble I am facing is that it seems that the location of the Tisean executables is somehow hard coded to the R workspace file. I assume this since when I try to rerun the sav_gol on the windows machine after copying the workspace file from linux and opening it in windows, RTisean tries to search the Tisean executables from the location that is valid for linux, not windows. RTisean help package says RTisean asks the location of the executables the first time a function is called and that this location is saved in user's home directory for future use. There is no specific information of how this works in windows where there is no obvious home directory. However, I have run R console on windows and it asked this location but I don't know where the information was stored. In linux it is in .RTiseanSettings file in user's home as explained. My questions are: 1) Is there a way I could break the link of the Tisean executables to the linux location so that when run in windows the executables in windows will be used? 2) Is the hard coding of the location of Tisean executables to the workspace image deliberate and necessary? Many thanks, Kari Ruohonen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Status of the bs Package
Perhaps there's a problem with the function rbs, that generates a random sample from the Birnbaum-Saunders distribution. The rgbs function (package gbs) does it better. Look at these code and results: library(bs) set.seed(1) alpha-0.17 beta-130 x-rbs(n=1000,alpha,beta) # sample mean mean(x) [1] 150.8288 # expected value beta*(1+alpha^2/2) [1] 131.8785 est1bs(x) $beta.start [1] 149.9556 $alpha [1] 0.1079173 $beta [1] 149.9558 $converge [1] TRUE $iteration [1] 2 #not fine library(gbs) # set.seed(1) x-rgbs(n=1000,alpha,beta) # sample mean mean(x) [1] 131.7481 # expected value beta*(1+alpha^2/2) [1] 131.8785 est1bs(x) $beta.start [1] 129.7422 $alpha [1] 0.1758475 $beta [1] 129.7421 $converge [1] TRUE $iteration [1] 2 #fine -- View this message in context: http://r.789695.n4.nabble.com/Status-of-the-bs-Package-tp827806p3033734.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] help to merge two data frame if name matches
Dear All, I have two data like this : $cat main.csv name,id,memory,storage mohan,1,100.20,1.10 ram,1,200,100 kumar,1,400,50 xxx,1,100,40 aaa,1,800,45 mount,1,200,80 main - read.csv(file='main.csv',sep=',' , header=TRUE) main nameidmemory storage 1 mohan 1100.2 10 2 ram 1 200.0 100 3 kumar1 400.0 50 4 xxx 1 100.0 40 5 aaa 1 800.0 45 6 mount1 200.0 80 $cat other.csv name,ip,bsent,breceived mohan,1,12.00,0.01 xxx,1,00.00,1.110 kumat,1,1.00,1.00 mmm,1,10.00,8.08 own,1,20.13,12.08 per,1,1.89,0.89 other - read.csv(file='other.csv',sep=',' , header=TRUE) other nameip bsent breceived 1 mohan 1 12.00 0.01 2 xxx 1 0.00 1.11 3 kumat1 1.00 1.00 4 mmm 1 10.00 8.08 5 own 1 20.13 12.08 6 per 1 1.89 0.89 I want to merge ip,bsent,breceived column to main , If the name in the the main data frame is there in the other data frame . some thinng like this: nameid memory storage ip bsent breceived mohan1100 20 1 12.00 0.01 ram1200 1000 00.000.00 kumar1400 50 1 1.00 1.00 xxx1100 40 1 00.001.110 aaa 1800 45 0 00.0000.00 mount1200 80 0 00.0000.00 If in case the name in the main data frame does not there in the other data frame, simple I want to add zero to ip,bsent,breceived value. I hope this can be done with R. Any help will appricated. Thanks for you time. Thanks Rg Mohan L __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] the formula of quantile regression for panel data, which is correct?
Date: Tue, 9 Nov 2010 00:41:26 -0800 From: 523541...@qq.com To: r-help@r-project.org Subject: [R] the formula of quantile regression for panel data, which is correct? Hi,everyone I have some trouble in understanding the formula. http://r.789695.n4.nabble.com/file/n3033305/%E6%9C%AA%E5%91%BD%E5%90%8D.jpg http://r.789695.n4.nabble.com/file/n3033305/%E6%9C%AA%E5%91%BD%E5%90%8D1.jpg which is correct? I didn't see anyone else answer this but presumably more context would help including things like variable defintions. How are the deltas and lambdas defined or doesn't that matter? You see sign and other conventions change in many works, especially between disciplines. When in doubt of course, paper and pencil with test data can be quite illuminating too :) I guess you could assume that someone who knows the answer would recognize the source of the nice pictures and the meanings of the variables but that isn't always the case. best wish. thanks -- View this message in context: http://r.789695.n4.nabble.com/the-formula-of-quantile-regression-for-panel-data-which-is-correct-tp3033305p3033305.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tukey.1
Including pen.df is a good start, but we likely can't help without more info: Where'd you get tukey.1.r and what's in it? What's aov.pen? On Tue, Nov 9, 2010 at 10:13 AM, Raphael Fraser raphael.fra...@gmail.com wrote: I have been trying to do tukey's test to no avail. This is what I have and the error produced: pen.df = data.frame(blend, treatment, y) source(tukey.1.r) tukey.1(aov.pen, pen.df) Error in tukey.1(aov.pen, pen.df) : the model must be two-way This is a two-way design. Therefore I am confused. Can anyone help? Raphael pen.df blend treatment y 1 1 A 89 2 2 A 84 3 3 A 81 4 4 A 87 5 5 A 79 6 1 B 88 7 2 B 77 8 3 B 87 9 4 B 92 10 5 B 81 11 1 C 97 12 2 C 92 13 3 C 87 14 4 C 89 15 5 C 80 16 1 D 94 17 2 D 79 18 3 D 85 19 4 D 84 20 5 D 88 -- 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] help to merge two data frame if name matches
On 09.11.2010 16:17, Mohan L wrote: Dear All, I have two data like this : $cat main.csv name,id,memory,storage mohan,1,100.20,1.10 ram,1,200,100 kumar,1,400,50 xxx,1,100,40 aaa,1,800,45 mount,1,200,80 main- read.csv(file='main.csv',sep=',' , header=TRUE) main nameidmemory storage 1 mohan 1100.2 10 2 ram 1 200.0 100 3 kumar1 400.0 50 4 xxx 1 100.0 40 5 aaa 1 800.0 45 6 mount1 200.0 80 $cat other.csv name,ip,bsent,breceived mohan,1,12.00,0.01 xxx,1,00.00,1.110 kumat,1,1.00,1.00 mmm,1,10.00,8.08 own,1,20.13,12.08 per,1,1.89,0.89 other- read.csv(file='other.csv',sep=',' , header=TRUE) other nameip bsent breceived 1 mohan 1 12.00 0.01 2 xxx 1 0.00 1.11 3 kumat1 1.00 1.00 4 mmm 1 10.00 8.08 5 own 1 20.13 12.08 6 per 1 1.89 0.89 I want to merge ip,bsent,breceived column to main , If the name in the the main data frame is there in the other data frame . some thinng like this: nameid memory storage ip bsent breceived mohan1100 20 1 12.00 0.01 ram1200 1000 00.000.00 kumar1400 50 1 1.00 1.00 xxx1100 40 1 00.001.110 aaa 1800 45 0 00.0000.00 mount1200 80 0 00.0000.00 If in case the name in the main data frame does not there in the other data frame, simple I want to add zero to ip,bsent,breceived value. I hope this can be done with R. Any help will appricated. See ?merge including its argument all=TRUE. Uwe Ligges Thanks for you time. Thanks Rg Mohan L __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] library(kernlab) --- unable to load shared library
Dear R users, I have recently encountered a problem with using the function `library` in order to load the package `kernlab`. My output of sessionInfo() is as follows: R version 2.10.1 (2009-12-14) x86_64-unknown-linux-gnu locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base I have installed the package by install.packages(kernlab), and it had ended up in giving a message about the package being installed successfully. But as soon as I type library(kernlab) the output is: Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/usr/local/sage/local/lib/R//library/kernlab/libs/kernlab.so': /usr/local/sage/local/lib/R//library/kernlab/libs/kernlab.so: undefined symbol: dgemv_ Error: package/namespace load failed for 'kernlab' The call to .libPaths() lists '/usr/local/sage/local/lib/R//library' and one more path. I have manually checked if the package is in the directory /usr/local/sage/local/lib/R//library = it is there... (at least there is a folder with the name `kernlab`) Could you please make any suggestions concerning the causes and/or solution of this problem ? Any help would be greatly appreciated. Sincerely yours, Yuliya Matveyeva. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a list to store output objects from a recursive loop
On 09.11.2010 09:51, Santosh Srinivas wrote: Dear Group, I am having a function that I am running in a loop that generated two results for each loop The result1 is a zoo object The result2 is a data frame Now I want to put both of them in a list Just generate a list of lists, the latter list each containing one zoo object and 1 data.frame. Or use a list with dim attributes, so that it is like the matrix you gave below. Uwe Ligges or some structure ... that I can access or output to a file after the loop is done. For e.g. for (i in 1:20){ niceFunction(x[i],i) } niceFunction (x,i) { result1 = someOperations() #zoo object result2 = someOperations() #data.frame OutputObj[i,1]=result1 OutputObj[i,2]=result2 } How can I go about this? Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extending the accuracy of exp(1) in R
On 09/11/2010 8:21 AM, Shant Ch wrote: Hi, I want to use a more accurate value of exp(1). The value given by R is 2.718282. I want a value which has more than 15 decimal places. Can anyone let me know how can I increase the accuracy level. The value in R is accurate to approximately 15 decimal places; it only prints to 6 by default. Actually there are some large multipliers of exp(1) in my whole expression, and I want a more accurate result at the last step of my program, and for that I need to use highly accurate value of exp(1). It's really unlikely that this would help. Most computations in R are done in double precision, so having one constant at higher precision won't affect much. You could replace all computation with higher precision by using the gmp package, but it's not a painless procedure, and it would cut you off from code in most packages. I think you probably want to re-think the computation you're doing to figure out how to do it with 15 digit arithmetic. Have you looked at the expm1() and related functions? Duncan Murdoch Can anyone help me out? Thanks. Shant [[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] FCS Files
Hi I've got a problem: I will read FCS 3.0 files with programm r 2.12, package flowViz. But the programm says Fehler in readFCSgetPar(x, $DATATYPE), Parameter (s) $DATATYPE Not contained in 'x'. ^ Fabio -- View this message in context: http://r.789695.n4.nabble.com/FCS-Files-tp3033718p3033718.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] : unusual combinations of categorical data
On 11/8/2010 5:25 PM, Alan Chalk wrote: Regarding unusual combinations of factors in categorical data. Are there any R packages that can be used to identify the outliers i.e. unusual combinations in categorical datasets ? Unusual combinations of factors are those that have large residuals in some loglinear model (or glm with poisson link)-- positive if the observed frequencies are expected, negative otherwise. The most basic 'null' loglinear model is that of mutual independence, however, if some of the factors are predictors, it makes sense to include their highest interaction in the null model. Fit the model with loglm() or glm(), and use vcd::mosaic() to visualize the outliers. HTH -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] location of Tisean executables when using RTisean and jumping between linux and windows
I have quickly looked into the code. It shows that: If you have copied your workspace, then you have also copied the object .TISEANpath along with your workspace and RTisean looks at first at the contents of that object. So just open the workspace, delete the object and save the workspace again. Then you will be asked. Otherwise, RTisean will look for the file .RTiseanSettings in the home directory, which is derived on Windows by: Sys.getenv(HOME) Best wishes, Uwe Ligges On 09.11.2010 16:03, Kari Ruohonen wrote: Hi, I wonder if someone could help. I needed to transfer (copy) a workspace file that had been generated in linux (R 2.11) to windows running the same version of R 2.11 (but of course windows binary). Usually, there is no problem in doing this and all objects work as expected. I am often doing this to be able to produce wmf or emf graphic files that I need. This time I had some spectra that I have taken the first derivative of with the sav_gol function in the RTisean package. I know RTisean is just an interface to the Tisean executables. The trouble I am facing is that it seems that the location of the Tisean executables is somehow hard coded to the R workspace file. I assume this since when I try to rerun the sav_gol on the windows machine after copying the workspace file from linux and opening it in windows, RTisean tries to search the Tisean executables from the location that is valid for linux, not windows. RTisean help package says RTisean asks the location of the executables the first time a function is called and that this location is saved in user's home directory for future use. There is no specific information of how this works in windows where there is no obvious home directory. However, I have run R console on windows and it asked this location but I don't know where the information was stored. In linux it is in .RTiseanSettings file in user's home as explained. My questions are: 1) Is there a way I could break the link of the Tisean executables to the linux location so that when run in windows the executables in windows will be used? 2) Is the hard coding of the location of Tisean executables to the workspace image deliberate and necessary? Many thanks, Kari Ruohonen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Auto-killing processes spawned by foreach::doMC
Hi Henrik, Firstly, thanks for keeping an eye out and sharing. On Tue, Nov 9, 2010 at 12:59 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: I just stumbled into the 'fork' package (GPL-2). It allows you do send signals from within R. Unfortunately it is not available on Windows, but it is definitely a start. This isn't so horrible within the context of my question (which was using foreach with doMC -- the wrapper for multicore) since multicore itself doesn't run on windows. I guess we'd just have to have some global cache in the main R workspace (that drives the processor splitting) that stores PIDs of the child processes spawned by foreach/doMC, which I guess we could later send kill() signals to if they were abnormally interrupted ... will have to look into it later. Thinking about it, I reckon the multicore package must have something similar? Will investigate ... -steve Here is an example how an R session can send an interrupt signal (SIGINT) to itself: library(fork); # Get the process ID of the current R session pid - getpid(); # Run some code and interrupt the current R session tryCatch({ print(Tic); Sys.sleep(2); print(Tac); kill(pid, signal=sigval(SIGINT)$val); for (kk in 1:100) { print(kk); } }, interrupt=function(int) { print(int); }) which gives: [1] Tic [1] Tac [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 interrupt: Interestingly, the SIGINT signal is not interrupting R momentarily, which is why the code following kill() is still executed for a while before the interrupt is caught. /Henrik On Wed, Nov 3, 2010 at 5:06 PM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: Hi, I am also interest in ways to in R send signals to other R sessions/processes, ideally in (what appears to be) an OS-independent way. For what it is worth, related question have been asked before, cf. R-devel thread 'Sending signals to current R process from R running under MS Windows (c.f. Esc)' started on 2009-11-28: http://www.mail-archive.com/r-de...@r-project.org/msg18790.html Still no workable suggestions/solutions AFAIK. /Henrik On Wed, Nov 3, 2010 at 2:55 PM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: Hi all, Sometimes I'll find myself ctrl-c-ing like a madman to kill some code that's parallelized via foreach/doMC when I realized that I just set my cpu off to do something boneheaded, and it will keep doing that thing for a while. In these situations, since I interrupted its normal execution, foreach/doMC doesn't clean up after itself by killing the processes that were spawned. Furthermore, I believe that when I quit my main R session, the spawned processes still remain (there, but idle). I can go in via terminal (or some task manager/activity monitor) and kill them manually, but does foreach (or something else (maybe multicore?)) keep track of the process IDs that it spawned? Is there some simple doCleanup() function I can write to get these R processes and kill them automagically? For what it's worth, I'm running on linux os x, R-2.12 and the latest versions of foreach/doMC/multicore (though, I feel like this has been true since I've started using foreach/doMC way back when). Thanks, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] code ok in unix R2.6 , fails in windows R 2.12
hello ... Can anyone help me with this : In R.exe 2.6 , Unix , :- plot.data-model[[i]]$data$conc newdata-seq(min(plot.data),max(plot.data),by=1) model.pred-predict(model[[i]],data.frame(newdata),interval=prediction) matpoints(newdata,model.pred[,c(Lower,Upper)],l,col=blue,lty=1) works OK ... in Rgui 2.12 , Windows XP , same code plot.data-model[[i]]$data$conc newdata-seq(min(plot.data),max(plot.data),by=1) model.pred-predict(model[[i]],data.frame(newdata),interval=prediction) Error in `[.data.frame`(newdata, , 2) : undefined columns selected Robert Kinley ( 'baffled' of Berkshire ) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help to merge two data frame if name matches
Hi Mohan, Mohan L l.mohanphys...@gmail.com 09-Nov-10 15:17: I want to merge ip,bsent,breceived column to main , If the name in the the main data frame is there in the other data frame . some thinng like this: nameid memory storage ip bsent breceived mohan1100 20 1 12.00 0.01 ram1200 1000 00.000.00 kumar1400 50 1 1.00 1.00 xxx1100 40 1 00.001.110 aaa 1800 45 0 00.0000.00 mount1200 80 0 00.0000.00 If in case the name in the main data frame does not there in the other data frame, simple I want to add zero to ip,bsent,breceived value. Is this what you want? newdat - merge(main,other,by=name,all.x=T) name id memory storage ip bsent breceived 1 aaa 1 800.045.0 NANANA 2 kumar 1 400.050.0 NANANA 3 mohan 1 100.2 1.1 112 0.01 4 mount 1 200.080.0 NANANA 5 ram 1 200.0 100.0 NANANA 6 xxx 1 100.040.0 1 0 1.11 newdat[is.na(newdat)] - 0 newdat name id memory storage ip bsent breceived 1 aaa 1 800.045.0 0 0 0.00 2 kumar 1 400.050.0 0 0 0.00 3 mohan 1 100.2 1.1 112 0.01 4 mount 1 200.080.0 0 0 0.00 5 ram 1 200.0 100.0 0 0 0.00 6 xxx 1 100.040.0 1 0 1.11 Marianne -- Marianne Promberger PhD, King's College London http://promberger.info R version 2.12.0 (2010-10-15) Ubuntu 9.04 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] likelyhood maximization problem with polr
Thank you for your answer. I have already tried lrm and it's true that it works better than polr in such a case. Nevertheless lrm does not work with the addterm and dropterm functions (to my knowledge) and I need to use them. Maybe do you know alternate functions that would do the same job and that would work with lrm ? Many thanks -- View this message in context: http://r.789695.n4.nabble.com/likelyhood-maximization-problem-with-polr-tp2528818p3034385.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] help to add a new column filled with value 1
Mohan L l.mohanphys...@gmail.com 09-Nov-10 14:25: Dear All, I have a data frame with 5 column and 201 row data. I want to add one more column between column 1 and 2 with value of 1. So the new column has to be the second column filled with 1. Any help will be appreciated. You need two steps Assume your data frame main: main name id memory storage 1 mohan 1 100.2 1.1 2 ram 1 200.0 100.0 3 kumar 1 400.050.0 4 xxx 1 100.040.0 5 aaa 1 800.045.0 6 mount 1 200.080.0 main$newcol - rep(1,nrow(main)) # make new column main name id memory storage newcol 1 mohan 1 100.2 1.1 1 2 ram 1 200.0 100.0 1 3 kumar 1 400.050.0 1 4 xxx 1 100.040.0 1 5 aaa 1 800.045.0 1 6 mount 1 200.080.0 1 main[,c(1,5,2,3,4)] # order columns by indexing -- Marianne Promberger PhD, King's College London http://promberger.info R version 2.12.0 (2010-10-15) Ubuntu 9.04 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] randomForest parameters for image classification
I am implementing an image classification algorithm using the randomForest package. The training data consists of 31000+ training cases over 26 variables, plus one factor predictor variable (the training class). The main issue I am encountering is very low overall classification accuracy (a lot of confusion between classes). However, I know from other classifications (including a regular decision tree classifier) that the training and validation data is sound and capable of producing good accuracies). Currently, I am using the default parameters (500 trees, mtry not set (default), nodesize = 1, replace=TRUE). Does anyone have experience using this with large datasets? Currently I need to randomly sample my training data because giving it the full 31000+ cases returns an out of memory error; the same thing happens with large numbers of trees. From what I read in the documentation, perhaps I do not have enough trees to fully capture the training data? Any suggestions or ideas will be greatly appreciated. Benjamin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Several lattice plots on one page
Another solution is using grid.arrange in the gridExtra package. This works like the par(mfrow=...) command, but for grid-based graphics like lattice and ggplot2 On Nov 8, 2010, at 1:19 PM, Marcus Drescher wrote: Dear all, I am trying (!!!) to generate pdfs that have 8 plots on one page: df = data.frame( day = c(1,2,3,4), var1 = c(1,2,3,4), var2 = c(100,200,300,4000), var3 = c(10,20,300,4), var4 = c(10,2,3,4000), var5 = c(10,20,30,40), var6 = c(0.001,0.002,0.003,0.004), var7 = c(123,223,123,412), var8 = c(213,123,234,435), all = as.factor(c(1,1,1,1))) pdf(test1.pdf, width=20, heigh=27, paper=a4) print(plot(groupedData(var1 ~ day | all, data = df), main = var1, xlab=, ylab=), split=c(1,1,2,4), more=TRUE) print(plot(groupedData(var2 ~ day | all, data = df), main = var2, xlab=, ylab=), split=c(1,2,2,4), more=TRUE) print(plot(groupedData(var3 ~ day | all, data = df), main = var3, xlab=, ylab=), split=c(1,3,2,4), more=TRUE) print(plot(groupedData(var4 ~ day | all, data = df), main = var4, xlab=, ylab=), split=c(1,4,2,4), more=TRUE) print(plot(groupedData(var5 ~ day | all, data = df), main = var5, xlab=, ylab=), split=c(2,1,2,4), more=TRUE) print(plot(groupedData(var6 ~ day | all, data = df), main = var6, xlab=, ylab=), split=c(2,2,2,4), more=TRUE) print(plot(groupedData(var7 ~ day | all, data = df), main = var7, xlab=, ylab=), split=c(2,3,2,4), more=TRUE) print(plot(groupedData(var8 ~ day | all, data = df), main = var8, xlab=, ylab=), split=c(2,4,2,4)) dev.off() My problem is that the separate plots all have different sizes. (Some are tall, but very small, or the other way around. The target is to have equally tall and wide graphs. (The variables have different scales. Grouping does not work.) Optimally, the plots would use the complete pdf page. Any ideas how to adjust height and width? Best Marcus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extending the accuracy of exp(1) in R
On 09-Nov-10 13:57:08, Hadley Wickham wrote: Where the value of exp(1) as computed by R is concerned, you have been deceived by what R displays (prints) on screen. The default is to display any number to 7 digits of accuracy, but that is not the accuracy of the number held internally by R: _exp(1) _# [1] 2.718282 _exp(1) - 2.718282 _# [1] -1.715410e-07 I encourage anyone confused about this issue to study http://en.wikipedia.org/wiki/The_Treachery_of_Images And to watch http://www.youtube.com/watch?v=ejweI0EQpX8 Hadley YES! And to really clinch the point, have a look at: http://www.preventblindness.org/playitsafe/ teachers_guide_grade3_grade4/paradoxelephant.jpg and perhaps also my own composition at: http://www.zen89632.zen.co.uk/Misc/multinecker.pdf What you *see* in treacherous (or any) images is marks on paper, or on a computer screen, ... What you *perceive* is different. Always. (Well, almost always: you can make a deliberate effort to study the marks on the paper as marks on paper). Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 09-Nov-10 Time: 14:57:31 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Merging data frames one of which is NULL
Hello! I am running a loop. The result of each run of the loop is a data frame. I am merging all the data frames. For exampe: The dataframe from run 1: x-data.frame(a=1,b=2,c=3) The dataframe from run 2: y-data.frame(a=10,b=20,d=30) What I want to get is: merge(x,y,all.x=T,all.y=T) Then I want to merge it with the output of the 3rd run, etc. Unfortunately, I can't create the placeholder for the overall resutls BEFORE I run the loop because I don't even know how many columns I'll end up with - after merging all the data frames. I was thinking of creating an empty list: first-NULL ...and then updating it during each run by merging it with the data frame that is the output of the run. However, when I try to merge the empty list with any non-empty data frame - it ends up empty: merge(first,a,,all.x=T,all.y=T) Is there a way to make it merge while keeping everything? Thanks a lot! -- 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] How to eliminate this for loop ?
Oops, my version added cc instead of subtracted, it still works if you multiply cc by -1 (except the initial 1). -- 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 Greg Snow Sent: Monday, November 08, 2010 1:15 PM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? If you are willing to shift the c vector by 1 and have 1 (the initial value) as the start of c, then you can just do: cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 ) to compare: cc - c(1, rnorm(999) ) b - 0.5 n - length(cc) a1 - numeric(100) a1[1] - 1 system.time(for(i in 2:n ) { a1[i] - b*a1[i-1] + cc[i] }) system.time(a2 - cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 )) all.equal(a1,a2) Though you could have problems with the b^ part if the length gets too long. -- 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 PLucas Sent: Monday, November 08, 2010 2:26 AM To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } Is it possible ? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to- eliminate-this-for-loop-tp3031667p3031667.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] location of Tisean executables when using RTisean and jumping between linux and windows
Hi, I wonder if someone could help. I needed to transfer (copy) a workspace file that had been generated in linux (R 2.11) to windows running the same version of R 2.11 (but of course windows binary). Usually, there is no problem in doing this and all objects work as expected. I am often doing this to be able to produce wmf or emf graphic files that I need. This time I had some spectra that I have taken the first derivative of with the sav_gol function in the RTisean package. I know RTisean is just an interface to the Tisean executables. The trouble I am facing is that it seems that the location of the Tisean executables is somehow hard coded to the R workspace file. I assume this since when I try to rerun the sav_gol on the windows machine after copying the workspace file from linux and opening it in windows, RTisean tries to search the Tisean executables from the location that is valid for linux, not windows. RTisean help package says RTisean asks the location of the executables the first time a function is called and that this location is saved in user's home directory for future use. There is no specific information of how this works in windows where there is no obvious home directory. However, I have run R console on windows and it asked this location but I don't know where the information was stored. In linux it is in .RTiseanSettings file in user's home as explained. My questions are: 1) Is there a way I could break the link of the Tisean executables to the linux location so that when run in windows the executables in windows will be used? 2) Is the hard coding of the location of Tisean executables to the workspace image deliberate and necessary? Many thanks, Kari Ruohonen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 eliminate this for loop ?
Erich: (Assuming this is correct), this is very nice. However, I just wanted to point out that if you look at the code for Reduce, you'll find it's implemented with for loops. So the OP's original version using a for loop is likely to be faster (just as it's likely to be faster than my actual recursive version). Cheers, Bert On Mon, Nov 8, 2010 at 4:14 PM, Erich Neuwirth erich.neuwi...@univie.ac.at wrote: Reduce(function(x1,x2)b*x1-x2,c,init=1,accum=TRUE) might be what you are looking for. This is not fully tested, so you should test it before you want to use it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] simulation from pareto distn
Dear all, I am trying to simulate from truncated Pareto distribution. I know there is a package called PtProcess for Pareto distribution...but it is not for truncated one. Can anyone please help me with this? Thanks in advance. Cassie [[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] code ok in unix R2.6 , fails in windows R 2.12
You probably forgot to say that you have also different versions of the package installed! I get on all platforms: drm(formula = response ~ conc, data = assay.data, fct = l4()) Error in drm(formula = response ~ conc, data = assay.data, fct = l4()) : Cluster not specified. Use e.g. y ~ x + cluster(id) with recent versions of R and drm. So time to update R and all your packages on all your platforms. Best, Uwe Ligges On 09.11.2010 17:26, Robert Kinley wrote: apologies for omitting the data conc response curve 1 50 0.7533954 1 2 50 0.7755960 2 3 50 0.8001151 3 4 89 0.2858031 1 5 89 0.2883478 2 6 89 0.2954936 3 7 158 0.4296482 1 8 158 0.4406220 2 9 158 0.4567403 3 10 282 0.6484347 1 11 282 0.6555722 2 12 282 0.7361552 3 13 501 0.9768917 1 14 501 0.9809505 2 15 501 0.9952711 3 16 890 1.395 1 17 890 1.3262830 2 18 890 1.4754281 3 19 1582 2.2157078 1 20 1582 2.2918927 2 21 1582 2.5538562 3 22 2813 3.7403291 1 23 2813 4.0623972 2 24 2813 4.1439147 3 25 5000 5.1405423 1 26 5000 5.4242582 2 27 5000 5.4322730 3 also - model [[1]] A 'drc' model. Call: drm(formula = response ~ conc, data = assay.data, fct = l4()) Coefficients: b:(Intercept) c:(Intercept) d:(Intercept) e:(Intercept) -1.6958 0.5089 6.9764 2629.7526 attr(,logScale) [1] TRUE attr(,modelType) [1] 4pl attr(,method) [1] drc attr(,class) [1] multFit *Uwe Ligges lig...@statistik.tu-dortmund.de* 09/11/2010 16:21 To Robert Kinley kinley_rob...@lilly.com cc r-help@r-project.org Subject Re: [R] code ok in unix R2.6 , fails in windows R 2.12 We cannot help since we do not have the data. Uwe On 09.11.2010 16:40, Robert Kinley wrote: hello ... Can anyone help me with this : In R.exe 2.6 , Unix , :- plot.data-model[[i]]$data$conc newdata-seq(min(plot.data),max(plot.data),by=1) model.pred-predict(model[[i]],data.frame(newdata),interval=prediction) matpoints(newdata,model.pred[,c(Lower,Upper)],l,col=blue,lty=1) works OK ... in Rgui 2.12 , Windows XP , same code plot.data-model[[i]]$data$conc newdata-seq(min(plot.data),max(plot.data),by=1) model.pred-predict(model[[i]],data.frame(newdata),interval=prediction) Error in `[.data.frame`(newdata, , 2) : undefined columns selected Robert Kinley ( 'baffled' of Berkshire ) [[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] How to program an error into an if-then statement
Hello! I am running a loop (for a range of dates) and in this loop I am reading in different files - based on a date that is part of the file name. However, for some of the dates, I have no file (no way to know which dates). So, when I try to read it in I get an error: Error in file(file, rt) : cannot open the connection Question: I'd like to program an if-then statement in my code that says something like this: myfile-read.csv(myfilename) if cannot open the connection - then do X What statement should I use under if? Thanks a lot! -- 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] How to program an error into an if-then statement
Take a look in ?try and ?tryCatch myfile - tryCatch(read.csv(myfilename), error = invisible) myfile$message On Tue, Nov 9, 2010 at 2:55 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! I am running a loop (for a range of dates) and in this loop I am reading in different files - based on a date that is part of the file name. However, for some of the dates, I have no file (no way to know which dates). So, when I try to read it in I get an error: Error in file(file, rt) : cannot open the connection Question: I'd like to program an if-then statement in my code that says something like this: myfile-read.csv(myfilename) if cannot open the connection - then do X What statement should I use under if? Thanks a lot! -- 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to eliminate this for loop ?
Note that for long vectors the OP's code would go much faster if he preallocated the output vector a to its eventual length. I.e., start with a - numeric(N) instead of a - c() I defined 2 functions that differed only in how a was initialized f0 - function(b, c) { N - length(c) a - c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } a } f1 - function(b, c) { N - length(c) a- numeric(N) a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } a } and timed them for a 100,000 long vector: c - rnorm(1e5) system.time(a0 - f0(b=0.5, c=c)) user system elapsed 17.270 1.410 18.704 system.time(a1 - f1(b=0.5, c=c)) user system elapsed 0.400 0.000 0.401 identical(a0, a1) [1] TRUE If that is not fast enough then you have to start thinking harder. E.g., look at functions like filter() and/or do some algebra. (Greg's code also had an error of that sort, preallocating 100 entries where the eventual length was 1000). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Greg Snow Sent: Tuesday, November 09, 2010 8:31 AM To: Greg Snow; PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? Oops, my version added cc instead of subtracted, it still works if you multiply cc by -1 (except the initial 1). -- 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 Greg Snow Sent: Monday, November 08, 2010 1:15 PM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? If you are willing to shift the c vector by 1 and have 1 (the initial value) as the start of c, then you can just do: cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 ) to compare: cc - c(1, rnorm(999) ) b - 0.5 n - length(cc) a1 - numeric(100) a1[1] - 1 system.time(for(i in 2:n ) { a1[i] - b*a1[i-1] + cc[i] }) system.time(a2 - cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 )) all.equal(a1,a2) Though you could have problems with the b^ part if the length gets too long. -- 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 PLucas Sent: Monday, November 08, 2010 2:26 AM To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } Is it possible ? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to- eliminate-this-for-loop-tp3031667p3031667.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging data frames one of which is NULL
Hi Dimitri, I have some doubts whether storing the results of a loop in a data frame and merging it with every run is the most efficient way of doing things, but I do not know your situation. This does what you want, I believe, but I suspect it could be quite slow. I worked around the placeholder issue using an if statement. HTH, Josh for (i in 1:10) { x - data.frame(a = 1, b = 2, c = i) if (i == 1) { y - x } else { y - merge(x, y, all.x = TRUE, all.y = TRUE) } } On Tue, Nov 9, 2010 at 8:42 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! I am running a loop. The result of each run of the loop is a data frame. I am merging all the data frames. For exampe: The dataframe from run 1: x-data.frame(a=1,b=2,c=3) The dataframe from run 2: y-data.frame(a=10,b=20,d=30) What I want to get is: merge(x,y,all.x=T,all.y=T) Then I want to merge it with the output of the 3rd run, etc. Unfortunately, I can't create the placeholder for the overall resutls BEFORE I run the loop because I don't even know how many columns I'll end up with - after merging all the data frames. I was thinking of creating an empty list: first-NULL ...and then updating it during each run by merging it with the data frame that is the output of the run. However, when I try to merge the empty list with any non-empty data frame - it ends up empty: merge(first,a,,all.x=T,all.y=T) Is there a way to make it merge while keeping everything? Thanks a lot! -- 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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging data frames one of which is NULL
Thanks a lot, Joshua. You might be right. I am thinking of creating a list (as a placeholder) and then merging the elements of the list. Dimitri On Tue, Nov 9, 2010 at 12:11 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi Dimitri, I have some doubts whether storing the results of a loop in a data frame and merging it with every run is the most efficient way of doing things, but I do not know your situation. This does what you want, I believe, but I suspect it could be quite slow. I worked around the placeholder issue using an if statement. HTH, Josh for (i in 1:10) { x - data.frame(a = 1, b = 2, c = i) if (i == 1) { y - x } else { y - merge(x, y, all.x = TRUE, all.y = TRUE) } } On Tue, Nov 9, 2010 at 8:42 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! I am running a loop. The result of each run of the loop is a data frame. I am merging all the data frames. For exampe: The dataframe from run 1: x-data.frame(a=1,b=2,c=3) The dataframe from run 2: y-data.frame(a=10,b=20,d=30) What I want to get is: merge(x,y,all.x=T,all.y=T) Then I want to merge it with the output of the 3rd run, etc. Unfortunately, I can't create the placeholder for the overall resutls BEFORE I run the loop because I don't even know how many columns I'll end up with - after merging all the data frames. I was thinking of creating an empty list: first-NULL ...and then updating it during each run by merging it with the data frame that is the output of the run. However, when I try to merge the empty list with any non-empty data frame - it ends up empty: merge(first,a,,all.x=T,all.y=T) Is there a way to make it merge while keeping everything? Thanks a lot! -- 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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ -- 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] spatstat error with plotting envelopes for fitted model
Hello, I am facing an error when I try to plot envelopes of a fitted model in spatstat. My model is fitted using the Geyer Saturation process as follows: * geyer.fit-ppm(points, ~el+asp, Geyer(r=1, sat=2), covariates=list(el=el, asp=asp))* It fits well, but when I try to plot the envelopes to test its goodness-of-fit using the command: * plot(envelope(geyer.fit, Kest, nsim=19, global=T))* I get the error message: Error in plot(envelope(geyer.fit, Lest, nsim = 19, global = T)) : error in evaluating the argument 'x' in selecting a method for function 'plot' Could anyone help me on this? Is there something I am not doing right here? -- Neba, Funwi-Gabga Universitat Jaume I, Castellon Spain. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to program an error into an if-then statement
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Dimitri Liakhovitski Sent: Tuesday, November 09, 2010 8:56 AM To: r-help Subject: [R] How to program an error into an if-then statement Hello! I am running a loop (for a range of dates) and in this loop I am reading in different files - based on a date that is part of the file name. However, for some of the dates, I have no file (no way to know which dates). So, when I try to read it in I get an error: Error in file(file, rt) : cannot open the connection Question: I'd like to program an if-then statement in my code that says something like this: myfile-read.csv(myfilename) if cannot open the connection - then do X What statement should I use under if? Thanks a lot! Rather than trying to read a non-existent file and generating an error, you might want to check if the file exists before trying to read it and take your alternative action if it doesn't exist. Check out ?file.exists Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to program an error into an if-then statement
Thanks a lot, everybody- it's very helpful! On Tue, Nov 9, 2010 at 12:20 PM, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Dimitri Liakhovitski Sent: Tuesday, November 09, 2010 8:56 AM To: r-help Subject: [R] How to program an error into an if-then statement Hello! I am running a loop (for a range of dates) and in this loop I am reading in different files - based on a date that is part of the file name. However, for some of the dates, I have no file (no way to know which dates). So, when I try to read it in I get an error: Error in file(file, rt) : cannot open the connection Question: I'd like to program an if-then statement in my code that says something like this: myfile-read.csv(myfilename) if cannot open the connection - then do X What statement should I use under if? Thanks a lot! Rather than trying to read a non-existent file and generating an error, you might want to check if the file exists before trying to read it and take your alternative action if it doesn't exist. Check out ?file.exists Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] replaing 1-digit months with 2-digit months in a date
Hello again! Sorry, if it's a simple question - I am very bad in working with strings. I have a vector of strings: x-c(2000.1,2000.2,2000.10,2000.12) I'd like to change it so that it the month always has 2 digits, like this: 2000.01,2000.02,2000.10,2000.12 Is it possible? Thanks a lot! -- 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] help to add a new column filled with value 1
Mohan - Suppose your data frame is named df. Try this: data.frame(df[,1],1,df[,2:5]) - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 9 Nov 2010, Mohan L wrote: Dear All, I have a data frame with 5 column and 201 row data. I want to add one more column between column 1 and 2 with value of 1. So the new column has to be the second column filled with 1. Any help will be appreciated. Thanks for your time. Thanks Rg Mohan L __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replaing 1-digit months with 2-digit months in a date
Try this: gsub(\\.(\\d{1}$), .0\\1, x) On Tue, Nov 9, 2010 at 3:28 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello again! Sorry, if it's a simple question - I am very bad in working with strings. I have a vector of strings: x-c(2000.1,2000.2,2000.10,2000.12) I'd like to change it so that it the month always has 2 digits, like this: 2000.01,2000.02,2000.10,2000.12 Is it possible? Thanks a lot! -- 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] library(kernlab) --- unable to load shared library
Yuliya - The error message doesn't say that the file doesn't exist -- it says that it contains a symbol which can't be resolved, in this case dgemv_ . A quick google search shows that this is part of the BLAS library. So my guess is that you have installed the BLAS library in some non-standard location. You didn't mention what Linux distribution you're using, or whether you built R and the kernlab library from source or not, so it's hard to give specific guidance to solve your problem. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 9 Nov 2010, Yuliya Matveyeva wrote: Dear R users, I have recently encountered a problem with using the function `library` in order to load the package `kernlab`. My output of sessionInfo() is as follows: R version 2.10.1 (2009-12-14) x86_64-unknown-linux-gnu locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base I have installed the package by install.packages(kernlab), and it had ended up in giving a message about the package being installed successfully. But as soon as I type library(kernlab) the output is: Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/usr/local/sage/local/lib/R//library/kernlab/libs/kernlab.so': /usr/local/sage/local/lib/R//library/kernlab/libs/kernlab.so: undefined symbol: dgemv_ Error: package/namespace load failed for 'kernlab' The call to .libPaths() lists '/usr/local/sage/local/lib/R//library' and one more path. I have manually checked if the package is in the directory /usr/local/sage/local/lib/R//library = it is there... (at least there is a folder with the name `kernlab`) Could you please make any suggestions concerning the causes and/or solution of this problem ? Any help would be greatly appreciated. Sincerely yours, Yuliya Matveyeva. [[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] How to eliminate this for loop ?
OK, double oops. I first tested my code with length 100, then upped the number but forgot to up the preallocation part, I should have used a variable there instead so that only one place needed to be changed. My version did have problems when I tried to do a vector of length 10,000, some values were NaN probably due to b^largenumber being essentially 0, then being in the denominator. Though for really long vectors the round off error in any version could accumulate to the point of affecting the results. This could start a debate about whether the missing value could be seen as better than a potentially incorrect non-missing value. It would mainly depend on the purpose and I don't think there would be a general preference either way. -- 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 William Dunlap Sent: Tuesday, November 09, 2010 10:07 AM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? Note that for long vectors the OP's code would go much faster if he preallocated the output vector a to its eventual length. I.e., start with a - numeric(N) instead of a - c() I defined 2 functions that differed only in how a was initialized f0 - function(b, c) { N - length(c) a - c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } a } f1 - function(b, c) { N - length(c) a- numeric(N) a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } a } and timed them for a 100,000 long vector: c - rnorm(1e5) system.time(a0 - f0(b=0.5, c=c)) user system elapsed 17.270 1.410 18.704 system.time(a1 - f1(b=0.5, c=c)) user system elapsed 0.400 0.000 0.401 identical(a0, a1) [1] TRUE If that is not fast enough then you have to start thinking harder. E.g., look at functions like filter() and/or do some algebra. (Greg's code also had an error of that sort, preallocating 100 entries where the eventual length was 1000). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Greg Snow Sent: Tuesday, November 09, 2010 8:31 AM To: Greg Snow; PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? Oops, my version added cc instead of subtracted, it still works if you multiply cc by -1 (except the initial 1). -- 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 Greg Snow Sent: Monday, November 08, 2010 1:15 PM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? If you are willing to shift the c vector by 1 and have 1 (the initial value) as the start of c, then you can just do: cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 ) to compare: cc - c(1, rnorm(999) ) b - 0.5 n - length(cc) a1 - numeric(100) a1[1] - 1 system.time(for(i in 2:n ) { a1[i] - b*a1[i-1] + cc[i] }) system.time(a2 - cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 )) all.equal(a1,a2) Though you could have problems with the b^ part if the length gets too long. -- 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 PLucas Sent: Monday, November 08, 2010 2:26 AM To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } Is it possible ? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to- eliminate-this-for-loop-tp3031667p3031667.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] Question regarding to replace NA
Dear r-users, Basically, I have a data as follows, data S s1 s2 s3 s4 s5 prob obs num.strata 1 N N N N N N 0.108 32 NA 2 Y N N N N Y 0.0005292 16 NA 3 NNNYN N N N Y N 0.0005292 24 NA 4 NNNYY N N N Y Y 0.0259308 8 1 I want to replace NA by 0, when I tried the following command, I get som error message. data[is.na(data)]-0 Warning message: In `[-.factor`(`*tmp*`, thisvar, value = 0) : invalid factor level, NAs generated Anyone knows how to deal with this? Thanks, Kate [[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] Merging data frames one of which is NULL
Dimitri - Usually the easiest way to solve problems like this is to put all the dataframes in a list, and then use the Reduce() function to merge them all together at the end. You don't give many details about how the data frames are constructed, so it's hard to be specific about the best way to put them in a list, but this short example should give you an idea of what I'm talking about: x-data.frame(a=1,b=2,c=3) y-data.frame(a=10,b=20,d=30) z-data.frame(a=12,b=19,f=25) a-data.frame(a=9,b=10,g=15) Reduce(function(x,y)merge(x,y,all=TRUE),list(x,y,z,a)) a b c d f g 1 1 2 3 NA NA NA 2 9 10 NA NA NA 15 3 10 20 NA 30 NA NA 4 12 19 NA NA 25 NA Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 9 Nov 2010, Dimitri Liakhovitski wrote: Hello! I am running a loop. The result of each run of the loop is a data frame. I am merging all the data frames. For exampe: The dataframe from run 1: x-data.frame(a=1,b=2,c=3) The dataframe from run 2: y-data.frame(a=10,b=20,d=30) What I want to get is: merge(x,y,all.x=T,all.y=T) Then I want to merge it with the output of the 3rd run, etc. Unfortunately, I can't create the placeholder for the overall resutls BEFORE I run the loop because I don't even know how many columns I'll end up with - after merging all the data frames. I was thinking of creating an empty list: first-NULL ...and then updating it during each run by merging it with the data frame that is the output of the run. However, when I try to merge the empty list with any non-empty data frame - it ends up empty: merge(first,a,,all.x=T,all.y=T) Is there a way to make it merge while keeping everything? Thanks a lot! -- 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help to add a new column filled with value 1
Here are 2 possibilities: cbind( iris[,1, drop=FALSE], 1, iris[,2:5] ) cbind( iris, 1) [ ,c(1,6,2:5) ] -- 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 Mohan L Sent: Tuesday, November 09, 2010 7:26 AM To: r-help@r-project.org Subject: [R] help to add a new column filled with value 1 Dear All, I have a data frame with 5 column and 201 row data. I want to add one more column between column 1 and 2 with value of 1. So the new column has to be the second column filled with 1. Any help will be appreciated. Thanks for your time. Thanks Rg Mohan L __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question regarding to replace NA
Hi Kate, is.na() does not work on entire data frames. You just need to specify the column, for example: data[is.na(data[, 8]), 8] - 0 if the NAs were in column 8. Best regards, Josh On Tue, Nov 9, 2010 at 9:33 AM, Kate Hsu yhsu.rh...@gmail.com wrote: Dear r-users, Basically, I have a data as follows, data S s1 s2 s3 s4 s5 prob obs num.strata 1 N N N N N N 0.108 32 NA 2 Y N N N N Y 0.0005292 16 NA 3 NNNYN N N N Y N 0.0005292 24 NA 4 NNNYY N N N Y Y 0.0259308 8 1 I want to replace NA by 0, when I tried the following command, I get som error message. data[is.na(data)]-0 Warning message: In `[-.factor`(`*tmp*`, thisvar, value = 0) : invalid factor level, NAs generated Anyone knows how to deal with this? Thanks, Kate [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging data frames one of which is NULL
Thanks a lot, Phil. I decided to do it via the list - as you suggested, but had to do some gymnastics, which Reduce will greatly help me to avoid now! Dimitri On Tue, Nov 9, 2010 at 12:36 PM, Phil Spector spec...@stat.berkeley.edu wrote: Dimitri - Usually the easiest way to solve problems like this is to put all the dataframes in a list, and then use the Reduce() function to merge them all together at the end. You don't give many details about how the data frames are constructed, so it's hard to be specific about the best way to put them in a list, but this short example should give you an idea of what I'm talking about: x-data.frame(a=1,b=2,c=3) y-data.frame(a=10,b=20,d=30) z-data.frame(a=12,b=19,f=25) a-data.frame(a=9,b=10,g=15) Reduce(function(x,y)merge(x,y,all=TRUE),list(x,y,z,a)) a b c d f g 1 1 2 3 NA NA NA 2 9 10 NA NA NA 15 3 10 20 NA 30 NA NA 4 12 19 NA NA 25 NA Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 9 Nov 2010, Dimitri Liakhovitski wrote: Hello! I am running a loop. The result of each run of the loop is a data frame. I am merging all the data frames. For exampe: The dataframe from run 1: x-data.frame(a=1,b=2,c=3) The dataframe from run 2: y-data.frame(a=10,b=20,d=30) What I want to get is: merge(x,y,all.x=T,all.y=T) Then I want to merge it with the output of the 3rd run, etc. Unfortunately, I can't create the placeholder for the overall resutls BEFORE I run the loop because I don't even know how many columns I'll end up with - after merging all the data frames. I was thinking of creating an empty list: first-NULL ...and then updating it during each run by merging it with the data frame that is the output of the run. However, when I try to merge the empty list with any non-empty data frame - it ends up empty: merge(first,a,,all.x=T,all.y=T) Is there a way to make it merge while keeping everything? Thanks a lot! -- 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. -- 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] jags error message
Could anyone give me some clues as to the best way to debug this error message? I think it is from the passing of variables back to R from the jags function which does Bayesian fitting. The curious part for me is that the error messages seem random, yet the input data are always the same. Any suggestions most welcome. Thanks J Compiling model graph Resolving undeclared variables Allocating nodes Graph Size: 1604 |++| 100% |**| 100% Error : NA/NaN/Inf in foreign function call (arg 1) In addition: There were 15 warnings (use warnings() to see them) === Dr. Jim Maas University of East Anglia [[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] Calculate Mean from List
You could use the Reduce function to get the sum of the matrices, then if there are no missing vales just divide by the number of matrices. If there are missing values then you would probably need to use Reduce again to count the number of non-missing values. Since all the matrices are the same dimensions you could also reformat the list into a 3 dimensional array and use the apply function to find the means. -- 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 Suphajak Ngamlak Sent: Tuesday, November 09, 2010 1:24 AM To: 'r-help@r-project.org' Subject: [R] Calculate Mean from List Dear all, I have a list of correlation coefficient matrixes. Each matrix represents one date. For example A[[1]] A B C A 1 0.2 0.3 B 0.2 1 0.4 C 0.3 0.4 1 A[[2]] A B C A 1 0.5 0.6 B 0.5 1 0.7 C 0.6 0.7 1 A[[n]] I would like to calculate the mean of correlation coefficient from the whole time series, i.e. Average cor(A,B) = (A[[1]][2,1] + A[[2]] [2,1] + ... + A[[n]] [2,1])/n Average cor(A,C) = (A[[1]][3,1] + A[[2]] [3,1] + ... + A[[n]] [3,1])/n Average cor(B,C) = (A[[1]][3,2] + A[[2]] [3,2] + ... + A[[n]] [3,2])/n Please note that some cells are NA; so I need to remove them when calculating average. How could I get this efficiently? Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities Public Company Limited Tel: (66)2-305-9179 Email: supha...@phatrasecurities.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question regarding to replace NA
Kate - As the error message indicates, num.strata is a factor. This can occur when you're reading in data and R encounters a non-numeric value which was not specified in the na.strings= argument to read.table. To do what you want, you'll need to convert it to a character variable first: myvar = factor(c(NA,NA,NA,'1')) myvar[is.na(myvar)] = 0 Warning message: In `[-.factor`(`*tmp*`, is.na(myvar), value = 0) : invalid factor level, NAs generated myvar = as.character(myvar) myvar[is.na(myvar)] = 0 myvar [1] 0 0 0 1 If you want the variable to be treated as a numeric variable, you can use as.numeric: as.numeric(myvar) [1] 0 0 0 1 Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 9 Nov 2010, Kate Hsu wrote: Dear r-users, Basically, I have a data as follows, data S s1 s2 s3 s4 s5 prob obs num.strata 1 N N N N N N 0.108 32 NA 2 Y N N N N Y 0.0005292 16 NA 3 NNNYN N N N Y N 0.0005292 24 NA 4 NNNYY N N N Y Y 0.0259308 8 1 I want to replace NA by 0, when I tried the following command, I get som error message. data[is.na(data)]-0 Warning message: In `[-.factor`(`*tmp*`, thisvar, value = 0) : invalid factor level, NAs generated Anyone knows how to deal with this? Thanks, Kate [[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] help to add a new column filled with value 1
Try this: as.data.frame(append(iris, 1, after = 2)) On Tue, Nov 9, 2010 at 12:25 PM, Mohan L l.mohanphys...@gmail.com wrote: Dear All, I have a data frame with 5 column and 201 row data. I want to add one more column between column 1 and 2 with value of 1. So the new column has to be the second column filled with 1. Any help will be appreciated. Thanks for your time. Thanks Rg Mohan L __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question regarding to replace NA
On Tue, Nov 9, 2010 at 9:39 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi Kate, is.na() does not work on entire data frames. whoops, I did not mean that. is.na() has a data frame method, but there are assignment issues (as you saw) when you use it that way. Josh [snip] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.