[R] confused with indexing
Dear all, I have a code that looks like the following (I am sorry that this is not a reproducible example) indexSkipped-NULL code Skipped that might alter indexSkipped if (length(indexSkipped)==0) spatial_structure-spatial_structures_from_measurements(DataList[[i]]$Lon,DataList[[i]]$Lat,meanVector) else spatial_structure-spatial_structures_from_measurements(DataList[[i]]$Lon[-indexSkipped],DataList[[i]]$Lat[-indexSkipped],meanVector) # What I am doing here is that I am processing files. Every files has a measurement table and Longtitude and Latitude fields. If one file is marked as invalid I keep a number of of the skipped index so to remove the element of the Longtitude and Latitide vectors. 1) That works correct, I was just wondering if it would be possible to remove some how the given if statement and initialize the indexSkipped in such a way so the DataList[[i]]$Lon[-indexSkipped],DataList[[i]]$Lat[-indexSkipped] do nothing, aka remove no element, in case the indexSkipped remains unchanged (in its initial value). 2) When u define a variable as empty, I usually use NULL, how I can check afterwords if that holds or not. If I use the (indexSkipped==NULL) logical(0) this does not return true or false. How I can do that check? Iwould like to thank you in advance for your help B.R Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Need to help to get value for bigger calculation
Hello R-Experts, I want to calculate values like 15^200 or 17^300 in R. In normal case it can calculate the small values of b (a^b). I have fixed width = 1 and digits = 22 but still answers are Inf. How to deal the cases like these? Thanks in advance. Regards, rehena [[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] Noninferiority Testing
Are there any packages that allow for noninferiority, equivalence, or superiority testing and associated graphics such as confidence intervals? -- View this message in context: http://r.789695.n4.nabble.com/Noninferiority-Testing-tp4630818.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] Quantmod, Xts, TTR and Postgresql
Hi Everyone, I'm currently using the latest build of R and R-Studio server (both are amazing products) I'm still very new to this but I came across this issue: I'm trying to do a select from postgres and put the data into and xts object like so: # Libs library('RPostgreSQL') # http://code.google.com/p/rpostgresql/ library('quantmod') library('TTR') library('xts') # http://cran.r-project.org/web/packages/xts/vignettes/xts.pdf # Connect and get data drv - dbDriver('PostgreSQL') db - dbConnect(drv, host='localhost', user='postgres', dbname='technica', password='password') fr - dbGetQuery(db, 'SELECT date as Date, open as Open, high as High, low as Low, close as Close, volume as Volume, random() as Adjusted FROM stocks s INNER JOIN historical_prices hp ON s.id = hp.stock_id WHERE s.symbol = \'SDL\' ORDER BY date DESC limit 50') # copied from the mysql code in the quantmod source fr - data.frame(fr[,-1],row.names=fr[,1]) fr - xts(as.matrix(fr[,-1]), order.by=as.Date(fr[,1], origin='1970-01-01'), src='technica', updated=Sys.time()) colnames(fr) - paste('SDL', c('Open','High','Low','Close','Volume','Adjusted'), sep='.') dvi - DVI(Cl(fr)) print(dvi) When the code is executed I receive the error for the line dvi - DVI(Cl(fr)): Error in runSum(x, n) : Invalid 'n' But if I do this (fetch the data from yahoo): getSymbols(SDL.AX) dvi - DVI(Cl(SDL.AX)) print(dvi) All seems to work fine, but I cant see any difference when I print the two data sets out, except the data set size. Any ideas what I'm doing wrong? Id really like to be able to import from my postgres database. Also i would be happy to write a postgres routine and submit it to quantmod if i get this working Thanks! Max [[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] “For” calculation is so slow
Dear All, The function I wrote can run well with the small data, but with the large data, the function runs very very slowly. How can I correct it? Thank you very much. My function as below: a-c(1:240) b-c(1:240) l=function(a,b){ v=0 u=0 uv=0 v[1]=0 u[1]=0 uv[1]=0 for (i in 1:(length(s)-1)){ v[i]-((gx[[i]][b,(gx[[i]][a,1]+1)])-(gx[[i]][a,gx[[i]][a,1]+1]))/(gx[[i]][a,gx[[i]][a,1]+1]) u[i]-((gy[[i]][a,(gy[[i]][a,1]+1)])-(gy[[i]][b,gy[[i]][a,1]+1]))/(gy[[i]][a,gy[[i]][a,1]+1]) uv[i]-v[i]+u[i] } w=0 w=mean(uv) } kk-data.frame() for (a in 1:240){ for (b in 1:240){ if (ab) kk[a,b]=l(a,b) else kk[a,b]=0 }} max(kk) -- View this message in context: http://r.789695.n4.nabble.com/For-calculation-is-so-slow-tp4630830.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 with melt/cast in reshape-package
Hi everyone, I have an issue with the reshape package. Since it's quite a while that I used it, I feel kind of rusty... I got a data.frame like this id Sample.Name Marker Allele.1 Allele.2sample_idspecies 101_primer01 Dalb01 165 179 SH233 D. madagascariensis 201_primer04 Dalb04221 225 SH233 D. madagascariensis 301_primer08 Dalb08218 218 SH233 D. madagascariensis 401_primer10 Dalb10134 134 SH233 D. madagascariensis 501_primer14 Dalb14250 250 SH233 D. madagascariensis 601_primer16 Dalb16232 232 SH233 D. madagascariensis this was just the head(), in fact, the sample_id col has different ids, I would like to aggregate them into one and I would like to get something like this: species sample_id Marker1_Allele1 Marker1_Allele2 Marker2_Allele1 Marker2_Allele2 (etc. 35 markers) D. madagascariensis SH233 179 225 134 244 .. I tried to prepare the cast() but didn't quite figure out how to achieve this. I tried to first merge with the following: genMelt - melt(geno, id = c(1:2, 5:6)) then I created a column: genMelt$Locus - substring(as.character(genMelt$Panel),5, 6) genMelt$Locus - paste(genMelt$Locus, genMelt$variable, sep = _) So I get a column in the appropriate format. But when I cast : go - cast(genMelt,sample_id~Locus) I get just the frequencies of the Loci per sample_id Maybe I don't even need reshape. If you have any idea on this, I appreciate it Cheers, Martin [[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] Noninferiority Testing
Hi, Jacob, RSiteSearch( noninferiority testing) gives only two hits, but RSiteSearch( equivalence testing) give *numerous* hits. Hth -- Gerrit Are there any packages that allow for noninferiority, equivalence, or superiority testing and associated graphics such as confidence intervals? -- View this message in context: http://r.789695.n4.nabble.com/Noninferiority-Testing-tp4630818.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] “For” calculation is so slow
On Tue, May 22, 2012 at 9:01 AM, jiangxijixzy jiangxiji...@163.com wrote: The function I wrote can run well with the small data, but with the large data, the function runs very very slowly. How can I correct it? Thank you very much. My function as below: I guess this is a classic loops vs vectorization problem. fortune('treat') Contrary to popular belief the speed of R's interpreter is rarely the limiting factor to R's speed. People treating R like C is typically the limiting factor. You have vector operations, USE THEM. -- Byron Ellis R-help (October 2005) I would suggest that you read up on vectorization in R to understand why it is often preferred to loops. Two obvious places are an Rnews article by John Fox (if I remember well) and his Companion to Applied Regression book. Moreover, please sign your messages with your real name. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] What's wrong with MEAN?
Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16) [1] 18 mean(14, 11, 17, 9, 5, 18) [1] 14 So instead of calculating simple Arithmetic average, mean command is generating first element as average. I restarted the machine, changed the machine, but still the reply is same. I have been using this mean function ever since I strated learning R, but this has never happened. Kindly guide Vincy [[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] barplot: legend: two rows
Hello Uwe, thanks for drawing this to my attention! I tried it again without adding another empty legend element and it worked - yes, the second row not being visible was my problem. Now it works! Thanks again, Marion 2012/5/15 Uwe Ligges lig...@statistik.tu-dortmund.de On 15.05.2012 17:38, Marion Wenty wrote: Hello, I solved my problem with the uneven numbers of legend elements, which should be put into more than one rows, in the following way: I added another legend element which is empty () and is filled with white: legend(0,-1.4,xjust=0,ncol=3,**legend=c(colnames(dat)[-1],)** ,fill=c(navyblue,**steelblue4,steelblue2,**lightsteelblue3,** lightsteelblue1,white),bty=**n,border=white,cex=1.2) Not quite such a nice way, but it works, anyway. The previous version already worked for me, you just had to increase the bottom margin to make the second row of labels visible: For example par(mar=c(10,4.5+0.3529412*(**max(nchar(colnames(dat1)))-1),**1,1)) worked for me. Uwe Marion 2012/5/11 Marion Wentymarion.we...@gmail.com Hello, thank you very much for your answers. Using the command ncol worked in my special case, if I have got a legend with 4 elements, but with 5 it doesn't work. I am using two functions which I had created and checked what might be the difference, so that the second one doesn't work, but I couldn't find out what the problem is. So I am including the text of my .csv files and my functions: My .csv file abb8a looks like this: ;sehr gut;eher gut;eher nicht gut;nicht gut Kontakt mit der Schule;46;49;4;1 Die richtige Wahl;32;58;8;2 mw_g_4stap-function(pfad=F:/**04 Archiv/04 Programme/19 R_Syntaxe/Grafiken_Funktionen**,abb=abb8a) { setwd(pfad) postscript(file=paste(abb,.**eps,sep=)) dat-read.csv2(paste(abb,.**csv,sep=),header=T,check.**names=F) dat1-t(as.matrix(dat[,2:5],**nrow=2)) colnames(dat1)-dat[,1] zehn-seq(10,100,10) xmax-max(dat1) ind-min(which(zehn=xmax)) ticks-seq(0,100,10) par(las=1) par(mar=c(5.9,4.5+0.3529412*(**max(nchar(colnames(dat1)))-1),**1,1)) barplot(dat1,width=0.61,horiz=**T,col=c(steelblue4,** steelblue2,lightsteelblue3,**lightsteelblue1),border=NA** ,axes=F,beside=F,xlim=c(0,100)**,cex.names=1.2,ylim=c(0,10)) par(xpd=TRUE) abline(v = seq(10, 100, by = 10), col = white) par(xpd=F) axis(1,at=ticks,las=1,labels=**paste(ticks,%,sep=)) par(xpd=TRUE) legend(0,-1.4,xjust=0,ncol=2,**legend=colnames(dat)[-1],fill=** c(steelblue4,steelblue2,**lightsteelblue3,** lightsteelblue1),bty=n,**border=white,cex=1.2) par(xpd=FALSE) dev.off() } mw_g_4stap() ### My .csv file probe8_5 looks like this: ;stimme zu;stimme zu;stimme zu;stimme zu;stimme zu Eltern konnten mir beim ler;23;70;1;1;5 leichte Ent;20;10;10;10;50 leichte Ent;20;10;10;10;50 leichte Ent;20;10;10;10;50 leichte Ent;20;10;10;10;50 leichte Ent;20;10;10;10;50 leichte Ent;20;10;10;10;50 mw_g_5stap-function(pfad=F:/**04 Archiv/04 Programme/19 R_Syntaxe/Grafiken_Funktionen**,abb=probe8_5) { setwd(pfad) postscript(file=paste(abb,.**eps,sep=)) dat-read.csv2(paste(abb,.**csv,sep=),header=T,check.**names=F) dat1-t(as.matrix(dat[,2:6],**nrow=2)) dat1 colnames(dat1)-dat[,1] dat1 zehn-seq(10,100,10) xmax-max(dat1) ind-min(which(zehn=xmax)) ticks-seq(0,100,10) par(las=1) par(mar=c(5,4.5+0.3529412*(**max(nchar(colnames(dat1)))-1),**1,1)) barplot(dat1,width=0.61,horiz=**T,col=c(navyblue,** steelblue4,steelblue2,**lightsteelblue3,** lightsteelblue1),border=NA,**axes=F,beside=F,xlim=c(0,100),** cex.names=1.2,ylim=c(0,10)) par(xpd=TRUE) abline(v = seq(10, 100, by = 10), col = white) par(xpd=F) axis(1,at=ticks,las=1,labels=**paste(ticks,%,sep=)) par(xpd=TRUE) legend(0,-1.4,xjust=0,ncol=3,**legend=colnames(dat)[-1],fill=** c(navyblue,steelblue4,**steelblue2,lightsteelblue3,** lightsteelblue1),bty=n,**border=white,cex=1.2) dev.off() } mw_g_5stap() ### The first function works but the second one doesn't. Does anyone know why? Thank you very much for your help in advance!! Marion 2012/5/9 Uwe Liggeslig...@statistik.tu-**dortmund.delig...@statistik.tu-dortmund.de On 09.05.2012 13:23, Marion Wenty wrote: dear r-helpers, i have got another question: i am using the functions par(xpd=T) legend to create a legend below the x-axis. i used the parameter horiz=T. now i would like to put the elements of the legend in two rows: e.g. if my legend has got 5 elements, i would like 3 elements in one row and the last two elements in the next row. does anyone know how to do that? Example: bp- barplot(1) par(xpd = TRUE) legend(bp, 0, xjust=0.5, legend=letters[1:5], lwd=1:5, ncol=3) Uwe Ligges thank you very much for your help in advance! marion [[alternative HTML version deleted]] __ R-help@r-project.org mailing list
Re: [R] What's wrong with MEAN?
You'll need to pass the data as a vector. mean(16, 18) is asking the mean of 16. 18 is passed to the second argument which is trim. So you are doing mean(16, trim = 18) What you want is mean(c(16, 18)) Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Vincy Pyne Verzonden: dinsdag 22 mei 2012 11:10 Aan: r-help@r-project.org Onderwerp: [R] What's wrong with MEAN? Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16) [1] 18 mean(14, 11, 17, 9, 5, 18) [1] 14 So instead of calculating simple Arithmetic average, mean command is generating first element as average. I restarted the machine, changed the machine, but still the reply is same. I have been using this mean function ever since I strated learning R, but this has never happened. Kindly guide Vincy [[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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What's wrong with MEAN?
mean( 16, 18 ) [1] 16 mean( c( 16, 18 ) ) [1] 17 On Tuesday 22 May 2012 02:10:27 Vincy Pyne wrote: Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16) [1] 18 mean(14, 11, 17, 9, 5, 18) [1] 14 So instead of calculating simple Arithmetic average, mean command is generating first element as average. I restarted the machine, changed the machine, but still the reply is same. I have been using this mean function ever since I strated learning R, but this has never happened. Kindly guide Vincy [[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] What's wrong with MEAN?
you need to provide a vector: mean(c(16,18)) Sent from my iPad On May 22, 2012, at 5:10, Vincy Pyne vincy_p...@yahoo.ca wrote: Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16) [1] 18 mean(14, 11, 17, 9, 5, 18) [1] 14 So instead of calculating simple Arithmetic average, mean command is generating first element as average. I restarted the machine, changed the machine, but still the reply is same. I have been using this mean function ever since I strated learning R, but this has never happened. Kindly guide Vincy [[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] What's wrong with MEAN?
Dear Mr. Thierry, Thanks a lot for pointing out such a silly mistake from my side. I was simply wondering how come I am not getting such a simple mean. Thanks again. Vincy --- On Tue, 5/22/12, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: From: ONKELINX, Thierry thierry.onkel...@inbo.be Subject: RE: [R] What's wrong with MEAN? To: Vincy Pyne vincy_p...@yahoo.ca, r-help@r-project.org r-help@r-project.org Received: Tuesday, May 22, 2012, 9:17 AM You'll need to pass the data as a vector. mean(16, 18) is asking the mean of 16. 18 is passed to the second argument which is trim. So you are doing mean(16, trim = 18) What you want is mean(c(16, 18)) Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Vincy Pyne Verzonden: dinsdag 22 mei 2012 11:10 Aan: r-help@r-project.org Onderwerp: [R] What's wrong with MEAN? Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16) [1] 18 mean(14, 11, 17, 9, 5, 18) [1] 14 So instead of calculating simple Arithmetic average, mean command is generating first element as average. I restarted the machine, changed the machine, but still the reply is same. I have been using this mean function ever since I strated learning R, but this has never happened. Kindly guide Vincy [[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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. [[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] iterate over vector with range vector inside
Hello, Have anybody a hint, how I could iterate over the vector below. So I'll wish only 8 iterations. Put the range vector in c() didn't help. for(i in c(1,2,3,4,5,11:20,21:50,51:100)) { sum(dfc[i,cnt]) # or similar actions } Thanks in advance Christian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] iterate over vector with range vector inside
use 'list' instead of 'c' Sent from my iPad On May 22, 2012, at 5:23, chsch...@email.de wrote: Hello, Have anybody a hint, how I could iterate over the vector below. So I'll wish only 8 iterations. Put the range vector in c() didn't help. for(i in c(1,2,3,4,5,11:20,21:50,51:http://spinroot.com/spin/Doc/Book91_PDF/x20v_1991.pdf)) { sum(dfc[i,cnt]) # or similar actions } Thanks in advance Christian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What's wrong with MEAN?
On Tue, May 22, 2012 at 11:22 AM, Vincy Pyne vincy_p...@yahoo.ca wrote: Thanks a lot for pointing out such a silly mistake from my side. I was simply wondering how come I am not getting such a simple mean. To avoid such mistakes it would help to first store your data in a vector. x-c(16,18) mean(x) [1] 17 If you did otherwise: x- 16,18 Error: unexpected ',' in x- 16, then R would complain. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] confused with indexing
use is.null for the test if (is.null(indexSkipped)) Sent from my iPad On May 22, 2012, at 2:10, Alaios ala...@yahoo.com wrote: Dear all, I have a code that looks like the following (I am sorry that this is not a reproducible example) indexSkipped-NULL code Skipped that might alter indexSkipped if (length(indexSkipped)==0) spatial_structure-spatial_structures_from_measurements(DataList[[i]]$Lon,DataList[[i]]$Lat,meanVector) else spatial_structure-spatial_structures_from_measurements(DataList[[i]]$Lon[-indexSkipped],DataList[[i]]$Lat[-indexSkipped],meanVector) # What I am doing here is that I am processing files. Every files has a measurement table and Longtitude and Latitude fields. If one file is marked as invalid I keep a number of of the skipped index so to remove the element of the Longtitude and Latitide vectors. 1) That works correct, I was just wondering if it would be possible to remove some how the given if statement and initialize the indexSkipped in such a way so the DataList[[i]]$Lon[-indexSkipped],DataList[[i]]$Lat[-indexSkipped] do nothing, aka remove no element, in case the indexSkipped remains unchanged (in its initial value). 2) When u define a variable as empty, I usually use NULL, how I can check afterwords if that holds or not. If I use the (indexSkipped==NULL) logical(0) this does not return true or false. How I can do that check? Iwould like to thank you in advance for your help B.R Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sweave tables as images?
On Mon, May 21, 2012 at 10:29 PM, Alexander Shenkin ashen...@ufl.edu wrote: So, I think it will be better if I can somehow generate the tables as images. Is there any way to generate tables as images in separate files in Sweave? Or, is there another tree up which I should be barking? Hmm, there are Sweave equivalents for LibreOffice [1] and MS Word [2]. Have you looked into those? You may find other suggestions in the ReproducibleResearch Task View [3]. Liviu [1] http://crantastic.org/packages/odfWeave [2] http://crantastic.org/packages/SWordInstaller [3] http://crantastic.org/task_views/ReproducibleResearch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] “For” calculation is so slow
Hi Dear All, The function I wrote can run well with the small data, but with the large data, the function runs very very slowly. How can I correct it? Thank you Your function does not run slowly, it does not run at all. l(10,20) Error in l(10, 20) : object 's' not found No s object found. I presume that also gx and gy will not be found. And besides I am pretty sure that you probably does not need any loop at all. very much. My function as below: a-c(1:240) b-c(1:240) l=function(a,b){ v=0 u=0 uv=0 v[1]=0 Why? v-0 v [1] 0 v[1]-0 v [1] 0 So there is no difference between first v and second v u[1]=0 uv[1]=0 for (i in 1:(length(s)-1)){ v[i]-((gx[[i]][b,(gx[[i]][a,1]+1)])-(gx[[i]][a,gx[[i]][a,1]+1]))/(gx[[i]] [a,gx[[i]][a,1]+1]) u[i]-((gy[[i]][a,(gy[[i]][a,1]+1)])-(gy[[i]][b,gy[[i]][a,1]+1]))/(gy[[i]] [a,gy[[i]][a,1]+1]) uv[i]-v[i]+u[i] } w=0 w=mean(uv) Your function does not return anything. Here you can test it by yourself on shortened version l=function(a,b){ v=0 u=0 uv=0 v-10 u-20 uv-v+u w=0 w=mean(uv) } Regards Petr } kk-data.frame() for (a in 1:240){ for (b in 1:240){ if (ab) kk[a,b]=l(a,b) else kk[a,b]=0 }} max(kk) -- View this message in context: http://r.789695.n4.nabble.com/For- calculation-is-so-slow-tp4630830.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] Quantmod, Xts, TTR and Postgresql
On Tue, May 22, 2012 at 2:15 AM, R-type Studios rtypestud...@gmail.com wrote: Hi Everyone, I'm currently using the latest build of R and R-Studio server (both are amazing products) I'm still very new to this but I came across this issue: I'm trying to do a select from postgres and put the data into and xts object like so: # Libs library('RPostgreSQL') # http://code.google.com/p/rpostgresql/ library('quantmod') library('TTR') library('xts') # http://cran.r-project.org/web/packages/xts/vignettes/xts.pdf # Connect and get data drv - dbDriver('PostgreSQL') db - dbConnect(drv, host='localhost', user='postgres', dbname='technica', password='password') fr - dbGetQuery(db, 'SELECT date as Date, open as Open, high as High, low as Low, close as Close, volume as Volume, random() as Adjusted FROM stocks s INNER JOIN historical_prices hp ON s.id = hp.stock_id WHERE s.symbol = \'SDL\' ORDER BY date DESC limit 50') # copied from the mysql code in the quantmod source fr - data.frame(fr[,-1],row.names=fr[,1]) fr - xts(as.matrix(fr[,-1]), order.by=as.Date(fr[,1], origin='1970-01-01'), src='technica', updated=Sys.time()) colnames(fr) - paste('SDL', c('Open','High','Low','Close','Volume','Adjusted'), sep='.') dvi - DVI(Cl(fr)) print(dvi) When the code is executed I receive the error for the line dvi - DVI(Cl(fr)): Error in runSum(x, n) : Invalid 'n' The defaults for DVI's magnitude and stretch arguments require there be at least 100 observations. My guess is that your 'fr' object doesn't have the required 100 observations. If it doesn't, then using the default value of n = 252 may also be an issue (giving misleading results, if not an error). But if I do this (fetch the data from yahoo): getSymbols(SDL.AX) dvi - DVI(Cl(SDL.AX)) print(dvi) All seems to work fine, but I cant see any difference when I print the two data sets out, except the data set size. Any ideas what I'm doing wrong? Id really like to be able to import from my postgres database. Also i would be happy to write a postgres routine and submit it to quantmod if i get this working Thanks! Max Best, -- Joshua Ulrich | FOSS Trading: www.fosstrading.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] Need to help to get value for bigger calculation
Rehena Sultana hena_4567 at yahoo.com writes: I want to calculate values like 15^200 or 17^300 in R. In normal case it can calculate the small values of b (a^b). I have fixed width = 1 and digits = 22 but still answers are Inf. How to deal the cases like these? Thanks in advance. library(Rmpfr) m15 - mpfr(15, precBits= 1024) m15^200 165291991078820803015600259355571011187461128806050897708002963982861165 279305672605355515846488679511983197774726563035424119280679882914553697 406070345089013507994161512883544043567583004683422057135011584705353016 03376865386962890625 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Quantmod, Xts, TTR and Postgresql
On Tue, May 22, 2012 at 5:54 AM, R-type Studios rtypestud...@gmail.com wrote: Hi Joshua, Oh snap, awesome to have the author of the blog your reading at that moment to reply to your message. I updated the query to be 200 sessions, the function now prints, but appears to get the dates all wrong. (I actually was following along with the post here: http://blog.fosstrading.com/2011/03/how-to-backtest-strategy-in-r.html great blog by the way.) What I have now (simplified it a bit): # Libs library('RPostgreSQL') # http://code.google.com/p/rpostgresql/ library('quantmod') library('TTR') # Connect and get data drv - dbDriver('PostgreSQL') db - dbConnect(drv, host='localhost', user='postgres', dbname='technica', password='password') fr - dbGetQuery(db, 'SELECT date as Date, open as Open, high as High, low as Low, close as Close, volume as Volume, 0 as Adjusted FROM stocks s INNER JOIN historical_prices hp ON s.id = hp.stock_id WHERE s.symbol = \'SDL\' ORDER BY date DESC limit 200') fr - data.frame(fr[,-1], row.names=fr[,1]) fr - xts(as.matrix(fr[,-1]), order.by=as.Date(fr[,1]), updated=Sys.time()) Your problem is likely here and has nothing to do with DVI. Take a step back and look at your intermediate objects. The result of dbGetQuery is a data.frame with columns Date, OHLC, Volume, and Adjusted. Then you overwrite 'fr' with another data.frame that drops the Date column after setting them as the row names. Then you overwrite 'fr' again with an xts object that contains HLC, Volume, and Adjusted columns, ordered by the Open prices converted to Dates. dvi - DVI(Cl(fr)) print(dvi) # Clean up. dbDisconnect(db) dbUnloadDriver(drv) Then as you can see below the dates are all out of whack, My guess was it was the date format that postgres returns (being mm/dd/) but no luck, any ideas? See above. If my assumptions aren't correct, then please provide a small sample of the result from dbGetQuery. Thanks! Max dvi.mag dvi.str dvi 1970-01-01 NA NA NA (Repeated a few hundread times) Then this: 1970-01-01 0.134920635 0.349206349 0.1778 snip 1970-01-01 0.734126984 0.996031746 0.78650794 On Tue, May 22, 2012 at 6:26 PM, Joshua Ulrich josh.m.ulr...@gmail.com wrote: On Tue, May 22, 2012 at 2:15 AM, R-type Studios rtypestud...@gmail.com wrote: Hi Everyone, I'm currently using the latest build of R and R-Studio server (both are amazing products) I'm still very new to this but I came across this issue: I'm trying to do a select from postgres and put the data into and xts object like so: # Libs library('RPostgreSQL') # http://code.google.com/p/rpostgresql/ library('quantmod') library('TTR') library('xts') # http://cran.r-project.org/web/packages/xts/vignettes/xts.pdf # Connect and get data drv - dbDriver('PostgreSQL') db - dbConnect(drv, host='localhost', user='postgres', dbname='technica', password='password') fr - dbGetQuery(db, 'SELECT date as Date, open as Open, high as High, low as Low, close as Close, volume as Volume, random() as Adjusted FROM stocks s INNER JOIN historical_prices hp ON s.id = hp.stock_id WHERE s.symbol = \'SDL\' ORDER BY date DESC limit 50') # copied from the mysql code in the quantmod source fr - data.frame(fr[,-1],row.names=fr[,1]) fr - xts(as.matrix(fr[,-1]), order.by=as.Date(fr[,1], origin='1970-01-01'), src='technica', updated=Sys.time()) colnames(fr) - paste('SDL', c('Open','High','Low','Close','Volume','Adjusted'), sep='.') dvi - DVI(Cl(fr)) print(dvi) When the code is executed I receive the error for the line dvi - DVI(Cl(fr)): Error in runSum(x, n) : Invalid 'n' The defaults for DVI's magnitude and stretch arguments require there be at least 100 observations. My guess is that your 'fr' object doesn't have the required 100 observations. If it doesn't, then using the default value of n = 252 may also be an issue (giving misleading results, if not an error). But if I do this (fetch the data from yahoo): getSymbols(SDL.AX) dvi - DVI(Cl(SDL.AX)) print(dvi) All seems to work fine, but I cant see any difference when I print the two data sets out, except the data set size. Any ideas what I'm doing wrong? Id really like to be able to import from my postgres database. Also i would be happy to write a postgres routine and submit it to quantmod if i get this working Thanks! Max Best, -- Joshua Ulrich | FOSS Trading: www.fosstrading.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] getting a Likert plot from a data frame
I'm creating a stacked bar chart using the likert command in the HH package. My data are in a data frame, with two numeric variables and a categorical variable, I can't get likert to use the column containing the categorical variable as a my y axis label. Here is a quick example: library(HH) #my data are: df-data.frame(as.character(cat=c(group1,group2,group3,group4, group5)),males=c(20,30,45,12,5),females=c(35,23,32,8,5)) #make a pyramid Likert chart p-likert(df) as.pyramidLikert(p) It tries to plot three variables here when I just want two. I think I understand what is happening - my categorical variable is treated as a factor and I think it gets inserted as an integer into the matrix which the command derives from my data fame, to make the plot with(?) It's then used as a variable to be plotted just like the other two variables. what I don't get is how the example given in the package does something differently, which is how I want mine to work. ## Population Pyramid data(USAge.table) USA79 - USAge.table[75:1, 2:1, 1979]/100 PL - likert(USA79, main=Population of United States 1979 (ages 0-74), xlab=Count in Millions, ylab=Age, scales=list( y=list( limits=c(0,77), at=seq(1,76,5), labels=seq(0,75,5), tck=.5)) ) PL as.pyramidLikert(PL) This does exactly what I'm trying to achieve. here the two population counts are plotted in the likert plot and the age groups in the first columns are used as labels. I can't work out why in my example the age group variable is not used in the same way as the in my plot in the same way as the agegroups in this example, other than the example takes it's data from a table and mine is coming from a data frame. The end point I want is a stacked Likert bar chart based on a data frame where the column containing the description of my groups is used as the y axis labels and the other two columns are used to draw the bars. I'm sure I'm missing a simple solution. any help gratefully received. Gavin. [[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] package grid: mirror grob objects along an axis
Hi everyone I'd like to flip grobs (grid graphical objects) along an axis, e.g. flip grobs horizontally or vertically. I couldn't find any hints, neither in the documentation nor by searching the web. Does anybody know how to achieve this? Cheers /thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variate generation
I think part of my question about using R facilities from a program is answered by http://binfalse.de/2011/02/talking-r-through-java/ Thanks. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Mohan Radhakrishnan Sent: Tuesday, May 22, 2012 10:33 AM To: R. Michael Weylandt Cc: r-help@r-project.org Subject: Re: [R] variate generation I was trying to understand how to use R to generate distributions of data, for example, uniform, and use the data in a program. I send raw bytes to the server. Is there a recommended way or book that I should read to understand this ? I use R but this is a beginner question. When I plot the no: of bytes against time I would like to ensure that over a period of 5 minutes the data fits a uniform distribution or an exponential one. This is to stress the SUT. Mohan -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Monday, May 21, 2012 8:39 PM To: Mohan Radhakrishnan Cc: r-help@r-project.org Subject: Re: [R] variate generation And what distribution would that be R provides many built in distributions, but if those aren't enough for you, you can check: http://cran.r-project.org/web/views/Distributions.html Best, Michael On Mon, May 21, 2012 at 7:26 AM, Mohan Radhakrishnan moh...@fss.co.in wrote: Hi, I plot no: of bytes against time and find the distribution curve using R. These bytes are sent from the client to the server. Is there a way to generate bytes randomly using R according to a distribution ? I would like to send these bytes to the server. Hope I am not misguided here. My goal is to simulate a certain distribution of bytes. Thanks, Mohan DISCLAIMER:\ ===...{{dropped:31}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. DISCLAIMER:\ ===...{{dropped:30}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. DISCLAIMER: ==The information contained in this e-mail message may be privileged and/or confidential and protected from disclosure under applicable law. It is intended only for the individual to whom or entity to which it is addressed as shown at the beginning of the message. If the reader of this message is not the intended recipient, or if the employee or agent responsible for delivering the message is not an employee or agent of the intended recipient, you are hereby notified that any review, dissemination,distribution, use, or copying of this message is strictly prohibited. If you have received this message in error, please notify us immediately by return e-mail and permanently delete this message and your reply to the extent it includes this message. Any views or opinions presented in this message or attachments are those of the aut! hor and do not necessarily represent those of the Company. All e-mails and attachments sent and received are subject to monitoring, reading, and archival by the Company.== __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] include a dataset in my package
On 22.05.2012 06:24, Richard M. Heiberger wrote: you do have a dataset x. it is probably inside the test.rda file. start a fresh R session and library(yourPackage) then ls() data(test) No, you meant data(x) Note that the name of the filename is still the original mname it had hen creating the rda file, the filename of the rda file is irrelevant (and it may contain more than just one object). Best, Uwe Ligges ls() ## you will probably have now have x. Should you need to use load, then use load(/full/path/to/test.rda) ## in quotes ls() The idiom for saving a dataset is save(mydataset, file=mydataset.rda) On Mon, May 21, 2012 at 8:45 PM, di jianingjianin...@gmail.com wrote: Hey R-users, I think I followed the steps but still couldn't figure this out.. I am creating a personal package and I want to include several datasets in the package. I created a subdirectory 'data' in the package, save a dataset 'test.rda' there, built the package, checked it, installed it. Then I loaded the package and tried load(test), data(test), attach(test), none of them gave me the actual data. Another thing, which I am not sure if it is relevant, is that when I was checking the package before installation, I got a warning (not an error) that I have a dataset 'x' without document. I actually don't have any dataset with the name 'x'. Any thoughts? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Interpreting output from the val.prob function in the rms package
Dear mail-list, I have used the val.prob function from the rms package to validate a logistic regression model. It is however not clear to me how to interpret the two different curves that are generated (logistic vs. nonparametric). The documentation doesn't enter into any detail on this point, and to a non-statistician like myself it isn't obvious. If I compare the output to that of the val.prob.ci function by E. Steyerberg, it looks like the non-parametric curve is a smoothed line between the means of quantiles. But what is then the logistic calibration line? Most grateful for any help to understand this. Best, Gustav Gustav Nilsonne, MD, PhD Postdoc +46 (0) 736-798 743 Stockholm University Stress Research Institute 106 91 Stockholm gustav.nilso...@stressforskning.su.se Karolinska Institutet Department of Clinical Neuroscience and Osher Center for Integrative Medicine Retzius väg 8 A2:3 171 77 Stockholm gustav.nilso...@ki.se [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to remove square brackets, etc. from address strings?
Hello, I'd like to remove the individual pairs of square brackets along with their content - plus the space directly behind it - from address strings such as this: [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA I'd like get the following result: Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA I tried address = gsub((.*)[(.*)], \\2, address) But this deletes everything from the first opening bracket to the last closing bracket and leaves only the very last address: Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA How can I remove only the individual pairs of square brackets along with their content? Thank you very much in advance! [[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] Quantmod, Xts, TTR and Postgresql
Hi Joshua, Oh snap, awesome to have the author of the blog your reading at that moment to reply to your message. I updated the query to be 200 sessions, the function now prints, but appears to get the dates all wrong. (I actually was following along with the post here: http://blog.fosstrading.com/2011/03/how-to-backtest-strategy-in-r.html great blog by the way.) What I have now (simplified it a bit): # Libs library('RPostgreSQL') # http://code.google.com/p/rpostgresql/ library('quantmod') library('TTR') # Connect and get data drv - dbDriver('PostgreSQL') db - dbConnect(drv, host='localhost', user='postgres', dbname='technica', password='password') fr - dbGetQuery(db, 'SELECT date as Date, open as Open, high as High, low as Low, close as Close, volume as Volume, 0 as Adjusted FROM stocks s INNER JOIN historical_prices hp ON s.id = hp.stock_id WHERE s.symbol = \'SDL\' ORDER BY date DESC limit 200') fr - data.frame(fr[,-1], row.names=fr[,1]) fr - xts(as.matrix(fr[,-1]), order.by=as.Date(fr[,1]), updated=Sys.time()) dvi - DVI(Cl(fr)) print(dvi) # Clean up. dbDisconnect(db) dbUnloadDriver(drv) Then as you can see below the dates are all out of whack, My guess was it was the date format that postgres returns (being mm/dd/) but no luck, any ideas? Thanks! Max dvi.mag dvi.strdvi 1970-01-01 NA NA NA (Repeated a few hundread times) Then this: 1970-01-01 0.134920635 0.349206349 0.1778 1970-01-01 0.079365079 0.369047619 0.13730159 1970-01-01 0.071428571 0.261904762 0.10952381 1970-01-01 0.067460317 0.281746032 0.11031746 1970-01-01 0.091269841 0.38889 0.15079365 1970-01-01 0.123015873 0.289682540 0.15634921 1970-01-01 0.170634921 0.289682540 0.1944 1970-01-01 0.075396825 0.289682540 0.11825397 1970-01-01 0.023809524 0.289682540 0.07698413 1970-01-01 0.023809524 0.492063492 0.11746032 1970-01-01 0.02778 0.492063492 0.12063492 1970-01-01 0.039682540 0.492063492 0.13015873 1970-01-01 0.285714286 0.575396825 0.34365079 1970-01-01 0.531746032 0.575396825 0.54047619 1970-01-01 0.559523810 0.615079365 0.57063492 1970-01-01 0.587301587 0.650793651 0.6000 1970-01-01 0.531746032 0.650793651 0.5556 1970-01-01 0.313492063 0.619047619 0.37460317 1970-01-01 0.202380952 0.52778 0.26746032 1970-01-01 0.198412698 0.452380952 0.24920635 1970-01-01 0.146825397 0.563492063 0.23015873 1970-01-01 0.198412698 0.6 0.26984127 1970-01-01 0.230158730 0.4 0.27301587 1970-01-01 0.309523810 0.456349206 0.3389 1970-01-01 0.329365079 0.341269841 0.33174603 1970-01-01 0.182539683 0.119047619 0.16984127 1970-01-01 0.063492063 0.130952381 0.07698413 1970-01-01 0.095238095 0.373015873 0.15079365 1970-01-01 0.043650794 0.488095238 0.13253968 1970-01-01 0.02778 0.353174603 0.09285714 1970-01-01 0.285714286 0.234126984 0.27539683 1970-01-01 0.599206349 0.234126984 0.52619048 1970-01-01 0.420634921 0.234126984 0.3833 1970-01-01 0.396825397 0.142857143 0.34603175 1970-01-01 0.515873016 0.142857143 0.44126984 1970-01-01 0.3 0.242063492 0.31507937 1970-01-01 0.186507937 0.142857143 0.1778 1970-01-01 0.234126984 0.007936508 0.1889 1970-01-01 0.261904762 0.003968254 0.21031746 1970-01-01 0.19444 0.003968254 0.15634921 1970-01-01 0.178571429 0.003968254 0.14365079 1970-01-01 0.226190476 0.007936508 0.18253968 1970-01-01 0.273809524 0.019841270 0.22301587 1970-01-01 0.329365079 0.011904762 0.26587302 1970-01-01 0.369047619 0.003968254 0.29603175 1970-01-01 0.380952381 0.003968254 0.3056 1970-01-01 0.337301587 0.007936508 0.27142857 1970-01-01 0.242063492 0.023809524 0.19841270 1970-01-01 0.206349206 0.023809524 0.16984127 1970-01-01 0.186507937 0.023809524 0.15396825 1970-01-01 0.226190476 0.05556 0.19206349 1970-01-01 0.182539683 0.05556 0.15714286 1970-01-01 0.178571429 0.05556 0.15396825 1970-01-01 0.190476190 0.099206349 0.1722 1970-01-01 0.238095238 0.091269841 0.20873016 1970-01-01 0.178571429 0.087301587 0.16031746 1970-01-01 0.269841270 0.079365079 0.23174603 1970-01-01 0.218253968 0.079365079 0.19047619 1970-01-01 0.289682540 0.150793651 0.26190476 1970-01-01 0.234126984 0.27778 0.24285714 1970-01-01 0.265873016 0.285714286 0.26984127 1970-01-01 0.309523810 0.448412698 0.33730159 1970-01-01 0.488095238 0.448412698 0.48015873 1970-01-01 0.3 0.297619048 0.32619048 1970-01-01 0.376984127 0.297619048 0.3611 1970-01-01 0.41667 0.452380952 0.42380952 1970-01-01 0.313492063 0.58333 0.36746032 1970-01-01 0.202380952 0.58333 0.27857143 1970-01-01 0.289682540 0.452380952 0.3222 1970-01-01 0.36111 0.452380952 0.37936508 1970-01-01 0.349206349 0.452380952 0.36984127 1970-01-01 0.309523810 0.297619048 0.30714286 1970-01-01 0.297619048 0.297619048 0.29761905 1970-01-01 0.503968254 0.297619048 0.46269841 1970-01-01 0.511904762 0.484126984 0.50634921 1970-01-01 0.757936508 0.642857143 0.73492063 1970-01-01 0.845238095 0.507936508 0.7778 1970-01-01 0.853174603 0.515873016
[R] Re : “For” calculation is so slow
Hello, 's' is missing in your code. Regards - Mail original - De : jiangxijixzy jiangxiji...@163.com À : r-help@r-project.org Cc : Envoyé le : Mardi 22 mai 2012 16h01 Objet : [R] “For” calculation is so slow Dear All, The function I wrote can run well with the small data, but with the large data, the function runs very very slowly. How can I correct it? Thank you very much. My function as below: a-c(1:240) b-c(1:240) l=function(a,b){ v=0 u=0 uv=0 v[1]=0 u[1]=0 uv[1]=0 for (i in 1:(length(s)-1)){ v[i]-((gx[[i]][b,(gx[[i]][a,1]+1)])-(gx[[i]][a,gx[[i]][a,1]+1]))/(gx[[i]][a,gx[[i]][a,1]+1]) u[i]-((gy[[i]][a,(gy[[i]][a,1]+1)])-(gy[[i]][b,gy[[i]][a,1]+1]))/(gy[[i]][a,gy[[i]][a,1]+1]) uv[i]-v[i]+u[i] } w=0 w=mean(uv) } kk-data.frame() for (a in 1:240){ for (b in 1:240){ if (ab) kk[a,b]=l(a,b) else kk[a,b]=0 }} max(kk) -- View this message in context: http://r.789695.n4.nabble.com/For-calculation-is-so-slow-tp4630830.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] ReName
Dear list, The name of R-language is too short and is not friendly to search engines. Do you think it can be renamed to something like Rsio or Radio ? Thank you so much for this useful software! Best wishes. [[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] ¨Time series and variables with different lengths
Hey, we are currently analyzing the liquidty in the Danish mortgage bond market. For this project we have several irregular time series variables as Bond prices, interest rates etc. We declared all the variables as irregular time series, and created the first differences of them to make them stationary. Now we are trying to run a linear regression on the price of the bon including dummy variables. The dummy variables are already included in the data table. Do we have to declare them in R in addition as dummy variables or is the command as.factor sufficient? Moreover we always get the error message that the variable lengths differ, since after taking the first differences the main variables have on observation less than the dummy variables.. How can I solve for this? Thanks a lot, [[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] writing my own logistic regression function
Hi, I have problems writing a script for a logistic model. My data looks something like this: PI A N1 N2 N3 0 9 0 1 0 1 4 1 0 1 0 8 0 0 0 1 6 0 1 0 And so on… The model I want to fit looks like this: PI=exp^f(sw)/1+exp^f(sw) where f(sw)=c+(a1*N1/A^z)+(a2*N2/A^z)+(a3*N3/A^z) So I want to estimate c,a1,a2,a3 and z… Is there someone who can help me on this problem, because I don’t even know how to start. Best, Anna -- View this message in context: http://r.789695.n4.nabble.com/writing-my-own-logistic-regression-function-tp4630843.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 remove square brackets, etc. from address strings?
Hi Sabina, You've run into two characteristics of regular expressions: [ ] are special characters * is a greedy match Reading an intro regular expression document will help with both of those. Meanwhile: x - [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA x [1] [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA gsub(\\[.*?\\] , , x) # escape [ and ] and make * lazy instead of greedy [1] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA Sarah On Tue, May 22, 2012 at 6:08 AM, Sabina Arndt sabina.ar...@hotmail.de wrote: Hello, I'd like to remove the individual pairs of square brackets along with their content - plus the space directly behind it - from address strings such as this: [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA I'd like get the following result: Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA I tried address = gsub((.*)[(.*)], \\2, address) But this deletes everything from the first opening bracket to the last closing bracket and leaves only the very last address: Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA How can I remove only the individual pairs of square brackets along with their content? Thank you very much in advance! [[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. -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com 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] “For” calculation is so slow
For loops are really, really slow in R. In general, you want to avoid them like the plague. If you absolutely must insist on using them in large, computationally intense and complex code, consider implementing the relevant parts in C, say, and calling that from R. Staying within R, you can probably considerably speed up that code by storing gx and gy as a multi-dimensional arrays. (e.g. for sample data, something like rawGy = sample( 1:240, 240^2* 241, replace = T) rawGx = sample( 1:240, 240^2 *241, replace = T) gx = array(rawGx, dim = c(length(s) - 1, 240, max(rawGx)+1 ) ) gy = array(rawGy, dim = c(length(s) - 1, 240, max(rawGy)+1 ) ) ), in which case, you can easily do the computation without loops by gxa = (gx[ ,a,1]+ 1) gya =(gy[ ,a, 1] +1) uv = gx[cbind(1:(length(s) - 1) , b, gxa)] / gx[cbind(1:(length(s) - 1) , a, gxa)] - gy[cbind(1:(length(s) - 1) ,b, gya)]/gy[cbind(1:(length(s) - 1) ,a, gya)] or similar, which will be enormously faster (on my computer, there's an over 30x speed up). With a bit of thought, I'm sure you can also figure out how to let it vectorise in a, as well... Zhou -- View this message in context: http://r.789695.n4.nabble.com/For-calculation-is-so-slow-tp4630830p4630855.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] as.function parameters
Hi there, ~ the 'problem' or rather the task I'm trying to solve is to implement an algorithm to compute the ask/bid price of american options in a close to R related program language. because i'm not really using R but just it's basic functionalities I cannot rely on different packages included in the R space. is it usual for R to compute nested functions with such a workload? Best thanks -- View this message in context: http://r.789695.n4.nabble.com/as-function-parameters-tp4620390p4630858.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] package grid: mirror grob objects along an axis
Hello, Just flip 'xlim' or 'ylim'. Or both. Using the iris example in help(grid), make the following changes: op - par(mfcol = c(2,2)) # Two columns, first is the original, second flipped. with(iris, [... etc ...] # row 1, col 2: flip x axis plot(Sepal.Length, Sepal.Width, col = as.integer(Species), xlim = c(8, 4), ylim = c(2, 4.5), panel.first = grid(), main = with(iris, plot(, panel.first = grid(), ..) )) # row 2, col 2: flip y axis plot(Sepal.Length, Sepal.Width, col = as.integer(Species), xlim = c(4, 8), ylim = c(4.5, 2), panel.first = grid(3, lty=1,lwd=2), main = ... panel.first = grid(3, lty=1,lwd=2), ..) [... etc ...] ) par(op) Hope this helps, Rui Barradas Thomas Zumbrunn-3 wrote Hi everyone I'd like to flip grobs (grid graphical objects) along an axis, e.g. flip grobs horizontally or vertically. I couldn't find any hints, neither in the documentation nor by searching the web. Does anybody know how to achieve this? Cheers /thomas __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/package-grid-mirror-grob-objects-along-an-axis-tp4630866p4630870.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] Adding Text to a Plot
Hi, all! I'm pretty sure I'm missing something about this. Is there a smart way of typping hat(R)^2 and it's value from a linear regression? I've just found this tricky one: # Sample data x - sample(1:100,10) y - 2+3*x+rnorm(10) # Run the regression lm1 - lm(y~x) # Plotting plot(x,y, main=Linear Regression, col=red) abline(lm1, col=blue) placex - par(usr)[1]+.1*(par(usr)[2]-par(usr)[1]) placey1 - par(usr)[3]+.9*(par(usr)[4]-par(usr)[3]) placey2 - par(usr)[3]+.8*(par(usr)[4]-par(usr)[3]) # HERE: Is this the right way? text(x=placex, y=placey1, bquote(R^2 == .(summary(lm1)$r.squared)), adj=c(0,0)) text(x=placex, y=placey2, bquote(R^2 == .(summary(lm1)$adj.r.squared)), adj=c(0,0)) text(x=placex,y=placey2, expression(hat(R)), adj=c(0,0)) In addition, when I save the plot as PDF, the expression hat(R) seems to be somewhat displaced. Any advice? Thanks in advance, Vicente Aviso de confidencialidad Este correo electrónico y, en su caso, cualquier fichero anexo, contiene información confidencial exclusivamente dirigida a su(s) destinatario(s). Toda copia o divulgación deberá ser autorizada por la Subdirección de Análisis y Control Interno. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente por esta misma vía y proceda a su eliminación. Antes de imprimir este mensaje, asegúrese de que es necesario. El medio ambiente está en nuestras manos. [[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] getting a Likert plot from a data frame
Gavin, thank you for using likert() There are several problems in the use of a data.frame. 1. df is a bad name to use because df is the name of a base function (that isn't an error, it is bad style). 2. the as.character() made the line you sent not work. 3. you indeed have the variable cat as a factor. you need to make it the row.names of the data.frame. mydata - data.frame( row.names=c(group1, group2, group3, group4, group5), males=c(20,30,45,12,5), females=c(35,23,32,8,5)) ## make a pyramid Likert chart as.pyramidLikert(likert(mydata), panel.width=.46) Rich On Tue, May 22, 2012 at 7:29 AM, Gavin Rudge g.ru...@bham.ac.uk wrote: I'm creating a stacked bar chart using the likert command in the HH package. My data are in a data frame, with two numeric variables and a categorical variable, I can't get likert to use the column containing the categorical variable as a my y axis label. Here is a quick example: library(HH) #my data are: df-data.frame(as.character(cat=c(group1,group2,group3,group4, group5)),males=c(20,30,45,12,5),females=c(35,23,32,8,5)) #make a pyramid Likert chart p-likert(df) as.pyramidLikert(p) It tries to plot three variables here when I just want two. I think I understand what is happening - my categorical variable is treated as a factor and I think it gets inserted as an integer into the matrix which the command derives from my data fame, to make the plot with(?) It's then used as a variable to be plotted just like the other two variables. what I don't get is how the example given in the package does something differently, which is how I want mine to work. ## Population Pyramid data(USAge.table) USA79 - USAge.table[75:1, 2:1, 1979]/100 PL - likert(USA79, main=Population of United States 1979 (ages 0-74), xlab=Count in Millions, ylab=Age, scales=list( y=list( limits=c(0,77), at=seq(1,76,5), labels=seq(0,75,5), tck=.5)) ) PL as.pyramidLikert(PL) This does exactly what I'm trying to achieve. here the two population counts are plotted in the likert plot and the age groups in the first columns are used as labels. I can't work out why in my example the age group variable is not used in the same way as the in my plot in the same way as the agegroups in this example, other than the example takes it's data from a table and mine is coming from a data frame. The end point I want is a stacked Likert bar chart based on a data frame where the column containing the description of my groups is used as the y axis labels and the other two columns are used to draw the bars. I'm sure I'm missing a simple solution. any help gratefully received. Gavin. [[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] sweave tables as images?
Thanks Liviu, I've looked into SWord, and while it's an impressive project, I'm concerned that it doesn't quite give me the fine-grain control I'd like over the R environment where it's being executed. It's still in the back of my mind though, and I may indeed go with it at some point. If I understand it correctly, odfWeave doesn't have a path backwards from the odf doc back to the original odfWeave doc (which is the main restriction of all these Sweave/knitr/etc solutions in my use case). Please correct me if I'm wrong about that! Thanks, Allie On 5/22/2012 4:36 AM, Liviu Andronic wrote: On Mon, May 21, 2012 at 10:29 PM, Alexander Shenkin ashen...@ufl.edu wrote: So, I think it will be better if I can somehow generate the tables as images. Is there any way to generate tables as images in separate files in Sweave? Or, is there another tree up which I should be barking? Hmm, there are Sweave equivalents for LibreOffice [1] and MS Word [2]. Have you looked into those? You may find other suggestions in the ReproducibleResearch Task View [3]. Liviu [1] http://crantastic.org/packages/odfWeave [2] http://crantastic.org/packages/SWordInstaller [3] http://crantastic.org/task_views/ReproducibleResearch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sweave tables as images?
On Tue, May 22, 2012 at 3:24 PM, Alexander Shenkin ashen...@ufl.edu wrote: If I understand it correctly, odfWeave doesn't have a path backwards from the odf doc back to the original odfWeave doc (which is the main restriction of all these Sweave/knitr/etc solutions in my use case). Please correct me if I'm wrong about that! Unfortunately I cannot help you with this specific question, not least because I've never used odfWeave. From a quick glance to the docs, it seems that you always have two documents: source odfWeave .odt (equivalent to .Rnw) and output .odt (equivalent to .tex). Then using the .odt (.tex) you can generate a PDF. I would be surprised if it were possible to go back from .odt (.tex) to the source .odt (.Rnw). I would suggest that you contact the authors of the respective packages to make sure that the functionality is (not) available. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting a Likert plot from a data frame
Dear Richard On Tue, May 22, 2012 at 3:20 PM, Richard M. Heiberger r...@temple.edu wrote: mydata - data.frame( row.names=c(group1, group2, group3, group4, group5), males=c(20,30,45,12,5), females=c(35,23,32,8,5)) ## make a pyramid Likert chart as.pyramidLikert(likert(mydata), panel.width=.46) Loading library(HH) and running the code above fails with this error: as.pyramidLikert(likert(mydata), panel.width=.46) Error in inherits(x, trellis) : could not find function likert Am I doing something wrong? Liviu sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] splines grid stats graphics grDevices utils datasets [8] methods base other attached packages: [1] HH_2.2-23 latticeExtra_0.6-19 RColorBrewer_1.0-5 [4] leaps_2.9 multcomp_1.2-12 survival_2.36-12 [7] mvtnorm_0.9-9992lattice_0.20-6 plyr_1.7.1 [10] Defaults_1.1-1 fortunes_1.5-0 sos_1.3-1 [13] brew_1.0-6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting a Likert plot from a data frame
out-of-phase problem Update to HH_2.3-15 that was published on CRAN yesterday. In HH_2.2-23 you needed to use a slightly longer name plot.likert() instead of likert() On Tue, May 22, 2012 at 9:44 AM, Liviu Andronic landronim...@gmail.comwrote: Dear Richard On Tue, May 22, 2012 at 3:20 PM, Richard M. Heiberger r...@temple.edu wrote: mydata - data.frame( row.names=c(group1, group2, group3, group4, group5), males=c(20,30,45,12,5), females=c(35,23,32,8,5)) ## make a pyramid Likert chart as.pyramidLikert(likert(mydata), panel.width=.46) Loading library(HH) and running the code above fails with this error: as.pyramidLikert(likert(mydata), panel.width=.46) Error in inherits(x, trellis) : could not find function likert Am I doing something wrong? Liviu sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] splines grid stats graphics grDevices utils datasets [8] methods base other attached packages: [1] HH_2.2-23 latticeExtra_0.6-19 RColorBrewer_1.0-5 [4] leaps_2.9 multcomp_1.2-12 survival_2.36-12 [7] mvtnorm_0.9-9992lattice_0.20-6 plyr_1.7.1 [10] Defaults_1.1-1 fortunes_1.5-0 sos_1.3-1 [13] brew_1.0-6 [[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] “For” calculation is so slow
Hi For loops are really, really slow in R. In general, you want to avoid them I strongly disagree. ***Proper*** use of looping is quite convenient and reasonably fast. Consider system.time( { + a=0 + for (i in 1:1000) { + a -a+i + } + a + }) user system elapsed 10.220.02 10.28 system.time(b-sum(as.numeric(1:1000))) user system elapsed 0.090.010.11 identical(a,b) [1] TRUE It is usually implementing C habits into R code what makes looping slow. The slowest part of a program is usually programming and it is influenced mainly by programmer. Regards Petr like the plague. If you absolutely must insist on using them in large, computationally intense and complex code, consider implementing the relevant parts in C, say, and calling that from R. Staying within R, you can probably considerably speed up that code by storing gx and gy as a multi-dimensional arrays. (e.g. for sample data, something like rawGy = sample( 1:240, 240^2* 241, replace = T) rawGx = sample( 1:240, 240^2 *241, replace = T) gx = array(rawGx, dim = c(length(s) - 1, 240, max(rawGx)+1 ) ) gy = array(rawGy, dim = c(length(s) - 1, 240, max(rawGy)+1 ) ) ), in which case, you can easily do the computation without loops by gxa = (gx[ ,a,1]+ 1) gya =(gy[ ,a, 1] +1) uv = gx[cbind(1:(length(s) - 1) , b, gxa)] / gx[cbind(1:(length(s) - 1) , a, gxa)] - gy[cbind(1:(length(s) - 1) ,b, gya)]/gy[cbind(1:(length(s) - 1) ,a, gya)] or similar, which will be enormously faster (on my computer, there's an over 30x speed up). With a bit of thought, I'm sure you can also figure out how to let it vectorise in a, as well... Zhou -- View this message in context: http://r.789695.n4.nabble.com/For- calculation-is-so-slow-tp4630830p4630855.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] “For” calculation is so slow
And as followup system.time(d-1000*1001/2) user system elapsed 0.020.000.02 identical(a,b,d) [1] TRUE Regards Petr Hi For loops are really, really slow in R. In general, you want to avoid them I strongly disagree. ***Proper*** use of looping is quite convenient and reasonably fast. Consider system.time( { + a=0 + for (i in 1:1000) { + a -a+i + } + a + }) user system elapsed 10.220.02 10.28 system.time(b-sum(as.numeric(1:1000))) user system elapsed 0.090.010.11 identical(a,b) [1] TRUE It is usually implementing C habits into R code what makes looping slow. The slowest part of a program is usually programming and it is influenced mainly by programmer. Regards Petr like the plague. If you absolutely must insist on using them in large, computationally intense and complex code, consider implementing the relevant parts in C, say, and calling that from R. Staying within R, you can probably considerably speed up that code by storing gx and gy as a multi-dimensional arrays. (e.g. for sample data, something like rawGy = sample( 1:240, 240^2* 241, replace = T) rawGx = sample( 1:240, 240^2 *241, replace = T) gx = array(rawGx, dim = c(length(s) - 1, 240, max(rawGx)+1 ) ) gy = array(rawGy, dim = c(length(s) - 1, 240, max(rawGy)+1 ) ) ), in which case, you can easily do the computation without loops by gxa = (gx[ ,a,1]+ 1) gya =(gy[ ,a, 1] +1) uv = gx[cbind(1:(length(s) - 1) , b, gxa)] / gx[cbind(1:(length(s) - 1) , a, gxa)] - gy[cbind(1:(length(s) - 1) ,b, gya)]/gy[cbind(1:(length(s) - 1) ,a, gya)] or similar, which will be enormously faster (on my computer, there's an over 30x speed up). With a bit of thought, I'm sure you can also figure out how to let it vectorise in a, as well... Zhou -- View this message in context: http://r.789695.n4.nabble.com/For- calculation-is-so-slow-tp4630830p4630855.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.
Re: [R] ReName
On May 22, 2012, at 4:08 AM, HAOLONG HOU wrote: Dear list, The name of R-language is too short and is not friendly to search engines. Do you think it can be renamed to something like Rsio or Radio ? Thank you so much for this useful software! The notion of renaming R to 'radio' seems at best humorous. Try searching with: r-project CRAN Or use:Rseek.org Or use:allinurl:r-project in a google search Or: http://code.google.com/hosting/search?q=label:R+ At one point I used `language:r` but I can find no support in the google search documentation that currently supports that strategy. -- 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] Creating functions with a loop.
Hi I am trying to create n functions where each function is defined in function one step before, i.e. something like ff.k(x) = ff.j(x) - sum(1:j), for j=k-1 Is it possible? If it isn't and I manually create each function then is their a way to call them through a loop? My objective is to calculate something like result.k = ff.k(x1)/ff.k(x2) for k in 2:n Thank you for your time, Etienne __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ReName
No. There are search tools that work. The RSiteSearch() function and the rseek.org website are two such options. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. HAOLONG HOU hihaol...@gmail.com wrote: Dear list, The name of R-language is too short and is not friendly to search engines. Do you think it can be renamed to something like Rsio or Radio ? Thank you so much for this useful software! Best wishes. [[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] ReName
Hi On May 22, 2012, at 4:08 AM, HAOLONG HOU wrote: Dear list, The name of R-language is too short and is not friendly to search engines. Did you try it? Even with plain Google something R will usually lead to quite good hit. Try e.g. linear model R Regards Petr Do you think it can be renamed to something like Rsio or Radio ? Thank you so much for this useful software! The notion of renaming R to 'radio' seems at best humorous. Try searching with: r-project CRAN Or use:Rseek.org Or use:allinurl:r-project in a google search Or: http://code.google.com/hosting/search?q=label:R+ At one point I used `language:r` but I can find no support in the google search documentation that currently supports that strategy. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] “For” calculation is so slow
Thanks, I will take that factor of 100 anytime rather than keep some syntactic familiarity from other languages. Not to say I don't ever use loops, but I always try to vectorize the inner loop, if not the inner two loops. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Petr PIKAL petr.pi...@precheza.cz wrote: Hi For loops are really, really slow in R. In general, you want to avoid them I strongly disagree. ***Proper*** use of looping is quite convenient and reasonably fast. Consider system.time( { + a=0 + for (i in 1:1000) { + a -a+i + } + a + }) user system elapsed 10.220.02 10.28 system.time(b-sum(as.numeric(1:1000))) user system elapsed 0.090.010.11 identical(a,b) [1] TRUE It is usually implementing C habits into R code what makes looping slow. The slowest part of a program is usually programming and it is influenced mainly by programmer. Regards Petr like the plague. If you absolutely must insist on using them in large, computationally intense and complex code, consider implementing the relevant parts in C, say, and calling that from R. Staying within R, you can probably considerably speed up that code by storing gx and gy as a multi-dimensional arrays. (e.g. for sample data, something like rawGy = sample( 1:240, 240^2* 241, replace = T) rawGx = sample( 1:240, 240^2 *241, replace = T) gx = array(rawGx, dim = c(length(s) - 1, 240, max(rawGx)+1 ) ) gy = array(rawGy, dim = c(length(s) - 1, 240, max(rawGy)+1 ) ) ), in which case, you can easily do the computation without loops by gxa = (gx[ ,a,1]+ 1) gya =(gy[ ,a, 1] +1) uv = gx[cbind(1:(length(s) - 1) , b, gxa)] / gx[cbind(1:(length(s) - 1) , a, gxa)] - gy[cbind(1:(length(s) - 1) ,b, gya)]/gy[cbind(1:(length(s) - 1) ,a, gya)] or similar, which will be enormously faster (on my computer, there's an over 30x speed up). With a bit of thought, I'm sure you can also figure out how to let it vectorise in a, as well... Zhou -- View this message in context: http://r.789695.n4.nabble.com/For- calculation-is-so-slow-tp4630830p4630855.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.
Re: [R] “For” calculation is so slow
I'm not sure what you are trying to prove with that example - the loopless versions are massively faster, no? I don't disagree that loops are sometimes unavoidable, and I suppose sometimes loops can be faster when the non-loop version e.g. breaks your memory budget, or performs tons of needless computations. But I think avoiding for loops whenever you can is a good rule of thumb in R coding. -- View this message in context: http://r.789695.n4.nabble.com/For-calculation-is-so-slow-tp4630830p4630897.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] getting a Likert plot from a data frame
On Tue, May 22, 2012 at 4:00 PM, Richard M. Heiberger r...@temple.edu wrote: out-of-phase problem Update to HH_2.3-15 that was published on CRAN yesterday. Thanks! It works nicely now. Liviu In HH_2.2-23 you needed to use a slightly longer name plot.likert() instead of likert() On Tue, May 22, 2012 at 9:44 AM, Liviu Andronic landronim...@gmail.com wrote: Dear Richard On Tue, May 22, 2012 at 3:20 PM, Richard M. Heiberger r...@temple.edu wrote: mydata - data.frame( row.names=c(group1, group2, group3, group4, group5), males=c(20,30,45,12,5), females=c(35,23,32,8,5)) ## make a pyramid Likert chart as.pyramidLikert(likert(mydata), panel.width=.46) Loading library(HH) and running the code above fails with this error: as.pyramidLikert(likert(mydata), panel.width=.46) Error in inherits(x, trellis) : could not find function likert Am I doing something wrong? Liviu sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] splines grid stats graphics grDevices utils datasets [8] methods base other attached packages: [1] HH_2.2-23 latticeExtra_0.6-19 RColorBrewer_1.0-5 [4] leaps_2.9 multcomp_1.2-12 survival_2.36-12 [7] mvtnorm_0.9-9992 lattice_0.20-6 plyr_1.7.1 [10] Defaults_1.1-1 fortunes_1.5-0 sos_1.3-1 [13] brew_1.0-6 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adding Text to a Plot
On May 22, 2012, at 9:10 AM, Canto Casasola, Vicente David wrote: I'm pretty sure I'm missing something about this. Is there a smart way of typping hat(R)^2 and it's value from a linear regression? I've just found this tricky one: # Sample data x - sample(1:100,10) y - 2+3*x+rnorm(10) # Run the regression lm1 - lm(y~x) # Plotting plot(x,y, main=Linear Regression, col=red) abline(lm1, col=blue) placex - par(usr)[1]+.1*(par(usr)[2]-par(usr)[1]) placey1 - par(usr)[3]+.9*(par(usr)[4]-par(usr)[3]) placey2 - par(usr)[3]+.8*(par(usr)[4]-par(usr)[3]) # HERE: Is this the right way? # To do what? I see that you over-plotted the R, presumably because you did not like the way that: bquote(hat(R)^2 == .(summary(lm1)$adj.r.squared)) ... ended up looking (with the exponent higher than in the non-hatted version.) text(x=placex, y=placey1, bquote(R^2 == .(summary(lm1)$r.squared)), adj=c(0,0)) text(x=placex, y=placey2, bquote(R^2 == .(summary(lm1)$adj.r.squared)), adj=c(0,0)) text(x=placex,y=placey2, expression(hat(R)), adj=c(0,0)) In addition, when I save the plot as PDF, the expression hat(R) seems to be somewhat displaced. Any advice? Are you sure? It looks to me that the lower R is slightly shifted to the left, but when I actually measure it, there does not appear to be a shift. If it is real and not just an optical illusion, this may have something to do with your unstated version of R or your also unstated OS. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating functions with a loop.
On May 22, 2012, at 10:06 AM, Etienne Larrivée-Hardy wrote: Hi I am trying to create n functions where each function is defined in function one step before, i.e. something like ff.k(x) = ff.j(x) - sum(1:j), for j=k-1 There is a cumsum function: cumsum(1:10) [1] 1 3 6 10 15 21 28 36 45 55 Did you mean something like?: ff.k[j] - ff.j[j] - sum(1:j), for j=k-1 In R the paren, (, indicates that you are calling a function whereas you appear interested in making an indexed assignment to a vector. Is it possible? If it isn't and I manually create each function then is their a way to call them through a loop? My objective is to calculate something like result.k = ff.k(x1)/ff.k(x2) for k in 2:n You may have clear idea about which k-indices should go where in that expression, but I surely do not. What are 'x1' and 'x2'? -- 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] as.function parameters
Jumping in from a finance perspective... You really don't want to actually use nested lists for this -- the overhead and index-book-keeping will quickly become quite annoying. Instead use a 2D array (I assume you're using the CRR Binomial Tree model for an American Option) where the column number less one is how many steps into the tree you are and the row is how many ups/downs you've had (your call which one) -- then just roll your option valuing formula with loops over the array. This is implemented in the fOptions package in the CRRBinomialTree function, but if you can't use real R that might/might not help you. It is open source however... Michael On Tue, May 22, 2012 at 6:22 AM, jackl jacks...@hotmail.de wrote: Hi there, ~ the 'problem' or rather the task I'm trying to solve is to implement an algorithm to compute the ask/bid price of american options in a close to R related program language. because i'm not really using R but just it's basic functionalities I cannot rely on different packages included in the R space. is it usual for R to compute nested functions with such a workload? Best thanks -- View this message in context: http://r.789695.n4.nabble.com/as-function-parameters-tp4620390p4630858.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] RE : Creating functions with a loop.
I must say I'm new here and I don't quite know how things work so you will have to excuse me. The first part of my problem is that it would help me greatly to have a loop creating all the functions. Here is an example of how the 10th function would need to look like: ff10 - function (q, alph, lam) { ff9(q, alph, lam) - sum(v.pp[1:(10 - 1)] * exp(-v.beta[1:(10 - 1)] * cc1 * 10^(1:(10 - 1) - 1))) } where v.pp and v.beta are vector for which values are known up to 9 in this case. cc1, bb, alpha, lambda are fixed. The second part of my problem is that with those functions I need to calculate the next value of v.beta and v.pp. v.beta[10] - 1/((bb-1)*cc1*10^-(10-1))*log(ff2(cc1*10^-(10-1),alpha,lambda)/ff10(cc1*10^-(10-1)*bb,alpha,lambda)) and v.pp[10] - ... I don't know if that made it any clearer... De : David Winsemius [dwinsem...@comcast.net] Date d'envoi : 22 mai 2012 11:08 À : Etienne Larrivée-Hardy Cc : r-help@r-project.org Objet : Re: [R] Creating functions with a loop. On May 22, 2012, at 10:06 AM, Etienne Larrivée-Hardy wrote: Hi I am trying to create n functions where each function is defined in function one step before, i.e. something like ff.k(x) = ff.j(x) - sum(1:j), for j=k-1 There is a cumsum function: cumsum(1:10) [1] 1 3 6 10 15 21 28 36 45 55 Did you mean something like?: ff.k[j] - ff.j[j] - sum(1:j), for j=k-1 In R the paren, (, indicates that you are calling a function whereas you appear interested in making an indexed assignment to a vector. Is it possible? If it isn't and I manually create each function then is their a way to call them through a loop? My objective is to calculate something like result.k = ff.k(x1)/ff.k(x2) for k in 2:n You may have clear idea about which k-indices should go where in that expression, but I surely do not. What are 'x1' and 'x2'? -- 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] RNORM matrix based on CSV file values for MEAN and SD
This should (hopefully) be a pretty simple task. What I'd like to do is read in a csv file containing means and standard deviations for a large number of 'n' parameters (up to 2000). The list would be in the following format (see attached read.csv): Paramter(1), mean, standard dev., Paramter(2), mean, standard dev., Paramter(3), mean, standard dev., ... Paramter(n), mean, standard dev., Based on the above csv file, I would then like to generate a large sample matrix for 's' samples, using the rnorm function. The matrix will be in the following format: 1,0,0, P1(1), P2(1), P3(1), ... Pn(1) 2,0,0, P1(2), P2(2), P3(2), ... Pn(2) s,0,0, P1(s), P2(s), P3(s), ... Pn(s) The first column contains the Row number. Taking s=3, we would have rows numbered 1 to 30,000. The second and third column are fixed values - 0 The forth and subsequent columns contain values from the rnorm distribution for each parameter. P1(1) is the first value generated for the first parameter, P1(2) is the second value generated and so forth. P2(1) is the first value generated for the second parameter, P2(2) is the second value generated and so forth. Pn(1) is the first value generated for the n'th parameter, Pn(2) is the second value generated and so forth. Again the number of rows depends on 's', the number of samples. Therefore, I will be generating a fairly large matrix. This could be a 1,000,000 x 2,000 matrix. However, due to memory constraints, it may be necessary to break this down into smaller sub-matrices where I limit the number of rows. Firstly, is this possible in r, and secondly, can anyone help suggest a method for creating such a matrix. I'd really appreciate any help on this. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/RNORM-matrix-based-on-CSV-file-values-for-MEAN-and-SD-tp4630901.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] Graph to visualize paired t test
http://r.789695.n4.nabble.com/file/n4630909/pfaff_fig1.gif I have run the statistics and found no significance in my pairwise t test. I want to create a graph similar to the one I included showing similar slopes/lines for my data points. For my data a correlation graph is not appropriate and looks very confusing. Is the easiest way to create several lines between points I enter manually or is there a way to create this graph from entering my pairwise.t.test data? Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Graph-to-visualize-paired-t-test-tp4630909.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 evaluate R things from Visual Studio?
Hello all, Iâm new here and this is actually my very first post. My name is Giannis and I am an undergraduate student. I am programming in Microsoftâs Visual Studio 2010 (VB.NET mostly) and I want to create a program for the research group I am in. I merely want to evaluate actions and use simple statistical things such as ks test (Kolmogorov-Smirnov), and some plots. The reason I need to call R from my program is that the users of my program will NOT know any programming language, and by extension they will not know R either. So everything will happen by the click of a button. For me to do that, I need to be able to use interoperability between R and VS.NET 2010, so that I can use Râs evaluator. Iâve already tried Baierâs StatConnDCOM (http://rcom.univie.ac.at) and I did succeed in creating a program that runs perfectly but came to see the hard way that â for my case, is kind of useless for the sole reason of StatconnDCOMâs redistribution restriction. As Mr. Baier told me himself, there is no guarantee that StatconnDCOM will be available free of charge for ever. Hence I cannot create a freeware program now, and have my users uncertain of where they will be able to use this program for free in the future. Iâve already tried R.NET (http://rdotnet.codeplex.com/ ) Version 1.4 (stable) and 1.4.1 (Change Set: 6d2c3f161801 ). This does seem wonderful and it doesnât have StaconnDCOMâs ridiculous restrictions, BUT it refuses to work on me! So, now that you have all the necessary background info, it is time I presented my questions: 1) Is there another way of using R from Visual Studio that you can point me to? 2) Is anyone here using R.NET (any version) successfully? If so, can you help me to get it working? Unfortunately they canât help me on R.NETâs official discussion forum I mean, I just need to evaluate the basic R stuff.. Why is it THAT difficult? Last but not least, let me give you info that might be relevant in your deciding how to aid me. OS: Windows 7 Professional x64 English (Genuine, it is purchased) R: Version 2.15.0 Programming Environment: Microsoft Visual Studio .net 2010 For any additional Info, please do not hesitate to ask me either here or directly at giannis_mamaliki...@msn.com I hope we can make this work. thanks in advance. [[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 functions with a loop.
Interpreting your question slightly differently, where ff.k(x) is a function call. Suppose you want to get a list of functions like x^2 x^2 -1 x^2 - 3 x^2 - 6 It's perfectly possible with something like this: NextFunc - function(f, i) { # Takes in a function f and returns # a different function that gives you # f(x) - i force(i) # probably unnecessary, but good practice as this just might bite you in a loop function(x) f(x) - i } Then f - function(x) x^2 f2 - NextFunc(f, 1) f3 - NextFunc(f2, 2) f3(3) # 6 = 3^2 - 1 - 2 Which should be wrappable in a loop. Michael On Tue, May 22, 2012 at 11:08 AM, David Winsemius dwinsem...@comcast.net wrote: On May 22, 2012, at 10:06 AM, Etienne Larrivée-Hardy wrote: Hi I am trying to create n functions where each function is defined in function one step before, i.e. something like ff.k(x) = ff.j(x) - sum(1:j), for j=k-1 There is a cumsum function: cumsum(1:10) [1] 1 3 6 10 15 21 28 36 45 55 Did you mean something like?: ff.k[j] - ff.j[j] - sum(1:j), for j=k-1 In R the paren, (, indicates that you are calling a function whereas you appear interested in making an indexed assignment to a vector. Is it possible? If it isn't and I manually create each function then is their a way to call them through a loop? My objective is to calculate something like result.k = ff.k(x1)/ff.k(x2) for k in 2:n You may have clear idea about which k-indices should go where in that expression, but I surely do not. What are 'x1' and 'x2'? -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] LM with summation function
Hi all, Thanks for the replies, but I realize I've done a bad job explaining my problem. To help, I've created some sample data to explain the problem. df - data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), y=c(109, 232, 363, 496, 625, 744, 847, 928, 981, 1000, 979, 912), s=c(109, 341, 704, 1200, 1825, 2569, 3416, 4344, 5325, 6325, 7304, 8216)) In this data frame, y results from y = x * b1 + x^2 * b2 + x^3 * b3 and s is sum of the current y and all previous y (s3 = y1 + y2 + y3). I know I can find b1, b2 and b3 using: lm(y ~ 0 + x + I(x^2) + I(x^3), data=df) yielding... Coefficients: x I(x^2) I(x^3) 100 10 -1 However, I need to find b1, b2 and b3 using the s column. The reason being, I don't actually know the values of y in the actual data set. And in the actual data, I only have a few of the values. Imagine this data is being used a reward schedule for like a loyalty points program. y represents the number of points needed for each level while s is the total number of points to reach that level. In the real problem, my data looks more like this: d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) Where I need to use a few sample points to help define the parameters of the curve. thanks again and hopefully this makes the problem a bit clearer. robbie On Fri, May 18, 2012 at 7:40 PM, David Winsemius dwinsem...@comcast.netwrote: On May 18, 2012, at 1:44 PM, Robbie Edwards wrote: Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. cumsum( rowSums( cbind(B1 * x, B2 * x^2, B3 * x^3))) Anyway, if it wasn't for the summation, I know I would do it like this lm(y ~ x + x2 + x3) Where x2 and x3 are x^2 and x^3. However, since each value of x is related to the previous values of x, I don't know how to do this. Any help is greatly appreciated. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RNORM matrix based on CSV file values for MEAN and SD
No CSV came through so I'll just assume you get in a data.frame from read.csv() that looks something like this params - data.frame(mean = c(1,4,7), sd = c(2,2,5)) and you want 10 samples from each. If you're on memory constraints, you can simply loop over rows and append to a growing CSV. for(i in NROW(params)){ write.table(c(i, 0, 0, rnorm(10, params$mean[i], params$sd[i])), out.csv, append = TRUE, sep =,, row.names = FALSE, col.names = FALSE) } Note that we have to set the names to false or the appending gets messy. It's probably faster (though more work) to do a few rows at a time and to use textConnections so you aren't constantly opening and closing the file, but this should get you started. See the examples of ?textConnection for how to do that bit properly. Best, Michael On Tue, May 22, 2012 at 10:43 AM, dcoakley danielcoakl...@gmail.com wrote: This should (hopefully) be a pretty simple task. What I'd like to do is read in a csv file containing means and standard deviations for a large number of 'n' parameters (up to 2000). The list would be in the following format (see attached read.csv): Paramter(1), mean, standard dev., Paramter(2), mean, standard dev., Paramter(3), mean, standard dev., ... Paramter(n), mean, standard dev., Based on the above csv file, I would then like to generate a large sample matrix for 's' samples, using the rnorm function. The matrix will be in the following format: 1,0,0, P1(1), P2(1), P3(1), ... Pn(1) 2,0,0, P1(2), P2(2), P3(2), ... Pn(2) s,0,0, P1(s), P2(s), P3(s), ... Pn(s) The first column contains the Row number. Taking s=3, we would have rows numbered 1 to 30,000. The second and third column are fixed values - 0 The forth and subsequent columns contain values from the rnorm distribution for each parameter. P1(1) is the first value generated for the first parameter, P1(2) is the second value generated and so forth. P2(1) is the first value generated for the second parameter, P2(2) is the second value generated and so forth. Pn(1) is the first value generated for the n'th parameter, Pn(2) is the second value generated and so forth. Again the number of rows depends on 's', the number of samples. Therefore, I will be generating a fairly large matrix. This could be a 1,000,000 x 2,000 matrix. However, due to memory constraints, it may be necessary to break this down into smaller sub-matrices where I limit the number of rows. Firstly, is this possible in r, and secondly, can anyone help suggest a method for creating such a matrix. I'd really appreciate any help on this. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/RNORM-matrix-based-on-CSV-file-values-for-MEAN-and-SD-tp4630901.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] Graph to visualize paired t test
If I understand what you are looking for, this should get you started: https://www.stat.math.ethz.ch/pipermail/r-help/2012-May/312287.html Michael On Tue, May 22, 2012 at 11:14 AM, jhartsho jhart...@uark.edu wrote: http://r.789695.n4.nabble.com/file/n4630909/pfaff_fig1.gif I have run the statistics and found no significance in my pairwise t test. I want to create a graph similar to the one I included showing similar slopes/lines for my data points. For my data a correlation graph is not appropriate and looks very confusing. Is the easiest way to create several lines between points I enter manually or is there a way to create this graph from entering my pairwise.t.test data? Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Graph-to-visualize-paired-t-test-tp4630909.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] Graph to visualize paired t test
tmp - data.frame(A=sample(20,10), B=sample(20, 10)) with(tmp, t.test(A, B)) matplot(t(tmp), type=b) This does what you asked for. I don't understand the legend on your plot. For future queries, 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. The nabble interface is not encouraged. Please write directly to the list R-help@r-project.org Rich On Tue, May 22, 2012 at 11:14 AM, jhartsho jhart...@uark.edu wrote: http://r.789695.n4.nabble.com/file/n4630909/pfaff_fig1.gif I have run the statistics and found no significance in my pairwise t test. I want to create a graph similar to the one I included showing similar slopes/lines for my data points. For my data a correlation graph is not appropriate and looks very confusing. Is the easiest way to create several lines between points I enter manually or is there a way to create this graph from entering my pairwise.t.test data? Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Graph-to-visualize-paired-t-test-tp4630909.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax for lme function to model random factors and interactions
See inline On Mon, May 21, 2012 at 11:17 AM, i_like_macs dk...@mac.com wrote: Hello Joshua, Many thanks for your help, especially from a fellow Bruin (I went there as an undergrad!). I understand that there is another forum for mixed models. If my problem can't be solved within this thread, I'll have to go there. I do understand some theory about mixed models, but obviously am far from an expert. My question is not so much statistical advice, as it concerns the correct syntax to include random factors and interactions (which include these random factors) for the lme function. Maybe it's because I'm used to SPSS, but I find R very difficult to use, even after looking up its built-in help. I could run your neat code suggestion: lme(Y ~ (A + B + C + D)^3, data = myData, random = ~ 1 | C, method = ML) but would like to know how to also include D as a random factor. My understanding is that the random argument for the lme function is coded as: ~ x1 + ... + xn | g1 / ... / gm so in this case x1 ... xn are random effects where the effects are allowed to vary across levels of g1 .. gm. where the left side describes the model for random effects, and the right side describes the grouping structure. Reading other posts, I learned that I need both sides for the code to run without errors. However, it's not clear that is correct, the left side is the random effect (random intercepts and/or random slopes), the right side is whatever variable codes the levels that the random effect can vary across. to me what both sides represent. The left side appears to be where the random factors are specified, perhaps like this: random = ~ C + D so this would indicate that C and D are random effects, but you will need something to indicate what they get to vary across. But then this results in errors. Does this mean I have to somehow join the two following lines of code to specify both random factors? random = ~ 1 | C random = ~ 1 | D I do not think that is what you want (and besides I do not think that lme() allows multiple random arguments though I could be wrong because I work with lmer more than lme). It's not clear what the ~ 1 represents here, as I would have guessed that this is where the random factors would be specified. Is this related to an intercept-only model? yes, ~ 1 | C means that there is a random intercept for each level of C. If you do this, you will get an estimate of the average intercept for the intercept in your model, but you will also get an estimate of the variance in intercepts (technically the intercepts are assumed to come from a normal distribution, you will get the mean and variance (or standard deviation) of the maximum likelihood estimate of that distribution). I'm sorry for sounding so lost. This is because I am. Perhaps I need to know more theory of mixed models, but this seems to be possible only if I Understanding more theory would probably help. The Pinheiro and Bates text as wonderful as it is, may not be the easiest place to start. I have not seen you mention anything about a grouping or nesting structure in your data. This may be part of the confusion too. Many uses of mixed models are for that case. A classical example would be students nested within classrooms. In that case, the research question could be does number of hours spent on homework predict grades. The model could look like: grades ~ 1 + homework or in ordinary regression notation instead of R's formula: grades = Xb + e where X is a design matrix the first few rows of which might look like: 1 2 1 2.5 1 3 1 2 the first column being the intercept adn the second the number of hours spent on homework for each student. b will be a vector of coefficients, the first coefficient being the estimated intercept and the second the slope of grades on homework. e is a vector of residuals, that part of grades which cannot be explained by the intercept and homework. The assumption in ordinary regression is that e is identically and independently distributed, but students are within classrooms, and we might guess that in fact, each student was not really an indepedent observation---there is some similarity because they share a classroom. Mixed models address this by adding random effects. Following the above example, we might do: grades ~ 1 + homework random = ~ 1 | ClassroomID this allows the intercepts to randomly vary by classroom, which is sensible---some classes may have more or less skilled students so given that everyone did 0 hours of homework, we still might expect some classrooms to have higher or lower grades. This models that. Now lets say that further, you think that the effects of homework might vary across classrooms. Perhaps for students in very low performing classes, they get an enormous benefit from spending time on homework, whereas in the very high performing classes, their grades only marginally improve for every additional hour of homework.
[R] how to remove the 'promise' attribute of an R object (.Random.seed)?
Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] integer rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer vector but of type 'promise' typeof(.Random.seed) # [1] integer So there must be an attribute promise somewhere attached to .Random.seed, and I cannot find it. The R function typeof() does not reveal it, but the TYPEOF() function in src/main/RNG.c says it is a 'promise'. My question is, how to make R use the real value of .Random.seed instead of complaining about the promise? Thanks! Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] LM with summation function
But if I understand your problem correctly, you can get the y values from the s values. I'm relying on your statement that s is sum of the current y and all previous y (s3 = y1 + y2 + y3). E.g., y - c(1, 4, 6, 9, 3, 7) s1 = 1 s2 = 4 + s1 = 5 s3 = 6 + s2 = 11 more generally s - cumsum(y) Then if we only see s, we can get back the y vector by doing c(s[1], diff(s)) which is identical to y. So for your data, the underlying y must have been c(109, 1091, 4125, 2891) right? Or have I completely misunderstood your problem? Michael On Tue, May 22, 2012 at 12:25 PM, Robbie Edwards robbie.edwa...@gmail.com wrote: Actually, I can't. I don't know the y values. Only the s and only for a subset of the data. Like this. d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) On Tue, May 22, 2012 at 11:57 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: You can reconstruct the y values by taking first-differences of the s vector, no? Then it sounds like you're good to go Best, Michael On Tue, May 22, 2012 at 11:40 AM, Robbie Edwards robbie.edwa...@gmail.com wrote: Hi all, Thanks for the replies, but I realize I've done a bad job explaining my problem. To help, I've created some sample data to explain the problem. df - data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), y=c(109, 232, 363, 496, 625, 744, 847, 928, 981, 1000, 979, 912), s=c(109, 341, 704, 1200, 1825, 2569, 3416, 4344, 5325, 6325, 7304, 8216)) In this data frame, y results from y = x * b1 + x^2 * b2 + x^3 * b3 and s is sum of the current y and all previous y (s3 = y1 + y2 + y3). I know I can find b1, b2 and b3 using: lm(y ~ 0 + x + I(x^2) + I(x^3), data=df) yielding... Coefficients: x I(x^2) I(x^3) 100 10 -1 However, I need to find b1, b2 and b3 using the s column. The reason being, I don't actually know the values of y in the actual data set. And in the actual data, I only have a few of the values. Imagine this data is being used a reward schedule for like a loyalty points program. y represents the number of points needed for each level while s is the total number of points to reach that level. In the real problem, my data looks more like this: d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) Where I need to use a few sample points to help define the parameters of the curve. thanks again and hopefully this makes the problem a bit clearer. robbie On Fri, May 18, 2012 at 7:40 PM, David Winsemius dwinsem...@comcast.netwrote: On May 18, 2012, at 1:44 PM, Robbie Edwards wrote: Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. cumsum( rowSums( cbind(B1 * x, B2 * x^2, B3 * x^3))) Anyway, if it wasn't for the summation, I know I would do it like this lm(y ~ x + x2 + x3) Where x2 and x3 are x^2 and x^3. However, since each value of x is related to the previous values of x, I don't know how to do this. Any help is greatly appreciated. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] LM with summation function
I don't think I can. For the sample data d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) when x = 4, s = 1200. However, that s4 is sum of y1 + y2 + y3 + y4. Wouldn't I have to know the y for x = 2 and x = 3 to get the value of y for x = 4? In the previous message, I created two sample data frames. d is what I'm trying to use to create df. I only know what's in d, df is just used to illustrate what I'm trying to get from d. robbie On Tue, May 22, 2012 at 12:30 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: But if I understand your problem correctly, you can get the y values from the s values. I'm relying on your statement that s is sum of the current y and all previous y (s3 = y1 + y2 + y3). E.g., y - c(1, 4, 6, 9, 3, 7) s1 = 1 s2 = 4 + s1 = 5 s3 = 6 + s2 = 11 more generally s - cumsum(y) Then if we only see s, we can get back the y vector by doing c(s[1], diff(s)) which is identical to y. So for your data, the underlying y must have been c(109, 1091, 4125, 2891) right? Or have I completely misunderstood your problem? Michael On Tue, May 22, 2012 at 12:25 PM, Robbie Edwards robbie.edwa...@gmail.com wrote: Actually, I can't. I don't know the y values. Only the s and only for a subset of the data. Like this. d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) On Tue, May 22, 2012 at 11:57 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: You can reconstruct the y values by taking first-differences of the s vector, no? Then it sounds like you're good to go Best, Michael On Tue, May 22, 2012 at 11:40 AM, Robbie Edwards robbie.edwa...@gmail.com wrote: Hi all, Thanks for the replies, but I realize I've done a bad job explaining my problem. To help, I've created some sample data to explain the problem. df - data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), y=c(109, 232, 363, 496, 625, 744, 847, 928, 981, 1000, 979, 912), s=c(109, 341, 704, 1200, 1825, 2569, 3416, 4344, 5325, 6325, 7304, 8216)) In this data frame, y results from y = x * b1 + x^2 * b2 + x^3 * b3 and s is sum of the current y and all previous y (s3 = y1 + y2 + y3). I know I can find b1, b2 and b3 using: lm(y ~ 0 + x + I(x^2) + I(x^3), data=df) yielding... Coefficients: x I(x^2) I(x^3) 100 10 -1 However, I need to find b1, b2 and b3 using the s column. The reason being, I don't actually know the values of y in the actual data set. And in the actual data, I only have a few of the values. Imagine this data is being used a reward schedule for like a loyalty points program. y represents the number of points needed for each level while s is the total number of points to reach that level. In the real problem, my data looks more like this: d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) Where I need to use a few sample points to help define the parameters of the curve. thanks again and hopefully this makes the problem a bit clearer. robbie On Fri, May 18, 2012 at 7:40 PM, David Winsemius dwinsem...@comcast.netwrote: On May 18, 2012, at 1:44 PM, Robbie Edwards wrote: Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. cumsum( rowSums( cbind(B1 * x, B2 * x^2, B3 * x^3))) Anyway, if it wasn't for the summation, I know I would do it like this lm(y ~ x + x2 + x3) Where x2 and x3 are x^2 and x^3. However, since each value of x is related to the previous values of x, I don't know how to do this. Any help is greatly appreciated. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] LM with summation function
Ahh sorry -- I didn't understand that x was supposed to be an index so I was using the row number an index for the summation -- yes, my proposal probably won't work without further assumptions[I.e., you could assume linear growth between observations, but that will bias something some direction...(not sure which)] I'll ponder it some more and get back to you if I come up with anything Michael On Tue, May 22, 2012 at 12:43 PM, Robbie Edwards robbie.edwa...@gmail.com wrote: I don't think I can. For the sample data d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) when x = 4, s = 1200. However, that s4 is sum of y1 + y2 + y3 + y4. Wouldn't I have to know the y for x = 2 and x = 3 to get the value of y for x = 4? In the previous message, I created two sample data frames. d is what I'm trying to use to create df. I only know what's in d, df is just used to illustrate what I'm trying to get from d. robbie On Tue, May 22, 2012 at 12:30 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: But if I understand your problem correctly, you can get the y values from the s values. I'm relying on your statement that s is sum of the current y and all previous y (s3 = y1 + y2 + y3). E.g., y - c(1, 4, 6, 9, 3, 7) s1 = 1 s2 = 4 + s1 = 5 s3 = 6 + s2 = 11 more generally s - cumsum(y) Then if we only see s, we can get back the y vector by doing c(s[1], diff(s)) which is identical to y. So for your data, the underlying y must have been c(109, 1091, 4125, 2891) right? Or have I completely misunderstood your problem? Michael On Tue, May 22, 2012 at 12:25 PM, Robbie Edwards robbie.edwa...@gmail.com wrote: Actually, I can't. I don't know the y values. Only the s and only for a subset of the data. Like this. d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) On Tue, May 22, 2012 at 11:57 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: You can reconstruct the y values by taking first-differences of the s vector, no? Then it sounds like you're good to go Best, Michael On Tue, May 22, 2012 at 11:40 AM, Robbie Edwards robbie.edwa...@gmail.com wrote: Hi all, Thanks for the replies, but I realize I've done a bad job explaining my problem. To help, I've created some sample data to explain the problem. df - data.frame(x=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), y=c(109, 232, 363, 496, 625, 744, 847, 928, 981, 1000, 979, 912), s=c(109, 341, 704, 1200, 1825, 2569, 3416, 4344, 5325, 6325, 7304, 8216)) In this data frame, y results from y = x * b1 + x^2 * b2 + x^3 * b3 and s is sum of the current y and all previous y (s3 = y1 + y2 + y3). I know I can find b1, b2 and b3 using: lm(y ~ 0 + x + I(x^2) + I(x^3), data=df) yielding... Coefficients: x I(x^2) I(x^3) 100 10 -1 However, I need to find b1, b2 and b3 using the s column. The reason being, I don't actually know the values of y in the actual data set. And in the actual data, I only have a few of the values. Imagine this data is being used a reward schedule for like a loyalty points program. y represents the number of points needed for each level while s is the total number of points to reach that level. In the real problem, my data looks more like this: d - data.frame(x=c(1, 4, 9, 12), s=c(109, 1200, 5325, 8216)) Where I need to use a few sample points to help define the parameters of the curve. thanks again and hopefully this makes the problem a bit clearer. robbie On Fri, May 18, 2012 at 7:40 PM, David Winsemius dwinsem...@comcast.netwrote: On May 18, 2012, at 1:44 PM, Robbie Edwards wrote: Hi all, I'm trying to model some data where the y is defined by y = summation[1 to 50] B1 * x + B2 * x^2 + B3 * x^3 Hopefully that reads clearly for email. cumsum( rowSums( cbind(B1 * x, B2 * x^2, B3 * x^3))) Anyway, if it wasn't for the summation, I know I would do it like this lm(y ~ x + x2 + x3) Where x2 and x3 are x^2 and x^3. However, since each value of x is related to the previous values of x, I don't know how to do this. Any help is greatly appreciated. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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
[R] Could incomplete final line found be more serious than a warning?
Dear all, I've been successfully reading Web of Science-data from tab-delimited text files into a data.frame using an R-script based on readLines(). With new data I just downloaded I suddenly get this warning: incomplete final line found I know this warning has already been discussed numerous times but none of the previously suggested solutions worked for me, unfortunately; so please bear with me: I shut the warning down using warn = FALSE, but the data still won't get read so this seems to be more serious than a warning. Adding a blank line or two at the end of the file did NOT help, i.e. R still does not read the file. But my old files still work properly, though. So I opened the text files using Notepad++ and saw that the last lines of both old text files (i.e. working) as well as new text files (i.e. the ones that don't work for some reason) always end with a tab stop followed by a line break. Personally I couldn't tell any difference between the ways these files ended. Their endings looked identical to me. I was using R 2.14.0 (64 bit) on Windows when I dioscovered the problem. So I upgraded to 2.15.0 (64-bit) but the problem persists. You can see small examples of an old and new file at https://www.dropbox.com/s/2joadjo9ce86rij/WoS-old.txt and https://www.dropbox.com/s/lp9l1exx4mfws1s/WoS-new.txt, respectively. Does anybody happen to have an idea of what could cause these problems for me? Thank you very much for your consideration! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] utils:::menuInstallLocal()
Hello R, I'm trying to install a package (class) locally; in windows 7, 64 bits machine. The only massage I see on the R Console is: utils:::menuInstallLocal() nothing else. What does this means, shouldn't I got some source of massage on the Console. EZ [[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] R Memory Issues
As a continuation to my original question, here is the massage that I get: Error in glm.fit(x = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, : cannot allocate memory block of size 2.1 Gb The model glm.fit is a logistic type (in the family of GLM) model. Maybe this is not enough information; again!, but some feedback will be appreciated. To me the issues appears to be associated with manipulation of large dataset. Howeverl the algorithm runs fine in Unix; but not in Windows (64 bits windows 7). EZ On Sun, May 20, 2012 at 4:09 PM, Emiliano Zapata ezapata...@gmail.comwrote: Already then, thank you everyone. This information was extremly useful, and I'll do a better job on the web next time. On Sun, May 20, 2012 at 2:10 PM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: On 20/05/2012 18:42, jim holtman wrote: At the point in time that you get the error message, how big are the objects that you have in memory? What does 'memory.size()' show as being used? What does 'memory.limit()' show? Have you tried using 'gc()' periodically to do some garbage collection? It might be that you memory is fragmented. You need to supply some additional information. Either this is a 32-bit version of R in which case the wrong version is being used, or your advice is wrong: there are no credible fragmentation issues (and no need to use gc()) on a 64-bit build of R. But, we have a posting guide, we require 'at a minimum information', and the OP failed to give it to us so we are all guessing, completely unnecessarily. On Sun, May 20, 2012 at 12:09 PM, Emiliano Zapataezapata...@gmail.com wrote: -- Forwarded message -- From: Emiliano Zapataezapata...@gmail.com Date: Sun, May 20, 2012 at 12:09 PM Subject: To: R-help@r-project.org Hi, I have a 64 bits machine (Windows) with a total of 192GB of physical memory (RAM), and total of 8 CPU. I wanted to ask how can I make R make use of all the memory. I recently ran a script requiring approximately 92 GB of memory to run, and got the massage: cannot allocate memory block of size 2.1 Gb I read on the web that if you increase the memory you have to reinstall R; would that be enough. Could I just increase the memory manually. Take you for any comments, or links on the web. EZ [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/%7Eripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[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 remove square brackets, etc. from address strings?
Hi, text - [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA gsub(\\[.+?],,text) A.K. - Original Message - From: Sabina Arndt sabina.ar...@hotmail.de To: r-help@r-project.org Cc: Sent: Tuesday, May 22, 2012 6:08 AM Subject: [R] How to remove square brackets, etc. from address strings? Hello, I'd like to remove the individual pairs of square brackets along with their content - plus the space directly behind it - from address strings such as this: [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA I'd like get the following result: Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA I tried address = gsub((.*)[(.*)], \\2, address) But this deletes everything from the first opening bracket to the last closing bracket and leaves only the very last address: Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA How can I remove only the individual pairs of square brackets along with their content? Thank you very much in advance! [[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] RNORM matrix based on CSV file values for MEAN and SD
Thanks Michael, This seems to get me half-way towards a solution. However, I am still having some difficulty in getting the out.csv exactly as I would like. I should probably explain the issue a bit further. I am reading in a csv file containing a list of 'n' parameters. I have attached a csv ( http://r.789695.n4.nabble.com/file/n4630928/read.csv read.csv ) which contains 10 parameters as an example. However, the final problem may have up to 2000 parameters. Currently, these have string titles in the first column. However, I can change these to numbers if it causes problems in R. As you said correctly, this will give me a data.frame with mean and sd values. The problem I have is in the creation of the matrix of rnorm values. Using the for loop specified, I am getting a single column with the rnorm values for the last parameter specified (see attached http://r.789695.n4.nabble.com/file/n4630928/out.csv out.csv ). Re-running the for loop appends another column to the csv file, below the original column. I have attached an example of the output I am looking for ( http://r.789695.n4.nabble.com/file/n4630928/OutputSample.csv OutputSample.csv ). I believe, the approach here is correct, I just need to make a few modifications to the for loop. This also needs to be scalable to allow for the inclusion of multiple paramters (up to 2000) and samples (up to 1 million). I will look into the dataConnections process you mentioned to address this task. Also, just in case the above attachments don't work, here is a link to the shared files on Google Drive: https://docs.google.com/open?id=0Bwwrh1DeZXteSFBXNVI1NGZfQjg Thanks again for the help. Very much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/RNORM-matrix-based-on-CSV-file-values-for-MEAN-and-SD-tp4630901p4630928.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] RNORM matrix based on CSV file values for MEAN and SD
On Tue, May 22, 2012 at 12:40 PM, dcoakley danielcoakl...@gmail.com wrote: Thanks Michael, This seems to get me half-way towards a solution. However, I am still having some difficulty in getting the out.csv exactly as I would like. I should probably explain the issue a bit further. I am reading in a csv file containing a list of 'n' parameters. I have attached a csv ( http://r.789695.n4.nabble.com/file/n4630928/read.csv read.csv ) which contains 10 parameters as an example. However, the final problem may have up to 2000 parameters. Currently, these have string titles in the first column. However, I can change these to numbers if it causes problems in R. It looks like read.csv(http://r.789695.n4.nabble.com/file/n4630928/read.csv;) works just fine for me here -- can you provide the code you're using to read things in? It might be that you need header = TRUE if you're using read.table() instead of read.csv() [The only reason I'm having you use write.table() is that write.csv() doesn't append nicely] As you said correctly, this will give me a data.frame with mean and sd values. The problem I have is in the creation of the matrix of rnorm values. Using the for loop specified, I am getting a single column with the rnorm values for the last parameter specified (see attached http://r.789695.n4.nabble.com/file/n4630928/out.csv out.csv ). Re-running the for loop appends another column to the csv file, below the original column. Ahh, my apologies -- you probably need to transpose your data to a row before writing: e.g., write.table(1:10, temp.csv, sep = ,, row.names = FALSE, col.names = FALSE) read.csv(temp.csv, header = FALSE) # Gives a single column write.table(t(1:10), temp.csv, sep = ,, row.names = FALSE, col.names = FALSE) read.csv(temp.csv, header = FALSE) # Gives a single row Best, Michael I have attached an example of the output I am looking for ( http://r.789695.n4.nabble.com/file/n4630928/OutputSample.csv OutputSample.csv ). I believe, the approach here is correct, I just need to make a few modifications to the for loop. This also needs to be scalable to allow for the inclusion of multiple paramters (up to 2000) and samples (up to 1 million). I will look into the dataConnections process you mentioned to address this task. Also, just in case the above attachments don't work, here is a link to the shared files on Google Drive: https://docs.google.com/open?id=0Bwwrh1DeZXteSFBXNVI1NGZfQjg Thanks again for the help. Very much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/RNORM-matrix-based-on-CSV-file-values-for-MEAN-and-SD-tp4630901p4630928.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] In R, how do I execute a script that sets environment variables within the same shell session?
In R, how do I execute a script that sets environment variables within the same shell session? Hi all, Could you please shed some lights on how to do this? In a shell, I launched the R session. But then in R, I realized that some environment variables need to be set up. Of course I can use Sys.setenv()... But I have so many of them... And for some special reason, I have to first launch R and then run the script from within R to set up the environment variables... i.e. I cannot do the other way around, which is first execute the script in the shell, and then launch the R session(which is the usual sequenc of ordering)... So my question is: I have to launch R session first, and then run the scrip from within R. But if I naively use shell or system, that's going to not affect the same shell that the R is using... I would like the R session to be able to access those global environment variables... How do I do that? Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Could incomplete final line found be more serious than a warning?
(Original below) Looks like someone had the bright idea of changing it to 16-bit UTF, so every 2nd byte is NUL. It works for me with x - readLines(file(~/Downloads/WoS-new.txt, encoding=UTF-16)) (except that for some reason, x won't print properly although each individual line prints fine. Never mind, who cares as long as it reads...) -pd PS: The reason the printing is wacky is that one line has 148934 characters in it and the print routines pad all lines to the maximum length. Not sure what the point is in that. On May 22, 2012, at 18:26 , Michael Bärtl wrote: Dear all, I've been successfully reading Web of Science-data from tab-delimited text files into a data.frame using an R-script based on readLines(). With new data I just downloaded I suddenly get this warning: incomplete final line found I know this warning has already been discussed numerous times but none of the previously suggested solutions worked for me, unfortunately; so please bear with me: I shut the warning down using warn = FALSE, but the data still won't get read so this seems to be more serious than a warning. Adding a blank line or two at the end of the file did NOT help, i.e. R still does not read the file. But my old files still work properly, though. So I opened the text files using Notepad++ and saw that the last lines of both old text files (i.e. working) as well as new text files (i.e. the ones that don't work for some reason) always end with a tab stop followed by a line break. Personally I couldn't tell any difference between the ways these files ended. Their endings looked identical to me. I was using R 2.14.0 (64 bit) on Windows when I dioscovered the problem. So I upgraded to 2.15.0 (64-bit) but the problem persists. You can see small examples of an old and new file at https://www.dropbox.com/s/2joadjo9ce86rij/WoS-old.txt and https://www.dropbox.com/s/lp9l1exx4mfws1s/WoS-new.txt, respectively. Does anybody happen to have an idea of what could cause these problems for me? Thank you very much for your consideration! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package grid: mirror grob objects along an axis
Maybe my question was not concise enough. I was referring to objects created with the package grid (also called grobs), not to the function grid from package graphics. For instance, let's say I have a polygon createad with grid::polygonGrob and want to mirror it along a specified axis. Of course one could transform the polygon's coordinates, but I was hoping that there is some more generic way of doing this (and that this could e.g. also be done with text grobs). Cheers /thomas On Tuesday 22 May 2012, Rui Barradas wrote: Hello, Just flip 'xlim' or 'ylim'. Or both. Using the iris example in help(grid), make the following changes: op - par(mfcol = c(2,2)) # Two columns, first is the original, second flipped. with(iris, [... etc ...] # row 1, col 2: flip x axis plot(Sepal.Length, Sepal.Width, col = as.integer(Species), xlim = c(8, 4), ylim = c(2, 4.5), panel.first = grid(), main = with(iris, plot(, panel.first = grid(), ..) )) # row 2, col 2: flip y axis plot(Sepal.Length, Sepal.Width, col = as.integer(Species), xlim = c(4, 8), ylim = c(4.5, 2), panel.first = grid(3, lty=1,lwd=2), main = ... panel.first = grid(3, lty=1,lwd=2), ..) [... etc ...] ) par(op) Hope this helps, Rui Barradas Thomas Zumbrunn-3 wrote Hi everyone I'd like to flip grobs (grid graphical objects) along an axis, e.g. flip grobs horizontally or vertically. I couldn't find any hints, neither in the documentation nor by searching the web. Does anybody know how to achieve this? Cheers /thomas __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/package-grid-mirror-grob-objects-along-an-ax is-tp4630866p4630870.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. -- Thomas Zumbrunn, PhD Clinical Trial Unit (CTU) Universitätsspital Basel Schanzenstr. 55, CH-4031 Basel Tel +41 (0)61 556 52 92 Fax +41 (0)61 265 94 10 http://www.clinicaltrialunit.ch/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 remove the 'promise' attribute of an R object (.Random.seed)?
On Tue, 22 May 2012, Yihui Xie wrote: Hi, The problem arises when I lazyLoad() the .Random.seed from a previously saved database. To simplify the process of reproducing the problem, see the example below: ## this assignment may not really make sense, but illustrates the problem delayedAssign('.Random.seed', 1L) typeof(.Random.seed) # [1] integer rnorm(1) # Error in rnorm(1) : # .Random.seed is not an integer vector but of type 'promise' typeof(.Random.seed) # [1] integer So there must be an attribute promise somewhere attached to .Random.seed, and I cannot find it. The R function typeof() does not reveal it, but the TYPEOF() function in src/main/RNG.c says it is a 'promise'. My question is, how to make R use the real value of .Random.seed instead of complaining about the promise? Thanks! Siple answer: Don't creat the promise in the first place, i.e. don't use delayedAssign. What is the real context where this arises? Knowing that may help us decide whether the internals should address this possibility. Best, luke Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tier...@uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 save EVERYTHING in R?
Is there a way to save EVERYTHING in R? Hi all, Could you please shed some lights on me about this? I am trying to see if there is a way to save EVERYTHING in R to a file, something like save.image... But save.image doesn't save environment variables such as those properties that are obtained using Sys.getenv() function... So is there a way to save EVERYTHING? Thanks a lot! [[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] Adding Text to a Plot
On 2012-05-22 07:51, David Winsemius wrote: On May 22, 2012, at 9:10 AM, Canto Casasola, Vicente David wrote: I'm pretty sure I'm missing something about this. Is there a smart way of typping hat(R)^2 and it's value from a linear regression? I've just found this tricky one: # Sample data x- sample(1:100,10) y- 2+3*x+rnorm(10) # Run the regression lm1- lm(y~x) # Plotting plot(x,y, main=Linear Regression, col=red) abline(lm1, col=blue) placex- par(usr)[1]+.1*(par(usr)[2]-par(usr)[1]) placey1- par(usr)[3]+.9*(par(usr)[4]-par(usr)[3]) placey2- par(usr)[3]+.8*(par(usr)[4]-par(usr)[3]) # HERE: Is this the right way? # To do what? I see that you over-plotted the R, presumably because you did not like the way that: bquote(hat(R)^2 == .(summary(lm1)$adj.r.squared)) ... ended up looking (with the exponent higher than in the non-hatted version.) text(x=placex, y=placey1, bquote(R^2 == .(summary(lm1)$r.squared)), adj=c(0,0)) text(x=placex, y=placey2, bquote(R^2 == .(summary(lm1)$adj.r.squared)), adj=c(0,0)) text(x=placex,y=placey2, expression(hat(R)), adj=c(0,0)) In addition, when I save the plot as PDF, the expression hat(R) seems to be somewhat displaced. Any advice? Are you sure? It looks to me that the lower R is slightly shifted to the left, but when I actually measure it, there does not appear to be a shift. If it is real and not just an optical illusion, this may have something to do with your unstated version of R or your also unstated OS. I don't see any shift either (Windows), easily checked with insert of an appropriate vertical line, but I would recommend not overwriting the 'R' by using the phantom() construct: text(x=placex, y=placey2, bquote(phantom(R)^2 == .(summary(lm1)$adj.r.squared)), adj=c(0,0)) text(x=placex, y=placey2, expression(hat(R)), adj=c(0,0)) Peter Ehlers -- 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] Naming dimnames in an array using the results of an expression
dear all i'm struggling with naming in an array diag.data is one of a series of 2x2 diagnostic testing arrays, with 'Outcome' columns (true/false) and 'Test' rows (High-risk, Low-risk), drawn from a larger list object of 'results' i can hard-code the names of the array using dimnames; diag.data-array(c(19,2,125,50),c(2,2)) #example to run - actually comes out with rownames/colnames already attached dimnames(diag.data)-list(Rule=c(LR,HR),Outcome=c(FALSE,TRUE)) but i would really love to be able to soft-code it, using the different 'rule' names and slightly different 'outcomes' as extracted from the main list of results, rather than just 'rule' and 'outcome' e.g. dimnames(diag.data)-list(names(result[1])=rownames(diag.data),names(result[[1]][2])=colnames(diag.data)) this doesn't work i understand that the dimnames command is NOT executing the function 'names' and giving me the result of this, and have struggled and failed to use the 'eval' expression with alternative environments (which i don't understand ...) can anyone assist? cheers - bob -- Dr Bob Phillips MRC Research Training Fellow CRD University of York York YO10 5DD t: +44 (0)1904 321099 f: +44 (0)1904 321041 e: bob.phill...@york.ac.uk www.york.ac.uk/inst/crd www.crd.york.ac.uk/prospero CRD is part of the National Institute for Health Research and is a department of the University of York. EMAIL DISCLAIMER: http://www.york.ac.uk/docs/disclaimer/email.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Could incomplete final line found be more serious than a warning?
If you look at the new file in raw mode, you'll see that it's chock full of ASCII nuls, while the old file has none. This is probably what's giving you the problems, because R does not allow strings containing embedded nul characters. (I believe this is because Nul in strings is pretty dangerous in programming, because they are often used to delimit the end of strings, and so allowing you to read it in directly can be used for various code injection exploits.) To read the new data files, you need some way of dealing with the file as a raw stream, and stripping out all the nul characters before converting back to character. Investigate ?readBin... Zhou -- View this message in context: http://r.789695.n4.nabble.com/Could-incomplete-final-line-found-be-more-serious-than-a-warning-tp4630932p4630944.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating functions with a loop.
Michael's method seems to be working but I still can't get to wrap it in a loop since I cannot get the loop to dynamically change the functions' name, i.e. ff1, ff2, ff3, ... In other words, I would need the first iteration to create the function ff1, the second to create the function ff2, ... Furthermore, does anyone know of a way to call said functions from a loop in a way that the first step of the loop calls ff1, the second calls ff2 and so on? The 2 problems should be closely related I think. Thanks for the time -- View this message in context: http://r.789695.n4.nabble.com/Creating-functions-with-a-loop-tp4630896p4630938.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] scatterplot x axis specifications
I have created a scatter plot that has come out okay but I am having trouble with the x axis. My data consists of 4 treatments but these treatments are days so R keeps reading them as numeric and making my x axis continuous. Here is what I have so far: plot(pair$MC~pair$Day, pch=c(19,24)[as.factor(Cookie)], main='Paired t Test', xlab='Days in Field', ylab='Moisture Content (Percent)') I have also done: as.factor(Day) to change it to 4 levels and when I do is.factor(Day) it returns with FALSE. I'm assuming this is the reason that I get the message that my x and y lengths differ when trying to convert my x axis using: axis(side=1, at=c(0,15,30,45) When I switch my numbers to words (i.e. zero, fifteen...) it only brings up a boxplot and I specifically want the points so I can assign different pch by group. Am I totally missing something here? -- View this message in context: http://r.789695.n4.nabble.com/scatterplot-x-axis-specifications-tp4630952.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] Is there a way to save EVERYTHING in R?
On 22.05.2012 19:50, Michael wrote: Is there a way to save EVERYTHING in R? Hi all, Could you please shed some lights on me about this? I am trying to see if there is a way to save EVERYTHING in R to a file, something like save.image... But save.image doesn't save environment variables such as those properties that are obtained using Sys.getenv() function... So is there a way to save EVERYTHING? Well, the answer is yes, but not as you expect: If you have a virtual machine running only accessing a local filesystem, you can create a snapshot. So, for other practical purposes and in the sense but not wording of you question: No, environment variables are part of the OS (or the shell). If you want to save EVERYTHING this way, you'd need an image of both, the RAM of you machine as well as the current state of all filesystems etc. Best, Uwe Ligges Thanks a lot! [[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] Is there a way to save EVERYTHING in R?
Hi Michael, check ?save Regards, Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ From: Michael comtech@gmail.com To: r-help r-h...@stat.math.ethz.ch Sent: Tuesday, May 22, 2012 7:50 PM Subject: [R] Is there a way to save EVERYTHING in R? Is there a way to save EVERYTHING in R? Hi all, Could you please shed some lights on me about this? I am trying to see if there is a way to save EVERYTHING in R to a file, something like save.image... But save.image doesn't save environment variables such as those properties that are obtained using Sys.getenv() function... So is there a way to save EVERYTHING? Thanks a lot! [[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] scatterplot x axis specifications
On 22.05.2012 19:59, jhartsho wrote: I have created a scatter plot that has come out okay but I am having trouble with the x axis. My data consists of 4 treatments but these treatments are days so R keeps reading them as numeric and making my x axis continuous. Here is what I have so far: plot(pair$MC~pair$Day, pch=c(19,24)[as.factor(Cookie)], main='Paired t Test', xlab='Days in Field', ylab='Moisture Content (Percent)') I have also done: as.factor(Day) to change it to 4 levels and when I do is.factor(Day) it returns with FALSE. I'm assuming this is the reason that I get the message that my x and y lengths differ when trying to convert my x axis using: axis(side=1, at=c(0,15,30,45) When I switch my numbers to words (i.e. zero, fifteen...) it only brings up a boxplot and I specifically want the points so I can assign different pch by group. Am I totally missing something here? Yes, missing a reproducible example so that we could easily show how it works. Best, Uwe Ligges -- View this message in context: http://r.789695.n4.nabble.com/scatterplot-x-axis-specifications-tp4630952.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 to evaluate R things from Visual Studio?
Sorry, I have no solution for your problem, but a comment; see inline below. On 2012-05-22 08:02, Giannis Mamalikidis wrote: Hello all, I’m new here and this is actually my very first post. My name is Giannis and I am an undergraduate student. I am programming in Microsoft’s Visual Studio 2010 (VB.NET mostly) and I want to create a program for the research group I am in. I merely want to evaluate actions and use simple statistical things such as ks test (Kolmogorov-Smirnov), and some plots. The reason I need to call R from my program is that the users of my program will NOT know any programming language, and by extension they will not know R either. So everything will happen by the click of a button. For me to do that, I need to be able to use interoperability between R and VS.NET 2010, so that I can use R’s evaluator. I’ve already tried Baier’s StatConnDCOM (http://rcom.univie.ac.at) and I did succeed in creating a program that runs perfectly but came to see the hard way that – for my case, is kind of useless for the sole reason of StatconnDCOM’s redistribution restriction. As Mr. Baier told me himself, there is no guarantee that StatconnDCOM will be available free of charge for ever. Hence I cannot create a freeware program now, and have my users uncertain of where they will be able to use this program for free in the future. I’ve already tried R.NET (http://rdotnet.codeplex.com/ ) Version 1.4 (stable) and 1.4.1 (Change Set: 6d2c3f161801 ). This does seem wonderful and it doesn’t have StaconnDCOM’s ridiculous restrictions, BUT it refuses to work on me! So, now that you have all the necessary background info, it is time I presented my questions: 1) Is there another way of using R from Visual Studio that you can point me to? 2) Is anyone here using R.NET (any version) successfully? If so, can you help me to get it working? Unfortunately they can’t help me on R.NET’s official discussion forum I mean, I just need to evaluate the basic R stuff.. Why is it THAT difficult? This appears to imply that you consider it to be R's fault that you can't easily interface it with Visual Studio. Isn't that rather the fault of VS? If VS were open source, as R is, you could probably find an easy solution yourself. If you don't get a solution from one of those much more knowledgeable than I, perhaps you might contact Microsoft. Peter Ehlers Last but not least, let me give you info that might be relevant in your deciding how to aid me. OS: Windows 7 Professional x64 English (Genuine, it is purchased) R: Version 2.15.0 Programming Environment: Microsoft Visual Studio .net 2010 For any additional Info, please do not hesitate to ask me either here or directly at giannis_mamaliki...@msn.com I hope we can make this work. thanks in advance. [[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] pad leading zeros in front of strings
Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD [[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] Is there an inverse function of Sys.getenv()
Using Sys.getenv(), I got a list of 380 environment variables... Now I open a new R session, how do I set those environment variables in my new R session using Sys.setenv()? There is no batch function for Sys.setenv()? Is there an import/export environment variables function? Basically I want to export all the environment variables from one R session and import them into another R session... Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] pad leading zeros in front of strings
I think once upon a time this was found to be OS-dependent since it calls the system's C sprintf() -- I get the leading zeros on Mac. I presume you're on Windows? Michael On Tue, May 22, 2012 at 2:41 PM, Hui Du hui...@dataventures.com wrote: Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD [[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] pad leading zeros in front of strings
Hi, I think it's because is used to pad strings, while 0 is used to pad numbers*. If your values are always numeric, but stored as strings, you could use: x - 123 sprintf(%05d, as.numeric(x)) [1] 00123 * From ?sprintf: ‘0’ For numbers, pad to the field width with leading zeros. I think some language implementations allow for specifying different pad characters, but R's doesn't seem to. Sarah On Tue, May 22, 2012 at 2:41 PM, Hui Du hui...@dataventures.com wrote: Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD -- 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] pad leading zeros in front of strings
Please do reply to the list -- I'm not on Windows so someone else will have to pick the question up to help you out. It's not great, but you could do something like zeroPad - function(str, len.out, num.zeros = len.out[1] - nchar(str)){ paste0(paste(rep(0, num.zeros), collapse = ), str) } as a temporary work-around. Probably possible to vectorize that pretty easily as well. Best, Michael On Tue, May 22, 2012 at 2:50 PM, Hui Du hui...@dataventures.com wrote: Thank you for your replay. Yes, I am on windows. Best Regards, Hui Du Data Ventures Inc -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Tuesday, May 22, 2012 11:49 AM To: Hui Du Cc: r-help@r-project.org Subject: Re: [R] pad leading zeros in front of strings I think once upon a time this was found to be OS-dependent since it calls the system's C sprintf() -- I get the leading zeros on Mac. I presume you're on Windows? Michael On Tue, May 22, 2012 at 2:41 PM, Hui Du hui...@dataventures.com wrote: Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD [[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] pad leading zeros in front of strings
Michael, I'm curious: if you pass sprintf() a string, it still pads with zeros? What's the output of: sprintf(%05s, 123) sprintf(%05s, abc) On linux, sprintf() pads strings with spaces, as you'd expect. Padding strings with zeros is... odd. Sarah sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-redhat-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.0 On Tue, May 22, 2012 at 2:49 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I think once upon a time this was found to be OS-dependent since it calls the system's C sprintf() -- I get the leading zeros on Mac. I presume you're on Windows? Michael On Tue, May 22, 2012 at 2:41 PM, Hui Du hui...@dataventures.com wrote: Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD -- 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] pad leading zeros in front of strings
I get 00123 and 00abc respectively. Agreed it's perhaps odd, but c'est la OS. M On Tue, May 22, 2012 at 2:57 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Michael, I'm curious: if you pass sprintf() a string, it still pads with zeros? What's the output of: sprintf(%05s, 123) sprintf(%05s, abc) On linux, sprintf() pads strings with spaces, as you'd expect. Padding strings with zeros is... odd. Sarah sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-redhat-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.0 On Tue, May 22, 2012 at 2:49 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I think once upon a time this was found to be OS-dependent since it calls the system's C sprintf() -- I get the leading zeros on Mac. I presume you're on Windows? Michael On Tue, May 22, 2012 at 2:41 PM, Hui Du hui...@dataventures.com wrote: Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD -- 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] pad leading zeros in front of strings
Thanks all. I am trying to cleaning up user-inputted zip code. Most of them are pure numeric values but someone put characters in zipcode field, so I have to treat that field as a string rather than number. HXD -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Tuesday, May 22, 2012 12:00 PM To: Sarah Goslee Cc: Hui Du; r-help@r-project.org Subject: Re: [R] pad leading zeros in front of strings I get 00123 and 00abc respectively. Agreed it's perhaps odd, but c'est la OS. M On Tue, May 22, 2012 at 2:57 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Michael, I'm curious: if you pass sprintf() a string, it still pads with zeros? What's the output of: sprintf(%05s, 123) sprintf(%05s, abc) On linux, sprintf() pads strings with spaces, as you'd expect. Padding strings with zeros is... odd. Sarah sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-redhat-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.15.0 On Tue, May 22, 2012 at 2:49 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I think once upon a time this was found to be OS-dependent since it calls the system's C sprintf() -- I get the leading zeros on Mac. I presume you're on Windows? Michael On Tue, May 22, 2012 at 2:41 PM, Hui Du hui...@dataventures.com wrote: Dear All, This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, 123 becomes 00123. What is wrong if I do following? sprintf(%05s, 123) [1] 123 It didn't return 00123, instead it padded with 'blank'. Thank you for your help in advance. HXD -- 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.
[R] Working directory
I am not experienced at R but have searched the manuals. . . . I have tried placing a setwd command in the Rprofile.site and Rprofile files. But it does not seem to work. It always reverts to a particular directory I have been using (saved in workspace image?) for a while. However, I can print out text from thr Rprofile files! Could this be an issue with confilcts between my workspace/ session and my startup files? I am running R version 2.13.1 on Windows 7. Thanks, Alan [[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] scatterplot x axis specifications
Bolt Day CookieMC 1 MCA01 0 Bottom 60.28 2 MCB01 0 Bottom 83.63 3 MCC01 0 Bottom 48.34 4 MCB02 0 Bottom 84.52 5 MCA05 0 Bottom 74.92 6 MCA01 0Top 65.35 7 MCB01 0Top 88.68 8 MCC01 0Top 29.19 9 MCB02 0Top 82.63 10 MCA05 0Top 77.61 MC151 15 Bottom 63.92 12 MC152 15 Bottom 68.24 13 MC153 15 Bottom 63.42 14 MC154 15 Bottom 43.15 15 MC155 15 Bottom 52.04 16 MC151 15Top 53.39 17 MC152 15Top 55.45 18 MC153 15Top 56.24 19 MC154 15Top 53.52 20 MC155 15Top 42.83 This is a small subset of my data. plot(pair$MC~pair$Day, pch=c(19,24)[as.factor(Cookie)], xaxt=n, main='Paired t Test', xlab='Days in Field', ylab='Moisture Content (Percent)') Gives me the plot I need minus the x axis. Adding axis(1, at=0,15,30,45) or using a sequence of axis(1, at=seq(0,45,15)) gives me either x and y are different lengths or plot.new has not been called yet. Everything else is perfect. -- View this message in context: http://r.789695.n4.nabble.com/scatterplot-x-axis-specifications-tp4630952p4630961.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.