Re: [R] Problem Creating Partial Dependence Plot
Hi Jean, I did use a formula and a data frame in creating the rpart model, and the variable names are quite simple. And rpart is definitely supported. Best, Jane On Tue, May 27, 2014 at 5:44 AM, Adams, Jean jvad...@usgs.gov wrote: Jane, Page 9 of the reference manual, http://cran.r-project.org/web/packages/plotmo/plotmo.pdf, discusses this error. 'The work-around is to simplify or standardize the way the model function is called. Use a formula and a data frame, or at least explicitly name the variables rather than passing a matrix. Use simple variable names (so x1 rather than dat$x1, for example).' 'If the symptoms persist after changing the way the model is called, and the model is not one of those listed in âWhich variables are plottedâ, it is possible that the model class is not supported by plotmo. See âExtending plotmoâ.' Jean On Mon, May 26, 2014 at 7:50 PM, Jane Shevtsov jane@gmail.com wrote: I am trying to use the plotmo package to generate a partial dependence plot for a CART model created with rpart. When running plotmo, I get Error: get.plotmo.y returned the wrong length (got 204938 expected 205000). The rpart predict function does indeed return 204938 results, but plotmo is supposed to be able to handle NA's in rpart models. What I might do about this? Thanks, Jane -- - Jane Shevtsov, Ph.D. Mathematical Biology Curriculum Writer, UCLA co-founder, www.worldbeyondborders.org âThose who say it cannot be done should not interfere with those who are doing it.â --attributed to Robert Heinlein, George Bernard Shaw and others [[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. -- - Jane Shevtsov, Ph.D. Mathematical Biology Curriculum Writer, UCLA co-founder, www.worldbeyondborders.org âThose who say it cannot be done should not interfere with those who are doing it.â --attributed to Robert Heinlein, George Bernard Shaw and others [[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] LInes with types
Hello all, I want to plot the legend for the following two lines: I have two lines: X1-c(0,1,2,3,4) Y1-c(0,1,2,3,4) Y2-c(5,6,7,8,9) Y3-(32,33,34,35,36) plot(X1,Y3,pch=20) lines(X1,Y1,lty=1,type='o') lines(X1,Y2,lty=1,type='b') lines(X1,Y3,lty=2) Any ideas how? Best IOanna [[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] LInes with types
On Wed, 28 May 2014 01:20:33 AM ioanna ioannou wrote: X1-c(0,1,2,3,4) Y1-c(0,1,2,3,4) Y2-c(5,6,7,8,9) Y3-(32,33,34,35,36) plot(X1,Y3,pch=20) lines(X1,Y1,lty=1,type='o') lines(X1,Y2,lty=1,type='b') lines(X1,Y3,lty=2) Hi Ioanna, You actually have three lines, and on that basis I suggest (with corrected example): X1-c(0,1,2,3,4) Y1-c(0,1,2,3,4) Y2-c(5,6,7,8,9) Y3-c(32,33,34,35,36) plot(X1,Y3,pch=20,ylim=c(0,36)) lines(X1,Y1,lty=1,type='o') lines(X1,Y2,lty=1,type='b') lines(X1,Y3,lty=2) legend(1.5,25,paste(Number,1:3),lty=c(1,1,3),pch=c(1,1,20)) 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] I Need Help with AMMI
HI, data6$Gen=paste(G,data6$Gen,sep=) #Error in paste(G, data6$Gen, sep = ) : object 'data6' not found Please check this link: http://stackoverflow.com/questions/7027288/error-could-not-find-function-in-r A.K. R-Community, I am new to r. I have used SAS all my life. SO, here I am trying to use AMMI with agricolae package. Each time I have tried to run the program, I get the message that says, [error: could not find function ammi]. What could possibly be happening? Noble (Here is my code) data6$Gen=paste(G,data6$Gen,sep=) G=data6$Geno E=data6$Env TW=data6$TW n=length(TW) Rep=rep(1,n) ## Replication is needed for AMMI analysis. If there is no replication, just assign column of 1 par(mfrow=c(1,1)) #model- ammi(E, G, Rep, TW,graph=biplot) model=ammi(E, G, Rep, TW,graph=biplot,number=FALSE) biplot-model$biplot[,1:4] head(biplot) #attach(biplot) #par(cex=0.8) #length(biplot$PWT) par(mfrow=c(1,1)) plot(biplot$TW,biplot$PC1,cex=0.0,text(biplot$TW,biplot$PC1,labels=row.names(biplot),col=blue), main=AMMI BIPLOT,ylab=PC1,xlab=Test Weight, frame=TRUE) ##Bioplot based actual mean and PC1 MEANS-mean(TW) abline(h=0,v= MEANS,lty=2,col=red) names=rownames(bplot) id=which(biplot$type==ENV) enames=names[id] y=biplot[,2][id] pc1=biplot[,3][id] s - seq(enames) arrows(MEANS, 0, y[s], pc1[s], col = brown, lwd = 1.8, length = 0.1, code = 2) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot regression results with various predictors.
Hi What is plm? What is plot=(POLS), how do you expect this to be working? Many modelling methods have some kind of plotting functions. Does plm, regardless what it is, have some? Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of phil Sent: Tuesday, May 27, 2014 6:44 PM To: r-help@r-project.org Subject: [R] Plot regression results with various predictors. Dear all, I would like to know how to plot the results of a regression where various predictors resulted significant. Further, I would like how to add the regression line. Is that possible? For instance, I have run POLS=plm() where 6 coefficients resulted significant; then I would like to use plot=(POLS) adding further the regression line to illustrate the results graphically. Any help is highly appreciated. Thanks in advance. Phil -- View this message in context: http://r.789695.n4.nabble.com/Plot- regression-results-with-various-predictors-tp4691307.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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mle together with pnorm
Hi, The problem I have is that the standard errors for the estimates doesn't make any sense. Here is the background: The values in vector a are seen as the true values and I want to estimate them using mle. I make 100 disturbed vectors from a by adding noise, N(0,sigma^2). For every disturbed vector I sort them in decreasing order. Say that the observed order is: y[1]y[4]y[5]y[3]y[2] We want to calculate the probability to observe this order and we do so by: P(Y[1]-Y[4]0|a)*P(Y[4]-Y[5]0|a)*P(Y[5]-Y[3]0|a)*P(Y[3]-Y[2]0|a) (we ignore the dependency), where Y[1]-Y[4] ~ N(a[1]-a[4],2*std^2) and so on. Usually when you use mle you use density function, but here we use pnorm. The problem I have after running the code below is that the standard errors are all the same (and way too large) for the estimates. What can I have done wrong? R-code #library(stats4)n - 100x - mat.or.vec(n,5)y - mat.or.vec(n,5)a - c(100,100.5,100.75,100.7,100.25) std - sd(a)Var - std^2for(i in 1:n){ y[i,] - a+rnorm(5,mean=0,sd=std) x[i,] - sort(y[i,],decreasing = TRUE,index.return=TRUE)$ix } matris - mat.or.vec(n,4)sigma - sqrt(2*Var)fit - function(f1,f2,f3,f4,f5,x){ for(i in 1:n){ for(j in 1:4){ P - if(x[i,j] == 1) {f1} else if(x[i,j] == 2) {f2} else if(x[i,j] == 3) {f3} else if(x[i,j] == 4) {f4} else {f5} Q - if(x[i,j+1] == 1) {f1} else if(x[i,(j+1)] == 2) {f2} else if(x[i,(j+1)] == 3) {f3} else if(x[i,(j+1)] == 4) {f4} else {f5} mu - P-Q matris[i,j] - pnorm(0,mean=mu,sd=sigma,lower.tail=FALSE,log.p=TRUE)} } -sum(matris)}mle.results - mle(fit,start=list(f1=a[1],f2=a[2],f3=a[3],f4=a[4],f5=a[5]),fixed=list(x=x))summary(mle.results) Best regardsAlex [[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] Zoo: How to match secondary Y-axis ticks to primary ones
Thank you for the quick reply, your advice wasn't exactly what I was looking for. The plot 1 of the example was ment to show my problem: the secondary axis has it's first tick at the intersection with the x-axis whereas the primary y-axis shows a nice little offset. Using your advice i copied the y axis and tried to solve the Problem by foot. Unfortunately the lable text isn't willing to center to the ticks Here is the code: ## R-Help 2014-05-28 ## Test second. Y-Axix library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) axis(4, labels = FALSE) abline(h = axTicks(4), lty = dotted, col=grey) lablist.y-seq(0, max.yl, length.out=par(yaxp)[3]+1) ## my problem!! text doesn't center to the ticks text(y = seq(0, signif(max(na.omit(Zf$z1)*1.05),2), length.out=par(yaxp)[3]+1), par(usr)[2]+(par(usr)[2]-par(usr)[1])*0.025, labels = lablist.y, srt = 90, pos = 4, xpd = TRUE) I hope the problem gets clearer now and would be very glad if there is a streighter solution. Bastian 2014-05-27 19:03 GMT+02:00 Gabor Grothendieck ggrothendi...@gmail.com: On Tue, May 27, 2014 at 8:02 AM, Bastian Pöschl bstan0...@gmail.com wrote: Hallo, i try to draw a plot (plot.zoo) with a secondary y-axis. Further I want to draw reference lines. Unfortunately I do not manage to get control on the ticks, so that the reference lines match both- primary and secondary y-axis. Maybe someone already solved this problem?? It would be great. Bastian Here is some code to ty out: ## R-Help 2014-05-27 ## Test second. Y-Axix library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## Plot 1 plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) #grid(col = lightgray, lty = dotted) ## this plots at weird ticks #abline(h=ablineticks, col = lightgray, lty = dotted) ## need to write a vector for matching lines ## The following line of z1 doesn't match the first opar - par(usr = c(par(usr)[1:2], c(0,signif(max(na.omit(Zf$z1)*1.05),2 axis(side = 4) mtext(ylab2, side = 4, line = 3, cex=0.7) lines(Zf$z1, lty=2) par(opar) ## ## ## ## ## nice would be a sekundary axis of a second zoo series with ticks matching the first one plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) #grid(col = lightgray, lty = dotted) ## this plots at weird ticks #abline(h=ablineticks, col = lightgray, lty = dotted) ## need to write a vector for matching lines ## The following line of z1 doesn't match the first opar - par(usr = c(par(usr)[1:2], c(0,signif(max(na.omit(Zf$z2)*1.05),2 axis(side = 4) mtext(ylab2, side = 4, line = 3, cex=0.7) lines(Zf$z2, lty=2) par(opar) If the question is how to replicate the left side vertical axis on the right side and then draw horizontal grid lines at the tick marks then try this: plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) axis(4) abline(h = axTicks(4), lty = dotted) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Legend having lines with different types
Hello all, I want to plot the legend for the following two lines: I have two lines: X1-c(0,1,2,3,4) Y1-c(0,1,2,3,4) Y2-c(5,6,7,8,9) Y3-(32,33,34,35,36) plot(X1,Y3,pch=20) lines(X1,Y1,lty=1,type='o') lines(X1,Y2,lty=1,type='b') lines(X1,Y3,lty=2) Any ideas how? Best IOanna [[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 mean
Hi Eliza, No problem. You can also do: lst1 - vector(list,12) for(i in seq_along(lst1)) lst1[[i]] - colMeans(AAA[seq(i,nrow(AAA), by=12),]) A.K. On Wednesday, May 28, 2014 4:17 AM, eliza botto eliza_bo...@hotmail.com wrote: Thankyou very much dennis and arun, The codes worked as ever. :D Eliza Date: Tue, 27 May 2014 18:43:44 -0700 From: smartpink...@yahoo.com Subject: Re: [R] row mean To: r-help@r-project.org CC: eliza_bo...@hotmail.com Forgot, about the mean: lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) colMeans(AAA[i,])) A.K. On , arun smartpink...@yahoo.com wrote: Hi Eliza, May be this helps: lapply(split(seq_len(nrow(AAA)),((seq_len(nrow(AAA))-1)%%12)+1),function(i) AAA[i,]) A.K. On Tuesday, May 27, 2014 6:48 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear R family, I have this matrix say AAA-matrix(sample(1:240),ncol=2) I first want to combine every 13th row in both columns. precisely, starting from row-1 1,13,25,37,49, then starting from row-2 2,14,26,38,50 also 3,15,27,39,51 and similarly starting from row 4, row number 5, row 6... till 12th row,for both columns. so in a way we will have list of 12 matrices each with 10 rows and 2 columns. Finally, I want to calculate mean of each column of each matrix in that list, while keeping the integrity of the list intact. Kindly Advice! Thankyou very much indeed in advance. Eliza [[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] Plot regression results with various predictors.
Sorry for not explaining it further. plm() is the regression command for panel data, i.e., similar to lm() for simple linear regressions. I run the plm() and get an output which I call here POLS. Next I simply use plot(POLS) which looks like http://r.789695.n4.nabble.com/file/n4691355/plot_of_results_-_forum.jpg I am not totally unhappy about this plot. But my main problem is what is the indication of the axis. About the y-axis I know that it is my response variable. But what is plotted on the x-axis? Further, how can I implement the regression line? And obviously, what about adding a legend for the points since each color represents a different country in my case. I hope I could clarify my problem a little bit. Do you have any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Plot-regression-results-with-various-predictors-tp4691307p4691355.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] Plot regression results with various predictors.
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of phil Sent: Wednesday, May 28, 2014 10:41 AM To: r-help@r-project.org Subject: Re: [R] Plot regression results with various predictors. Sorry for not explaining it further. plm() is the regression command for panel data, i.e., similar to lm() for simple linear regressions. I run the plm() and get an output which I call here POLS. Next I simply use plot(POLS) which looks like http://r.789695.n4.nabble.com/file/n4691355/plot_of_results_- _forum.jpg I am not totally unhappy about this plot. But my main problem is what is the indication of the axis. About the y-axis I know that it is my response variable. But what is plotted on the x-axis? I am not familiar with plm function, in documentation there is no plot method indicated but it definitely has plot method. See methods(plot) Because plot.plm is nonvisible you cannot see the code just by plot.plm but you can see the code of plotting function by plm:::plot.plm To see what the function is really plotting you can go through source code and/or debug and inspect each object produced by the function debug(plm:::plot.plm) plot(POLS) I get also this error which means that the plot.plm function is not working properly even with toy data from package (Produc) Error in xy.coords(x, y) : 'x' and 'y' lengths differ It ends on this line after plotting points and axes. debug: lines(c(xmin, xmax), c(ymin, ymax), col = cols[i]) So try to address directly the maintainer. Regards Petr Further, how can I implement the regression line? And obviously, what about adding a legend for the points since each color represents a different country in my case. I hope I could clarify my problem a little bit. Do you have any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Plot- regression-results-with-various-predictors-tp4691307p4691355.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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which
Re: [R] Zoo: How to match secondary Y-axis ticks to primary ones
On Wed, May 28, 2014 at 4:28 AM, Bastian Pöschl bstan0...@gmail.com wrote: Thank you for the quick reply, your advice wasn't exactly what I was looking for. The plot 1 of the example was ment to show my problem: the secondary axis has it's first tick at the intersection with the x-axis whereas the primary y-axis shows a nice little offset. Using your advice i copied the y axis and tried to solve the Problem by foot. Unfortunately the lable text isn't willing to center to the ticks Here is the code: ## R-Help 2014-05-28 ## Test second. Y-Axix library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) axis(4, labels = FALSE) abline(h = axTicks(4), lty = dotted, col=grey) lablist.y-seq(0, max.yl, length.out=par(yaxp)[3]+1) ## my problem!! text doesn't center to the ticks text(y = seq(0, signif(max(na.omit(Zf$z1)*1.05),2), length.out=par(yaxp)[3]+1), par(usr)[2]+(par(usr)[2]-par(usr)[1])*0.025, labels = lablist.y, srt = 90, pos = 4, xpd = TRUE) If the problem is to center the labels on the right y axis then try this: plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, at4/20) abline(h = at4, lty = dotted, col=grey) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Zoo: How to match secondary Y-axis ticks to primary ones
Thank you, this is the solution. I just replaced at4/20 by seq(0, max.yl, length.out=par(yaxp)[3]+1) so it should work with any scale. here is the final code that worked for me: ## R-Help 2014-05-28 asked by Bastian Pöschl solved by Gabor Grothendieck library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, seq(0, max.yl, length.out=par(yaxp)[3]+1)) abline(h = at4, lty = dotted, col=grey) The Result is a time series plot of two variables, with nice ticks at primary and secondary y-axis at the same height connected with reference lines and thus easy to read. 2014-05-28 12:56 GMT+02:00 Gabor Grothendieck ggrothendi...@gmail.com: On Wed, May 28, 2014 at 4:28 AM, Bastian Pöschl bstan0...@gmail.com wrote: Thank you for the quick reply, your advice wasn't exactly what I was looking for. The plot 1 of the example was ment to show my problem: the secondary axis has it's first tick at the intersection with the x-axis whereas the primary y-axis shows a nice little offset. Using your advice i copied the y axis and tried to solve the Problem by foot. Unfortunately the lable text isn't willing to center to the ticks Here is the code: ## R-Help 2014-05-28 ## Test second. Y-Axix library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) axis(4, labels = FALSE) abline(h = axTicks(4), lty = dotted, col=grey) lablist.y-seq(0, max.yl, length.out=par(yaxp)[3]+1) ## my problem!! text doesn't center to the ticks text(y = seq(0, signif(max(na.omit(Zf$z1)*1.05),2), length.out=par(yaxp)[3]+1), par(usr)[2]+(par(usr)[2]-par(usr)[1])*0.025, labels = lablist.y, srt = 90, pos = 4, xpd = TRUE) If the problem is to center the labels on the right y axis then try this: plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, at4/20) abline(h = at4, lty = dotted, col=grey) [[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] Dataframe: Average cells of two rows and replace them with one row
Hey guys, thank you very much for your help. Since I am a R-newbie I am still checking out how your code works and how I could adapt it to my dataframe, which has 124 rows and 41 columns/variables. The first column would be name, the last ones, 40 and 41, contain the cells I want to average for some rows. Is it possible to read the dataframe without copying the whole thing into the text function (just tried it and got an error message)? Thank you! Verena On Wed, May 28, 2014 at 3:48 AM, arun smartpink...@yahoo.com wrote: Hi, You can also try: dat - read.table(text=Name C1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3 3 4 C 4 4 6 5 D 5 5 3,sep=,header=TRUE,stringsAsFactors=FALSE) library(plyr) ddply(dat,.(Name),numcolwise(mean,na.rm=TRUE)) A.K. On Tuesday, May 27, 2014 4:08 PM, Verena Weinbir vwein...@gmail.com wrote: Hello, I have a big dataframe, and want to average two specific cells of two specific rows and then replace those two rows with one row which contains the averaged cells. Example (row 3 and 4: Cells2 and Cells3 averaged and replaced) NameC1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3 3 4 C 4 4 6 5 D 5 5 3 NameC1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3.5 4.5 4 D 5 5 3 Many thanks in advance! Best, Verena [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Zoo: How to match secondary Y-axis ticks to primary ones
Sorry the last post has got a mistake, here is the corrected version: ## R-Help 2014-05-28 asked by Bastian Pöschl solved by Gabor Grothendieck library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)),2)), xlab=) ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, seq(0, max.yl, length.out=par(yaxp)[3]+1)) abline(h = at4, lty = dotted, col=grey) The Result is a time series plot of two variables, with nice ticks at primary and secondary y-axis at the same height connected with reference lines and thus easy to read. 2014-05-28 12:56 GMT+02:00 Gabor Grothendieck ggrothendi...@gmail.com: 2014-05-28 13:22 GMT+02:00 Bastian Pöschl bstan0...@gmail.com: Thank you, this is the solution. I just replaced at4/20 by seq(0, max.yl, length.out=par(yaxp)[3]+1) so it should work with any scale. here is the final code that worked for me: ## R-Help 2014-05-28 asked by Bastian Pöschl solved by Gabor Grothendieck library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, seq(0, max.yl, length.out=par(yaxp)[3]+1)) abline(h = at4, lty = dotted, col=grey) The Result is a time series plot of two variables, with nice ticks at primary and secondary y-axis at the same height connected with reference lines and thus easy to read. 2014-05-28 12:56 GMT+02:00 Gabor Grothendieck ggrothendi...@gmail.com: On Wed, May 28, 2014 at 4:28 AM, Bastian Pöschl bstan0...@gmail.com wrote: Thank you for the quick reply, your advice wasn't exactly what I was looking for. The plot 1 of the example was ment to show my problem: the secondary axis has it's first tick at the intersection with the x-axis whereas the primary y-axis shows a nice little offset. Using your advice i copied the y axis and tried to solve the Problem by foot. Unfortunately the lable text isn't willing to center to the ticks Here is the code: ## R-Help 2014-05-28 ## Test second. Y-Axix library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) axis(4, labels = FALSE) abline(h = axTicks(4), lty
Re: [R] Legend having lines with different types
I want to plot the legend for the following two lines: ... Any ideas how? Try ?legend S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Zoo: How to match secondary Y-axis ticks to primary ones
To get 0.5 Ticks the script was corrected another time ;) ## R-Help 2014-05-28 asked by Bastian Pöschl solved by Gabor Grothendieck library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)),2)), xlab=) ## use multiplication for even tick numbers and fake sekondary y-axis y2at-par(yaxp)[3]/floor(par(yaxp)[3]/max(na.omit(Zf$z1))) ## This is the changed line to get 0.5 steps etc. max.yl-roundup(max(na.omit(Zf$z1)), y2at) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, seq(0, max.yl, length.out=par(yaxp)[3]+1)) abline(h = at4, lty = dotted, col=grey) 2014-05-28 14:02 GMT+02:00 Bastian Pöschl bstan0...@gmail.com: Sorry the last post has got a mistake, here is the corrected version: ## R-Help 2014-05-28 asked by Bastian Pöschl solved by Gabor Grothendieck library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)),2)), xlab=) ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, seq(0, max.yl, length.out=par(yaxp)[3]+1)) abline(h = at4, lty = dotted, col=grey) The Result is a time series plot of two variables, with nice ticks at primary and secondary y-axis at the same height connected with reference lines and thus easy to read. 2014-05-28 12:56 GMT+02:00 Gabor Grothendieck ggrothendi...@gmail.com: 2014-05-28 13:22 GMT+02:00 Bastian Pöschl bstan0...@gmail.com: Thank you, this is the solution. I just replaced at4/20 by seq(0, max.yl, length.out=par(yaxp)[3]+1) so it should work with any scale. here is the final code that worked for me: ## R-Help 2014-05-28 asked by Bastian Pöschl solved by Gabor Grothendieck library(zoo) ## generate some smooth timeseries x1 - c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) x2 - c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) z1 - zooreg(x1, start=as.POSIXct(2013-01-01 00:00:01), frequency=0.006) z2 - zooreg(x2, start=as.POSIXct(2013-01-01 00:00:20), frequency=0.006) zt - zooreg(rnorm(1050), start=as.POSIXct(2013-01-01 00:00:01), frequency=0.7) z-merge(zt, z1, all = TRUE) z-merge(z, z2, all = TRUE) Zf-na.spline(z[,2:3], na.rm = FALSE) ## ## ## ## ## function to round up to a number divisible by n (2011 by Owen Jones) roundup - function(x,n){ceiling(ceiling(x)/n)*n} ## ## ## ## ## Plot How to match secondary Y-axis ticks to primary ones plot(Zf$z1, ylim=c(0,signif(max(na.omit(Zf$z1)*1.05),2)), xlab=) ## use multiplication for even tick numbers and fake sekondary y-axis max.yl-roundup(max(na.omit(Zf$z2)), par(yaxp)[3]) multipl.yl-max(na.omit(Zf$z2))/max.yl multipl.z2-signif(max(na.omit(Zf$z1)*1.05),2)/max.yl lines(Zf$z2*multipl.z2, lty=2) at4 - axTicks(4) axis(4, at = at4, seq(0, max.yl, length.out=par(yaxp)[3]+1)) abline(h = at4, lty = dotted, col=grey) The Result is a time series plot of two variables, with nice ticks at primary and secondary y-axis at the same height connected with reference lines and thus easy to read. 2014-05-28 12:56 GMT+02:00 Gabor Grothendieck ggrothendi...@gmail.com: On Wed, May 28, 2014 at 4:28 AM, Bastian Pöschl bstan0...@gmail.com wrote: Thank you for the quick reply, your advice wasn't exactly what I was looking for. The plot 1 of the example was ment to show my problem: the secondary axis
Re: [R] Legend having lines with different types
IOanna, If you are trying to distinguish between the type=b and the type=o in the legend, there does not appear to be a way to do this with the legend() function in base. I found a similar question posted on stackoverflow, and they suggested a work around for something similar (but not quite the same). http://stackoverflow.com/questions/18233236/how-to-get-lines-of-type-b-in-a-legend Here's an example, using your data. X1-c(0,1,2,3,4) Y1-c(0,1,2,3,4) Y2-c(5,6,7,8,9) Y3-c(32,33,34,35,36) plot(X1,Y3,pch=20, ylim=range(Y1, Y2, Y3)) lines(X1,Y1,lty=1,type='o') lines(X1,Y2,lty=1,type='o', pch=21, bg=white) lines(X1,Y3,lty=2) legend(center, c(Y3, Y2, Y1), lty=c(2, 1, 1), pch=c(20, 21, 1), pt.bg=c(NULL, white, NULL)) Jean On Wed, May 28, 2014 at 3:21 AM, IOANNA ii54...@msn.com wrote: Hello all, I want to plot the legend for the following two lines: I have two lines: X1-c(0,1,2,3,4) Y1-c(0,1,2,3,4) Y2-c(5,6,7,8,9) Y3-(32,33,34,35,36) plot(X1,Y3,pch=20) lines(X1,Y1,lty=1,type='o') lines(X1,Y2,lty=1,type='b') lines(X1,Y3,lty=2) Any ideas how? Best IOanna [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataframe: Average cells of two rows and replace them with one row
Hi AFAIK you can not average values only in 2 columns leaving others intact. The exact code depends on what are in columns 2-39 in your data frame. If numbers, you can averege them as well. Something like dat.ag - aggregate(dat[,-1], list(dat$Name), mean, na.rm=TRUE) if your data frame is named dat and first column calls Name. You get new object with aggregated values for the same Name. If some columns are nonnumeric the problem gets trickier and solution strongly depends what mode are those columns and what you want to do with them when aggregating values in column 40 and 41. Show us at least structure of your data frame. ?str Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Verena Weinbir Sent: Wednesday, May 28, 2014 2:00 PM To: arun Cc: r-help Subject: Re: [R] Dataframe: Average cells of two rows and replace them with one row Hey guys, thank you very much for your help. Since I am a R-newbie I am still checking out how your code works and how I could adapt it to my dataframe, which has 124 rows and 41 columns/variables. The first column would be name, the last ones, 40 and 41, contain the cells I want to average for some rows. Is it possible to read the dataframe without copying the whole thing into the text function (just tried it and got an error message)? Thank you! Verena On Wed, May 28, 2014 at 3:48 AM, arun smartpink...@yahoo.com wrote: Hi, You can also try: dat - read.table(text=Name C1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3 3 4 C 4 4 6 5 D 5 5 3,sep=,header=TRUE,stringsAsFactors=FALSE) library(plyr) ddply(dat,.(Name),numcolwise(mean,na.rm=TRUE)) A.K. On Tuesday, May 27, 2014 4:08 PM, Verena Weinbir vwein...@gmail.com wrote: Hello, I have a big dataframe, and want to average two specific cells of two specific rows and then replace those two rows with one row which contains the averaged cells. Example (row 3 and 4: Cells2 and Cells3 averaged and replaced) NameC1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3 3 4 C 4 4 6 5 D 5 5 3 NameC1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3.5 4.5 4 D 5 5 3 Many thanks in advance! Best, Verena [[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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this
Re: [R] How to unstack three columns into rows?
Hi Petr I think cast() has been dropped from the most recent reshape2 and you need dcast(data, siteS~species) instead John Kane Kingston ON Canada -Original Message- From: petr.pi...@precheza.cz Sent: Tue, 27 May 2014 11:46:13 + To: kristi.glo...@hotmail.com, r-help@r-project.org Subject: Re: [R] How to unstack three columns into rows? Hi cast(data, siteS~species) gives you quite close result, only row ordering is different Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Kristi Glover Sent: Tuesday, May 27, 2014 12:54 PM To: R-help Subject: [R] How to unstack three columns into rows? Dear R User, I was wondering how I can unstack my data. For example I have following data set data-structure(list(siteS = structure(c(3L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 1L, 1L, 1L, 2L), .Label = c(11a, 12d, 1a, 2v, 6a), class = factor), species = structure(c(1L, 2L, 3L, 1L, 4L, 1L, 4L, 5L, 2L, 3L, 1L, 6L, 3L, 1L), .Label = c(sa, sb, sc, sd, se, sg), class = factor), abundance = c(31L, 55L, 62L, 42L, 40L, 30L, 84L, 10L, 23L, 74L, 11L, 51L, 37L, 15L )), .Names = c(siteS, species, abundance), class = data.frame, row.names = c(NA, -14L)) I wanted to have this data into following format newData-structure(list(siteS = structure(c(3L, 4L, 5L, 1L, 2L), .Label = c(11a, 12d, 1a, 2v, 6a), class = factor), sa = c(31L, 42L, 30L, 11L, 15L), sb = c(55L, NA, 84L, NA, NA), sc = c(62L, NA, 10L, 37L, NA), sd = c(NA, 40L, 23L, NA, NA), se = c(NA, NA, 74L, NA, NA), sg = c(NA, NA, NA, 51L, NA)), .Names = c(siteS, sa, sb, sc, sd, se, sg), class = data.frame, row.names = c(NA, -5L)) I tried several ways such as: data.frame(unstack(data, species~siteS)) Error in data.frame(`11a` = c(sa, sg, sc), `12d` = sa, `1a` = c(sa, : arguments imply differing number of rows: 3, 1, 2, 5 [[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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so
[R] remove duplicated row according to NA condition
Hi everybody, I have a little problem in my R-code which seems be easy to solve, but I wasn't able to find the solution by myself for the moment. Here's an example of the form of my data: data - data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA)) I would like to remove duplicated data based on the first two columns (col1,col2), but in both cases here, I would like to remove the duplicated row which is equal to NA in col3. Here's the data.frame I would like to obtain: data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002)) I've been trying to mix duplicated() with is.na() but it doesn't work yet. Can someone tell me the best and easiest way to do this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.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] remove duplicated row according to NA condition
Hi! How about trying this: data[ data$col1!=data$col2 !is.na(data$col3), ] col1 col2 col3 2a1 ST001 3b2 ST002 HTH, Kimmo 28.05.2014 15:35, jeff6868 wrote: Hi everybody, I have a little problem in my R-code which seems be easy to solve, but I wasn't able to find the solution by myself for the moment. Here's an example of the form of my data: data - data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA)) I would like to remove duplicated data based on the first two columns (col1,col2), but in both cases here, I would like to remove the duplicated row which is equal to NA in col3. Here's the data.frame I would like to obtain: data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002)) I've been trying to mix duplicated() with is.na() but it doesn't work yet. Can someone tell me the best and easiest way to do this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.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] remove duplicated row according to NA condition
It would help if you said what you want done when none or all or some of the col1-col2 duplicates have NA's in the col3. E.g., what do you want the function to do for the following input? data2 - data.frame(col1=c(a,a,a,b,b,c,c,d,d,e), col2=c(1,1,1,2,2,3,3,4,4,5), col3=c(A1,NA,A3,NA,B2,C1,C2,NA,NA,NA)) data2 col1 col2 col3 1 a1 A1 2 a1 NA 3 a1 A3 4 b2 NA 5 b2 B2 6 c3 C1 7 c3 C2 8 d4 NA 9 d4 NA 10e5 NA (You may want it to return a data.frame or you may want the function to stop because the data is not considered legal, but you should decide what it should do.) Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, May 28, 2014 at 5:35 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Hi everybody, I have a little problem in my R-code which seems be easy to solve, but I wasn't able to find the solution by myself for the moment. Here's an example of the form of my data: data - data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA)) I would like to remove duplicated data based on the first two columns (col1,col2), but in both cases here, I would like to remove the duplicated row which is equal to NA in col3. Here's the data.frame I would like to obtain: data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002)) I've been trying to mix duplicated() with is.na() but it doesn't work yet. Can someone tell me the best and easiest way to do this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.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] remove duplicated row according to NA condition
Hi, May be this helps: data1 - data[with(data, order(col1, col2,1*is.na(col3))),] data1[!duplicated(data1[,1:2]),] A.K. On Wednesday, May 28, 2014 11:28 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Hi everybody, I have a little problem in my R-code which seems be easy to solve, but I wasn't able to find the solution by myself for the moment. Here's an example of the form of my data: data - data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA)) I would like to remove duplicated data based on the first two columns (col1,col2), but in both cases here, I would like to remove the duplicated row which is equal to NA in col3. Here's the data.frame I would like to obtain: data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002)) I've been trying to mix duplicated() with is.na() but it doesn't work yet. Can someone tell me the best and easiest way to do this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.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] Second axis on bottom of graph
Thank you Jeff for your good orientation. You are an educator. I looked at the documentation for more than an hour. Yes, there is a big learning curve. My R-coding friend doesn't know it either. Here is runnable code for a graph I would like to redo in the better code. The staxlab function was sent to me by the author. The remainder code isn't so long. An expert could rewrite it quickly. Any out there? #trying for both period-labeled and frequency-labeled horizontal axes rm(list=ls(all=TRUE)) install.packages('plotrix'); library(plotrix) #install.packages('lattice'); library(lattice) #install.packages('ggplot2'); library(ggplot2) #staxlab (to be standard soon) sent by author so staxlab works on second x axis. staxlab-function(side=1,at,labels,nlines=2,top.line=0.5, line.spacing=0.8,srt=NA,ticklen=0.03,adj=1,...) { if(missing(labels)) labels-at nlabels-length(labels) if(missing(at)) at-1:nlabels axislim-par(usr)[3:4-2*side%%2] if(any(at axislim[1]) || any(at axislim[2])) warning(Some axis labels are off the plot) if(is.na(srt)) { linepos-rep(top.line,nlines) for(i in 2:nlines) linepos[i]-linepos[i-1]+line.spacing linepos-rep(linepos,ceiling(nlabels/nlines))[1:nlabels] axis(side=side,at=at,labels=rep(,nlabels)) mtext(text=labels,side=side,line=linepos,at=at,...) } else { linewidth-strheight(M) xylim-par(usr) if(side == 1) { xpos-at if(par(ylog)) ypos-10^(xylim[3]-ticklen*(xylim[4]-xylim[3])) else ypos-xylim[3]-ticklen*(xylim[4]-xylim[3])-top.line*linewidth } if(side == 3) { xpos-at if(par(ylog)) ypos-10^(xylim[4]+ticklen*(xylim[4]-xylim[3])) else ypos-xylim[4]+ticklen*(xylim[4]-xylim[3])+top.line*linewidth } if(side == 2) { ypos-at if(par(xlog)) xpos-10^(xylim[1]-ticklen*(xylim[2]-xylim[1])) else xpos-xylim[1]-ticklen*(xylim[2]-xylim[1])-top.line*linewidth } if(side == 4) { ypos-at if(par(xlog)) xpos-10^(xylim[2]+ticklen*(xylim[2]-xylim[1])) else xpos-xylim[2]+ticklen*(xylim[2]-xylim[1])+top.line*linewidth } par(xpd=TRUE) text(xpos,ypos,labels,srt=srt,adj=adj,...) par(xpd=FALSE) } } par(lheight=0.7)#vertical text space = lheight * char height * character expansion par(mar=c(8,4,4,2)+.1) #margins: mar=c(bot,lef,top,rit); default:c(5,4,4,2)+.1 par(xaxs=i) #to make 2nd axis and plot width size match; others: xaxs= r, i, e, s, d. par(mgp=c(3,.5,0)) #default mgp=c(3,1,0) margin line in mex units c(axisTitle,axisLabel,axisLine) #set only by par():ask,fig,fin,lheight,mai,mar,mex,mfcol,mfrow,mfg,new,oma,omd,omi,pin,plt,ps,pty,usr,xlog,ylog,ylbias prdAxDistDown=0; frqAxDistDown=2.25; horAxFrqCntrlNums=c(-10.0,0.0,1.1,500.0,515.0) #=c(lefGrafBordFrq,lefScalEndFrq,lefPlotEndFrq,ritPlotEndFrq,ritScalEndFrq) horData=c(1.100,56.53,112.0,167.4,222.8,278.3,333.7,389.1,444.6,500.0) verData=c(57.67,98.33,82.40,68.15,78.89,93.53,22.54,37.60,87.19,49.35) prdTicLocs=c(1.10,12,52.2,91.3, 122, 183, 365,500) prdLabels=c(10.9\nMo,1Mo,1Wk,4Da,3Da,2Da,1Da,17.5\nHr) print(horAxFrqCntrlNums); print(prdLabels) nFrqTicInvls=9; frqTicLocs - vector(length=nFrqTicInvls+1); frqLabels - vector(length=nFrqTicInvls+1); frqInvl=(horAxFrqCntrlNums[5]-horAxFrqCntrlNums[2])/nFrqTicInvls for(i in 1:(nFrqTicInvls+1))frqTicLocs[i]=horAxFrqCntrlNums[2]+(i-1)*frqInvl; for(i in 1:(nFrqTicInvls+1))frqLabels[i]=format(round(frqTicLocs[i]),digits=4,trim=TRUE,scientific=FALSE) print(frqTicLocs); print(frqLabels) las=2; #las=2 makes axis labels perpendicular to axis plot(horData,verData,xaxt='n',xlim=c(horAxFrqCntrlNums[1],horAxFrqCntrlNums[5]),xlab=,ylab=) axis(2,tick=TRUE,line=0,at=NULL) #side: 1=below, 2=left, 3=above and 4=right #tck if = 0.5 then fraction of relevant side; if =1 then gridlines axis(1,tick=TRUE,line=prdAxDistDown,at=prdTicLocs,labels=rep(,length(prdLabels)),padj=0,tck=-.04) staxlab(1,top.line=(prdAxDistDown-0.8),at=prdTicLocs,labels=prdLabels,srt=90,adj=c(1,0)) axis(1,tick=TRUE,line=frqAxDistDown,at=frqTicLocs,labels=rep(,length(frqLabels)),padj=0,tck=-.04) staxlab(1,top.line=(frqAxDistDown+0.2),at=frqTicLocs,labels=frqLabels,srt=90,adj=c(1,0)) title(xlab=Cycles/Yr,line=4); title(ylab=verData,line=1.5); title(main=Trying Both Frequency And Period Axes) -- View this message in context: http://r.789695.n4.nabble.com/Second-axis-on-bottom-of-graph-tp4690696p4691377.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] Second axis on bottom of graph
Hi Hurr I'm getting curious! You have now spent several weeks on this plot. One reason to do this if the journal request it. Is that the case? Or is it your own hard minded way to have your plot made the way you like. In my mind a very good plot support ones data. Is that what you want? Does it then matters with details? Br. Frede Sendt fra Samsung mobil Oprindelig meddelelse Fra: Hurr Dato:28/05/2014 19.03 (GMT+01:00) Til: r-help@r-project.org Emne: Re: [R] Second axis on bottom of graph Thank you Jeff for your good orientation. You are an educator. I looked at the documentation for more than an hour. Yes, there is a big learning curve. My R-coding friend doesn't know it either. Here is runnable code for a graph I would like to redo in the better code. The staxlab function was sent to me by the author. The remainder code isn't so long. An expert could rewrite it quickly. Any out there? #trying for both period-labeled and frequency-labeled horizontal axes rm(list=ls(all=TRUE)) install.packages('plotrix'); library(plotrix) #install.packages('lattice'); library(lattice) #install.packages('ggplot2'); library(ggplot2) #staxlab (to be standard soon) sent by author so staxlab works on second x axis. staxlab-function(side=1,at,labels,nlines=2,top.line=0.5, line.spacing=0.8,srt=NA,ticklen=0.03,adj=1,...) { if(missing(labels)) labels-at nlabels-length(labels) if(missing(at)) at-1:nlabels axislim-par(usr)[3:4-2*side%%2] if(any(at axislim[1]) || any(at axislim[2])) warning(Some axis labels are off the plot) if(is.na(srt)) { linepos-rep(top.line,nlines) for(i in 2:nlines) linepos[i]-linepos[i-1]+line.spacing linepos-rep(linepos,ceiling(nlabels/nlines))[1:nlabels] axis(side=side,at=at,labels=rep(,nlabels)) mtext(text=labels,side=side,line=linepos,at=at,...) } else { linewidth-strheight(M) xylim-par(usr) if(side == 1) { xpos-at if(par(ylog)) ypos-10^(xylim[3]-ticklen*(xylim[4]-xylim[3])) else ypos-xylim[3]-ticklen*(xylim[4]-xylim[3])-top.line*linewidth } if(side == 3) { xpos-at if(par(ylog)) ypos-10^(xylim[4]+ticklen*(xylim[4]-xylim[3])) else ypos-xylim[4]+ticklen*(xylim[4]-xylim[3])+top.line*linewidth } if(side == 2) { ypos-at if(par(xlog)) xpos-10^(xylim[1]-ticklen*(xylim[2]-xylim[1])) else xpos-xylim[1]-ticklen*(xylim[2]-xylim[1])-top.line*linewidth } if(side == 4) { ypos-at if(par(xlog)) xpos-10^(xylim[2]+ticklen*(xylim[2]-xylim[1])) else xpos-xylim[2]+ticklen*(xylim[2]-xylim[1])+top.line*linewidth } par(xpd=TRUE) text(xpos,ypos,labels,srt=srt,adj=adj,...) par(xpd=FALSE) } } par(lheight=0.7)#vertical text space = lheight * char height * character expansion par(mar=c(8,4,4,2)+.1) #margins: mar=c(bot,lef,top,rit); default:c(5,4,4,2)+.1 par(xaxs=i) #to make 2nd axis and plot width size match; others: xaxs= r, i, e, s, d. par(mgp=c(3,.5,0)) #default mgp=c(3,1,0) margin line in mex units c(axisTitle,axisLabel,axisLine) #set only by par():ask,fig,fin,lheight,mai,mar,mex,mfcol,mfrow,mfg,new,oma,omd,omi,pin,plt,ps,pty,usr,xlog,ylog,ylbias prdAxDistDown=0; frqAxDistDown=2.25; horAxFrqCntrlNums=c(-10.0,0.0,1.1,500.0,515.0) #=c(lefGrafBordFrq,lefScalEndFrq,lefPlotEndFrq,ritPlotEndFrq,ritScalEndFrq) horData=c(1.100,56.53,112.0,167.4,222.8,278.3,333.7,389.1,444.6,500.0) verData=c(57.67,98.33,82.40,68.15,78.89,93.53,22.54,37.60,87.19,49.35) prdTicLocs=c(1.10,12,52.2,91.3, 122, 183, 365,500) prdLabels=c(10.9\nMo,1Mo,1Wk,4Da,3Da,2Da,1Da,17.5\nHr) print(horAxFrqCntrlNums); print(prdLabels) nFrqTicInvls=9; frqTicLocs - vector(length=nFrqTicInvls+1); frqLabels - vector(length=nFrqTicInvls+1); frqInvl=(horAxFrqCntrlNums[5]-horAxFrqCntrlNums[2])/nFrqTicInvls for(i in 1:(nFrqTicInvls+1))frqTicLocs[i]=horAxFrqCntrlNums[2]+(i-1)*frqInvl; for(i in 1:(nFrqTicInvls+1))frqLabels[i]=format(round(frqTicLocs[i]),digits=4,trim=TRUE,scientific=FALSE) print(frqTicLocs); print(frqLabels) las=2; #las=2 makes axis labels perpendicular to axis plot(horData,verData,xaxt='n',xlim=c(horAxFrqCntrlNums[1],horAxFrqCntrlNums[5]),xlab=,ylab=) axis(2,tick=TRUE,line=0,at=NULL) #side: 1=below, 2=left, 3=above and 4=right #tck if = 0.5 then fraction of relevant side; if =1 then gridlines axis(1,tick=TRUE,line=prdAxDistDown,at=prdTicLocs,labels=rep(,length(prdLabels)),padj=0,tck=-.04) staxlab(1,top.line=(prdAxDistDown-0.8),at=prdTicLocs,labels=prdLabels,srt=90,adj=c(1,0)) axis(1,tick=TRUE,line=frqAxDistDown,at=frqTicLocs,labels=rep(,length(frqLabels)),padj=0,tck=-.04) staxlab(1,top.line=(frqAxDistDown+0.2),at=frqTicLocs,labels=frqLabels,srt=90,adj=c(1,0)) title(xlab=Cycles/Yr,line=4); title(ylab=verData,line=1.5); title(main=Trying Both Frequency And Period Axes) -- View this message in context: http://r.789695.n4.nabble.com/Second-axis-on-bottom-of-graph-tp4690696p4691377.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list
[R] tk2listbox
Hello, I'm migrating an old S application to R, and having trouble passing tk2listbox selections to a function. Could not find a listbox example with tcltk2, just tcltk. The snippet below shows a few of the lines creating the gui, including a tk2entry box that works fine for passing content, and a tk2listbox that doesn't, and the button calling the function. Right now I'm just passing the default values for any listbox (OSType in the example below). I can't figure out how to pass a user selection. Have tried variations with tkcurselection(OSlist),tclGetValue(OSlist). How do I obtain the value from OSlist if Simple Random was selected by the user? OtofanR=tktoplevel() tktitle(OtofanR) - Age-Related Data Analysis with OTOFAN tkgrid(tklabel(OtofanR,text=DATA SELECTION DEFINITION),stick=we) . . . FreqVar - tclVar(NA) tkgrid(tklabel(OtofanR,text=Frequency variable),tk2entry(OtofanR, textvariable=FreqVar, width=20)) OSType - tclVar(Random at Length) OSlist=tk2listbox(OtofanR, values=c(Random at Length, Simple Random), value=OSType, selection=1, selectmode = single, height = 2, scroll = none, autoscroll = x, enabled = TRUE) tkgrid(tklabel(OtofanR,text=Otolith Sample Type),OSlist) . . . AppApply - tk2button(OtofanR, text = Apply, width = 7, command = function() OtofanDT(tclvalue(ADMBdata),tclvalue(ADMBFile),tclvalue(ADMBPin),ADMBF= NA,ADMBP=NA,tclvalue(GS),tclvalue(Regdata),tclvalue(CustomFile), tclvalue(Ages),tclvalue(FishLens),tclvalue(OtoWts),tclvalue(OtoLens),tcl value(FishWts),tclvalue(GroupID),tclvalue(YearID),tclvalue(Sex),tclvalue (LFdata),tclvalue(FreqVar),tclvalue(OSType),tclvalue(ASType), tclvalue(LAAdet),tclvalue(LPhase),tclvalue(Ldist),tclvalue(LAAstdev),tcl value(LSDPhase),tclvalue(LSDdist),tclvalue(LSDcov),tclvalue(OAA),tclvalu e(OAAdet),tclvalue(OPhase),tclvalue(Odist),tclvalue(OAAstdev),tclvalue(O SDPhase),tclvalue(OSDdist), tclvalue(CORR),tclvalue(CORest),tclvalue(CPhase),tclvalue(GS2),tclvalue( PAAPhase))) Mark Fowler Population Ecology Division Bedford Inst of Oceanography Dept Fisheries Oceans Dartmouth NS Canada B2Y 4A2 Tel. (902) 426-3529 Fax (902) 426-9710 Email mark.fow...@dfo-mpo.gc.ca mailto:mark.fow...@dfo-mpo.gc.ca [[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] Creating a new column with the number of the observation
I have a data frame like this: Category Observed_value A 100 A 130 A 140 B 90 C 80 D 120 D 130 I need to create an index column that show the number of the observation for each category. I have three observations in the category A, one in category B, one in category C and two in category D. The new matrix should be like this: Category Observed_value Index A 100 1 A 130 2 A 140 3 B 90 1 C 80 1 D 120 1 D 130 2 Please, could anyone help me with this problem? Thank you. -- Marcos Martins Santos mmsantos...@gmail.com -- Skype: marcosmartinssantos [[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] partykit ctree: minbucket and case weights
Hello, I am an R novice, and I am using the partykit package to create regression trees. I used the following to generate the trees: ctree(y~x1+x2+x3+x4,data=my_data,control=ctree_control(testtype = Bonferroni, mincriterion = 0.90, minsplit = 12, minbucket = 4, majority = TRUE) I thought that minbucket set the minimum value for the sum of weights in each terminal node, and that each case weight is 1, unless otherwise specified. In which case, the sum of case weights in a node should equal the number of cases (n) in that node. However, I sometimes obtain a tree with a terminal node that contains fewer than 4 cases. My data set has a total of 36 cases. The dependent and all independent variables are continuous data. Variables x1 and x2 contain missing (NA) values. Could someone please explain why I am getting these results? Am I mistaken about the value of case weights or about the use of minbucket to restrict the size of a terminal node? This is an example of the output: Model formula: y ~ x1 + x2 + x3 + x4 Fitted party: [1] root | [2] x4 = 30: 0.927 (n = 17, err = 1.1) | [3] x4 30 | | [4] x2 = 43: 0.472 (n = 8, err = 0.4) | | [5] x2 43 | | | [6] x3 = 0.4: 0.282 (n = 3, err = 0.0) | | | [7] x3 0.4: 0.020 (n = 8, err = 0.0) Number of inner nodes:3 Number of terminal nodes: 4 Many thanks! Amber Nolder Graduate Student Indiana University of Pennsylvania __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 new column with the number of the observation
Hi. Here is one approach: x - rep(c(A, B, C), c(3,1,2)) DF - data.frame(x, stringsAsFactors=FALSE) cbind(DF, new_c=c(lapply(rle(DF$x)[[1]], function(x) 1:x), recursive=T)) Andrija On Wed, May 28, 2014 at 10:46 PM, Marcos Santos mmsantos...@gmail.comwrote: I have a data frame like this: Category Observed_value A 100 A 130 A 140 B 90 C 80 D 120 D 130 I need to create an index column that show the number of the observation for each category. I have three observations in the category A, one in category B, one in category C and two in category D. The new matrix should be like this: Category Observed_value Index A 100 1 A 130 2 A 140 3 B 90 1 C 80 1 D 120 1 D 130 2 Please, could anyone help me with this problem? Thank you. -- Marcos Martins Santos mmsantos...@gmail.com -- Skype: marcosmartinssantos [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a new column with the number of the observation
Here is another approach: x - rep(c(A, B, C), c(3,1,2)) DF1 - data.frame(x) cbind(DF1, new_c=ave(as.numeric(DF1$x), DF1$x, FUN=function(x) 1:length(x))) Note the difference between DF (in previous solution) and DF1 str(DF) str(DF1) Andrija On Thu, May 29, 2014 at 12:03 AM, Andrija Djurovic djandr...@gmail.comwrote: Hi. Here is one approach: x - rep(c(A, B, C), c(3,1,2)) DF - data.frame(x, stringsAsFactors=FALSE) cbind(DF, new_c=c(lapply(rle(DF$x)[[1]], function(x) 1:x), recursive=T)) Andrija On Wed, May 28, 2014 at 10:46 PM, Marcos Santos mmsantos...@gmail.comwrote: I have a data frame like this: Category Observed_value A 100 A 130 A 140 B 90 C 80 D 120 D 130 I need to create an index column that show the number of the observation for each category. I have three observations in the category A, one in category B, one in category C and two in category D. The new matrix should be like this: Category Observed_value Index A 100 1 A 130 2 A 140 3 B 90 1 C 80 1 D 120 1 D 130 2 Please, could anyone help me with this problem? Thank you. -- Marcos Martins Santos mmsantos...@gmail.com -- Skype: marcosmartinssantos [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a new column with the number of the observation
Absolutely fantastic! Thank you for the TWO approachs. 2014-05-28 19:13 GMT-03:00 Andrija Djurovic djandr...@gmail.com: Here is another approach: x - rep(c(A, B, C), c(3,1,2)) DF1 - data.frame(x) cbind(DF1, new_c=ave(as.numeric(DF1$x), DF1$x, FUN=function(x) 1:length(x))) Note the difference between DF (in previous solution) and DF1 str(DF) str(DF1) Andrija On Thu, May 29, 2014 at 12:03 AM, Andrija Djurovic djandr...@gmail.comwrote: Hi. Here is one approach: x - rep(c(A, B, C), c(3,1,2)) DF - data.frame(x, stringsAsFactors=FALSE) cbind(DF, new_c=c(lapply(rle(DF$x)[[1]], function(x) 1:x), recursive=T)) Andrija On Wed, May 28, 2014 at 10:46 PM, Marcos Santos mmsantos...@gmail.comwrote: I have a data frame like this: Category Observed_value A 100 A 130 A 140 B 90 C 80 D 120 D 130 I need to create an index column that show the number of the observation for each category. I have three observations in the category A, one in category B, one in category C and two in category D. The new matrix should be like this: Category Observed_value Index A 100 1 A 130 2 A 140 3 B 90 1 C 80 1 D 120 1 D 130 2 Please, could anyone help me with this problem? Thank you. -- Marcos Martins Santos mmsantos...@gmail.com -- Skype: marcosmartinssantos [[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. -- Marcos Martins Santos mmsantos...@gmail.com -- Tel. (85) 3044-7436 Cel. (85) 9636-6612 -- Skype: marcosmartinssantos [[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] Second axis on bottom of graph
Thank you Frede Aakmann Tøgersen-2 for your criticism. Yes the data is only similar to the data it is being made for. Our Lab been looking for years for a good way to make our graphs without buying expensive software. We have used mostly MS Excel, but the two axes are difficult. Good graphing software is hard to find. Yes it is my own hard minded way to have my plot made the way I like it. But it is also the way that my supervisor likes to show the data. Even though the graph scale is frequency, we think in terms of period. Sorry I need someone to teach me. Have I satisfied a little of your curiosity? Hurr -- View this message in context: http://r.789695.n4.nabble.com/Second-axis-on-bottom-of-graph-tp4690696p4691398.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to access an executing environment?
Hello: I'm writing code to modify a function, and I want to know how to access the executing environment of the function. The example below extracts the body of a function and executes a single line but can't find x1 in the function's executing environment. How would you suggest fixing this? Thanks, Spencer fun1 - function(x1=1){ y - x1 } fun2 - function(fun=fun1){ bo - body(fun) bo2 - bo[[2]] z - eval(bo2) } tst - fun2() Error in eval(expr, envir, enclos) : object 'x1' not found __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 new column with the number of the observation
Hi, If it ordered by the variable x, you could also try: within(DF1, new_c-sequence(table(x))) A.K. On Wednesday, May 28, 2014 6:14 PM, Andrija Djurovic djandr...@gmail.com wrote: Here is another approach: x - rep(c(A, B, C), c(3,1,2)) DF1 - data.frame(x) cbind(DF1, new_c=ave(as.numeric(DF1$x), DF1$x, FUN=function(x) 1:length(x))) Note the difference between DF (in previous solution) and DF1 str(DF) str(DF1) Andrija On Thu, May 29, 2014 at 12:03 AM, Andrija Djurovic djandr...@gmail.comwrote: Hi. Here is one approach: x - rep(c(A, B, C), c(3,1,2)) DF - data.frame(x, stringsAsFactors=FALSE) cbind(DF, new_c=c(lapply(rle(DF$x)[[1]], function(x) 1:x), recursive=T)) Andrija On Wed, May 28, 2014 at 10:46 PM, Marcos Santos mmsantos...@gmail.comwrote: I have a data frame like this: Category Observed_value A 100 A 130 A 140 B 90 C 80 D 120 D 130 I need to create an index column that show the number of the observation for each category. I have three observations in the category A, one in category B, one in category C and two in category D. The new matrix should be like this: Category Observed_value Index A 100 1 A 130 2 A 140 3 B 90 1 C 80 1 D 120 1 D 130 2 Please, could anyone help me with this problem? Thank you. -- Marcos Martins Santos mmsantos...@gmail.com -- Skype: marcosmartinssantos [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 new column with the number of the observation
Perfect! Thank you a lot! 2014-05-28 21:57 GMT-03:00 arun smartpink...@yahoo.com: Hi, If it ordered by the variable x, you could also try: within(DF1, new_c-sequence(table(x))) A.K. On Wednesday, May 28, 2014 6:14 PM, Andrija Djurovic djandr...@gmail.com wrote: Here is another approach: x - rep(c(A, B, C), c(3,1,2)) DF1 - data.frame(x) cbind(DF1, new_c=ave(as.numeric(DF1$x), DF1$x, FUN=function(x) 1:length(x))) Note the difference between DF (in previous solution) and DF1 str(DF) str(DF1) Andrija On Thu, May 29, 2014 at 12:03 AM, Andrija Djurovic djandr...@gmail.com wrote: Hi. Here is one approach: x - rep(c(A, B, C), c(3,1,2)) DF - data.frame(x, stringsAsFactors=FALSE) cbind(DF, new_c=c(lapply(rle(DF$x)[[1]], function(x) 1:x), recursive=T)) Andrija On Wed, May 28, 2014 at 10:46 PM, Marcos Santos mmsantos...@gmail.com wrote: I have a data frame like this: Category Observed_value A 100 A 130 A 140 B 90 C 80 D 120 D 130 I need to create an index column that show the number of the observation for each category. I have three observations in the category A, one in category B, one in category C and two in category D. The new matrix should be like this: Category Observed_value Index A 100 1 A 130 2 A 140 3 B 90 1 C 80 1 D 120 1 D 130 2 Please, could anyone help me with this problem? Thank you. -- Marcos Martins Santos mmsantos...@gmail.com -- Skype: marcosmartinssantos [[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. -- Marcos Martins Santos mmsantos...@gmail.com -- Tel. (85) 3044-7436 Cel. (85) 9636-6612 -- Skype: marcosmartinssantos [[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] Confusing behavior when using gsub to insert unicode character (minimal working example provided)
Can anyone help me understand the following behavior? I want to replace the letter 'X' in âthe string â 'text X' with 'â¥' (\u226 â5 ). The output from gsub is not what I expect. It gives: text ââ°Â¥. Now, suppose I want to replace the character 'â¤' in â the stringâ 'text â¤' with 'â¥'. Then, gsub gives the expected, desired output. âWhat am I missing? Thanks for any insight. -tgs Minimal Working Example: string1 - text X; string1 new_string1 - gsub(X,\u2265,string1); new_string1 string2 - text \u2264; string2 new_string2 - gsub(\u2264,\u2265,string2); new_string2 charToRaw(new_string1) charToRaw(new_string2) sessionInfo() ## OUTPUT string1 - text X; string1 [1] text X new_string1 - gsub(X,\u2265,string1); new_string1 [1] text ââ°Â¥ string2 - text \u2264; string2 [1] text ⤠new_string2 - gsub(\u2264,\u2265,string2); new_string2 [1] text ⥠charToRaw(new_string1) [1] 74 65 78 74 20 e2 89 a5 charToRaw(new_string2) [1] 74 65 78 74 20 e2 89 a5 sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.0.2 [[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] Confusing behavior when using gsub to insert unicode character (minimal working example provided)
On May 28, 2014, at 7:25 PM, Thomas Stewart wrote: Can anyone help me understand the following behavior? I want to replace the letter 'X' in the string 'text X' with '≥' (\u226 5 ). The output from gsub is not what I expect. It gives: text ≥. Now, suppose I want to replace the character '≤' in the string 'text ≤' with '≥'. Then, gsub gives the expected, desired output. What am I missing? Thanks for any insight. -tgs Minimal Working Example: string1 - text X; string1 new_string1 - gsub(X,\u2265,string1); new_string1 Try this instead: new_string1 - gsub(X,\\\u2265,string1); new_string1 [1] text ≥ Each \ needs to be escaped, both the \ in \u2265 as well as the \ that escapes it. nchar(\\) [1] 1 nchar(\\\u2265) [1] 2 You would be well-served by spending effort at reading: ?Quotes -- David. string2 - text \u2264; string2 new_string2 - gsub(\u2264,\u2265,string2); new_string2 charToRaw(new_string1) charToRaw(new_string2) sessionInfo() ## OUTPUT string1 - text X; string1 [1] text X new_string1 - gsub(X,\u2265,string1); new_string1 [1] text ≥ string2 - text \u2264; string2 [1] text ≤ new_string2 - gsub(\u2264,\u2265,string2); new_string2 [1] text ≥ charToRaw(new_string1) [1] 74 65 78 74 20 e2 89 a5 charToRaw(\\\u2265) [1] 5c e2 89 a5 charToRaw(new_string2) [1] 74 65 78 74 20 e2 89 a5 sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) It was a good idea to post sessionInfo(), but it would have been even better to have posted in plain text. [[alternative HTML version deleted]] -- David Winsemius Alameda, CA, 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.