[R] Odp: Finding pairs
Hi without other details it is probably impossible to give you any reasonable advice. Do you have your data already in R? What is their form? Are they in 2 columns in data frame? How did you get them paired? So without some more information probably nobody will invest his time as it seems no trivial to me. Regards Petr r-help-boun...@r-project.org napsal dne 24.08.2010 20:28:42: > > > > > Dear R Helpers, > > > I am a newbie and recently got introduced to R. I have a large database > containing the names of bank branch offices along-with other details. I am > into Operational Risk as envisaged by BASEL II Accord. > > > I am trying to express my problem and I am using only an indicative data which > comes in coded format. > > > > > A (branch) B (controlled by) > > > 144 > 145 > 146 > 147 144 > 148 145 > 149 147 > 151 146 > .. ... > > .. ... > > > where 144's etc are branch codes in a given city and B is subset of A. > > > > > If a branch code appearing in "A" also appears in "B" (which is paired with > some otehr element of A e.g. 144 appearing in A, also appears in "B" and is > paired with 147 of "A" and likewise), then that means 144 is controlling > operations of bank office 147. Again, 147 itself appears again in B and is > paired with bank branch coded 149. Thus, 149 is controlled by 147 and 147 is > controlled by 144. Likewise there are more than 700 hundred branch name codes available. > > > My objective is to group them as follows - > > > Bank Branch > > > 144 147149 > > > 145 > > > 146 151 > > > 148 > . > > > or even the following output will do. > > > 144 > 147 > 149 > > > 145 > > > 146 > 151 > > > 148 > 151 > .. > > > I understand I should be writing some R code to begin with which I had tried > also but as of now I am helpless. Please guide me. > > > Mike > > > > > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot bar lines like excel
Thanks a lot for the nice explanation. however, you mention that it will be nicer if there is data. yes you are right it be very kind of you if you include a simple example. where my data are: x1<-c(11.5,9.38,9.3,9.8,9,9.06,9.42,8.8,9.05,8.14,8.2,7.59,6.92,6.47,7.12, 7.47,6.81,8.41,9.64,9.62,9.2,8.92,8,7.6,7.6,7.19,6.94,6.91,7,7.25,6.6,7.18,7.78, 7.37,7.29,6.71,7.05,6.69,6.05,6.38,6.18,7.67,7.34,7.13,6.95,6.8,6.45,6.81,6.27,6.35) x2<-c(11.5,8.959535,9.728104,9.609262,8.755494,9.221545,8.244458,7.63944,7.92052,7.690449,7.853247, 7.239616,6.609007,5.92946,6.47822,5.906936,6.966004,8.630517,9.506582,9.57479,9.236638,9.581875,8.838992,8.368731,8.608884,7.998023,7.918123,7.832322,7.930177,7.479222,6.866978,7.454062,8.206185,7.344037,7.059774,6.547646,7.005803,6.623987,5.992691,6.313481,6.194613,6.224266,7.084932,6.568976,6.43866,5.70081,6.7593,6.6929,6.46806,5.964816) regards, -- View this message in context: http://r.789695.n4.nabble.com/Plot-bar-lines-like-excel-tp2337089p2337394.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] modify a nomogram
Hi, I would like to emphasize ("zoom") the zone of a nomogram where the probability are > 0.01 (nomogram built with nomogram, Design). As a consequence, I don't need to draw the part of the "Total points" axis with score < 60 equivalent in my case to a linear predictor < 4.5 - As far as I know, this is not possible with the arguments of the function. - Changing the code of the function is beyond my abilities -- can not even create a "nomo.f" function with the same body: body(nomo) <- expression({ conf.lp <- match.arg(conf.lp) . rest of the function body this does not even work -- I am not sure to find the piece of code responsible for defining the axis nomogram(logistic.fit, fun = plogis, fun.at = c(seq(0.01,1,by=.2)), lmgp=.2, lp = T,maxscale = 100, total.sep.page = T ) Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Removing inter-bar spaces in barchart
Rhelpers: I'm trying to make a barchart of a 2-group dataset (barchart(x~y,data=data,groups=z,horizontal=FALSE)). My problem is that I can't, for the life of me, seem to get rid of the inter-bar space -- box.ratio set to 1 doesn't do much. Any ideas? I'd ideally want zero space between the bars. Thanks! --j -- Jonathan A. Greenberg, PhD Assistant Project Scientist Center for Spatial Technologies and Remote Sensing (CSTARS) Department of Land, Air and Water Resources University of California, Davis One Shields Avenue Davis, CA 95616 Phone: 415-763-5476 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Documenting S4 Methods
I'm in the process of converting some S3 methods to S4 methods. I have this function : setGeneric("enrichmentCalc", function(rs, organism, seqLen, ...){standardGeneric("enrichmentCalc")}) setMethod("enrichmentCalc", c("GenomeDataList", "BSgenome"), function(rs, organism, seqLen, ...) { ... ... ... }) setMethod("enrichmentCalc", c("GenomeData", "BSgenome"), function(rs, organism, seqLen=NULL, do.warn=FALSE) { ...... ... }) setMethod("enrichmentCalc", c("GRanges", "BSgenome"), function(rs, organism, seqLen=NULL) { ...... ... } and a part of my Rd file is : \name{enrichmentCalc} \docType{methods} \alias{enrichmentCalc,GenomeDataList,BSgenome-method} \alias{enrichmentCalc,GenomeData,BSgenome-method} \alias{enrichmentCalc,GRanges,BSgenome-method} ...... ... \usage{ enrichmentCalc(rs, organism, seqLen, ...) enrichmentCalc(rs, organism, seqLen=NULL, do.warn=FALSE) enrichmentCalc(rs, organism, seqLen=NULL) } ......... Can anyone suggest why I'm seeing this error : * checking for code/documentation mismatches ... WARNING Codoc mismatches from documentation object 'enrichmentCalc': enrichmentCalc Code: function(rs, organism, seqLen, ...) Docs: function(rs, organism, seqLen = NULL, do.warn = FALSE) Argument names in code not in docs: ... Argument names in docs not in code: do.warn Mismatches in argument names: Position: 4 Code: ... Docs: do.warn Mismatches in argument default values: Name: 'seqLen' Code: Docs: NULL enrichmentCalc Code: function(rs, organism, seqLen, ...) Docs: function(rs, organism, seqLen = NULL) Argument names in code not in docs: ... Mismatches in argument default values: Name: 'seqLen' Code: Docs: NULL * checking Rd \usage sections ... WARNING Objects in \usage without \alias in documentation object 'enrichmentCalc': enrichmentCalc Also, what is the difference between ... ... ... \docType{methods} ... ... ... \alias{methodName,class-method} ... ... ... \usage{methodName(arg1)} ... ... ... and ... ... ... \alias{methodName,class-method} ... ... ... \usage { \S4method{methodName}{class}(arg1) } ... ... ... I've seen both ways used for S4 methods and don't know what is the underlying difference. I haven't been able to find any good tutorials for the new S4 architecture (written post 2006), so I'm not sure where to start with S4. Thanks, Dario. -- Dario Strbenac Research Assistant Cancer Epigenetics Garvan Institute of Medical Research Darlinghurst NSW 2010 Australia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 all objects except a few specified objects?
Thanks Josh and Karl. function dnrm() works well for my purpose. -- View this message in context: http://r.789695.n4.nabble.com/How-to-remove-all-objects-except-a-few-specified-objects-tp2335651p2337398.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 do R calculates the number of intervals between tick-marks
Hello, I want to know how do R calculates the number of intervals between tick-marks in the y axis in a plot. I'm making a three y-axes plot and this information would help me a lot. Thanks in advance. Antonio Olinto Webmail - iBCMG Internet http://www.ibcmg.com.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 rows based on frequency of factor and then difference date scores
Many thanks to you both. I have now filed away for future reference the 2 factor tapply as well as the extremely useful looking plyr library. And the code worked beautifully :-) On 24 Aug 2010, at 19:47, "Abhijit Dasgupta, PhD" wrote: > The paste-y argument is my usual trick in these situations. I forget that > tapply can take multiple ordering arguments :) > > Abhijit > > On 08/24/2010 02:17 PM, David Winsemius wrote: >> >> On Aug 24, 2010, at 1:59 PM, Abhijit Dasgupta, PhD wrote: >> >>> The only problem with this is that Chris's unique individuals are a >>> combination of Type and ID, as I understand it. So Type=A, ID=1 is a >>> different individual from Type=B,ID=1. So we need to create a unique >>> identifier per person, simplistically by uniqueID=paste(Type, ID, sep=''). >>> Then, using this new identifier, everything follows. >> >> I see your point. I agree that a tapply method should present both factors >> in the indices argument. >> >> > new.df <- txt.df[ -which( txt.df$nn <=1), ] >> > new.df <- new.df[ with(new.df, order(Type, ID) ), ] # and possibly needs >> > to be ordered? >> > new.df$diffdays <- unlist( tapply(new.df$dt2, list(new.df$ID, >> > new.df$Type), function(x) x[1] -x) ) >> > new.df >> Type ID Date Valuedt2 nn diffdays >> 1A 1 16/09/2020 8 2020-09-16 30 >> 2A 1 23/09/2010 9 2010-09-23 3 3646 >> 4B 1 13/5/2010 6 2010-05-13 30 >> >> But do not agree that you need, in this case at least, to create a paste()-y >> index. Agreed, however, such a construction can be useful in other >> situations. >> > > > -- > > Abhijit Dasgupta, PhD > Director and Principal Statistician > ARAASTAT > Ph: 301.385.3067 > E: adasgu...@araastat.com > W: http://www.araastat.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] degree C symbol in a function
Thanks for the advice, problem solved. -daisy On Wed, Aug 25, 2010 at 1:35 PM, David Winsemius wrote: > > On Aug 24, 2010, at 10:45 PM, Daisy Englert Duursma wrote: > >> Hello help, >> >> I have changed around some graphing code and made it into a function. >> Previously they y label of the axis was inserted as text in its own >> layout box. >> >> text(1,1, expression(~degree~C),cex=1) >> >> This worked great and resulted in the symbol for degree. >> >> In the function, I have changed it so: >> >> text(1,1,paste(b_unit),cex=1) >> >> and >> >> b_unit<-expression(~degree~C) > > With the other suggestions regarding dropping paste ... it would look better > as: > > b_unit<-expression(~degree*C) # imo, of course > >> >> This now inserts ~degree~C instead of the symbol. >> >> >> Any advice? > > Well, you asked of "any" advice. > > -- > > David Winsemius, MD > West Hartford, CT > > -- Daisy Englert Duursma Room E8C156 Dept. Biological Sciences Macquarie University NSW 2109 Australia Tel +61 2 9850 9256 10A Carrington Rd Hornsby, NSW 2077 Mobile: 0421858456 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rotate x-axis label on log scale
On Aug 24, 2010, at 11:37 PM, Tim Elwell-Sutton wrote: Hi Jim Thanks for this. The staxlab function seems very useful. Unfortunately, the rotation option doesn't seem to work for me when the y-axis is on a log scale. What part of: "If srt is not NA, the labels will be rotated srt degrees and placed below the plot. This method will only place labels at the bottom." ... is unclear? You did say you wanted the rotation to be on the x- axis, did you not? You could, of course, look at Lemon's code and hack it to do the y-axis: else { xylim <- par("usr") ypos <- xylim[3] - ticklen * (xylim[4] - xylim[3]) par(xpd = TRUE) text(at, ypos, labels, srt = srt, adj = 1, ...) par(xpd = FALSE) } -- david. "It will stagger the labels but not rotate them. There's no error message. On a linear axis the rotation works nicely. Any ideas? The example below works if you omit log='y' or srt=45 Thanks very much Tim #Create plot with log-scale on the y-axis par(mar = c(7, 4, 4, 2) + 0.1) plot(1, type='n', bty='n', xlab="", ylab='Odds Ratio', xlim= c(0.5,4.5), ylim= c(0.75, 2), cex=2, xaxt='n', yaxt='n', cex.lab=1.3, log='y') #Estimates and confidence intervals points(c(1:4),c(1.1,1.32,1.14,1.36), pch=17, cex=1.5, col='blue') segments (c(1:4),c(0.93,1.11,0.94,1.15),c(1:4),c(1.3,1.58,1.37,1.61), col='blue', lwd=2) #Add x- and y-axes axis(1,c(1:4), labels= F) axis(2, at=seq(0.75,2, by=0.25), labels=seq(0.75,2, by=0.25), las=1) # Add x-axis labels labels <- paste("Label", 1:4, sep = " ") staxlab(side=1, at=1:4, labels, srt=45) -Original Message- From: Jim Lemon [mailto:j...@bitwrit.com.au] Sent: Tuesday, August 24, 2010 7:48 PM To: tesutton Cc: r-help@r-project.org Subject: Re: [R] Rotate x-axis label on log scale On 08/24/2010 11:44 AM, Tim Elwell-Sutton wrote: Hi I'd appreciate some help with plotting odds ratios. I want to rotate the labels on the x-axis by 45 degrees. The usual way of doing this, using text - e.g. text(1, par('usr')[3]-2.25..) - gives no result when the y-axis is a log scale. I guess this is because, as the par help says, for a logarithmic y- axis: y-limits will be 10 ^ par("usr")[3:4] Hi Tim, If you know where to put the labels, try: library(plotrix) staxlab(1,at=...,labels=...,srt=45) Jim -- 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] Rotate x-axis label on log scale
Hi Jim Thanks for this. The staxlab function seems very useful. Unfortunately, the rotation option doesn't seem to work for me when the y-axis is on a log scale. It will stagger the labels but not rotate them. There's no error message. On a linear axis the rotation works nicely. Any ideas? The example below works if you omit log='y' or srt=45 Thanks very much Tim #Create plot with log-scale on the y-axis par(mar = c(7, 4, 4, 2) + 0.1) plot(1, type='n', bty='n', xlab="", ylab='Odds Ratio', xlim= c(0.5,4.5), ylim= c(0.75, 2), cex=2, xaxt='n', yaxt='n', cex.lab=1.3, log='y') #Estimates and confidence intervals points(c(1:4),c(1.1,1.32,1.14,1.36), pch=17, cex=1.5, col='blue') segments (c(1:4),c(0.93,1.11,0.94,1.15),c(1:4),c(1.3,1.58,1.37,1.61), col='blue', lwd=2) #Add x- and y-axes axis(1,c(1:4), labels= F) axis(2, at=seq(0.75,2, by=0.25), labels=seq(0.75,2, by=0.25), las=1) # Add x-axis labels labels <- paste("Label", 1:4, sep = " ") staxlab(side=1, at=1:4, labels, srt=45) -Original Message- From: Jim Lemon [mailto:j...@bitwrit.com.au] Sent: Tuesday, August 24, 2010 7:48 PM To: tesutton Cc: r-help@r-project.org Subject: Re: [R] Rotate x-axis label on log scale On 08/24/2010 11:44 AM, Tim Elwell-Sutton wrote: > Hi > > I'd appreciate some help with plotting odds ratios. I want to rotate the > labels on the x-axis by 45 degrees. > > The usual way of doing this, using text - e.g. text(1, par('usr')[3]-2.25..) > - gives no result when the y-axis is a log scale. > > I guess this is because, as the par help says, for a logarithmic y-axis: > y-limits will be 10 ^ par("usr")[3:4] > Hi Tim, If you know where to put the labels, try: library(plotrix) staxlab(1,at=...,labels=...,srt=45) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] degree C symbol in a function
On Aug 24, 2010, at 10:45 PM, Daisy Englert Duursma wrote: Hello help, I have changed around some graphing code and made it into a function. Previously they y label of the axis was inserted as text in its own layout box. text(1,1, expression(~degree~C),cex=1) This worked great and resulted in the symbol for degree. In the function, I have changed it so: text(1,1,paste(b_unit),cex=1) and b_unit<-expression(~degree~C) With the other suggestions regarding dropping paste ... it would look better as: b_unit<-expression(~degree*C) # imo, of course This now inserts ~degree~C instead of the symbol. Any advice? Well, you asked of "any" advice. -- 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] Parsing a XML file
xmlDoc() is not the function to use to parse a file. Use doc = xmlParse("Malaria_Grave.xml") xmlDoc() is for programmatically creating a new XML within R. It could be more robust to being called with a string, but the key thing here is that it is not the appropriate function for what you want. Also, if there had been a problem with the parsing, you'd need to give me/us the offending XML file so that we could have a chance of reproducing the problem. D. On 8/24/10 2:35 PM, Orvalho Augusto wrote: > I have one XML file with 30MB that I need to read the data. > > I try this; > library(XML) > doc <- xmlDoc("Malaria_Grave.xml") > > And R answers like this > *** caught segfault *** > address 0x5, cause 'memory not mapped' > > Traceback: > 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") > 2: xmlDoc("Malaria_Grave.xml") > > Possible actions: > 1: abort (with core dump, if enabled) > 2: normal R exit > 3: exit R without saving workspace > 4: exit R saving workspace > > > Or I try this: > doc <- xmlTreeParse("Malaria_Grave.xml") > > I get this > xmlParseEntityRef: no name > xmlParseEntityRef: no name > Error: 1: xmlParseEntityRef: no name > 2: xmlParseEntityRef: no name > > Please guys help this simple mortal! > Caveman > > [[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] degree C symbol in a function
On Tue, Aug 24, 2010 at 10:45 PM, Daisy Englert Duursma wrote: > Hello help, > > I have changed around some graphing code and made it into a function. > Previously they y label of the axis was inserted as text in its own > layout box. > > text(1,1, expression(~degree~C),cex=1) > > This worked great and resulted in the symbol for degree. > > In the function, I have changed it so: > > text(1,1,paste(b_unit),cex=1) > > and > > b_unit<-expression(~degree~C) > > This now inserts ~degree~C instead of the symbol. > > Get rid of the paste: plot(1) text(1, 1, b_unit) Actually, if you are going to specify these as formulas anyways you can also get rid of "expression".and possibly the first ~ depending on what you want: plot(0, main = degree ~ C) e <- degree ~ C plot(0, main = e) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] degree C symbol in a function
Hi Daisy, Try it without paste(): > plot(1, col = 'white') > text(1,1, b_unit,cex=1) HTH, Jorge On Tue, Aug 24, 2010 at 10:45 PM, Daisy Englert Duursma <> wrote: > Hello help, > > I have changed around some graphing code and made it into a function. > Previously they y label of the axis was inserted as text in its own > layout box. > > text(1,1, expression(~degree~C),cex=1) > > This worked great and resulted in the symbol for degree. > > In the function, I have changed it so: > > text(1,1,paste(b_unit),cex=1) > > and > > b_unit<-expression(~degree~C) > > This now inserts ~degree~C instead of the symbol. > > > Any advice? > > Thanks, > Daisy > > > > -- > Daisy Englert Duursma > > Room E8C156 > Dept. Biological Sciences > Macquarie University NSW 2109 > Australia > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] degree C symbol in a function
Hello help, I have changed around some graphing code and made it into a function. Previously they y label of the axis was inserted as text in its own layout box. text(1,1, expression(~degree~C),cex=1) This worked great and resulted in the symbol for degree. In the function, I have changed it so: text(1,1,paste(b_unit),cex=1) and b_unit<-expression(~degree~C) This now inserts ~degree~C instead of the symbol. Any advice? Thanks, Daisy -- Daisy Englert Duursma Room E8C156 Dept. Biological Sciences Macquarie University NSW 2109 Australia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] degree C
-- Daisy Englert Duursma Room E8C156 Dept. Biological Sciences Macquarie University NSW 2109 Australia Tel +61 2 9850 9256 10A Carrington Rd Hornsby, NSW 2077 Mobile: 0421858456 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 all objects except a few specified objects?
Tena korua ls()[!(ls() %in% c('keepThis','andThis'))] will give the elements excluding 'keepThis' and 'andThis'. Thus rm(list= ls()[!(ls() %in% c('keepThis','andThis'))]) will remove everything except these two objects, and hidden objects. It you want to remove the hidden objects as be use ls(all=TRUE). HTH Peter Alspach > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Dejian Zhao > Sent: Wednesday, 25 August 2010 1:32 p.m. > To: r-help@r-project.org > Subject: Re: [R] How to remove all objects except a few specified > objects? > > If your specified objects have a certain pattern, you can use the > parameter "pattern" in ls() to remove or keep it. > rm(list=ls(..., pattern="your_pattern")) > If not, possibly you have to manually specify them. > > On 2010-8-24 3:00, Cheng Peng wrote: > > How to remove all R objects in the RAM except for a few specified > ones? > > rm(list=ls()) removes all R objects in the R work space. > > > > Another question is that whether removing all R objects actually > releases > > the RAM? Thanks. > > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] find most repeated item from column in dataframe
How about this approach, using aggregate(): > DF StandID PlotNum HerbNum Woody 1 001 1 1low 2 001 2 2 medium 3 001 3 1low 4 001 4 3low 5 001 5 1 high 6 001 6 2 medium 7 002 1 1 high 8 002 2 2 high 9 002 3 2low 10 002 4 3 high 11 002 5 1 high 12 002 6 2 medium > aggregate(DF[, 3:4], list(StandID = DF$StandID), function(x) names(which.max(table(x StandID HerbNum Woody 1 001 1 low 2 002 2 high HTH, Marc Schwartz On Aug 24, 2010, at 9:14 PM, bill.venab...@csiro.au wrote: > Do you expect this to be easy? It may be, but I can't see a particularly > graceful way to do it. Here is one possible solution. > >> dat > StandID PlotNum HerbNum Woody > 1 001 1 1low > 2 001 2 2 medium > 3 001 3 1low > 4 001 4 3low > 5 001 5 1 high > 6 001 6 2 medium > 7 002 1 1 high > 8 002 2 2 high > 9 002 3 2low > 10 002 4 3 high > 11 002 5 1 high > 12 002 6 2 medium >> getMostCommon <- function(x) { > tx <- table(x) > m <- which(tx == max(tx))[1] > as(names(tx)[m], class(x)) > } >> val <- unclass(by(dat[,-1], dat$StandID, function(x) lapply(x, >> getMostCommon))) >> (newDat <- cbind(StandID = names(val), as.data.frame(do.call(rbind, val >StandID PlotNum HerbNum Woody > 001 001 1 1 low > 002 002 1 2 high > > This sort of gets you the answer, but it is not quite what it seems. One way > to make it more manageable is > >> for(j in 2:ncol(newDat)) newDat[[j]] <- unlist(newDat[[j]]) >> newDat >StandID PlotNum HerbNum Woody > 001 001 1 1 low > 002 002 1 2 high > > This is now a data frame with columns (more or less) what they appear to be. > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Randy Cass > Sent: Wednesday, 25 August 2010 11:33 AM > To: r-help@r-project.org > Subject: [R] find most repeated item from column in dataframe > > R users, > > I am trying to find some way to find the value of a column that is repeated > the most for each StandID of a dataframe. I have research methods online > and the help page, but have had no success in finding a solution. I have > tried using the table function but it returns items for the whole dataset > and not by the StandID. Any help will be appreciated. Thanks in advance. > > R version 2.11.1 > Windows 7 > Dataframe is imported from text file > > StandID PlotNumHerbNum Woody > 0011 1low > 0012 2medium > 0013 1low > 0014 3low > 0015 1high > 0016 2medium > 0021 1high > 0022 2high > 0023 2low > 0024 3high > 0025 1high > 0026 2medium > > I would like to get the following from the dataframe > > StandIDHerbNum Woody > 001 1low > 002 2high > > Thanks, > > Randy > > [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] find most repeated item from column in dataframe
Tena koe Randy If your dataframe is called randy, then the following seems to work: aggregate(randy[,-(1:2)], list(randy[,1]), function(x) {tt <- table(x); names(tt)[which.max(tt)]}) HTH Peter Alspach > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Randy Cass > Sent: Wednesday, 25 August 2010 1:33 p.m. > To: r-help@r-project.org > Subject: [R] find most repeated item from column in dataframe > > R users, > > I am trying to find some way to find the value of a column that is > repeated > the most for each StandID of a dataframe. I have research methods > online > and the help page, but have had no success in finding a solution. I > have > tried using the table function but it returns items for the whole > dataset > and not by the StandID. Any help will be appreciated. Thanks in > advance. > > R version 2.11.1 > Windows 7 > Dataframe is imported from text file > > StandID PlotNumHerbNum Woody > 0011 1low > 0012 2medium > 0013 1low > 0014 3low > 0015 1high > 0016 2medium > 0021 1high > 0022 2high > 0023 2low > 0024 3high > 0025 1high > 0026 2medium > > I would like to get the following from the dataframe > > StandIDHerbNum Woody > 001 1low > 002 2high > > Thanks, > > Randy > > [[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] find most repeated item from column in dataframe
Do you expect this to be easy? It may be, but I can't see a particularly graceful way to do it. Here is one possible solution. > dat StandID PlotNum HerbNum Woody 1 001 1 1low 2 001 2 2 medium 3 001 3 1low 4 001 4 3low 5 001 5 1 high 6 001 6 2 medium 7 002 1 1 high 8 002 2 2 high 9 002 3 2low 10 002 4 3 high 11 002 5 1 high 12 002 6 2 medium > getMostCommon <- function(x) { tx <- table(x) m <- which(tx == max(tx))[1] as(names(tx)[m], class(x)) } > val <- unclass(by(dat[,-1], dat$StandID, function(x) lapply(x, > getMostCommon))) > (newDat <- cbind(StandID = names(val), as.data.frame(do.call(rbind, val StandID PlotNum HerbNum Woody 001 001 1 1 low 002 002 1 2 high This sort of gets you the answer, but it is not quite what it seems. One way to make it more manageable is > for(j in 2:ncol(newDat)) newDat[[j]] <- unlist(newDat[[j]]) > newDat StandID PlotNum HerbNum Woody 001 001 1 1 low 002 002 1 2 high This is now a data frame with columns (more or less) what they appear to be. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Randy Cass Sent: Wednesday, 25 August 2010 11:33 AM To: r-help@r-project.org Subject: [R] find most repeated item from column in dataframe R users, I am trying to find some way to find the value of a column that is repeated the most for each StandID of a dataframe. I have research methods online and the help page, but have had no success in finding a solution. I have tried using the table function but it returns items for the whole dataset and not by the StandID. Any help will be appreciated. Thanks in advance. R version 2.11.1 Windows 7 Dataframe is imported from text file StandID PlotNumHerbNum Woody 0011 1low 0012 2medium 0013 1low 0014 3low 0015 1high 0016 2medium 0021 1high 0022 2high 0023 2low 0024 3high 0025 1high 0026 2medium I would like to get the following from the dataframe StandIDHerbNum Woody 001 1low 002 2high Thanks, Randy [[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] break the long R code lines automatically
Thanks a lot, Charles and Yihui, Your ideas are great! Both worked, although Yihui's solutions are a lot more comprehensive. BTW as a comment on Charles idea, parse function works for loosen statement lines, for not for the code blocks of a function. For example, the following code for vennCounts function could not be sorted by using parse alone if we copy and paste into a source file. However, if we comment the first line out as: # vennCounts <- function (x, include = "both"), parse works and sorts the individual lines as expected. My problem is well solved with your suggestions. But both ways, we used Râs own resource/functionality. I am curious, are there any ways to break the long lines automatically just in the text editor Emacs/ESS without using R? Thanks! Heyi  vennCounts <- function (x, include = "both")  {        x <- as.matrix(x)            include <- match.arg(include, c("both", "up", "down"))            x <- sign(switch(include, both = abs(x), up = x > 0, down = x < 0))            nprobes <- nrow(x)            ncontrasts <- ncol(x)            names <- colnames(x)            if (is.null(names))                      names <- paste("Group", 1:ncontrasts)            noutcomes <- 2^ncontrasts            outcomes <- matrix(0, noutcomes, ncontrasts)            colnames(outcomes) <- names            for (j in 1:ncontrasts) outcomes[, j] <- rep(0:1, times = 2^(j - 1), each = 2^(ncontrasts - j))            xlist <- list()            for (i in 1:ncontrasts) xlist[[i]] <- factor(x[, ncontrasts - i + 1], levels = c(0, 1))            counts <- as.vector(table(xlist))            structure(cbind(outcomes, Counts = counts), class = "VennCounts")      }  --- On Tue, 8/24/10, Yihui Xie wrote: From: Yihui Xie Subject: Re: [R] break the long R code lines automatically To: "Charles C. Berry" Cc: "heyi xiao" , r-help@r-project.org Date: Tuesday, August 24, 2010, 7:23 PM Actually I've implemented Charles' idea in the function tidy.source() in package 'animation' years ago. An example can be found here: http://animation.yihui.name/animation:misc#tidy_up_r_source BTW, you might be interested in the 'formatR' package if you are somehow addicted to GUI: http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/ Regards, Yihui -- Yihui Xie Phone: 515-294-6609 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Tue, Aug 24, 2010 at 4:07 PM, Charles C. Berry wrote: > On Tue, 24 Aug 2010, heyi xiao wrote: > >> >> >> >> >> Dear >> all, >> >> I have >> written some R source program with many thousands of lines. I didnât >> insert >> line breaks automatically or manually for the long lines. But now I would >> like >> to edit the source code in Emacs/ESS to make it more formal as a package. >> One of >> the major problems here is how to break the long lines automatically. >> Emacs auto-fill-mode >> only works for the lines you are typing in currently, and fill commands >> like M-q >> (fill-paragraph) or M-x fill-region (fill-region) mess up the R code lines >> as >> they take a whole function/paragraph as a long line, and remove the >> original >> line breaks. >> >> I find >> simple solutions for indenting code regions in Emacs/ESS, but no good ones >> for >> breaking code lines. However, I saw the nice multi-line codes in all >> R/Bioconductor packages. Please let me know if you have any ideas on how >> people >> usually break the existent long R code lines automatically. I will really >> appreciate your kind help! > > > Not particualrly elegant, but a combination of parse and print will break > long lines: > > >> cat("y <- ",paste( 1:20,collapse=" + "),"\n","y2 <- ", > > +  paste( 1:20,collapse="+"),"\n",file="testwrap.R") >> >> for (iexpr in parse("testwrap.R")) print(iexpr) > > y <- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + >   14 + 15 + 16 + 17 + 18 + 19 + 20 > y2 <- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + >   14 + 15 + 16 + 17 + 18 + 19 + 20 >> >> nchar(readLines("testwrap.R")) > > [1] 95 59 >> > > and of course you will want 'sink' or some such to save the lines. > > HTH, > > Chuck > > >> >> Heyi >> >> >> >> >> >>     [[alternative HTML version deleted]] >> >> > > Charles C. Berry               (858) 534-2098 >                       Dept of > Family/Preventive > Medicine > E mailto:cbe...@tajo.ucsd.edu        UC San Diego > http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901 > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.or
[R] find most repeated item from column in dataframe
R users, I am trying to find some way to find the value of a column that is repeated the most for each StandID of a dataframe. I have research methods online and the help page, but have had no success in finding a solution. I have tried using the table function but it returns items for the whole dataset and not by the StandID. Any help will be appreciated. Thanks in advance. R version 2.11.1 Windows 7 Dataframe is imported from text file StandID PlotNumHerbNum Woody 0011 1low 0012 2medium 0013 1low 0014 3low 0015 1high 0016 2medium 0021 1high 0022 2high 0023 2low 0024 3high 0025 1high 0026 2medium I would like to get the following from the dataframe StandIDHerbNum Woody 001 1low 002 2high Thanks, Randy [[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 all objects except a few specified objects?
If your specified objects have a certain pattern, you can use the parameter "pattern" in ls() to remove or keep it. rm(list=ls(..., pattern="your_pattern")) If not, possibly you have to manually specify them. On 2010-8-24 3:00, Cheng Peng wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Comparing/diffing strings
On Tue, Aug 24, 2010 at 11:25 AM, Martin Morgan wrote: > On 08/24/2010 07:27 AM, Doran, Harold wrote: >> There is the stringMatch function in the MiscPsycho package. >> >>> stringMatch('Hadley', 'Hadley Wickham', normalize = 'no') >> [1] 8 >>> stringMatch('Hadley', 'Hadley Wickham', normalize = 'yes') >> [1] 0.4285714 >> >> It uses Levenshtein distance to tell you how much they differ by, either >> normalized or not. So, the above two tell you the first string differs from >> the second string by 8 insertions/deletions/substitutions. The second number >> normalizes the comparison such that 1 denotes perfect agreement and 2 >> denotes imperfect agreement. >> >> Examples of an exact match are below. >> >>> stringMatch('Hadley Wickham', 'Hadley Wickham', normalize = 'yes') >> [1] 1 >>> stringMatch('Hadley Wickham', 'Hadley Wickham', normalize = 'n') >> [1] 0 > > You're probably looking for something lighter weight, but Bioconductor > Biostrings has pairwiseAlignment. > >> library(Biostrings) >> pairwiseAlignment("Hadley Wickham", "Hadley Hamwick") > Global PairwiseAlignedFixedSubject (1 of 1) > pattern: [1] Hadley W---ick > subject: [1] Hadley Hamwick > score: 29.5102 > >> pairwiseAlignment("Hadley Hamwick", "Hadley Wickham") > Global PairwiseAlignedFixedSubject (1 of 1) > pattern: [1] Hadley Hamwick > subject: [1] Hadley W---ick > score: 29.5102 > >> aln <- pairwiseAlignment("Hadley Hamwick", "Haderley Hamwich") >> consensusMatrix(aln)["-",] > [1] 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 Thanks all for the suggestions! Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to plot y-axis on the right of x-axis
On Aug 24, 2010, at 7:12 PM, elaine kuo wrote: Dear List, I have a richness data distributing across 20 N to 20 S latitude. (120 E-140 E longitude). I would like to draw the richness in the north hemisphere and a regression line in the plot (x-axis: latitude, y-axis: richness in the north hemisphere). The above demand is done using plot. Then, south hemisphere richness and regression are required to be generated using the same y-axis above but an x-axis on the left side of the y-axis. (The higher latitude in the south hemisphere, the left it would move) Please kindly share how to design the south plot and regression line for richness. Also, please advise if any more info is in need. Reproducible code, now and forever shall be world without end, amen. #-- and provide commented, minimal, self-contained, reproducible code. #-- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] break the long R code lines automatically
Actually I've implemented Charles' idea in the function tidy.source() in package 'animation' years ago. An example can be found here: http://animation.yihui.name/animation:misc#tidy_up_r_source BTW, you might be interested in the 'formatR' package if you are somehow addicted to GUI: http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/ Regards, Yihui -- Yihui Xie Phone: 515-294-6609 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Tue, Aug 24, 2010 at 4:07 PM, Charles C. Berry wrote: > On Tue, 24 Aug 2010, heyi xiao wrote: > >> >> >> >> >> Dear >> all, >> >> I have >> written some R source program with many thousands of lines. I didn’t >> insert >> line breaks automatically or manually for the long lines. But now I would >> like >> to edit the source code in Emacs/ESS to make it more formal as a package. >> One of >> the major problems here is how to break the long lines automatically. >> Emacs auto-fill-mode >> only works for the lines you are typing in currently, and fill commands >> like M-q >> (fill-paragraph) or M-x fill-region (fill-region) mess up the R code lines >> as >> they take a whole function/paragraph as a long line, and remove the >> original >> line breaks. >> >> I find >> simple solutions for indenting code regions in Emacs/ESS, but no good ones >> for >> breaking code lines. However, I saw the nice multi-line codes in all >> R/Bioconductor packages. Please let me know if you have any ideas on how >> people >> usually break the existent long R code lines automatically. I will really >> appreciate your kind help! > > > Not particualrly elegant, but a combination of parse and print will break > long lines: > > >> cat("y <- ",paste( 1:20,collapse=" + "),"\n","y2 <- ", > > + paste( 1:20,collapse="+"),"\n",file="testwrap.R") >> >> for (iexpr in parse("testwrap.R")) print(iexpr) > > y <- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + > 14 + 15 + 16 + 17 + 18 + 19 + 20 > y2 <- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + > 14 + 15 + 16 + 17 + 18 + 19 + 20 >> >> nchar(readLines("testwrap.R")) > > [1] 95 59 >> > > and of course you will want 'sink' or some such to save the lines. > > HTH, > > Chuck > > >> >> Heyi >> >> >> >> >> >> [[alternative HTML version deleted]] >> >> > > Charles C. Berry (858) 534-2098 > Dept of Family/Preventive > Medicine > E mailto:cbe...@tajo.ucsd.edu UC San Diego > http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to plot y-axis on the right of x-axis
Dear List, I have a richness data distributing across 20 N to 20 S latitude. (120 E-140 E longitude). I would like to draw the richness in the north hemisphere and a regression line in the plot (x-axis: latitude, y-axis: richness in the north hemisphere). The above demand is done using plot. Then, south hemisphere richness and regression are required to be generated using the same y-axis above but an x-axis on the left side of the y-axis. (The higher latitude in the south hemisphere, the left it would move) Please kindly share how to design the south plot and regression line for richness. Also, please advise if any more info is in need. Elaine [[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] Constrained non-linear optimisation
David, I am not sure I completely understand your problem. However, you can take a look at a couple of packages in R that can handle (smooth) nonlinear optimization with general (smooth) constraints: library(alabama) ?constrOptim.nl and library(Rsolnp) ?solnp Best, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Dennis Murphy Date: Tuesday, August 24, 2010 4:44 pm Subject: Re: [R] Constrained non-linear optimisation To: David Beacham Cc: r-help@r-project.org > Hi: > > A reasonable place to start would be the Optimization task view at CRAN: > > > > HTH, > Dennis > > On Tue, Aug 24, 2010 at 10:47 AM, David Beacham > wrote: > > > I'm relatively new to R, but I'm attempting to do a non-linear maximum > > likelihood estimation (mle) in R, with the added problem that I > have a > > non-linear constraint. > > > > The basic problem is linear in the parameters (a_i) and has only one > > non-linear component, b, with the problem being linear when b = 0 and > > non-linear otherwise. Furthermore, f(a_i) <= b <= g(a_i) for some > (simple) f > > and g. > > > > Using optim, I can get the optimisation to work when the > non-linearity is > > included but not constrained, but gives poor results (as I'd expect). > > However, I'm not sure how best to go about the constraint > condition. My > > initial attempts revolve around the use of logarithmic barrier > function, but > > this only appears to work when using method="CG". When using > "BFGS", the > > value of b 'goes out of bounds' and the loglikelihood starts > throwing NaN, > > which is particularly bad if I want to box constrain the a_i using > the > > "L-BFGS-B" method. > > > > Are there any other methods/approaches/variations on the above > available to > > me in the form of other packages/R functions etc? Or any good > > references/books to help me out? > > > > Any help would be greatly appreciated, > > David. > > > > __ > > R-help@r-project.org mailing list > > > > PLEASE do read the posting guide > > > > and provide commented, minimal, self-contained, reproducible code. > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > > PLEASE do read the posting guide > 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] Parsing a XML file
My system is an Ubuntu 9.10 32bit: #uname -a Linux cavemanpc 2.6.31-22-generic #63-Ubuntu SMP Wed Aug 18 22:54:26 UTC 2010 i686 GNU/Linux # free -m total used free sharedbuffers cached Mem: 3000 1847 1152 0120961 -/+ buffers/cache:766 2234 Swap: 4769 0 4769 My Ubuntu XML related packages: r...@cavemanpc:~# dpkg -l | grep -i libxml | awk '{ print $2}' libxml++2.6-2 libxml++2.6-dev libxml-commons-external-java libxml-commons-resolver1.1-java libxml-java-openoffice.org libxml-parser-perl libxml-twig-perl libxml-xpath-perl libxml2 libxml2-dev libxml2-utils libxmlgraphics-commons-java python-libxml2 Thanks Caveman On Wed, Aug 25, 2010 at 12:43 AM, Orvalho Augusto wrote: > It seems to be a bug on the XML package. > > This is what I run (and it is not the only file): > > library("XML") > > doc <- xmlDoc("Malaria_Grave.xml") > > *** caught segfault *** > address 0x9, cause 'memory not mapped' > > Traceback: > 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") > 2: xmlDoc("Malaria_Grave.xml") > > Possible actions: > 1: abort (with core dump, if enabled) > 2: normal R exit > 3: exit R without saving workspace > 4: exit R saving workspace > Selection: 1 > aborting ... > Segmentation fault > > ##= > > sessionInfo() > R version 2.11.1 (2010-05-31) > i686-pc-linux-gnu > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] XML_3.1-1 > > > > ##= > > Thanks > Caveman > > > On Wed, Aug 25, 2010 at 12:02 AM, Gavin Simpson > wrote: > >> On Tue, 2010-08-24 at 23:35 +0200, Orvalho Augusto wrote: >> > I have one XML file with 30MB that I need to read the data. >> > >> > I try this; >> > library(XML) >> > doc <- xmlDoc("Malaria_Grave.xml") >> > >> > And R answers like this >> > *** caught segfault *** >> > address 0x5, cause 'memory not mapped' >> >> This is most likely a bug in your version (unstated) of the XML package. >> But it may be a problem with the file, though XML shouldn't crash R. >> Make sure you are using the latest version of the XML package and R is >> up-to-date, then retry your code in a new R session. If it still >> segfaults, you need to file a bug report with the maintainer: Duncan >> Temple Lang, and include all the relevant details such as output from >> >> sessionInfo() >> >> The .xml file you are trying to read and the code required to reproduce >> the segfault. >> >> HTH >> >> G >> >> > Traceback: >> > 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") >> > 2: xmlDoc("Malaria_Grave.xml") >> > >> > Possible actions: >> > 1: abort (with core dump, if enabled) >> > 2: normal R exit >> > 3: exit R without saving workspace >> > 4: exit R saving workspace >> > >> > >> > Or I try this: >> > doc <- xmlTreeParse("Malaria_Grave.xml") >> > >> > I get this >> > xmlParseEntityRef: no name >> > xmlParseEntityRef: no name >> > Error: 1: xmlParseEntityRef: no name >> > 2: xmlParseEntityRef: no name >> > >> > Please guys help this simple mortal! >> > Caveman >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > R-help@r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> -- >> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >> Dr. Gavin Simpson [t] +44 (0)20 7679 0522 >> ECRC, UCL Geography, [f] +44 (0)20 7679 0565 >> Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk >> Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ >> UK. WC1E 6BT. [w] http://www.freshwaters.org.uk >> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >> >> > > > > [[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] Parsing a XML file
It seems to be a bug on the XML package. This is what I run (and it is not the only file): > library("XML") > doc <- xmlDoc("Malaria_Grave.xml") *** caught segfault *** address 0x9, cause 'memory not mapped' Traceback: 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") 2: xmlDoc("Malaria_Grave.xml") Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Selection: 1 aborting ... Segmentation fault ##= > sessionInfo() R version 2.11.1 (2010-05-31) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] XML_3.1-1 > ##= Thanks Caveman On Wed, Aug 25, 2010 at 12:02 AM, Gavin Simpson wrote: > On Tue, 2010-08-24 at 23:35 +0200, Orvalho Augusto wrote: > > I have one XML file with 30MB that I need to read the data. > > > > I try this; > > library(XML) > > doc <- xmlDoc("Malaria_Grave.xml") > > > > And R answers like this > > *** caught segfault *** > > address 0x5, cause 'memory not mapped' > > This is most likely a bug in your version (unstated) of the XML package. > But it may be a problem with the file, though XML shouldn't crash R. > Make sure you are using the latest version of the XML package and R is > up-to-date, then retry your code in a new R session. If it still > segfaults, you need to file a bug report with the maintainer: Duncan > Temple Lang, and include all the relevant details such as output from > > sessionInfo() > > The .xml file you are trying to read and the code required to reproduce > the segfault. > > HTH > > G > > > Traceback: > > 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") > > 2: xmlDoc("Malaria_Grave.xml") > > > > Possible actions: > > 1: abort (with core dump, if enabled) > > 2: normal R exit > > 3: exit R without saving workspace > > 4: exit R saving workspace > > > > > > Or I try this: > > doc <- xmlTreeParse("Malaria_Grave.xml") > > > > I get this > > xmlParseEntityRef: no name > > xmlParseEntityRef: no name > > Error: 1: xmlParseEntityRef: no name > > 2: xmlParseEntityRef: no name > > > > Please guys help this simple mortal! > > Caveman > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > -- > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% > > [[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] Customized Sweavel Style File
Liviu, thanks again for the suggestion. Do you have a customized style file that you wouldn't mind sharing? I like the default output but I'm curious about others. Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Index list by other list (w/ logical elements)?
Marianne - The function you're looking for is mapply: mapply(function(one,two)one[two],x,y) [[1]] [1] "one" [[2]] [1] "four" "five" - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 24 Aug 2010, Marianne Promberger wrote: I have two lists of the same shape, like this: x <- list() x[[1]] <- c("one","two") x[[2]] <- c("three","four","five") y <- list() y[[1]] <- c(TRUE,FALSE) y[[2]] <- c(FALSE,TRUE,TRUE) I would like to index x "by" y, that is, the result in this case should be: z [[1]] [1] "one" [[2]] [1] "four" "five" I was hoping sapply(x,"[",y) would work, but it doesn't. I guess I need to sapply twice, like sapply(x, function() { sapply(y ... but I can't figure it out. Many thanks for any pointers Marianne -- Marianne Promberger PhD, King's College London http://promberger.info R version 2.11.1 (2010-05-31) Ubuntu 9.04 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Parsing a XML file
On Tue, 2010-08-24 at 23:35 +0200, Orvalho Augusto wrote: > I have one XML file with 30MB that I need to read the data. > > I try this; > library(XML) > doc <- xmlDoc("Malaria_Grave.xml") > > And R answers like this > *** caught segfault *** > address 0x5, cause 'memory not mapped' This is most likely a bug in your version (unstated) of the XML package. But it may be a problem with the file, though XML shouldn't crash R. Make sure you are using the latest version of the XML package and R is up-to-date, then retry your code in a new R session. If it still segfaults, you need to file a bug report with the maintainer: Duncan Temple Lang, and include all the relevant details such as output from sessionInfo() The .xml file you are trying to read and the code required to reproduce the segfault. HTH G > Traceback: > 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") > 2: xmlDoc("Malaria_Grave.xml") > > Possible actions: > 1: abort (with core dump, if enabled) > 2: normal R exit > 3: exit R without saving workspace > 4: exit R saving workspace > > > Or I try this: > doc <- xmlTreeParse("Malaria_Grave.xml") > > I get this > xmlParseEntityRef: no name > xmlParseEntityRef: no name > Error: 1: xmlParseEntityRef: no name > 2: xmlParseEntityRef: no name > > Please guys help this simple mortal! > Caveman > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave.sty
That is great Liviu, thanks for letting me know. My LaTeX documents have been looking like this, however I have been doing all the cosmetics through LaTeX. Thanks for letting me know about this! On Aug 24, 2010, at 2:34 PM, Liviu Andronic wrote: On Tue, Aug 24, 2010 at 10:40 PM, r.ookie wrote: > Does anyone know where I can download the latest version of Sweave.sty? I > have looked all over the site http://www.stat.umn.edu/~charlie/Sweave/ with > no luck. > Not exactly an answer, Frank Harrell once published a fork of Sweave, Sweavel [1], which can provide fancier output. Liviu [1] http://biostat.mc.vanderbilt.edu/wiki/Main/SweaveTemplate __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: [R-sig-hpc] Holtman's levelplot ?
On Aug 24, 2010, at 5:15 PM, Michel Lutz wrote: > Thank you David for your answer. > > To be honest, I didn't read those posting guide, because I don't > know where to find it - I just get this email from N. Gunther. > So here the txt file, and sorry for having sent a wrong format. > > I checked out ?image and tested, that's why I think my current issue > is more the creation of the input matrix. > > About what I want... well... exactly as in Holtman, 2005, fig. 6, ie > being able to plot minutes within a day as x, days within a month as > y, and get the CPU% used represented in the frame, according to its > level of use (see enclosed). > > My input txt or csv file : > Col. 1 : time stamp like 'MM/DD/ hh:mm' > Col. 2 : CPU use > (result of a SQL request) > I see commas as decimal points so be sure to read the docs on read.table regarding dec argument. Looks like you need to create a new variable that casts those dates into a day of month (which is the y axis on that levelplot). I cannot read the x axis on the attached image. ??? maybe it was the hour of the day? Perhaps using strsplit() function on the "time stamp" variable (second element in the list of split elements) with " " as the separator and then parsing out an hour.of.day value. Then use the chron package to extract a day.of.month or probably simpler use strsplit with "/" as the separator on the first element of the first split. Final processing step tabulate the CPU_use by Day.of.month and Hour.of.day. Then you will have a matrix (since r-tables are of class table and matrix): Then image or levelplot with: X= hour; Y= day; Z= CPU_use -- David. > I will also try again ! > > Thanks for your support, > > Michel > > > > > On Tue, Aug 24, 2010 at 10:49 PM, David Winsemius > wrote: > > On Aug 24, 2010, at 2:56 PM, Michel Lutz wrote: > > Hello, > > As recommended by N. Gunther, I'm writing you because I have some > difficulties to create a script to track computer performance, as > done in > Holtman, 2005 (Visualization techniques for analysing patterns in > system > performance). > > I would like to do a leveplot, with the kind of file here enclosed. > > Nope. You probably did not read all the way to the end of the > Posting Guide to see what kinds of attachments are allowed on this > list. > > > > I assume I should create a matrix in R, then use the function 'image'. > > Maybe. There is an image function for base graphics: > > ?image > > First example is very similar to the first example in levelplot. > They have very similar data layout requirements. > > > > As I am not familiar with the lattice package, I have some > difficulties to > move ahead : I think my pb is in the creation of the matrix. I am > not able > to create sthing consistent with the image function. I am even > thinking I > should build my input csv file differently, but I am not sure how to > do... > > Is someone able to help me ? > > Given Jim's propensity to finish his emails with "What problem are > you trying to solve", let me beat him to the punch. What's you data > layout look like and what do you want the plot to look like? If you > can convert that file to plain text and make sure its file extension > is .txt, it will probably make it through if you resend it. > > You can get some other ideas for specifics by running the first > example on the levelplot help page: > > ?levelplot > > Lattice graphic do not mix well with base graphics so you need to > keep them segregated in your plotting kitchen if you want to remain > r-kosher. > > -- > David. > > > Thank you very much ! > > REgards, > > Michel > > > > -- Forwarded message -- > From: Red Roo > Date: Tue, Aug 24, 2010 at 3:46 PM > Subject: Re: [R-sig-hpc] Holtman's levelplot ? > To: Michel Lutz > Cc: "r-sig-...@r-project.org" , redr...@yahoo.com > > > Michel, > > If you ask your plotting questions over at r-help@r-project.org, Jim > Holtman > will probably address them directly. He is also an instructor for my > "Guerrilla > Data Analysis Techniques" class > http://www.perfdynamics.com/Classes/Outlines/gdata.html and we just > discussed > this plot 2 weeks ago. > > > --Neil Gunther > > Taking The Pith Out Of Performance http://perfdynamics.blogspot.com/ > Follow me on Twitter http://twitter.com/DrQz > Performance Dynamics Company http://www.perfdynamics.com/ > > > > > On 08/24/2010 03:47 AM, Michel Lutz wrote: > > Hello to all, > > I am sorry for disturbing you, but I really don't know where/who to > ask... > so if this distribution list is not dealing with my concern, please > excuse > me... > > Here is my concern : I am trying to do a levelplot as in Holtman, 2005 > (Visualization techniques for analysing patterns in system performance > data), to display CPU usage according to the day of the month (y) and > minutes (x). > > I am familiar with R basic features, but not at all with lattice > package > and > I don't
[R] Index list by other list (w/ logical elements)?
I have two lists of the same shape, like this: x <- list() x[[1]] <- c("one","two") x[[2]] <- c("three","four","five") y <- list() y[[1]] <- c(TRUE,FALSE) y[[2]] <- c(FALSE,TRUE,TRUE) I would like to index x "by" y, that is, the result in this case should be: z [[1]] [1] "one" [[2]] [1] "four" "five" I was hoping sapply(x,"[",y) would work, but it doesn't. I guess I need to sapply twice, like sapply(x, function() { sapply(y ... but I can't figure it out. Many thanks for any pointers Marianne -- Marianne Promberger PhD, King's College London http://promberger.info R version 2.11.1 (2010-05-31) Ubuntu 9.04 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Parsing a XML file
I have one XML file with 30MB that I need to read the data. I try this; library(XML) doc <- xmlDoc("Malaria_Grave.xml") And R answers like this *** caught segfault *** address 0x5, cause 'memory not mapped' Traceback: 1: .Call("RS_XML_createDocFromNode", node, PACKAGE = "XML") 2: xmlDoc("Malaria_Grave.xml") Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Or I try this: doc <- xmlTreeParse("Malaria_Grave.xml") I get this xmlParseEntityRef: no name xmlParseEntityRef: no name Error: 1: xmlParseEntityRef: no name 2: xmlParseEntityRef: no name Please guys help this simple mortal! Caveman [[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.sty
On Tue, Aug 24, 2010 at 10:40 PM, r.ookie wrote: > Does anyone know where I can download the latest version of Sweave.sty? I > have looked all over the site http://www.stat.umn.edu/~charlie/Sweave/ with > no luck. > Not exactly an answer, Frank Harrell once published a fork of Sweave, Sweavel [1], which can provide fancier output. Liviu [1] http://biostat.mc.vanderbilt.edu/wiki/Main/SweaveTemplate __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot bar lines like excel
Hi: This is pretty straightforward to do in ggplot2, but it would be nice to have some data to work with (hint). The job requires processing the two input series and dates with melt() from the reshape package, a couple of opts() to change, proper rotation of the dates, etc. It's easier to show how to do it with actual data rather than to lay out the steps. Dennis On Tue, Aug 24, 2010 at 10:40 AM, abotaha wrote: > > Hello guys, > > I would to plot a bar line between to curves like in excel as shown in the > following image. but i do not know how I can do that in R. > http://r.789695.n4.nabble.com/file/n2337089/excel_Plot.png > any help would appreciate. > > -- > View this message in context: > http://r.789695.n4.nabble.com/Plot-bar-lines-like-excel-tp2337089p2337089.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trouble configuring R to use ACML
This is easier if you simply link to the ACML BLAS as an alternative to Rblas.so -- see the R-admin manual. If you need further help, please ask on the R-devel list (see the posting guide). It seems likely that you missed the comment in the R-admin manual about ensuring that the ACML lib directory is in LD_LIBRARY_PATH, so please check the manual subsection carefully. (More generally, you may well need to add that directory to the ld.so cache: some installation of ACML arrange to do so, some do not. I have gannet% cat /etc/ld.so.conf.d//acml-x86_64.conf /opt/acml4.4.0/gfortran64/lib /opt/acml4.4.0/gfortran64_mp/lib .) On Tue, 24 Aug 2010, szembek wrote: I am trying to get R to use the ACML BLAS, specifically the 'mp' version for multithreading. I have installed acml-4-4-0-gfortran-64bit I added /opt/acml4.4.0/gfortran64_mp/lib to $LD_LIBRARY_PATH. I ran: sudo ./configure --with-blas="-L/opt/acml4.4.0/gfortran64_mp/lib -lacml_mp" At the end of the configuration, the only external library listed is readline, and at the end of my post here is a section of my config.log that shows the problem. Any ideas as to what I'm missing here? I'm running Ubuntu Server 10. -- config.log --- configure:28567: checking for dgemm_ in -L/opt/acml4.4.0/gfortran64_mp/lib -lacml_mp configure:28588: gcc -std=gnu99 -o conftest -g -O2 -I/usr/local/include -L/usr/local/lib64 conftest.c -L/opt/acml4.4.0/gfortran64_mp/lib -lacml_mp -lgfortran -lm -ldl -lm >&5 conftest.c: In function 'main': conftest.c:193: warning: implicit declaration of function 'dgemm_' configure:28588: $? = 0 configure:28595: result: yes configure:29120: checking whether double complex BLAS can be used ./conftest: error while loading shared libraries: libacml_mp.so: cannot open shared object file: No such file or directory -- View this message in context: http://r.789695.n4.nabble.com/Trouble-configuring-R-to-use-ACML-tp2337193p2337193.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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] break the long R code lines automatically
On Tue, 24 Aug 2010, heyi xiao wrote: Dear all, I have written some R source program with many thousands of lines. I didn???t insert line breaks automatically or manually for the long lines. But now I would like to edit the source code in Emacs/ESS to make it more formal as a package. One of the major problems here is how to break the long lines automatically. Emacs auto-fill-mode only works for the lines you are typing in currently, and fill commands like M-q (fill-paragraph) or M-x fill-region (fill-region) mess up the R code lines as they take a whole function/paragraph as a long line, and remove the original line breaks. I find simple solutions for indenting code regions in Emacs/ESS, but no good ones for breaking code lines. However, I saw the nice multi-line codes in all R/Bioconductor packages. Please let me know if you have any ideas on how people usually break the existent long R code lines automatically. I will really appreciate your kind help! Not particualrly elegant, but a combination of parse and print will break long lines: cat("y <- ",paste( 1:20,collapse=" + "),"\n","y2 <- ", + paste( 1:20,collapse="+"),"\n",file="testwrap.R") for (iexpr in parse("testwrap.R")) print(iexpr) y <- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 y2 <- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 nchar(readLines("testwrap.R")) [1] 95 59 and of course you will want 'sink' or some such to save the lines. HTH, Chuck Heyi [[alternative HTML version deleted]] Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Compiling Fortran for R : .so: mach-o, but wrong architecture
R-sig-mac is the right list for Mac-specific questions. But Command-line R on Snow Leopard is 64-bit R.app is 32-bit. So either use R32 CMD INSTALL or use R64.app. (And as 'R' is 32-bit on Leopard, it is rather easy to get confused.) On Tue, 24 Aug 2010, Marie-Hélène Ouellette wrote: Dear all, I'm trying to compile FORTRAN code to be used in R, failing miserably. I got a simple code function to try to figure out what is going wrong. Here is the code (available on the web) : subroutine bar(n, x) integer n double precision x(n) integer i do 100 i = 1, n x(i) = x(i) ** 2 100 continue end 1. I compiled the code using 'R CMD SHLIB bar.f' in the terminal. This created files .o and so of the same name. Got the following output in the terminal : R CMD SHLIB bar.f gfortran -arch x86_64 -fPIC -g -O2 -c bar.f -o bar.o gcc -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o bar.so bar.o -lgfortran -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation 2. Tried to dynamically load the code. In the R console, typed dyn.load("~/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so") Erreur dans dyn.load("~/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so") : impossible de charger la biblioth?que partag?e '/Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so': dlopen(/Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so, 6): no suitable image found. Did find: /Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so: mach-o, but wrong architecture I have : Mac OS : 10.6.4 R 2.11.0 GUI 1.33 Leopard build 32-bit (5582) Xcode version 3.2.3 64-bit Installed gfortran 4.3.2 I hope this is all you need, feel free to ask me for any more info. Thank you for your time, MH [[alternative HTML version deleted]] -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lme4 + R 2.11.0 + mac unavailable
On Tue, 24 Aug 2010, Daniel Malter wrote: Hi, has there been a solution to this issue? I am encountering the same Yes, please look in the R-sig-mac archives (the place to ask Mac-specific questsions!). My notes say July 28, https://stat.ethz.ch/pipermail/r-sig-mac/2010-July/007601.html problem on a Mac with OSX 10.6.4. The problem persists when I try to install lme4 from the source (see below), and my R version is up to date according to R's update check. But have you installed the Fortran compiler from http://r.research.att.com/tools/ ? Thanks for any help, Daniel -- sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.1 -- install.packages("lme4") Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘lme4’ is not available -- install.packages("lme4", type = "source") trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/lme4_0.999375-35.tar.gz' Content type 'application/x-gzip' length 1017763 bytes (993 Kb) opened URL == downloaded 993 Kb * installing *source* package ‘lme4’ ... ** libs *** arch - i386 gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/include" -fPIC -g -O2 -c init.c -o init.o gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/include" -fPIC -g -O2 -c lmer.c -o lmer.o gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/include" -fPIC -g -O2 -c local_stubs.c -o local_stubs.o gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o lme4.so init.o lmer.o local_stubs.o -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRlapack -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRblas -lgfortran -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation ld: library not found for -lgfortran collect2: ld returned 1 exit status make: *** [lme4.so] Error 1 ERROR: compilation failed for package ‘lme4’ * removing ‘/Library/Frameworks/R.framework/Versions/2.11/Resources/library/lme4’ The downloaded packages are in ‘/private/var/folders/q5/q5YCJSnWH7arB5jzTZBIfTI/-Tmp-/Rtmp4tcqUG/downloaded_packages’ Updating HTML index of packages in '.Library' Warning message: In install.packages("lme4", type = "source") : installation of package 'lme4' had non-zero exit status -- View this message in context: http://r.789695.n4.nabble.com/lme4-R-2-11-0-mac-unavailable-tp2220331p2337213.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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drop unused levels in lattice dotplot axis?
Hi Dennis, thanks! No, this looks good to me, with equal-sized panels. I didn't realize there was such a similar post before - all my queries had retrieved questions about dropping categories in panels... but this is great - thank you.All the best!Stephen Date: Tue, 24 Aug 2010 12:58:20 -0700 Subject: Re: [R] drop unused levels in lattice dotplot axis? From: djmu...@gmail.com To: obsessiv...@hotmail.com CC: r-help@r-project.org Hi: This looks to be a step in the right direction, but the resulting panels are all the same size. Perhaps you can build on it... # Solution based on an R-help post by Deepayan Sarkar: # http://tolstoy.newcastle.edu.au/R/e2/help/06/09/1579.html dotplot(A ~ B | C, data=dfr, scales=list(y=list(relation="free")), prepanel = function(x, y, ...) { # drop unused levels yy <- y[, drop = TRUE] # reset y-limits list(ylim = levels(yy), yat = sort(unique(as.numeric(yy }, panel = function(x, y, ...) { # drop unused levels...again... yy <- y[, drop = TRUE] panel.dotplot(x, yy, ...) } ) HTH, Dennis On Tue, Aug 24, 2010 at 4:25 AM, Stephen T. wrote: Hi list, I have a data set - something like this dfr <- data.frame(A=factor(letters[1:25]),B=runif(25), C=sample(LETTERS[1:4],25,replace=TRUE)) and I want to create a dotplot: library(lattice)dotplot(A ~ B | C, data=dfr, scales=list(y=list(relation="free"))) but this puts uneven spaces along the y-axis in each panel. drop.unused.levels=TRUE will drop conditioning variables, but does not affect the levels in the y-variable. I can get something like what I want with ggplot2:library(ggplot2)ggplot(data=dfr,mapping=aes(x=B,y=A)) + geom_point() + facet_wrap( ~ C,scales="free_y") I wonder if this is possible in lattice? Thanks! Stephen [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Fwd: [R-sig-hpc] Holtman's levelplot ?
On Aug 24, 2010, at 2:56 PM, Michel Lutz wrote: Hello, As recommended by N. Gunther, I'm writing you because I have some difficulties to create a script to track computer performance, as done in Holtman, 2005 (Visualization techniques for analysing patterns in system performance). I would like to do a leveplot, with the kind of file here enclosed. Nope. You probably did not read all the way to the end of the Posting Guide to see what kinds of attachments are allowed on this list. I assume I should create a matrix in R, then use the function 'image'. Maybe. There is an image function for base graphics: ?image First example is very similar to the first example in levelplot. They have very similar data layout requirements. As I am not familiar with the lattice package, I have some difficulties to move ahead : I think my pb is in the creation of the matrix. I am not able to create sthing consistent with the image function. I am even thinking I should build my input csv file differently, but I am not sure how to do... Is someone able to help me ? Given Jim's propensity to finish his emails with "What problem are you trying to solve", let me beat him to the punch. What's you data layout look like and what do you want the plot to look like? If you can convert that file to plain text and make sure its file extension is .txt, it will probably make it through if you resend it. You can get some other ideas for specifics by running the first example on the levelplot help page: ?levelplot Lattice graphic do not mix well with base graphics so you need to keep them segregated in your plotting kitchen if you want to remain r-kosher. -- David. Thank you very much ! REgards, Michel -- Forwarded message -- From: Red Roo Date: Tue, Aug 24, 2010 at 3:46 PM Subject: Re: [R-sig-hpc] Holtman's levelplot ? To: Michel Lutz Cc: "r-sig-...@r-project.org" , redr...@yahoo.com Michel, If you ask your plotting questions over at r-help@r-project.org, Jim Holtman will probably address them directly. He is also an instructor for my "Guerrilla Data Analysis Techniques" class http://www.perfdynamics.com/Classes/Outlines/gdata.html and we just discussed this plot 2 weeks ago. --Neil Gunther Taking The Pith Out Of Performance http://perfdynamics.blogspot.com/ Follow me on Twitter http://twitter.com/DrQz Performance Dynamics Company http://www.perfdynamics.com/ On 08/24/2010 03:47 AM, Michel Lutz wrote: Hello to all, I am sorry for disturbing you, but I really don't know where/who to ask... so if this distribution list is not dealing with my concern, please excuse me... Here is my concern : I am trying to do a levelplot as in Holtman, 2005 (Visualization techniques for analysing patterns in system performance data), to display CPU usage according to the day of the month (y) and minutes (x). I am familiar with R basic features, but not at all with lattice package and I don't understand the logic of this leveplot function, especially in the particular case of a time series. I've read all the material found in the web, but I am completely stuck... Does someone have some clues or documentation that could help me to draw such a plot ? (which is nothing new : the plot I'm dreaming of is the Holtman's levelplot !). Thank you very much, and excuse-me if I'm not addressing the right distribution list. Best regards, Michel Lutz France - PhD Student 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] Constrained non-linear optimisation
Hi: A reasonable place to start would be the Optimization task view at CRAN: http://cran.r-project.org/web/views/ HTH, Dennis On Tue, Aug 24, 2010 at 10:47 AM, David Beacham wrote: > I'm relatively new to R, but I'm attempting to do a non-linear maximum > likelihood estimation (mle) in R, with the added problem that I have a > non-linear constraint. > > The basic problem is linear in the parameters (a_i) and has only one > non-linear component, b, with the problem being linear when b = 0 and > non-linear otherwise. Furthermore, f(a_i) <= b <= g(a_i) for some (simple) f > and g. > > Using optim, I can get the optimisation to work when the non-linearity is > included but not constrained, but gives poor results (as I'd expect). > However, I'm not sure how best to go about the constraint condition. My > initial attempts revolve around the use of logarithmic barrier function, but > this only appears to work when using method="CG". When using "BFGS", the > value of b 'goes out of bounds' and the loglikelihood starts throwing NaN, > which is particularly bad if I want to box constrain the a_i using the > "L-BFGS-B" method. > > Are there any other methods/approaches/variations on the above available to > me in the form of other packages/R functions etc? Or any good > references/books to help me out? > > Any help would be greatly appreciated, > David. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Time and space considerations in using predict.glm.
On Aug 24, 2010, at 3:16 PM, Daniel Yarlett wrote: Hello, I am using R to train a logistic regression model and save the resulting model to disk. I am then subsequently reloading these saved objects, and using predict.glm on them in order to make predictions about single- row data frames that are generated in real-time from requests arriving at an HTTP server. The following code demonstrates the sort of R calls that I have in mind: cases <- 200 data <- data .frame (x1=runif(cases),x2=runif(cases),y=sample(0:1,cases,replace=TRUE)) lr1 <- glm(y~x1*x2,family=binomial,data=data) new_data <- data.frame(x1=0,x2=0) out <- predict(lr1,type="response",newdata=new_data) The first thing I am noticing is that the models that I am storing are very large because I am using large data-sets, and the models seem to store residuals, fitted values and so on, by default. object.size(lr1) 1056071320 bytes Access to all this information is not necessary for my application -- all I really need is access to model$coefficients in order to make my predictions -- so I am wondering if there is some way to prevent this information from getting stored in the glm objects when they are created (or of removing it after the models have been trained)? I have discovered the model=FALSE,x=FALSE,y=FALSE switches to glm() and these seem to help somewhat, but perhaps there is some other way of only recording the coefficients of the model and other minimal details? Perhaps instead: lr2 <- coef ( glm (y~x1*x2,family=binomial,data=data,model=FALSE,x=FALSE,y=FALSE) ) object.size(lr2) Will be much smaller Secondly, on data-sets of the scale I am using, predict.glm seems to be taking a very long time to make its predictions. print(system.time(predict(lr1,type="response",newdata=new_data))) user system elapsed 0.136 0.040 0.175 print(system.time(predict(lr2,type="response",newdata=new_data))) user system elapsed 0.109 0.013 0.121 This may be an issue of swap-time, and so it could potentially be solved by addressing my first question above. However, given that I am essentially asking R to compute 1 / (1 + exp(-(b0 + b1*x1 + b2*x2 + b3*x1*x2))) I can't see any reason why this request should be taking longer than a hundredth or a thousandth of a second, say. You could try crossprod with a data.matrix and a matrix of coefficients. 1 / (1 + exp(-(crossprod(lr2, new_data))) > cases <- 2000 > data <- data .frame(x1=runif(cases),x2=runif(cases),y=sample(0:1,cases,replace=TRUE)) > lr1 <- coef(glm(y~x1*x2,family=binomial,data=data)) > new_data <- matrix(c(1, x1=0,x2=0, x1x2=0), nrow=4) # took me a while to figure out that I needed an interaction entry. > out <- 1 / (1 + exp(-(crossprod(new_data,lr1 > out [,1] [1,] 0.5107252 > lr1 (Intercept) x1 x2 x1:x2 0.04290728 -0.16826991 -0.03561711 0.06229122 > > object.size(lr1) 456 bytes Obviously R is providing a much greater level of functionality than I am requiring in this particular instance, so my overall question is what is the best way for me to reduce the size of the data I have to store in my GLM models, and to increase the speed at which I can use R to generate predictions of this sort (i.e. for novel x1,x2 pairs)? I could obviously write a custom function / class which only stores the model coefficients and computes predictions based on these using the equation above, but before I go down this route I wanted to get come advice from the R community about whether there might be a better way to address this problem and/or whether I have missed something obvious (to others). I also want to avoid writing custom code if possible because that obviously means sacrificing the great generality and power of R which could clearly be useful in my application down the line. Many thanks in advance for your assistance, Dan. 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] change order of plot panels in faceted ggplot/qplot
On Mon, Aug 23, 2010 at 1:02 PM, Alison Macalady wrote: > Hi, > > I have a 5-paneled figure that i made using the facet function in qplot > (ggplot). I've managed to arrange the panels into two rows/three columns, > but for the sake of easy visual comparisons between panels in my particular > dataset, I want to have the two plots on the bottom align on the right hand > side of the figure instead of the left. > > Here's an example: > m <- matrix(rnorm(300), nrow = 60) > colnames(m) <- paste('V', 1:5, sep = '') > b <- data.frame(site = factor(rep(c('A', 'B', 'C', 'D', 'E'), each = 12)), > status = factor(rep(rep(c('D','L'), each = 3), 10)), as.data.frame(m)) > > qplot(V2, V1, data=b, shape=status) + > scale_shape_manual(value=c(1,16))+facet_wrap(~site,nrow=2) > > What I would like to do is keep the 2 row shape, keep the order (A,B,C) of > the top plots, but have the D and E panels in this example align under the B > and C plots. > > Is this possible using qplot? Not currently. Regards, Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Trouble configuring R to use ACML
I am trying to get R to use the ACML BLAS, specifically the 'mp' version for multithreading. I have installed acml-4-4-0-gfortran-64bit I added /opt/acml4.4.0/gfortran64_mp/lib to $LD_LIBRARY_PATH. I ran: sudo ./configure --with-blas="-L/opt/acml4.4.0/gfortran64_mp/lib -lacml_mp" At the end of the configuration, the only external library listed is readline, and at the end of my post here is a section of my config.log that shows the problem. Any ideas as to what I'm missing here? I'm running Ubuntu Server 10. -- config.log --- configure:28567: checking for dgemm_ in -L/opt/acml4.4.0/gfortran64_mp/lib -lacml_mp configure:28588: gcc -std=gnu99 -o conftest -g -O2 -I/usr/local/include -L/usr/local/lib64 conftest.c -L/opt/acml4.4.0/gfortran64_mp/lib -lacml_mp -lgfortran -lm -ldl -lm >&5 conftest.c: In function 'main': conftest.c:193: warning: implicit declaration of function 'dgemm_' configure:28588: $? = 0 configure:28595: result: yes configure:29120: checking whether double complex BLAS can be used ./conftest: error while loading shared libraries: libacml_mp.so: cannot open shared object file: No such file or directory -- View this message in context: http://r.789695.n4.nabble.com/Trouble-configuring-R-to-use-ACML-tp2337193p2337193.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 with summary.lm aliased
Dear R users, I'm building linear models that use poly and has a lot of product terms. My model summaries look messy. I know that the summary could use aliases for the variable names, but I don't know how to get it to do that. Please help Thanks, -- View this message in context: http://r.789695.n4.nabble.com/help-with-summary-lm-aliased-tp2337270p2337270.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] Fwd: [R-sig-hpc] Holtman's levelplot ?
Hello, As recommended by N. Gunther, I'm writing you because I have some difficulties to create a script to track computer performance, as done in Holtman, 2005 (Visualization techniques for analysing patterns in system performance). I would like to do a leveplot, with the kind of file here enclosed. I assume I should create a matrix in R, then use the function 'image'. As I am not familiar with the lattice package, I have some difficulties to move ahead : I think my pb is in the creation of the matrix. I am not able to create sthing consistent with the image function. I am even thinking I should build my input csv file differently, but I am not sure how to do... Is someone able to help me ? Thank you very much ! REgards, Michel -- Forwarded message -- From: Red Roo Date: Tue, Aug 24, 2010 at 3:46 PM Subject: Re: [R-sig-hpc] Holtman's levelplot ? To: Michel Lutz Cc: "r-sig-...@r-project.org" , redr...@yahoo.com Michel, If you ask your plotting questions over at r-help@r-project.org, Jim Holtman will probably address them directly. He is also an instructor for my "Guerrilla Data Analysis Techniques" class http://www.perfdynamics.com/Classes/Outlines/gdata.html and we just discussed this plot 2 weeks ago. --Neil Gunther Taking The Pith Out Of Performance http://perfdynamics.blogspot.com/ Follow me on Twitter http://twitter.com/DrQz Performance Dynamics Company http://www.perfdynamics.com/ >>> >> >>On 08/24/2010 03:47 AM, Michel Lutz wrote: >> >>Hello to all, >>> >>>I am sorry for disturbing you, but I really don't know where/who to ask... >>>so if this distribution list is not dealing with my concern, please excuse >>>me... >>> >>>Here is my concern : I am trying to do a levelplot as in Holtman, 2005 >>>(Visualization techniques for analysing patterns in system performance >>>data), to display CPU usage according to the day of the month (y) and >>>minutes (x). >>> >>>I am familiar with R basic features, but not at all with lattice package and >>>I don't understand the logic of this leveplot function, especially in the >>>particular case of a time series. >>> >>>I've read all the material found in the web, but I am completely stuck... >>> >>>Does someone have some clues or documentation that could help me to draw >>>such a plot ? (which is nothing new : the plot I'm dreaming of is the >>>Holtman's levelplot !). >>> >>>Thank you very much, and excuse-me if I'm not addressing the right >>>distribution list. >>> >>>Best regards, >>> >>>Michel Lutz >>>France - PhD Student >>> >>> >>> [[alternative HTML version deleted]] >>> >>>___ >>>R-sig-hpc mailing list >>> >>>r-sig-...@r-project.org >>> >>>https://stat.ethz.ch/mailman/listinfo/r-sig-hpc >>> > >-- >Brian G. Peterson >http://braverock.com/brian/ >Ph: 773-459-4973 >IM: bgpbraverock > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and space considerations in using predict.glm.
Hello, I am using R to train a logistic regression model and save the resulting model to disk. I am then subsequently reloading these saved objects, and using predict.glm on them in order to make predictions about single-row data frames that are generated in real-time from requests arriving at an HTTP server. The following code demonstrates the sort of R calls that I have in mind: > cases <- 200 > data <- data.frame(x1=runif(cases),x2=runif(cases),y=sample(0:1,cases,replace=TRUE)) > lr1 <- glm(y~x1*x2,family=binomial,data=data) > new_data <- data.frame(x1=0,x2=0) > out <- predict(lr1,type="response",newdata=new_data) The first thing I am noticing is that the models that I am storing are very large because I am using large data-sets, and the models seem to store residuals, fitted values and so on, by default. > object.size(lr1) 1056071320 bytes Access to all this information is not necessary for my application -- all I really need is access to model$coefficients in order to make my predictions -- so I am wondering if there is some way to prevent this information from getting stored in the glm objects when they are created (or of removing it after the models have been trained)? I have discovered the model=FALSE,x=FALSE,y=FALSE switches to glm() and these seem to help somewhat, but perhaps there is some other way of only recording the coefficients of the model and other minimal details? > lr2 <- glm(y~x1*x2,family=binomial,data=data,model=FALSE,x=FALSE,y=FALSE) > object.size(lr2) 888065968 bytes Secondly, on data-sets of the scale I am using, predict.glm seems to be taking a very long time to make its predictions. > print(system.time(predict(lr1,type="response",newdata=new_data))) user system elapsed 0.136 0.040 0.175 > print(system.time(predict(lr2,type="response",newdata=new_data))) user system elapsed 0.109 0.013 0.121 This may be an issue of swap-time, and so it could potentially be solved by addressing my first question above. However, given that I am essentially asking R to compute 1 / (1 + exp(-(b0 + b1*x1 + b2*x2 + b3*x1*x2))) I can't see any reason why this request should be taking longer than a hundredth or a thousandth of a second, say. Obviously R is providing a much greater level of functionality than I am requiring in this particular instance, so my overall question is what is the best way for me to reduce the size of the data I have to store in my GLM models, and to increase the speed at which I can use R to generate predictions of this sort (i.e. for novel x1,x2 pairs)? I could obviously write a custom function / class which only stores the model coefficients and computes predictions based on these using the equation above, but before I go down this route I wanted to get come advice from the R community about whether there might be a better way to address this problem and/or whether I have missed something obvious (to others). I also want to avoid writing custom code if possible because that obviously means sacrificing the great generality and power of R which could clearly be useful in my application down the line. Many thanks in advance for your assistance, Dan. [[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] break the long R code lines automatically
Dear all, I have written some R source program with many thousands of lines. I didnât insert line breaks automatically or manually for the long lines. But now I would like to edit the source code in Emacs/ESS to make it more formal as a package. One of the major problems here is how to break the long lines automatically. Emacs auto-fill-mode only works for the lines you are typing in currently, and fill commands like M-q (fill-paragraph) or M-x fill-region (fill-region) mess up the R code lines as they take a whole function/paragraph as a long line, and remove the original line breaks. I find simple solutions for indenting code regions in Emacs/ESS, but no good ones for breaking code lines. However, I saw the nice multi-line codes in all R/Bioconductor packages. Please let me know if you have any ideas on how people usually break the existent long R code lines automatically. I will really appreciate your kind help! Heyi [[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.sty
On Tue, 2010-08-24 at 12:40 -0700, r.ookie wrote: > Does anyone know where I can download the latest version of > Sweave.sty? I have looked all over the site > http://www.stat.umn.edu/~charlie/Sweave/ with no luck. It is provided in the R sources as Sweave is an integrated part of R. You can get it here: http://svn.r-project.org/R/trunk/share/texmf/tex/latex/ So the version above is technically the latest as it is in the svn repository, but the version with your R should be late enough as long as your R is up-to-date (R 2.11.1 ). Is there a problem with the version you have or your use of it and Sweave? HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drop unused levels in lattice dotplot axis?
Hi: This looks to be a step in the right direction, but the resulting panels are all the same size. Perhaps you can build on it... # Solution based on an R-help post by Deepayan Sarkar: # http://tolstoy.newcastle.edu.au/R/e2/help/06/09/1579.html dotplot(A ~ B | C, data=dfr, scales=list(y=list(relation="free")), prepanel = function(x, y, ...) { # drop unused levels yy <- y[, drop = TRUE] # reset y-limits list(ylim = levels(yy), yat = sort(unique(as.numeric(yy }, panel = function(x, y, ...) { # drop unused levels...again... yy <- y[, drop = TRUE] panel.dotplot(x, yy, ...) } ) HTH, Dennis On Tue, Aug 24, 2010 at 4:25 AM, Stephen T. wrote: > > Hi list, I have a data set - something like this > dfr <- data.frame(A=factor(letters[1:25]),B=runif(25), > C=sample(LETTERS[1:4],25,replace=TRUE)) > and I want to create a dotplot: > library(lattice)dotplot(A ~ B | C, data=dfr, > scales=list(y=list(relation="free"))) > but this puts uneven spaces along the y-axis in each panel. > drop.unused.levels=TRUE will drop conditioning variables, but does not > affect the levels in the y-variable. > I can get something like what I want with > ggplot2:library(ggplot2)ggplot(data=dfr,mapping=aes(x=B,y=A)) + geom_point() > + facet_wrap( ~ C,scales="free_y") > I wonder if this is possible in lattice? > Thanks! > Stephen >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[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.sty
On 08/24/2010 09:40 PM, r.ookie wrote: > Does anyone know where I can download the latest version of > Sweave.sty? I have looked all over the site > http://www.stat.umn.edu/~charlie/Sweave/ with no luck. I don't think there is anything newer than what is inside the latest version of R. Look under share/texmf -- Peter Dalgaard Center for Statistics, Copenhagen Business School 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] Sweave.sty
Here is one: http://svn.r-project.org/R/trunk/share/texmf/tex/latex/Sweave.sty -Matt On Tue, 2010-08-24 at 15:40 -0400, r.ookie wrote: > Does anyone know where I can download the latest version of Sweave.sty? I > have looked all over the site http://www.stat.umn.edu/~charlie/Sweave/ with > no luck. > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sweave.sty
Does anyone know where I can download the latest version of Sweave.sty? I have looked all over the site http://www.stat.umn.edu/~charlie/Sweave/ with no luck. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Compiling Fortran for R : .so: mach-o, but wrong architecture
On 08/24/2010 09:01 PM, Marie-Hélène Ouellette wrote: > Dear all, > > I'm trying to compile FORTRAN code to be used in R, failing miserably. I got > a simple code function to try to figure out what is going wrong. Here is the > code (available on the web) : > > > > subroutine bar(n, x) > > integer n > > double precision x(n) > > integer i > > > > do 100 i = 1, n > > x(i) = x(i) ** 2 > > 100 continue > > > > end > > > > 1. I compiled the code using 'R CMD SHLIB bar.f' in the terminal. This > created files .o and so of the same name. Got the following output in the > terminal : > > > > R CMD SHLIB bar.f > > gfortran -arch x86_64 -fPIC -g -O2 -c bar.f -o bar.o > > gcc -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names > -undefined dynamic_lookup -single_module -multiply_defined suppress > -L/usr/local/lib -o bar.so bar.o -lgfortran > -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework > -Wl,CoreFoundation > > > > > > 2. Tried to dynamically load the code. In the R console, typed > >> dyn.load("~/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so") > > Erreur dans > dyn.load("~/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so") : > > impossible de charger la bibliothèque partagée > '/Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so': > dlopen(/Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so, > 6): no suitable image found. Did find: > /Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so: > mach-o, but wrong architecture > > > > I have : > > Mac OS : 10.6.4 > > R 2.11.0 GUI 1.33 Leopard build 32-bit (5582) > > Xcode version 3.2.3 64-bit > > Installed gfortran 4.3.2 > > > > I hope this is all you need, feel free to ask me for any more info. Thank > you for your time, Looks like you are trying to load a 64 bit module into a 32 bit R. Does it work better with R64? -- Peter Dalgaard Center for Statistics, Copenhagen Business School 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] How to obtain seed after generating random number?
> -Original Message- > From: r.ookie [mailto:r.oo...@live.com] > Sent: Tuesday, August 24, 2010 12:25 PM > To: William Dunlap > Cc: r-help@r-project.org > Subject: Re: [R] How to obtain seed after generating random number? > > Thanks for your solution, however, which values would I then > provide someone else so that they can produce the same results? Give them the .Random.seed attribute from the result of interest, just as I did in the example of reproducing the result z0. If they didn't want to use this function they would have to do .Random.seed <<- attr(z0, ".Random.seed") to set it. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > On Aug 24, 2010, at 12:06 PM, William Dunlap wrote: > > The following will attach (as an attribute) the current global value > of .Random.seed to the value of the evaluated 'expr' argument. If you > supply > the initial.Random.seed argument then it will use that when evaluating > the expression (and also attach it to the result) so you can > repeat the > 'unusual' computation. I sometimes use this sort of thing > when doing QA > work. >f <- function(expr, initial.Random.seed) { >if (missing(initial.Random.seed)) { > if (!exists(".Random.seed", envir=.GlobalEnv)) { > runif(1) # force generation of a .Random.seed > } > initial.Random.seed <- get(".Random.seed", > envir=.GlobalEnv) >} >.Random.seed <<- initial.Random.seed >structure(expr, .Random.seed=.Random.seed) >} > > E.g., > > z0 <- f(runif(3)) > > str(z0) > atomic [1:3] 0.15 0.225 0.607 > - attr(*, ".Random.seed")= int [1:626] 403 19 1644829386 1412664364 > -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > > z1 <- f(runif(3)) > > str(z1) > atomic [1:3] 0.786 0.325 0.789 > - attr(*, ".Random.seed")= int [1:626] 403 22 1644829386 1412664364 > -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > > str(f(runif(3), attr(z0,".Random.seed"))) # repeat with .Random.seed > used to make z0 > atomic [1:3] 0.15 0.225 0.607 > - attr(*, ".Random.seed")= int [1:626] 403 19 1644829386 1412664364 > -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > > -Original Message- > > From: r-help-boun...@r-project.org > > [mailto:r-help-boun...@r-project.org] On Behalf Of r.ookie > > Sent: Tuesday, August 24, 2010 11:48 AM > > To: Bogaso Christofer > > Cc: r-help@r-project.org > > Subject: Re: [R] How to obtain seed after generating random number? > > > > I have wondered this in the past too so thanks for the question. > > > > On Aug 24, 2010, at 10:11 AM, Bogaso Christofer wrote: > > > > Dear all, I was doing an experiment to disprove some theory > therefore > > performing lot of random simulation. Goal is to show the > audience that > > although something has very rare chance to occur but it > > doesn't mean that > > event would be impossible. > > > > > > > > In this case after getting that rare event I need to show > > that same scenario > > for multiple times to explain other audience. Hence I need to > > somehow save > > that seed which generates that random numbers after doing the > > experiment. > > However as it is very rare event it is not very practical to > > start with a > > fixed seed and then generate random numbers. Hence I am > > looking for some way > > which will tell me about that corresponding seed which was > > responsible to > > generate that particular series of random numbers responsible > > for occurrence > > of that rare event. > > > > > > > > In short, I need to know the seed ***after*** generating the > > random numbers. > > > > > > > > Is there any possibility to know this? > > > > > > > > Thanks and regards, > > > > > > [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and space considerations in using predict.glm()
Hello, I am using R to train a logistic regression model and save the resulting model to disk. I am then subsequently reloading these saved objects, and using predict.glm on them in order to make predictions about single-row data frames that are generated in real-time from requests arriving at an HTTP server. The following code demonstrates the sort of R calls that I have in mind: > cases <- 200 > data <- data.frame(x1=runif(cases),x2=runif(cases),y=sample(0:1,cases,replace=TRUE)) > lr1 <- glm(y~x1*x2,family=binomial,data=data) > new_data <- data.frame(x1=0,x2=0) > out <- predict(lr1,type="response",newdata=new_data) The first thing I am noticing is that the models that I am storing are very large because I am using large data-sets, and the models seem to store residuals, fitted values and so on, by default. > object.size(lr1) 1056071320 bytes Access to all this information is not necessary for my application -- all I really need is access to model$coefficients in order to make my predictions -- so I am wondering if there is some way to prevent this information from getting stored in the glm objects when they are created (or of removing it after the models have been trained)? I have discovered the model=FALSE,x=FALSE,y=FALSE switches to glm() and these seem to help somewhat, but perhaps there is some other way of only recording the coefficients of the model and other minimal details? > lr2 <- glm(y~x1*x2,family=binomial,data=data,model=FALSE,x=FALSE,y=FALSE) > object.size(lr2) 888065968 bytes Secondly, on data-sets of the scale I am using, predict.glm seems to be taking a very long time to make its predictions. > print(system.time(predict(lr1,type="response",newdata=new_data))) user system elapsed 0.136 0.040 0.175 > print(system.time(predict(lr2,type="response",newdata=new_data))) user system elapsed 0.109 0.013 0.121 This may be an issue of swap-time, and so it could potentially be solved by addressing my first question above. However, given that I am essentially asking R to compute 1 / (1 + exp(-(b0 + b1*x1 + b2*x2 + b3*x1*x2))) I can't see any reason why this request should be taking longer than a hundredth or a thousandth of a second, say. Obviously R is providing a much greater level of functionality than I am requiring in this particular instance, so my overall question is what is the best way for me to reduce the size of the data I have to store in my GLM models, and to increase the speed at which I can use R to generate predictions of this sort (i.e. for novel x1,x2 pairs)? I could obviously write a custom function / class which only stores the model coefficients and computes predictions based on these using the equation above, but before I go down this route I wanted to get come advice from the R community about whether there might be a better way to address this problem and/or whether I have missed something obvious (to others). I also want to avoid writing custom code if possible because that obviously means sacrificing the great generality and power of R which could clearly be useful in my application down the line. Many thanks in advance for your assistance, Dan. [[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] Applying t-test to matrix without using a loop
You can certainly use apply() #make up some data x <- 10; y <- 10; g <- 5 set.seed(1969) dat <- matrix(rnorm((x + y) * g), ncol = x + y) # apply() the t.test function to each row fo the matrix and extract just the p value results <- apply(dat, 1, function(dat) { t.test(x = dat[1:x], y = dat[(x + 1):(x + y)])$p.value}) # if you want, you can bind p-values back into the matrix cbind(dat, pvals = results) HTH, Josh P. S. If you are doing this for many rows, the p-values may not be meaningful in the sense of hypothesis testing (e.g., p < .05 is "significant") On Tue, Aug 24, 2010 at 12:09 PM, Cedric Laczny wrote: > Hi, > > the actual thread on "multiple assignments ?" made up an interesting point for > me. > If I have a matrix with g rows and x + y columns where columns 1 - x contain > values of group1 and columns x+1 to y contain the values of group2. > Now I want to compute a vector of length g that holds the p-value (e.g. via a > t-test) calculated for the appropriate row in the matrix. > > At the moment I am doing something like this: > # code might be wrong. Should just give the idea. > p = rep(-1, g) > for( i in 1: g) > p[i] = t.test(values[i, c(1:x)], values[i, c(x +1: x+y)] > > I am now wondering if there is a faster (maybe also more elegant) way to do > this, e.g. using something like lapply or such? > > Best, > > Cedric > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to obtain seed after generating random number?
Thanks for your solution, however, which values would I then provide someone else so that they can produce the same results? On Aug 24, 2010, at 12:06 PM, William Dunlap wrote: The following will attach (as an attribute) the current global value of .Random.seed to the value of the evaluated 'expr' argument. If you supply the initial.Random.seed argument then it will use that when evaluating the expression (and also attach it to the result) so you can repeat the 'unusual' computation. I sometimes use this sort of thing when doing QA work. f <- function(expr, initial.Random.seed) { if (missing(initial.Random.seed)) { if (!exists(".Random.seed", envir=.GlobalEnv)) { runif(1) # force generation of a .Random.seed } initial.Random.seed <- get(".Random.seed", envir=.GlobalEnv) } .Random.seed <<- initial.Random.seed structure(expr, .Random.seed=.Random.seed) } E.g., > z0 <- f(runif(3)) > str(z0) atomic [1:3] 0.15 0.225 0.607 - attr(*, ".Random.seed")= int [1:626] 403 19 1644829386 1412664364 -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > z1 <- f(runif(3)) > str(z1) atomic [1:3] 0.786 0.325 0.789 - attr(*, ".Random.seed")= int [1:626] 403 22 1644829386 1412664364 -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > str(f(runif(3), attr(z0,".Random.seed"))) # repeat with .Random.seed used to make z0 atomic [1:3] 0.15 0.225 0.607 - attr(*, ".Random.seed")= int [1:626] 403 19 1644829386 1412664364 -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of r.ookie > Sent: Tuesday, August 24, 2010 11:48 AM > To: Bogaso Christofer > Cc: r-help@r-project.org > Subject: Re: [R] How to obtain seed after generating random number? > > I have wondered this in the past too so thanks for the question. > > On Aug 24, 2010, at 10:11 AM, Bogaso Christofer wrote: > > Dear all, I was doing an experiment to disprove some theory therefore > performing lot of random simulation. Goal is to show the audience that > although something has very rare chance to occur but it > doesn't mean that > event would be impossible. > > > > In this case after getting that rare event I need to show > that same scenario > for multiple times to explain other audience. Hence I need to > somehow save > that seed which generates that random numbers after doing the > experiment. > However as it is very rare event it is not very practical to > start with a > fixed seed and then generate random numbers. Hence I am > looking for some way > which will tell me about that corresponding seed which was > responsible to > generate that particular series of random numbers responsible > for occurrence > of that rare event. > > > > In short, I need to know the seed ***after*** generating the > random numbers. > > > > Is there any possibility to know this? > > > > Thanks and regards, > > > [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lme4 + R 2.11.0 + mac unavailable
On Aug 24, 2010, at 3:13 PM, Daniel Malter wrote: Hi, has there been a solution to this issue? I am encountering the same problem on a Mac with OSX 10.6.4. The problem persists when I try to install lme4 from the source (see below), and my R version is up to date according to R's update check. But have you installed the correct versions of Xcode and the R- appropriate tools? http://r.research.att.com/tools/ The message complaining about missing ... ld: library not found for -lgfortran collect2: ld returned 1 exit status ... suggests no (or incorrect) Fortran compiler. -- David. Thanks for any help, Daniel -- sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.1 -- install.packages("lme4") Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘lme4’ is not available -- install.packages("lme4", type = "source") trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/lme4_0.999375-35.tar.gz' Content type 'application/x-gzip' length 1017763 bytes (993 Kb) opened URL == downloaded 993 Kb * installing *source* package ‘lme4’ ... ** libs *** arch - i386 gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/ Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/ include" -fPIC -g -O2 -c init.c -o init.o gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/ Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/ include" -fPIC -g -O2 -c lmer.c -o lmer.o gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/ Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/ include" -fPIC -g -O2 -c local_stubs.c -o local_stubs.o gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o lme4.so init.o lmer.o local_stubs.o -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRlapack -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRblas - lgfortran -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation ld: library not found for -lgfortran collect2: ld returned 1 exit status make: *** [lme4.so] Error 1 ERROR: compilation failed for package ‘lme4’ * removing ‘/Library/Frameworks/R.framework/Versions/2.11/Resources/library/lme4’ The downloaded packages are in ‘/private/var/folders/q5/q5YCJSnWH7arB5jzTZBIfTI/-Tmp-/ Rtmp4tcqUG/downloaded_packages’ Updating HTML index of packages in '.Library' Warning message: In install.packages("lme4", type = "source") : installation of package 'lme4' had non-zero exit status 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] Plot bar lines like excel
On Aug 24, 2010, at 1:40 PM, abotaha wrote: Hello guys, I would to plot a bar line between to curves like in excel as shown in the following image. but i do not know how I can do that in R. http://r.789695.n4.nabble.com/file/n2337089/excel_Plot.png any help would appreciate. ?segments And note that supplying x0 will suffice in this instance since x1=x0. For worked solutions, reproducible code is needed (as always stated in the message footers.) -- 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] lme4 + R 2.11.0 + mac unavailable
Hi, has there been a solution to this issue? I am encountering the same problem on a Mac with OSX 10.6.4. The problem persists when I try to install lme4 from the source (see below), and my R version is up to date according to R's update check. Thanks for any help, Daniel -- sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.1 -- install.packages("lme4") Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘lme4’ is not available -- install.packages("lme4", type = "source") trying URL 'http://lib.stat.cmu.edu/R/CRAN/src/contrib/lme4_0.999375-35.tar.gz' Content type 'application/x-gzip' length 1017763 bytes (993 Kb) opened URL == downloaded 993 Kb * installing *source* package ‘lme4’ ... ** libs *** arch - i386 gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/include" -fPIC -g -O2 -c init.c -o init.o gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/include" -fPIC -g -O2 -c lmer.c -o lmer.o gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.11/Resources/library/Matrix/include" -I"/Library/Frameworks/R.framework/Resources/library/stats/include" -fPIC -g -O2 -c local_stubs.c -o local_stubs.o gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o lme4.so init.o lmer.o local_stubs.o -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRlapack -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRblas -lgfortran -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation ld: library not found for -lgfortran collect2: ld returned 1 exit status make: *** [lme4.so] Error 1 ERROR: compilation failed for package ‘lme4’ * removing ‘/Library/Frameworks/R.framework/Versions/2.11/Resources/library/lme4’ The downloaded packages are in ‘/private/var/folders/q5/q5YCJSnWH7arB5jzTZBIfTI/-Tmp-/Rtmp4tcqUG/downloaded_packages’ Updating HTML index of packages in '.Library' Warning message: In install.packages("lme4", type = "source") : installation of package 'lme4' had non-zero exit status -- View this message in context: http://r.789695.n4.nabble.com/lme4-R-2-11-0-mac-unavailable-tp2220331p2337213.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] Applying t-test to matrix without using a loop
Hi, the actual thread on "multiple assignments ?" made up an interesting point for me. If I have a matrix with g rows and x + y columns where columns 1 - x contain values of group1 and columns x+1 to y contain the values of group2. Now I want to compute a vector of length g that holds the p-value (e.g. via a t-test) calculated for the appropriate row in the matrix. At the moment I am doing something like this: # code might be wrong. Should just give the idea. p = rep(-1, g) for( i in 1: g) p[i] = t.test(values[i, c(1:x)], values[i, c(x +1: x+y)] I am now wondering if there is a faster (maybe also more elegant) way to do this, e.g. using something like lapply or such? Best, Cedric __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 obtain seed after generating random number?
The following will attach (as an attribute) the current global value of .Random.seed to the value of the evaluated 'expr' argument. If you supply the initial.Random.seed argument then it will use that when evaluating the expression (and also attach it to the result) so you can repeat the 'unusual' computation. I sometimes use this sort of thing when doing QA work. f <- function(expr, initial.Random.seed) { if (missing(initial.Random.seed)) { if (!exists(".Random.seed", envir=.GlobalEnv)) { runif(1) # force generation of a .Random.seed } initial.Random.seed <- get(".Random.seed", envir=.GlobalEnv) } .Random.seed <<- initial.Random.seed structure(expr, .Random.seed=.Random.seed) } E.g., > z0 <- f(runif(3)) > str(z0) atomic [1:3] 0.15 0.225 0.607 - attr(*, ".Random.seed")= int [1:626] 403 19 1644829386 1412664364 -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > z1 <- f(runif(3)) > str(z1) atomic [1:3] 0.786 0.325 0.789 - attr(*, ".Random.seed")= int [1:626] 403 22 1644829386 1412664364 -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... > str(f(runif(3), attr(z0,".Random.seed"))) # repeat with .Random.seed used to make z0 atomic [1:3] 0.15 0.225 0.607 - attr(*, ".Random.seed")= int [1:626] 403 19 1644829386 1412664364 -3288017 -689767195 792688028 -702547982 -676502931 402532263 ... Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of r.ookie > Sent: Tuesday, August 24, 2010 11:48 AM > To: Bogaso Christofer > Cc: r-help@r-project.org > Subject: Re: [R] How to obtain seed after generating random number? > > I have wondered this in the past too so thanks for the question. > > On Aug 24, 2010, at 10:11 AM, Bogaso Christofer wrote: > > Dear all, I was doing an experiment to disprove some theory therefore > performing lot of random simulation. Goal is to show the audience that > although something has very rare chance to occur but it > doesn't mean that > event would be impossible. > > > > In this case after getting that rare event I need to show > that same scenario > for multiple times to explain other audience. Hence I need to > somehow save > that seed which generates that random numbers after doing the > experiment. > However as it is very rare event it is not very practical to > start with a > fixed seed and then generate random numbers. Hence I am > looking for some way > which will tell me about that corresponding seed which was > responsible to > generate that particular series of random numbers responsible > for occurrence > of that rare event. > > > > In short, I need to know the seed ***after*** generating the > random numbers. > > > > Is there any possibility to know this? > > > > Thanks and regards, > > > [[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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Compiling Fortran for R : .so: mach-o, but wrong architecture
Dear all, I'm trying to compile FORTRAN code to be used in R, failing miserably. I got a simple code function to try to figure out what is going wrong. Here is the code (available on the web) : subroutine bar(n, x) integer n double precision x(n) integer i do 100 i = 1, n x(i) = x(i) ** 2 100 continue end 1. I compiled the code using 'R CMD SHLIB bar.f' in the terminal. This created files .o and so of the same name. Got the following output in the terminal : R CMD SHLIB bar.f gfortran -arch x86_64 -fPIC -g -O2 -c bar.f -o bar.o gcc -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o bar.so bar.o -lgfortran -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation 2. Tried to dynamically load the code. In the R console, typed > dyn.load("~/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so") Erreur dans dyn.load("~/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so") : impossible de charger la bibliothèque partagée '/Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so': dlopen(/Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so, 6): no suitable image found. Did find: /Users/maryh2002/Documents/Marietravail/articles/MRTspatial/SIMSSDenR/bar.so: mach-o, but wrong architecture I have : Mac OS : 10.6.4 R 2.11.0 GUI 1.33 Leopard build 32-bit (5582) Xcode version 3.2.3 64-bit Installed gfortran 4.3.2 I hope this is all you need, feel free to ask me for any more info. Thank you for your time, MH [[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 obtain seed after generating random number?
> On Aug 24, 2010, at 10:11 AM, Bogaso Christofer wrote: > > Dear all, I was doing an experiment to disprove some theory therefore > performing lot of random simulation. Goal is to show the audience that > although something has very rare chance to occur but it doesn't mean that > event would be impossible. > > In short, I need to know the seed ***after*** generating the random numbers. Does ?.Random.seed help? It doesn't let you "go back and get the random seed that this sequence was started from", though. So you may need to checkpoint reasonably frequently by saving .Random.seed ... Another alternative is to use set.seed() at the same checkpointing intervals (e.g. a different sequential value for each in a series of simulations) -- that might run the risk of a slightly higher correlation between successive simulations (I'm not sure what can be guaranteed about the properties of sequences from neighboring seeds) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot bar lines like excel
Hello guys, I would to plot a bar line between to curves like in excel as shown in the following image. but i do not know how I can do that in R. http://r.789695.n4.nabble.com/file/n2337089/excel_Plot.png any help would appreciate. -- View this message in context: http://r.789695.n4.nabble.com/Plot-bar-lines-like-excel-tp2337089p2337089.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] Finding pairs
Dear R Helpers, I am a newbie and recently got introduced to R. I have a large database containing the names of bank branch offices along-with other details. I am into Operational Risk as envisaged by BASEL II Accord. I am trying to express my problem and I am using only an indicative data which comes in coded format. A (branch) B (controlled by) 144 145 146 147 144 148 145 149 147 151 146 .. ... .. ... where 144's etc are branch codes in a given city and B is subset of A. If a branch code appearing in "A" also appears in "B" (which is paired with some otehr element of A e.g. 144 appearing in A, also appears in "B" and is paired with 147 of "A" and likewise), then that means 144 is controlling operations of bank office 147. Again, 147 itself appears again in B and is paired with bank branch coded 149. Thus, 149 is controlled by 147 and 147 is controlled by 144. Likewise there are more than 700 hundred branch name codes available. My objective is to group them as follows - Bank Branch 144 147 149 145 146 151 148 . or even the following output will do. 144 147 149 145 146 151 148 151 .. I understand I should be writing some R code to begin with which I had tried also but as of now I am helpless. Please guide me. Mike [[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 obtain seed after generating random number?
I have wondered this in the past too so thanks for the question. On Aug 24, 2010, at 10:11 AM, Bogaso Christofer wrote: Dear all, I was doing an experiment to disprove some theory therefore performing lot of random simulation. Goal is to show the audience that although something has very rare chance to occur but it doesn't mean that event would be impossible. In this case after getting that rare event I need to show that same scenario for multiple times to explain other audience. Hence I need to somehow save that seed which generates that random numbers after doing the experiment. However as it is very rare event it is not very practical to start with a fixed seed and then generate random numbers. Hence I am looking for some way which will tell me about that corresponding seed which was responsible to generate that particular series of random numbers responsible for occurrence of that rare event. In short, I need to know the seed ***after*** generating the random numbers. Is there any possibility to know this? Thanks and regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to remove rows based on frequency of factor and then difference date scores
The paste-y argument is my usual trick in these situations. I forget that tapply can take multiple ordering arguments :) Abhijit On 08/24/2010 02:17 PM, David Winsemius wrote: On Aug 24, 2010, at 1:59 PM, Abhijit Dasgupta, PhD wrote: The only problem with this is that Chris's unique individuals are a combination of Type and ID, as I understand it. So Type=A, ID=1 is a different individual from Type=B,ID=1. So we need to create a unique identifier per person, simplistically by uniqueID=paste(Type, ID, sep=''). Then, using this new identifier, everything follows. I see your point. I agree that a tapply method should present both factors in the indices argument. > new.df <- txt.df[ -which( txt.df$nn <=1), ] > new.df <- new.df[ with(new.df, order(Type, ID) ), ] # and possibly needs to be ordered? > new.df$diffdays <- unlist( tapply(new.df$dt2, list(new.df$ID, new.df$Type), function(x) x[1] -x) ) > new.df Type ID Date Valuedt2 nn diffdays 1A 1 16/09/2020 8 2020-09-16 30 2A 1 23/09/2010 9 2010-09-23 3 3646 4B 1 13/5/2010 6 2010-05-13 30 But do not agree that you need, in this case at least, to create a paste()-y index. Agreed, however, such a construction can be useful in other situations. -- Abhijit Dasgupta, PhD Director and Principal Statistician ARAASTAT Ph: 301.385.3067 E: adasgu...@araastat.com W: http://www.araastat.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] lattice: plot alignment fails
Dear expeRts, I would like to have four plots appearing in one figure. The minimal example shows this. However, the four figures are not properly aligned. Why? If I comment out the scales=... arguments, then it works, but I would like to use this... :-) Cheers, Marius library(lattice) set.seed(1) ## plot: xyplot, histogram, qqplot, acf res.plots <- function(x){ x.max <- max(abs(min(x)),abs(max(x))) ## xyplot x0 <- 1 x1 <- length(x) y0 <- -x.max y1 <- x.max xy <- xyplot(x~(1:length(x)),xlim=c(x0,x1),ylim=c(y0,y1), aspect=1,scales=list(relation="free",alternating=c(1,1),tck=c(1,0))) ## histogram x0 <- -x.max x1 <- x.max h <- histogram(x,xlim=c(x0,x1),aspect=1,type="density", scales=list(relation="free",alternating=c(1,1),tck=c(1,0))) ## qqplot y0 <- -x.max y1 <- x.max qq <- qqmath(x,ylim=c(y0,y1),aspect=1,scales=list(tck=c(1,0),y=list(rot=90)), panel=function(...){ panel.qqmath(...) panel.qqmathline(x) }) ## ACF myacf <- acf(x,plot=F,lag.max=24) x0=0 x1=24 y0=-1 y1=1 ACF <- xyplot(0~0,xlim=c(x0,x1),ylim=c(y0,y1),aspect=1, scales=list(tck=c(1,0),y=list(rot=90)), panel=function(...){ for(i in 1:24){ panel.segments(i,0,i,myacf$acf[i]) } panel.abline(h=0) }) ## plot function plot.list <- list(xy,qq,h,ACF) counter <- 1 trellis.device(pdf,paper="special",width=6,height=6,file="myplot.pdf") for(i in 1:2){ for(j in 1:2){ if(i==2 && j==2) print(plot.list[[counter]], split=c(j,i,2,2)) else print(plot.list[[counter]], split=c(j,i,2,2), more=TRUE) counter <- counter + 1 } } dev.off() } x <- rexp(1000) res.plots(x) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 rows based on frequency of factor and then difference date scores
On Aug 24, 2010, at 1:59 PM, Abhijit Dasgupta, PhD wrote: The only problem with this is that Chris's unique individuals are a combination of Type and ID, as I understand it. So Type=A, ID=1 is a different individual from Type=B,ID=1. So we need to create a unique identifier per person, simplistically by uniqueID=paste(Type, ID, sep=''). Then, using this new identifier, everything follows. I see your point. I agree that a tapply method should present both factors in the indices argument. > new.df <- txt.df[ -which( txt.df$nn <=1), ] > new.df <- new.df[ with(new.df, order(Type, ID) ), ] # and possibly needs to be ordered? > new.df$diffdays <- unlist( tapply(new.df$dt2, list(new.df$ID, new.df $Type), function(x) x[1] -x) ) > new.df Type ID Date Valuedt2 nn diffdays 1A 1 16/09/2020 8 2020-09-16 30 2A 1 23/09/2010 9 2010-09-23 3 3646 4B 1 13/5/2010 6 2010-05-13 30 But do not agree that you need, in this case at least, to create a paste()-y index. Agreed, however, such a construction can be useful in other situations. -- David. On 08/24/2010 01:53 PM, David Winsemius wrote: On Aug 24, 2010, at 1:19 PM, Chris Beeley wrote: Hello- A basic question which has nonetheless floored me entirely. I have a dataset which looks like this: Type ID DateValue A 116/09/2020 8 A 1 23/09/2010 9 B 3 18/8/20107 B 1 13/5/20106 There are two Types, which correspond to different individuals in different conditions, and loads of ID labels (1:50) corresponding to the different individuals in each condition, and measurements at different times (from 1 to 10 measurements) for each individual. I want to perform the following operations: 1) Delete all individuals for whom only one measurement is available. In the dataset above, you can see that I want to delete the row Type B ID 3, and Type B ID 1, but without deleting the Type A ID 1 data because there is more than one measurement for Type A ID 1 (but not for Type B ID1) 2) Produce difference scores for each of the Dates, so each individual (Type A ID1 and all the others for whom more than one measurement exists) starts at Date "1" and goes up in integers according to how many days have elapsed. I just know there's some incredibly cunning R-ish way of doing this but after many hours of fiddling I have had to admit defeat. Not sure about terribly cunning. Let's assume your dataframe was read in with stringsAsFactors=FALSE and is called txt.df: > txt.df$dt2 <- as.Date(txt.df$Date, format="%d/%m/%Y") > txt.df Type ID Date Valuedt2 1A 1 16/09/2020 8 2020-09-16 2A 1 23/09/2010 9 2010-09-23 3B 3 18/8/2010 7 2010-08-18 4B 1 13/5/2010 6 2010-05-13 > txt.df$nn <- ave(txt.df$ID,txt.df$ID, FUN=length) > txt.df Type ID Date Valuedt2 nn 1A 1 16/09/2020 8 2020-09-16 3 2A 1 23/09/2010 9 2010-09-23 3 3B 3 18/8/2010 7 2010-08-18 1 4B 1 13/5/2010 6 2010-05-13 3 > txt.df[ -which( txt.df$nn <=1), ] Type ID Date Valuedt2 nn 1A 1 16/09/2020 8 2020-09-16 3 2A 1 23/09/2010 9 2010-09-23 3 4B 1 13/5/2010 6 2010-05-13 3 # Task #1 accomplished > tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) $`1` Time differences in days [1]0 3646 3779 $`3` Time difference of 0 days > unlist( tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) ) 11 12 133 0 3646 37790 > txt.df$diffdays <- unlist( tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) ) > txt.df Type ID Date Valuedt2 nn diffdays 1A 1 16/09/2020 8 2020-09-16 30 2A 1 23/09/2010 9 2010-09-23 3 3646 3B 3 18/8/2010 7 2010-08-18 1 3779 4B 1 13/5/2010 6 2010-05-13 30 > David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to remove rows based on frequency of factor and then difference date scores
The only problem with this is that Chris's unique individuals are a combination of Type and ID, as I understand it. So Type=A, ID=1 is a different individual from Type=B,ID=1. So we need to create a unique identifier per person, simplistically by uniqueID=paste(Type, ID, sep=''). Then, using this new identifier, everything follows. On 08/24/2010 01:53 PM, David Winsemius wrote: On Aug 24, 2010, at 1:19 PM, Chris Beeley wrote: Hello- A basic question which has nonetheless floored me entirely. I have a dataset which looks like this: Type ID DateValue A 116/09/2020 8 A 1 23/09/2010 9 B 3 18/8/20107 B 1 13/5/20106 There are two Types, which correspond to different individuals in different conditions, and loads of ID labels (1:50) corresponding to the different individuals in each condition, and measurements at different times (from 1 to 10 measurements) for each individual. I want to perform the following operations: 1) Delete all individuals for whom only one measurement is available. In the dataset above, you can see that I want to delete the row Type B ID 3, and Type B ID 1, but without deleting the Type A ID 1 data because there is more than one measurement for Type A ID 1 (but not for Type B ID1) 2) Produce difference scores for each of the Dates, so each individual (Type A ID1 and all the others for whom more than one measurement exists) starts at Date "1" and goes up in integers according to how many days have elapsed. I just know there's some incredibly cunning R-ish way of doing this but after many hours of fiddling I have had to admit defeat. Not sure about terribly cunning. Let's assume your dataframe was read in with stringsAsFactors=FALSE and is called txt.df: > txt.df$dt2 <- as.Date(txt.df$Date, format="%d/%m/%Y") > txt.df Type ID Date Valuedt2 1A 1 16/09/2020 8 2020-09-16 2A 1 23/09/2010 9 2010-09-23 3B 3 18/8/2010 7 2010-08-18 4B 1 13/5/2010 6 2010-05-13 > txt.df$nn <- ave(txt.df$ID,txt.df$ID, FUN=length) > txt.df Type ID Date Valuedt2 nn 1A 1 16/09/2020 8 2020-09-16 3 2A 1 23/09/2010 9 2010-09-23 3 3B 3 18/8/2010 7 2010-08-18 1 4B 1 13/5/2010 6 2010-05-13 3 > txt.df[ -which( txt.df$nn <=1), ] Type ID Date Valuedt2 nn 1A 1 16/09/2020 8 2020-09-16 3 2A 1 23/09/2010 9 2010-09-23 3 4B 1 13/5/2010 6 2010-05-13 3 # Task #1 accomplished > tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) $`1` Time differences in days [1]0 3646 3779 $`3` Time difference of 0 days > unlist( tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) ) 11 12 133 0 3646 37790 > txt.df$diffdays <- unlist( tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) ) > txt.df Type ID Date Valuedt2 nn diffdays 1A 1 16/09/2020 8 2020-09-16 30 2A 1 23/09/2010 9 2010-09-23 3 3646 3B 3 18/8/2010 7 2010-08-18 1 3779 4B 1 13/5/2010 6 2010-05-13 30 > I would be very grateful for any words of advice. Many thanks, Chris Beeley, Institute of Mental Health, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. 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. -- Abhijit Dasgupta, PhD Director and Principal Statistician ARAASTAT Ph: 301.385.3067 E: adasgu...@araastat.com W: http://www.araastat.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 rows based on frequency of factor and then difference date scores
An answer to 1) > x = data.frame(Type=c('A','A','B','B'), ID=c(1,1,3,1), Date = c('16/09/2010','23/09/2010','18/8/2010','13/5/2010'), Value=c(8,9,7,6)) > x Type ID Date Value 1A 1 16/09/2010 8 2A 1 23/09/2010 9 3B 3 18/8/2010 7 4B 1 13/5/2010 6 > x$Date = as.Date(x$Date,format='%d/%m/%Y') > library(plyr) > x$uniqueID = paste(x$Type, x$ID, sep='') > nobs = daply(x, ~uniqueID, nrow) > keep = names(nobs)[nobs>1] > newx = x[x$uniqueID %in% keep,] An answer to 2) > require(plyr) > ddply(newx, ~uniqueID, transform, newDate = as.numeric(Date - min(Date)+1)) On 08/24/2010 01:19 PM, Chris Beeley wrote: Hello- A basic question which has nonetheless floored me entirely. I have a dataset which looks like this: Type ID DateValue A 116/09/2020 8 A 1 23/09/2010 9 B 3 18/8/20107 B 1 13/5/20106 There are two Types, which correspond to different individuals in different conditions, and loads of ID labels (1:50) corresponding to the different individuals in each condition, and measurements at different times (from 1 to 10 measurements) for each individual. I want to perform the following operations: 1) Delete all individuals for whom only one measurement is available. In the dataset above, you can see that I want to delete the row Type B ID 3, and Type B ID 1, but without deleting the Type A ID 1 data because there is more than one measurement for Type A ID 1 (but not for Type B ID1) 2) Produce difference scores for each of the Dates, so each individual (Type A ID1 and all the others for whom more than one measurement exists) starts at Date "1" and goes up in integers according to how many days have elapsed. I just know there's some incredibly cunning R-ish way of doing this but after many hours of fiddling I have had to admit defeat. I would be very grateful for any words of advice. Many thanks, Chris Beeley, Institute of Mental Health, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Abhijit Dasgupta, PhD Director and Principal Statistician ARAASTAT Ph: 301.385.3067 E: adasgu...@araastat.com W: http://www.araastat.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 rows based on frequency of factor and then difference date scores
On Aug 24, 2010, at 1:19 PM, Chris Beeley wrote: Hello- A basic question which has nonetheless floored me entirely. I have a dataset which looks like this: Type ID DateValue A 116/09/2020 8 A 1 23/09/2010 9 B 3 18/8/20107 B 1 13/5/20106 There are two Types, which correspond to different individuals in different conditions, and loads of ID labels (1:50) corresponding to the different individuals in each condition, and measurements at different times (from 1 to 10 measurements) for each individual. I want to perform the following operations: 1) Delete all individuals for whom only one measurement is available. In the dataset above, you can see that I want to delete the row Type B ID 3, and Type B ID 1, but without deleting the Type A ID 1 data because there is more than one measurement for Type A ID 1 (but not for Type B ID1) 2) Produce difference scores for each of the Dates, so each individual (Type A ID1 and all the others for whom more than one measurement exists) starts at Date "1" and goes up in integers according to how many days have elapsed. I just know there's some incredibly cunning R-ish way of doing this but after many hours of fiddling I have had to admit defeat. Not sure about terribly cunning. Let's assume your dataframe was read in with stringsAsFactors=FALSE and is called txt.df: > txt.df$dt2 <- as.Date(txt.df$Date, format="%d/%m/%Y") > txt.df Type ID Date Valuedt2 1A 1 16/09/2020 8 2020-09-16 2A 1 23/09/2010 9 2010-09-23 3B 3 18/8/2010 7 2010-08-18 4B 1 13/5/2010 6 2010-05-13 > txt.df$nn <- ave(txt.df$ID,txt.df$ID, FUN=length) > txt.df Type ID Date Valuedt2 nn 1A 1 16/09/2020 8 2020-09-16 3 2A 1 23/09/2010 9 2010-09-23 3 3B 3 18/8/2010 7 2010-08-18 1 4B 1 13/5/2010 6 2010-05-13 3 > txt.df[ -which( txt.df$nn <=1), ] Type ID Date Valuedt2 nn 1A 1 16/09/2020 8 2020-09-16 3 2A 1 23/09/2010 9 2010-09-23 3 4B 1 13/5/2010 6 2010-05-13 3 # Task #1 accomplished > tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) $`1` Time differences in days [1]0 3646 3779 $`3` Time difference of 0 days > unlist( tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) ) 11 12 133 0 3646 37790 > txt.df$diffdays <- unlist( tapply(txt.df$dt2, txt.df$ID, function(x) x[1] -x) ) > txt.df Type ID Date Valuedt2 nn diffdays 1A 1 16/09/2020 8 2020-09-16 30 2A 1 23/09/2010 9 2010-09-23 3 3646 3B 3 18/8/2010 7 2010-08-18 1 3779 4B 1 13/5/2010 6 2010-05-13 30 > I would be very grateful for any words of advice. Many thanks, Chris Beeley, Institute of Mental Health, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. 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] odd behavior of "summary" function
On 2010-08-24 11:06, Mike Williamson wrote: Hello All, Using the standard "summary" function in 'R', I ran across some odd behavior that I cannot understand. Easy to reproduce: Typing: summary(c(6,207936)) Yields:: Min. *1st Qu. MedianMean 3rd Qu.Max.* 6 *51990 104000 104000 156000 207900* None of these values are correct except for the minimum. If I perform "quantile(c(6, 207936))", it gives the correct values. I originally presumed that summary was merely calling "quantile" if it saw a numeric, but this doesn't seem to be the case. Anyone know what's going on here? On a related note, what is the statistically correct answer for calculating the 1st quartile& 3rd quartile when only 2 values are present? I presume one takes the mid-point between the median (also calculated) and the min or max. So in this case, 51988.5 for 1st& 155953.5 for 3rd (which is what quantile calculates). But taking 25%& 75% of the sum of the 2 also seems "reasonable". Either way, "summary" is calculating the wrong number, and most disturbing is that it mis-calculates the max. Regards, Mike This is one of those (many) situations where reading the help pages really helps nicely: help(summary) points you to the 'digits' argument (as David has said) and that probably defaults to 'digits=4' for you. So, no, R is not miscalculating anything. help(quantile) shows that there are quite a few ways to define quantiles and that R defaults to 'type=7'. -Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Constrained non-linear optimisation
I'm relatively new to R, but I'm attempting to do a non-linear maximum likelihood estimation (mle) in R, with the added problem that I have a non-linear constraint. The basic problem is linear in the parameters (a_i) and has only one non-linear component, b, with the problem being linear when b = 0 and non-linear otherwise. Furthermore, f(a_i) <= b <= g(a_i) for some (simple) f and g. Using optim, I can get the optimisation to work when the non-linearity is included but not constrained, but gives poor results (as I'd expect). However, I'm not sure how best to go about the constraint condition. My initial attempts revolve around the use of logarithmic barrier function, but this only appears to work when using method="CG". When using "BFGS", the value of b 'goes out of bounds' and the loglikelihood starts throwing NaN, which is particularly bad if I want to box constrain the a_i using the "L-BFGS-B" method. Are there any other methods/approaches/variations on the above available to me in the form of other packages/R functions etc? Or any good references/books to help me out? Any help would be greatly appreciated, David. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] odd behavior of "summary" function
summary.default uses the signif function to round for display purposes. In ?summary, we can see the digits argument is used to control the value passed to signif. > lapply(1:6, function(x) summary(c(6, 207936), digits = x)) [[1]] Min. 1st Qu. MedianMean 3rd Qu.Max. 6e+00 5e+04 1e+05 1e+05 2e+05 2e+05 [[2]] Min. 1st Qu. MedianMean 3rd Qu.Max. 6 52000 10 10 16 21 [[3]] Min. 1st Qu. MedianMean 3rd Qu.Max. 6 52000 104000 104000 156000 208000 [[4]] Min. 1st Qu. MedianMean 3rd Qu.Max. 6 51990 104000 104000 156000 207900 [[5]] Min. 1st Qu. MedianMean 3rd Qu.Max. 6 51988 103970 103970 155950 207940 [[6]] Min. 1st Qu. Median Mean 3rd Qu. Max. 6.0 51988.5 103971.0 103971.0 155954.0 207936.0 Mike Williamson wrote: Hello All, Using the standard "summary" function in 'R', I ran across some odd behavior that I cannot understand. Easy to reproduce: Typing: summary(c(6,207936)) Yields:: Min. *1st Qu. MedianMean 3rd Qu.Max.* 6 *51990 104000 104000 156000 207900* None of these values are correct except for the minimum. If I perform "quantile(c(6, 207936))", it gives the correct values. I originally presumed that summary was merely calling "quantile" if it saw a numeric, but this doesn't seem to be the case. Anyone know what's going on here? On a related note, what is the statistically correct answer for calculating the 1st quartile & 3rd quartile when only 2 values are present? I presume one takes the mid-point between the median (also calculated) and the min or max. So in this case, 51988.5 for 1st & 155953.5 for 3rd (which is what quantile calculates). But taking 25% & 75% of the sum of the 2 also seems "reasonable". Either way, "summary" is calculating the wrong number, and most disturbing is that it mis-calculates the max. Regards, Mike "Telescopes and bathyscaphes and sonar probes of Scottish lakes, Tacoma Narrows bridge collapse explained with abstract phase-space maps, Some x-ray slides, a music score, Minard's Napoleanic war: The most exciting frontier is charting what's already here." -- xkcd -- Help protect Wikipedia. Donate now: http://wikimediafoundation.org/wiki/Support_Wikipedia/en [[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] Strange space characters in character strings
Hello J.R.M. Hosking, charToRaw() works perfectly, thank you: > charToRaw(as.character(moose[1, "V3"])) [1] 24 38 38 30 2c 33 37 30 c2 a0 gsub("[[:space:]]", "", ...) did not remove them, but now I know what they are (hex: c2 a0) I can remove them with gsub() by: > gsub("[$,\xc2\xa0]", "", as.character(moose[1, "V3"])) [1] "880370" Kind regards, -Mark- 2010/8/24 J. R. M. Hosking > On 2010-08-23 11:03, Mark Breman wrote: > >> Hello everyone, >> >> I am reading a HTML table from a website with readHTMLTable() from the XML >> package: >> >> library(XML) >>> moose = readHTMLTable("http://www.decisionmoose.com/Moosistory.html";, >>> >> header=FALSE, skip.rows=c(1,2), trim=TRUE)[[1]] >> >>> moose >>> >> V1 V2 V3 >> 1 07.02.2010 SWITCH to Long Bonds\n(BTTRX) $880,370 >> 2 05.07.2010 Switch to Gold (GLD) $878,736 >> 3 03.05.2010 Switch to US Small-cap Equities (IWM) $895,676 >> 4 01.22.2010 Switch to Cash (3moT) $895,572 >> . truncated by me! >> >> I am interested in the values in the third column: >> >> as.character(moose$V3) >>> >> [1] "$880,370 " "$878,736 " "$895,676 " "$895,572 " "$932,139 " >> "$932,131 " "$1,013,505 " "$817,451 " "$817,082 " "$848,133" >> [11] "$904,527 " " $903,981 " "$902,582 " "$896,170 " "$809,853 " >> " >> $808,852 " " $807,409 " "$802,658 " "$747,629 " "$672,465 " >> [21] " $671,826 " "$645,352 " "$615,174 " "$609,415 " " $590,664 " >> " >> $586,785 " "$561,056 " "$537,307 " " $535,744 " " $552,712 " >> [31] "$551,615 " " $508,790 " "$501,161 " "$499,023 " " $446,568 " >> "$423,727 " "$421,967 " "$396,007 " "$395,943 " " $270,011 " >> [41] "$264,386 " "$278,513 " "$251,855 " "$251,685 " " $129,198 " >> "$127,541 " "$117,381 " "$100,000 " " " " $275,417" >> [51] "$266,459"" $214,552" "$207,312""$173,557""$167,647" >> "$150,516""$135,842""$126,667""$131,642""$113,804" >> [61] "$107,364""$108,242"" $102,881" " $100,000" >> >> Notice the spaces leading and lagging some of the values. >> >> I want to get the values as numeric values, so I try to get rid of the >> $-character and comma's with gsub() and a regular expression: >> >> gsub("[$,]", "", as.character(moose$V3)) >>> >> [1] "880370 " "878736 " "895676 " "895572 " "932139 " "932131 " >> "1013505 " "817451 " "817082 " "848133 " "904527 " " 903981 " "902582 >> " >> [14] "896170 " "809853 " " 808852 " " 807409 " "802658 " "747629 " >> "672465 " " 671826 " "645352 " "615174 " "609415 " " 590664 " " >> 586785 >> " >> [27] "561056 " "537307 " " 535744 " " 552712 " "551615 " " 508790 " >> "501161 " "499023 " " 446568 " "423727 " "421967 " "396007 " "395943" >> [40] " 270011 " "264386 " "278513 " "251855 " "251685 " " 129198 " >> "127541 " "117381 " "10 " " "" 275417" "266459" " >> 214552" >> [53] "207312" "173557" "167647" "150516" "135842" "126667" >> "131642" "113804" "107364" "108242" " 102881" " 10" >> >> Looks fine to me. Now I can use as.numeric() to convert to numbers >> (leading >> and lagging spaces should not be a problem): >> >> as.numeric(gsub("[$,]", "", as.character(moose$V3))) >>> >> [1] NA NA NA NA NA NA NA NA NA NA >> NA NA NA NA NA NA NA NA NA NA >> [21] NA NA NA NA NA NA NA NA NA NA >> NA NA NA NA NA NA NA NA NA NA >> [41] NA NA NA NA NA NA NA NA NA NA >> 266459 NA 207312 173557 167647 150516 135842 126667 131642 113804 >> [61] 107364 108242 NA NA >> Warning message: >> NAs introduced by coercion >> >> Something is wrong here! Let's have a look at one specific value: >> >> gsub("[$,]", "", as.character(moose$V3))[1] >>> >> [1] "880370 " >> >>> as.numeric(gsub("[$,]", "", as.character(moose$V3))[1]) >>> >> [1] NA >> Warning message: >> NAs introduced by coercion >> >> If the last character in the string would be a regular space it would not >> be >> a problem for as.numeric(): >> >> as.numeric("880370 ") >>> >> [1] 880370 >> >> But it looks like it's not a regular space character: >> >> substr(gsub("[$,]", "", as.character(moose$V3))[1], 7, 7) == " " >>> >> [1] FALSE >> >> It looks to me the spaces in some of the cells are not regular spaces. In >> the original HTML table they are defined as "non breaking spaces" i.e. >> >> >> So my question is WHAT ARE THEY? >> Is there a way to show the binary (hex) values of these characters? >> > > charToRaw(...) will show them > > gsub("[[:space:]]", "", ...) may remove them > > > J. R. M. Hosking > > >> Here is my environment: >> >> sessionInfo() >>> >> R version 2.11.1 (2010-05-31) >> i486-pc-linux-gnu >> >> locale: >> [1]
[R] Using kfilter in package sspir - dimensions do not agree
I'm currently running into a little trouble with the kfilter method, and would love some clarification if you are able to offer it. When trying to run kfilter, I've been running into errors that seem to result from having mismatched dimensions. Specifically, the dimension of my observations is 2, while the dimension of the state space is 4. In the filterstep function (file sspir_kfs.R), this causes an error at line 111: e <- y - f. Vector y has dimension 4, while vector f has dimension 2. Here's some sample code: ## require(sspir) # getting the hang of the kalman filter x.coords <- c(5,6,5,6,8,9,8,8,10,11) y.coords <- c(25,30,42,51,55,52,42,28,24,31) times <- 1:10 x.vel <- c(0,diff(x.coords)/diff(times)) y.vel <- c(0,diff(y.coords)/diff(times)) kal.df <- data.frame(x.coords,x.vel,y.coords,y.vel) kal.ts <- ts(kal.df,deltat=mean(diff(times))) my.Fmat <- function(tt,x,phi){ mf <- matrix(c(1,0,0,0,0,1,0,0),nrow=4,byrow=T) return(mf) } my.Gmat <- function(tt,x,phi){ mat <- matrix(c(1,x[[1]][tt],0,0,0,1,0,0,0,0,1,x[[1]][tt],0,0,0,1),nrow=4,byrow=T) return(mat) } my.Wmat <- function(tt,x,phi){ row.1 <- c((x[[1]][tt]^4)/4,(x[[1]][tt]^3)/2,(x[[1]][tt]^4)/4,(x[[1]][tt]^3)/2) row.2 <- c((x[[1]][tt]^3)/2,x[[1]][tt]^2,(x[[1]][tt]^3)/2,x[[1]][tt]^2) mat <- rbind(row.1,row.2,row.1,row.2) # no need for as.matrix mat <- mat * phi[1] return(mat) } kal.SS <- SS(kal.ts, x=list(x=c(0,diff(times))), phi=0.5, Fmat=my.Fmat, Gmat=my.Gmat, Vmat=matrix(c(3,0,0,1),nrow=2,byrow=T), Wmat=my.Wmat, m0=t(matrix(c(5,0,25,0))), #initial state - currently x,x*,y,y* (*=velocity) # initialize cov matrix for the filter C0=matrix(c(5,-0.5,0.5,0.5,-0.5,0.5,0,0,0.5,0,5,0,0.5,0,0,1),nrow=4,byrow=T) ) kfilter(kal.SS) ## And the error it produces: Error in y - f : non-conformable arrays If I look at the offending variables, here's what I get, and obviously it's impossible to add these two Browse[1]> y [,1] [1,]5 [2,]0 [3,] 25 [4,]0 Browse[1]> f [,1] [1,]5 [2,] 25 ## Should I simply coerce the dimensions of my inputs such that the dimension of my observation vectors are the same as the dimensions of my state vectors? Thank you in advance. -John Dryden __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 rows based on frequency of factor and then difference date scores
Hello- A basic question which has nonetheless floored me entirely. I have a dataset which looks like this: Type ID DateValue A 116/09/2020 8 A 1 23/09/2010 9 B 3 18/8/20107 B 1 13/5/20106 There are two Types, which correspond to different individuals in different conditions, and loads of ID labels (1:50) corresponding to the different individuals in each condition, and measurements at different times (from 1 to 10 measurements) for each individual. I want to perform the following operations: 1) Delete all individuals for whom only one measurement is available. In the dataset above, you can see that I want to delete the row Type B ID 3, and Type B ID 1, but without deleting the Type A ID 1 data because there is more than one measurement for Type A ID 1 (but not for Type B ID1) 2) Produce difference scores for each of the Dates, so each individual (Type A ID1 and all the others for whom more than one measurement exists) starts at Date "1" and goes up in integers according to how many days have elapsed. I just know there's some incredibly cunning R-ish way of doing this but after many hours of fiddling I have had to admit defeat. I would be very grateful for any words of advice. Many thanks, Chris Beeley, Institute of Mental Health, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple assignments ?
On Tue, Aug 24, 2010 at 8:45 AM, Maas James Dr (MED) wrote: > Thanks Bert, will have a look. I'm originally a Fortran programmer so tend > to think in loops ... so yes expect it may be job for loops, just tried to > avoid it because several references say not to use loops in R. -- Yes, an unfortunate misunderstanding. The references refer mostly to the unnecessary use of loops at the R (interpreted) level -- which also includes _apply type constructs -- vs inbuilt vectorization, which are loops at the C level and so orders of magnitude faster and cleaner code, to boot. An example would be what you might be doing following the Fortran paradigm: ## warning BAAAD R code myvec <- vector("numeric", 1E5) for(i in 1:(1E5))myvec[i] <- sin(i) versus myvec <- sin( (1:(1E5))) ## because sin() is vectorized But conventional use of looping (often better --cleaner code, data structures-- in their list versions: lapply, mapply, tapply,...) at the interpreted R level is perfectly apporpriate; the only caveat being that they can apparently bog down if the number of loops is "very" large, perhaps > 1E5 or more. I have never actually experienced such problems, however, so can't really speak to them. -- Bert > > I note your helpful comments about lists, will see if I can do it that way! > > Will check this out, thanks > > Jim > > > === > Dr. Jim Maas > Research Associate in Network Meta-Analysis > School of Medicine, Health Policy and Practice > CD Annex, Room 1.04 > University of East Anglia > Norwich, UK > NR4 7TJ > > +44 (0) 1603 591412 > > > -Original Message- > From: Bert Gunter [mailto:gunter.ber...@gene.com] > Sent: Tuesday, August 24, 2010 4:39 PM > To: r.ookie > Cc: Maas James Dr (MED); r-help@r-project.org > Subject: Re: [R] multiple assignments ? > > None of this would work if the list is long. Isn't this an obvious > task for a loop, explicit or implicit? > > e.g. > > for(i in 1:100)assign(paste("vec",i,sep=""), vector("integer",5)) > > or probably better because it creates a list structure: > > ## warning, untested. You may have to fool with the syntax a bit: > > listofempties <- lapply(1:100, vector,mode="integer",length=5) > > ## you can name the components with names(listofempties) <- > paste("vec",1:100,sep="") > > HOWEVER, I rather doubt that any of this is necessary: that is, it is > rarely necessary or wise in R to first create empty objects and then > populate them. Using lists and list operations usually allows both to > be done more efficiently and conveniently in one step. > > -- > Bert Gunter > Genentech Nonclinical Statistics > > On Tue, Aug 24, 2010 at 8:19 AM, r.ookie wrote: >> Do you mean something like this? >> >>> >> n <- 5 >> >>> >> (vec1 <- matrix(rep(1, n))) >> [,1] >> [1,] 1 >> [2,] 1 >> [3,] 1 >> [4,] 1 >> [5,] 1 >> >>> >> (vec2 <- matrix(rep(2, n))) >> [,1] >> [1,] 2 >> [2,] 2 >> [3,] 2 >> [4,] 2 >> [5,] 2 >> >>> >> (vec3 <- matrix(rep(3, n))) >> [,1] >> [1,] 3 >> [2,] 3 >> [3,] 3 >> [4,] 3 >> [5,] 3 >> >>> >> >> >>> >> (vec <- matrix(c(vec1, vec2, vec3))) >> [,1] >> [1,] 1 >> [2,] 1 >> [3,] 1 >> [4,] 1 >> [5,] 1 >> [6,] 2 >> [7,] 2 >> [8,] 2 >> [9,] 2 >> [10,] 2 >> [11,] 3 >> [12,] 3 >> [13,] 3 >> [14,] 3 >> [15,] 3 >> >>> >> >> On Aug 24, 2010, at 4:58 AM, Maas James Dr (MED) wrote: >> >> Simple one, have read and googled, still no luck! >> >> I want to create several empty vectors all of the same length. >> >> I would like multiple empty vectors (vec1, vec2, vec3) and want to create >> them all in one line. >> >> I've tried >> >> vec1,vec2,vec3 <- vector(length=5) >> and >> c(vec1,vec2,vec3) <- vector(length=5) >> >> and several other attempts but nothing seems to work ... suggestions? >> >> Thanks >> >> Jim >> >> === >> Dr. Jim Maas >> University of East Anglia >> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/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] odd behavior of "summary" function
On Aug 24, 2010, at 1:06 PM, Mike Williamson wrote: Hello All, Using the standard "summary" function in 'R', I ran across some odd behavior that I cannot understand. Easy to reproduce: Typing: summary(c(6,207936)) Yields:: Min. *1st Qu. MedianMean 3rd Qu.Max.* 6 *51990 104000 104000 156000 207900* None of these values are correct except for the minimum. If I perform "quantile(c(6, 207936))", it gives the correct values. I originally presumed that summary was merely calling "quantile" if it saw a numeric, but this doesn't seem to be the case. I would have assumed as you did, and continue to think so with appropriate modification of "merely" after reading the code in summary.default: else if (is.numeric(object)) { nas <- is.na(object) object <- object[!nas] qq <- stats::quantile(object) qq <- signif(c(qq[1L:3L], mean(object), qq[4L:5L]), digits) names(qq) <- c("Min.", "1st Qu.", "Median", "Mean", "3rd Qu.", "Max.") if (any(nas)) c(qq, `NA's` = sum(nas)) else qq Notice the digits argument: > summary(c(6,207936)) Min. 1st Qu. MedianMean 3rd Qu.Max. 6 51990 104000 104000 156000 207900 > quantile(c(6,207936)) 0% 25% 50% 75% 100% 6.0 51988.5 103971.0 155953.5 207936.0 > summary(c(6,207936), digits=6) Min. 1st Qu. Median Mean 3rd Qu. Max. 6.0 51988.5 103971.0 103971.0 155954.0 207936.0 Anyone know what's going on here? On a related note, what is the statistically correct answer for calculating the 1st quartile & 3rd quartile when only 2 values are present? I presume one takes the mid-point between the median (also calculated) and the min or max. So in this case, 51988.5 for 1st & 155953.5 for 3rd (which is what quantile calculates). But taking 25% & 75% of the sum of the 2 also seems "reasonable". Either way, "summary" is calculating the wrong number, and most disturbing is that it mis-calculates the max. Regards, 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] generate random numbers from a multivariate distribution with specified correlation matrix
BTW, can you recommend a book on statistical simulations? I want to know more on how to generate random numbers from distributions, how to generate the theoretical models,... Thanks a lot. 2010/8/24 Michael Dewey > At 02:40 24/08/2010, rusers.sh wrote: > >> Hi all, >> rmvnorm()can be used to generate the random numbers from a multivariate >> normal distribution with specified means and covariance matrix, but i want >> to specify the correlation matrix instead of covariance matrix for the >> multivariate >> normal distribution. >> > > Jane, perhaps I misunderstand you but the correlation matrix is a > covariance matrix > > > Does anybody know how to generate the random numbers from a multivariate >> normal distribution with specified correlation matrix? What about >> other non-normal >> distribution? >> > > There is corcounts for correlated count variables and a couple of packages > for correlated binary variables, search the packages list for correlated for > details. I have not used any of these so can offer no recommendations. > > Thanks a lot. >> >> -- >> - >> Jane Chang >> Queen's >> >>[[alternative HTML version deleted]] >> > > Michael Dewey > m...@aghmed.fsnet.co.uk > http://www.aghmed.fsnet.co.uk/home.html > > -- - Jane Chang Queen's [[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] xylab formatting
On Aug 24, 2010, at 12:39 PM, Jennifer Hains wrote: Dear r-help, I'm having trouble formatting xy labels for plot in r. I want to make the following y-label "benzene (mug-3)" where mu is greek and -3 is superscript and benzene is held in an array. I tried this, myname = c("benzene", "etc") plot (c(0:10), ylab = bquote(.(myname[1])~~(mu~g ~m^-3))) ?plotmath Use "*" instead of "~" but it leaves a space between the "mu" and the "g". Any suggestions? Thank you for your help, Jennifer -- 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] graphing plots of plots
In addition to the other suggestions you may also want to look at the subplot function in the TeachingDemos package (the version in Hmisc is a copy of a prior version of this one) as well as the my.symbols or panel.my.symbols functions in the same package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Bernard Leemon > Sent: Saturday, August 21, 2010 1:41 PM > To: R-help@r-project.org > Subject: [R] graphing plots of plots > > I want to make a graph where each element plotted is itself a graph. I > can > see how to use par(fig=) and viewport to do that, but they require (i > think) > me to do my own scaling as they are scaled to the graphics window. any > advice on which approach I should take (just bite the bullet and do my > own > scaling), or is there something else I should try, or any examples I > should > look at. many thanks for any pointers. > > bernie leemon (aka gary mcclelland) > > [[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] SAMR for paired samples
Hi R-help, I am trying to use 'samr' for 10 pre and post paired samples to test whether post is different from pre (i.e., the location shift for the delta of (post-pre)). However, I got an error message saying > samr.obj<-samr(d, resp.type="Two class paired", nperms=100, random.seed=100) perm= 1 Error in !logged2 : invalid argument type Does anyone know what this means? or how to solve this error? Also, the options 'One Sample paired' is for testing the differences directly (d1, d2,...), I suppose. The source code is * function() { library(samr) attach(proto_data) x <- cbind(pre1, pre2, pre3, pre4, pre5, ... post1, post2,post3,post4,post5, ) y <- c(-(1:10),1:10) d <- list(x=x,y=y, geneid=array.id) samr.obj<-samr(d, resp.type="Two class paired", nperms=100) samr.plot(samr.obj) } * Thank you HS __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] odd behavior of "summary" function
Hello All, Using the standard "summary" function in 'R', I ran across some odd behavior that I cannot understand. Easy to reproduce: Typing: summary(c(6,207936)) Yields:: Min. *1st Qu. MedianMean 3rd Qu.Max.* 6 *51990 104000 104000 156000 207900* None of these values are correct except for the minimum. If I perform "quantile(c(6, 207936))", it gives the correct values. I originally presumed that summary was merely calling "quantile" if it saw a numeric, but this doesn't seem to be the case. Anyone know what's going on here? On a related note, what is the statistically correct answer for calculating the 1st quartile & 3rd quartile when only 2 values are present? I presume one takes the mid-point between the median (also calculated) and the min or max. So in this case, 51988.5 for 1st & 155953.5 for 3rd (which is what quantile calculates). But taking 25% & 75% of the sum of the 2 also seems "reasonable". Either way, "summary" is calculating the wrong number, and most disturbing is that it mis-calculates the max. Regards, Mike "Telescopes and bathyscaphes and sonar probes of Scottish lakes, Tacoma Narrows bridge collapse explained with abstract phase-space maps, Some x-ray slides, a music score, Minard's Napoleanic war: The most exciting frontier is charting what's already here." -- xkcd -- Help protect Wikipedia. Donate now: http://wikimediafoundation.org/wiki/Support_Wikipedia/en [[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] generate random numbers from a multivariate distribution with specified correlation matrix
Great. It is more clearer for me. Thanks all. 2010/8/24 Michael Dewey > At 02:40 24/08/2010, rusers.sh wrote: > >> Hi all, >> rmvnorm()can be used to generate the random numbers from a multivariate >> normal distribution with specified means and covariance matrix, but i want >> to specify the correlation matrix instead of covariance matrix for the >> multivariate >> normal distribution. >> > > Jane, perhaps I misunderstand you but the correlation matrix is a > covariance matrix > > > Does anybody know how to generate the random numbers from a multivariate >> normal distribution with specified correlation matrix? What about >> other non-normal >> distribution? >> > > There is corcounts for correlated count variables and a couple of packages > for correlated binary variables, search the packages list for correlated for > details. I have not used any of these so can offer no recommendations. > > Thanks a lot. >> >> -- >> - >> Jane Chang >> Queen's >> >>[[alternative HTML version deleted]] >> > > Michael Dewey > m...@aghmed.fsnet.co.uk > http://www.aghmed.fsnet.co.uk/home.html > > -- - Jane Chang Queen's [[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 obtain seed after generating random number?
Dear all, I was doing an experiment to disprove some theory therefore performing lot of random simulation. Goal is to show the audience that although something has very rare chance to occur but it doesn't mean that event would be impossible. In this case after getting that rare event I need to show that same scenario for multiple times to explain other audience. Hence I need to somehow save that seed which generates that random numbers after doing the experiment. However as it is very rare event it is not very practical to start with a fixed seed and then generate random numbers. Hence I am looking for some way which will tell me about that corresponding seed which was responsible to generate that particular series of random numbers responsible for occurrence of that rare event. In short, I need to know the seed ***after*** generating the random numbers. Is there any possibility to know this? Thanks and regards, [[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] xylab formatting
Dear r-help, I'm having trouble formatting xy labels for plot in r. I want to make the following y-label "benzene (mug-3)" where mu is greek and -3 is superscript and benzene is held in an array. I tried this, myname = c("benzene", "etc") plot (c(0:10), ylab = bquote(.(myname[1])~~(mu~g ~m^-3))) but it leaves a space between the "mu" and the "g". Any suggestions? Thank you for your help, Jennifer Jennifer Hains Research Statistician Ambient Air Monitoring Program Maryland Department of the Environment 1800 Washington Blvd., Ste. 730 Baltimore, MD 21230-1720 Phone: 410-537-4027 Fax: 410-537-4243 [[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] Comparing/diffing strings
On 08/24/2010 07:27 AM, Doran, Harold wrote: > There is the stringMatch function in the MiscPsycho package. > >> stringMatch('Hadley', 'Hadley Wickham', normalize = 'no') > [1] 8 >> stringMatch('Hadley', 'Hadley Wickham', normalize = 'yes') > [1] 0.4285714 > > It uses Levenshtein distance to tell you how much they differ by, either > normalized or not. So, the above two tell you the first string differs from > the second string by 8 insertions/deletions/substitutions. The second number > normalizes the comparison such that 1 denotes perfect agreement and 2 denotes > imperfect agreement. > > Examples of an exact match are below. > >> stringMatch('Hadley Wickham', 'Hadley Wickham', normalize = 'yes') > [1] 1 >> stringMatch('Hadley Wickham', 'Hadley Wickham', normalize = 'n') > [1] 0 You're probably looking for something lighter weight, but Bioconductor Biostrings has pairwiseAlignment. > library(Biostrings) > pairwiseAlignment("Hadley Wickham", "Hadley Hamwick") Global PairwiseAlignedFixedSubject (1 of 1) pattern: [1] Hadley W---ick subject: [1] Hadley Hamwick score: 29.5102 > pairwiseAlignment("Hadley Hamwick", "Hadley Wickham") Global PairwiseAlignedFixedSubject (1 of 1) pattern: [1] Hadley Hamwick subject: [1] Hadley W---ick score: 29.5102 > aln <- pairwiseAlignment("Hadley Hamwick", "Haderley Hamwich") > consensusMatrix(aln)["-",] [1] 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 Martin > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Hadley Wickham > Sent: Tuesday, August 24, 2010 10:17 AM > To: R-help > Subject: [R] Comparing/diffing strings > > Hi all, > > all.equal is generally very useful when you want to find the > differences between two objects. It breaks down however, when you > have two long strings to compare: > >> all.equal(a, b) > [1] "1 string mismatch" > > Does any one know of any good text diffing tools implemented in R? > > Thanks, > > Hadley > -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Minus values in Tps
Hello there, I am using the Tps function to fit a spline to my data which is measurements of a sedimentary layer on an xy plane to see how the thickness of the layer changes. I was wondering if it was possible to change the Tps code so that no minus values are calculated by the spline as these are obviously unfeasible. Any help would be much appreciated, Thanks, Sam -- View this message in context: http://r.789695.n4.nabble.com/Minus-values-in-Tps-tp2336949p2336949.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] multiple assignments ?
None of this would work if the list is long. Isn't this an obvious task for a loop, explicit or implicit? e.g. for(i in 1:100)assign(paste("vec",i,sep=""), vector("integer",5)) or probably better because it creates a list structure: ## warning, untested. You may have to fool with the syntax a bit: listofempties <- lapply(1:100, vector,mode="integer",length=5) ## you can name the components with names(listofempties) <- paste("vec",1:100,sep="") HOWEVER, I rather doubt that any of this is necessary: that is, it is rarely necessary or wise in R to first create empty objects and then populate them. Using lists and list operations usually allows both to be done more efficiently and conveniently in one step. -- Bert Gunter Genentech Nonclinical Statistics On Tue, Aug 24, 2010 at 8:19 AM, r.ookie wrote: > Do you mean something like this? > >> > n <- 5 > >> > (vec1 <- matrix(rep(1, n))) > [,1] > [1,] 1 > [2,] 1 > [3,] 1 > [4,] 1 > [5,] 1 > >> > (vec2 <- matrix(rep(2, n))) > [,1] > [1,] 2 > [2,] 2 > [3,] 2 > [4,] 2 > [5,] 2 > >> > (vec3 <- matrix(rep(3, n))) > [,1] > [1,] 3 > [2,] 3 > [3,] 3 > [4,] 3 > [5,] 3 > >> > > >> > (vec <- matrix(c(vec1, vec2, vec3))) > [,1] > [1,] 1 > [2,] 1 > [3,] 1 > [4,] 1 > [5,] 1 > [6,] 2 > [7,] 2 > [8,] 2 > [9,] 2 > [10,] 2 > [11,] 3 > [12,] 3 > [13,] 3 > [14,] 3 > [15,] 3 > >> > > On Aug 24, 2010, at 4:58 AM, Maas James Dr (MED) wrote: > > Simple one, have read and googled, still no luck! > > I want to create several empty vectors all of the same length. > > I would like multiple empty vectors (vec1, vec2, vec3) and want to create > them all in one line. > > I've tried > > vec1,vec2,vec3 <- vector(length=5) > and > c(vec1,vec2,vec3) <- vector(length=5) > > and several other attempts but nothing seems to work ... suggestions? > > Thanks > > Jim > > === > Dr. Jim Maas > University of East Anglia > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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 remove all objects except a few specified objects?
Hi Cheng, Check out the keep() function in package:gdata. And to be sure the "removed" objects are really removed from system memory i think you need to run gc(). hth, Karl On 8/23/2010 9:00 PM, Cheng Peng wrote: How to remove all R objects in the RAM except for a few specified ones? rm(list=ls()) removes all R objects in the R work space. Another question is that whether removing all R objects actually releases the RAM? Thanks. -- Karl Brand Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.