Re: [R] "rounding" to next lowest/highest 'x%%y' (mod) equals zero?
Richard M. Heiberger wrote: >> tmp <- c(0,.5,1.5,2.1,3.1,4) >> floor(tmp/2) > [1] 0 0 0 1 1 2 >> floor(tmp/2)*2 > [1] 0 0 0 2 2 4 Thanks so much! Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] "rounding" to next lowest/highest 'x%%y' (mod) equals zero?
Dear smart ones, Image a vector 'test' that looks like so: 0 0.5 1.5 2.1 3.1 4 I'm looking for an efficient function that would do something like moddown <- function(test,integer){ for (element %in% test){ if (element%%integer != 0) { "return next lowest integer for which '%%' returns 0" } else { "return element" } } } and return for 'test' a vector like so: 0 0 0 2 2 4 My current solution like outlined above seems very inelegant ... Thanks for any hints, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Choice of data.frame column by index?
Thanks! Joh On Thursday 23 August 2007 12:01:50 you wrote: > x[cbind(1:nrow(x), the.vector)] > > Patrick Burns > [EMAIL PROTECTED] > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of S Poetry and "A Guide for the Unwilling S User") > > Johannes Graumann wrote: > >Hello, > > > >Imagine a data frame like so: > > > > Intensity0 Intensity1 > >1 767432.1 451743.4 > >2 3998988.0 4642145.0 > >3 818974.6 552315.8 > > > >and a vector like so: > > > >[1] 1 2 1 > > > >How can I get R to produce a vector that contains the value in one column > > or the other depending on the vector? The result should look like > > > >[1] 767432.1 4642145.0 818974.6 > > > >Thanks for any hints! > > > >Joh > > > >__ > >R-help@stat.math.ethz.ch mailing list > >https://stat.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html and provide commented, > > minimal, self-contained, reproducible code. signature.asc Description: This is a digitally signed message part. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Choice of data.frame column by index?
Hello, Imagine a data frame like so: Intensity0 Intensity1 1 767432.1 451743.4 2 3998988.0 4642145.0 3 818974.6 552315.8 and a vector like so: [1] 1 2 1 How can I get R to produce a vector that contains the value in one column or the other depending on the vector? The result should look like [1] 767432.1 4642145.0 818974.6 Thanks for any hints! Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Subsetting Enigma: More rows after dataframe[-list,]?
Hello again, I'm trying to purge the indexes in i.delete from frame and end up with more rows!? Please be so kind and let me know where I screw this up ... Joh > i.delete [1] 40 45 165 212 253 270 280 287 301 352 421 433 463 467 487 [16] 517 537 542 573 594 596 612 614 621 635 650 696 699 707 732 [31] 738 776 826 891 892 936 937 935 940 976 988 995 1037 1043 1059 [46] 1081 1123 1128 1132 1140 1153 1155 1165 1176 1179 1200 1281 1289 1300 [61] 1320 1346 1356 1366 1369 1396 1406 1420 1428 1429 1471 1474 1475 1525 1540 [76] 1554 1565 1645 1667 1665 1706 1711 1724 1764 1788 1791 1805 1808 1847 1881 [91] 10 18 137 238 254 260 262 288 292 314 338 349 414 447 457 [106] 465 470 478 511 530 536 552 582 588 644 655 687 693 701 724 [121] 739 763 771 836 848 859 888 900 902 919 939 972 979 989 1000 [136] 1002 1015 1020 1026 1029 1032 1055 1060 1073 1088 1104 1117 1124 1130 1135 [151] 1144 1221 1225 1249 1251 1257 1376 1384 1386 1453 1487 1529 1532 1534 1605 [166] 1624 1633 1646 1648 1702 1787 1948 1951 > length(i.delete) [1] 173 > nrow(frame) [1] 1975 > nrow(frame[-i.delete,]) [1] 1802 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] SLLOOOWWW function ...
Does anybody have any insight into how to make this faster? I suspect, that the rounding going on may be an issue, as is the stepping through data frame rows using integers ... If you have the patience to teach a noob, he will highly appreciate it ;0) Joh digit <- 4 for (minute in seq(from=25,to=lrange[2])){ # Extract all data associtaed with the current time (minute) frame <- subset(mylist,mylist[["Time"]] == minute) # Sort by Intensity frame <- frame[order(frame[["Intensity"]],decreasing = TRUE),] # Establish output frame using the most intense candidate newframe <- frame[1,] # Establish overlap-checking vector using the most intense candidate lowppm <- round(newframe[1,][["Mass"]]-newframe[1, [["Mass"]]/1E6*ppmrange,digits=digit) highppm <- round(newframe[1,][["Mass"]]+newframe[1, [["Mass"]]/1E6*ppmrange,digits=digit) presence <- seq(from=lowppm,to=highppm,by=10^(-digit)) # Walk through the entire original frame and check whether peaks are overlap-free ... do so until max of 2000 entries for (int in seq(from=2,to=nrow(frame))) { if(nrow(newframe) < 2000) { lowppm <- round(frame[int,][["Mass"]]-frame[int, [["Mass"]]/1E6*ppmrange,digits=digit) highppm <- round(frame[int,][["Mass"]]+frame[int, [["Mass"]]/1E6*ppmrange,digits=digit) windowrange <- seq(from=lowppm,to=highppm,by=10^(-digit)) if (sum(round(windowrange,digits=digit) %in% round(presence,digits=digit)) < 1) { newframe <- rbind(newframe,frame[int,]) presence <- c(presence,windowrange) } } else { break() } } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Pairlist of pairlsit assembly howto
Thanks for the hints ... there was another issue: "minute" was integers starting with 0, which made R a bit upset on top of the subset/element issue. Joh On Sunday 15 July 2007 16:08:12 Duncan Murdoch wrote: > (This isn't important to your question, but those aren't pairlists. > Pairlists are rarely used in R code, except implicitly in the way R > stores parsed code.) > > On 15/07/2007 10:00 AM, Johannes Graumann wrote: > > Hy guys, > > > > I'm trying something like this > > > > minbins <- list() > > for (minute in sequence(3)) { > > minbins[minute] <- list(data="a",variable="b") > > } > > You want to use > > minbins[[minute]] <- list(data="a",variable="b") > > The difference between [[ ]] and [ ] is that the former works on the > element, the latter works on a subset. So your version tried to change > a subset of length 1 into a subset of length 2, which generates the > warnings. You want to assign a list of length 2 as an element of minbins. > > Duncan Murdoch > > > And it doesn't work ... > > Warning messages: > > 1: number of items to replace is not a multiple of replacement length in: > > minbins[minute] <- list(data = "a", variable = "b") > > 2: number of items to replace is not a multiple of replacement length in: > > minbins[minute] <- list(data = "a", variable = "b") > > 3: number of items to replace is not a multiple of replacement length in: > > minbins[minute] <- list(data = "a", variable = "b") > > > > What am I doing wrong and how to do this properly? > > > > Thanks, Joh > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html and provide commented, > > minimal, self-contained, reproducible code. signature.asc Description: This is a digitally signed message part. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Pairlist of pairlsit assembly howto
Hy guys, I'm trying something like this minbins <- list() for (minute in sequence(3)) { minbins[minute] <- list(data="a",variable="b") } And it doesn't work ... Warning messages: 1: number of items to replace is not a multiple of replacement length in: minbins[minute] <- list(data = "a", variable = "b") 2: number of items to replace is not a multiple of replacement length in: minbins[minute] <- list(data = "a", variable = "b") 3: number of items to replace is not a multiple of replacement length in: minbins[minute] <- list(data = "a", variable = "b") What am I doing wrong and how to do this properly? Thanks, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Algorythmic Question on Array Filtration
John Kane wrote: Thanks for your time. Please find a small example below - the real data is MUCH bigger. If you look at rows 5 and 6 of this and calculate the mass precision window I have to deal with (5 ppm), you'll find the following: Row Lower 5ppm MassHigher 5ppm Intensity 5 312.9419312.9435312.945120236.181 6 312.9422312.9438312.945414404.502 The precision windows here obviously overlap and I need to get rid of one of them, which in this case should be row6, since it has the lower intensity associated with it. For now I resort to doing an intensity sort and descending into the list populate a fresh data.frame with entries that do not have any overlap, skipping those that do. If somebody has any more sound ideas, I'd appreciate to hear about them. Thanks, Joh MassIntensity 304.9117 35595.780 305.1726 18760.413 311.0636 24047.307 312.9303 12886.216 312.9435 20236.181 312.9438 14404.502 313.1763 61033.830 313.1766 50788.418 316.9118 5908.166 317.2805 14084.841 317.2833 25603.689 317.2837 22866.578 318.0114 37929.855 318.9274 27883.295 318.9889 4496.716 321.2784 3893.165 326.1166 23745.851 327.2894 5318.226 328.8852 60934.030 329.1517 31985.486 331.0426 14883.231 332.0268 55126.078 332.2798 47364.519 333.2813 11423.807 337.1990 5330.360 339.2144 38450.804 339.2867 4065.709 340.9561 54101.844 340.9770 28172.160 345.0583 17945.025 345.0583 17877.900 347.1742 7359.428 347.2407 204792.999 353.2302 87864.153 353.2302 129691.696 363.0161 20453.771 363.0943 19481.234 363.2142 9238.244 363.2315 23323.527 363.2533 20039.607 363.2534 22068.718 364.8918 16857.488 364.9368 9527.642 366.9029 18174.233 373.2197 7730.009 385.1147 27907.070 385.1148 19383.655 393.2913 11860.719 396.9074 10793.823 400.8792 10750.249 402.8729 12411.966 407.2771 11270.566 442.8689 18101.972 442.8697 10671.199 447.3470 35927.046 449.2347 6959.247 456.9339 50402.820 461.1670 8636.998 461.1670 8151.706 473.2985 13782.291 490.9224 18510.760 > I think we need a bit more information and perhaps a > small example data set to see what you want. > > I am not familiar with term mass window. Is this a > confidence interval around the mass value? > > > --- Johannes Graumann <[EMAIL PROTECTED]> > wrote: > >> Dear All, >> >> I have a data frame with the columns "Mass" and >> "Intensity" (this is mass >> spectrometry stuff). Each of the mass values gives >> rise to a mass window of >> 5 ppm around the individual mass (from mass - >> mass/1E6*5 to mass + >> mass/1E5*5). I need to filter the array such that in >> case these mass >> windows overlap I retain the mass/intensity pair >> with the highest >> intensity. >> I apologize for this question, but I have no formal >> IT education and would >> value any nudges toward favorable algorithmic >> solutions highly. >> >> Thanks for any help, >> >> Joh >> >> __ >> R-help@stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Algorythmic Question on Array Filtration
Dear All, I have a data frame with the columns "Mass" and "Intensity" (this is mass spectrometry stuff). Each of the mass values gives rise to a mass window of 5 ppm around the individual mass (from mass - mass/1E6*5 to mass + mass/1E5*5). I need to filter the array such that in case these mass windows overlap I retain the mass/intensity pair with the highest intensity. I apologize for this question, but I have no formal IT education and would value any nudges toward favorable algorithmic solutions highly. Thanks for any help, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] "S3method" equivalent to "exportPattern"
Hi, I'm just trying to figure this out ... for any function I want my package to generally provide, I need to export it and define it as an "S3method" (?). "exportPattern" is really convenient. Is there a regex based analogon for "S3method"? Thanks, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 mimic plot=F for truehist?
Dear Rologists, In order to combine plots I need to get access to the some "par"s specific to my plot prior to replot it with modified parameters. I have not found any option like "plot=F" associated with truehist and would like to know whether someone can point out how to overcome this problem. Thanks, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subsetting list of vectors with list of (boolean) vectors?
Thanks everybody, Seth's solution is not the general one I was looking for. Both of the others are. Thanks! Joh Liaw, Andy wrote: > From: Marc Schwartz >> >> On Thu, 2007-04-12 at 18:12 +0200, Johannes Graumann wrote: >> > Dear Rologists, >> > >> > I'm stuck with this. How would you do this efficiently: >> > >> > > aPGI >> > [[1]] >> > [1] "864" "5576" >> > >> > >> > > aPGItest >> > [[1]] >> > [1] TRUE FALSE >> > >> > > result <- [magic box involving subset) >> > >> > > result >> > [[1]] >> > [1] "864" >> > >> > Thanks for any hints, >> > >> > Joh >> >> >> > lapply(seq(along = length(aPGI)), function(x) >> > aPGI[[x]][aPGItest[[x]]]) >> [[1]] >> [1] "864" > > Alternatively: > > R> mapply("[", aPGI, aPGItest, SIMPLIFY=FALSE) > [[1]] > [1] "864" > > Cheers, > Andy > > >> >> I think that this should be a generic solution for multiple >> (but common) levels in each list. >> >> HTH, >> >> Marc Schwartz >> >> __ >> [EMAIL PROTECTED] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> >> > > > -- > Notice: This e-mail message, together with any attachments,...{{dropped}} > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code. __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/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] Subsetting list of vectors with list of (boolean) vectors?
Dear Rologists, I'm stuck with this. How would you do this efficiently: > aPGI [[1]] [1] "864" "5576" > aPGItest [[1]] [1] TRUE FALSE > result <- [magic box involving subset) > result [[1]] [1] "864" Thanks for any hints, Joh __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/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] Referencing function name from within function
Hello, For verbose coding I'd like to do something like: > myfunction <- function(x){ > if (a){ > stop(paste(myfunction_name_here,"requires xyz!") > } Is that possible? Thanks for any hints, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Matrix conversion question
Christos Hatzis wrote: > Try > > split(x, row(x)) H! THE ELEGANCE! Thanks a lot! Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Matrix conversion question
Hello, Please help - I'm blanking on this ... I have a matrix like this: [,1] [,2] [1,]12 [2,]13 [3,]23 and would like to have a list of vectors, where a vector contains the entries in a matrix row ... Can somebody nudge me to the place I need to go? Thanks, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Test of Presence Matrix HOWTO?
Hello, Imagine 3 lists like so: > a <- list("A","B","C","D") > b <- list("A","B","E","F") > c <- list("A","C","E","G") What I need (vennDiagram) is a matrix characterizing with 1 or 0 whether any given member is present or not like so: x1 x2 x3 [1,] 1 1 1 [2,] 1 1 0 [3,] 1 0 1 [4,] 1 0 0 [5,] 0 1 1 [6,] 0 1 0 [7,] 0 0 1 (where the rows represent "A"-"G" and the columns a-c, respectively). > table(c(a,b,c)) will give me a quick answer for the "1 1 1" case, but how to deal with the other cases efficiently without looping over each string and looking for membership %in% each list? Thanks for enlightening the learning, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] List filtration
Thanks for your help! Joh Dimitris Rizopoulos wrote: > try this: > > lis. <- lapply(lis, function(x) if (length(ind <- grep("^IPI", x))) > x[ind[1]] else NULL) > lis.[!sapply(lis., is.null)] > > > I hope it helps. > > Best, > Dimitris > > > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > - Original Message - > From: "Johannes Graumann" <[EMAIL PROTECTED]> > To: > Sent: Thursday, February 22, 2007 3:33 PM > Subject: [R] List filtration > > >> Hello R-ologists, >> >> Imagine you have a list "list" like so: >> >>>list >> [[1]] >> [1] "IPI00776145.1" "IPI00776187.1" >> >> [[2]] >> [1] "Something" "IPI00807764.1" "IPI00807887.1" >> >> [[3]] >> [1] "IPI00807764.1" >> >> [[4]] >> [1] "Somethingelse" >> >> What I need to achieve is a filtered list "list2" like so: >> >>>list2 >> [[1]] >> [1] "IPI00776145.1" >> >> [[2]] >> [1] "IPI00807764.1" >> >> [[3]] >> [1] "IPI00807764.1" >> >> So: >> - if sublist-entry 1 start with "^IPI" make it the list-entry. >> - otherwise chose the first "^IPI" sublist-entry present. >> - delete the list-entry if not "^IPI" sublist-entry present. >> >> Can anybody nudge me towards an elegant solution without looping - I >> have >> LOTS of entries to process ... >> >> Thanks for your Teachings, >> >> Joh >> >> __ >> R-help@stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] List filtration
Hello R-ologists, Imagine you have a list "list" like so: >list [[1]] [1] "IPI00776145.1" "IPI00776187.1" [[2]] [1] "Something" "IPI00807764.1" "IPI00807887.1" [[3]] [1] "IPI00807764.1" [[4]] [1] "Somethingelse" What I need to achieve is a filtered list "list2" like so: >list2 [[1]] [1] "IPI00776145.1" [[2]] [1] "IPI00807764.1" [[3]] [1] "IPI00807764.1" So: - if sublist-entry 1 start with "^IPI" make it the list-entry. - otherwise chose the first "^IPI" sublist-entry present. - delete the list-entry if not "^IPI" sublist-entry present. Can anybody nudge me towards an elegant solution without looping - I have LOTS of entries to process ... Thanks for your Teachings, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Another subsetting enigma
jim holtman wrote: >> matches <- sapply(result, function(x){ > + .comma <- strsplit(x, ',')[[1]] # get the fields > + any(my.list %in% .comma) > + }) Thanks for that! Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Another subsetting enigma
On Monday 19 February 2007 17:49, jim holtman wrote: > have you tried 'unlist(strsplit())'?The 'unlist' will probably give > you more values than you have rows, so it would be good if you could > explain what it is you are trying to do. I want to isolate a data frame containing all rows of 'dataframe' which contain a member of 'list' in the field 'Field', which itself is a comma separated list of entries. Better this (know in brain ...)? Joh > On 2/19/07, Johannes Graumann <[EMAIL PROTECTED]> wrote: > > Hello again, > > > > I'm trying to do the following: > > > > subset(dataframe,list %in% strsplit(dataframe[[Field]],",")) > > > > But This returns always the complete dataframe, since the > > strsplit(dataframe[[Field]],",") is evaluated as one big list for the > > whole > > data frame rather than one list per row. How can I have this evaluated on > > a > > per row basis? > > > > After 1.5 h hitting head against wall - begging for insights ... > > > > Joh > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. pgp7XFEEUi9oM.pgp Description: PGP signature __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Another subsetting enigma
Hello again, I'm trying to do the following: subset(dataframe,list %in% strsplit(dataframe[[Field]],",")) But This returns always the complete dataframe, since the strsplit(dataframe[[Field]],",") is evaluated as one big list for the whole data frame rather than one list per row. How can I have this evaluated on a per row basis? After 1.5 h hitting head against wall - begging for insights ... Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data frame: how to create list of row max?
Thanks to you and Brian Ripley. Quite confusing all this ... Thanks again. Joh On Monday 19 February 2007 13:42, David Barron wrote: > Try do.call("pmax",c(dataframe[,intensityindices],na.rm=TRUE)) > > This is like the second example in the help page for do.call > > On 19/02/07, Johannes Graumann <[EMAIL PROTECTED]> wrote: > > On Monday 19 February 2007 11:53, Prof Brian Ripley wrote: > > > do.call("pmax", dataframe[,intensityindeces]) > > > > Thank you very much for your help! > > > > Any idea why > > do.call("pmax",list(na.rm=TRUE),dataframe[,intensityindeces]) would give > > me > > > > Error in if (quote) { : argument is not interpretable as logical > > In addition: Warning message: > > the condition has length > 1 and only the first element will be used in: > > if (quote) { > > > > ? > > > > Thanks, Joh > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html and provide commented, > > minimal, self-contained, reproducible code. pgp4utFI3ZYyo.pgp Description: PGP signature __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data frame: how to create list of row max?
On Monday 19 February 2007 11:53, Prof Brian Ripley wrote: > do.call("pmax", dataframe[,intensityindeces]) Thank you very much for your help! Any idea why do.call("pmax",list(na.rm=TRUE),dataframe[,intensityindeces]) would give me Error in if (quote) { : argument is not interpretable as logical In addition: Warning message: the condition has length > 1 and only the first element will be used in: if (quote) { ? Thanks, Joh pgpgfKKtY5smH.pgp Description: PGP signature __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Data frame: how to create list of row max?
Dear all, Can anyone please shed some light onto how to do this? This will give me all "intensity" columsn in my data frame: intensityindeces <- grep("^Intensity",names(dataframe),value=TRUE) This will give me the maximum intensity for the first row: intensityone <- max(dataframe[1,intensityindeces]) What I'm now looking for is how to dfo this for the whole data frame. Should yield a list of maximum intensities of all rows. Can't figure it out ... please nudge me where I need to go. Thanks, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Conditional data frame manipulation
Hi all, My current project brought forth the snippet below, which modifies in each row of a data frame a certain field depending on another field in the same row. Dealing with data of some 3 entries this works, but is horribly slow. Can anyone show this newbie how to do this properly (faster ;0)? for (i in 1:nrow(dataframe)){ if (any(grep('^yes$',dataframe[i,][['Field1']]))){ dataframe[i,]['Field1'] <- dataframe[i,]['Field2'] } else { dataframe[i,]['Field1'] <- NA } } Thanks for your insights, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lapply and use.names howto
Thanks a lot for opening my eyes. Joh Prof Brian Ripley wrote: > On Thu, 15 Feb 2007, Johannes Graumann wrote: > >> How do I make R use the use.names option in a context like this: > > What 'use.names option'? sapply has a USE.NAMES argument, but lapply does > not. > >> lapply(data, function(x)(read.table(x,quote="",header=TRUE,sep="\t")), >> use.names=TRUE) > > 'data' is the name of an R function. If say 'dd' were a character vector > of file names you could do > > res <- lapply(dd, function(x)(read.table(x,quote="",header=TRUE,sep="\t")) > names(res) <- dd > > or even > > sapply(dd, function(x)(read.table(x,quote="",header=TRUE,sep="\t"), > simplify = FALSE) > > which does the same thing. > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] lapply and use.names howto
Hello, How do I make R use the use.names option in a context like this: lapply(data, function(x)(read.table(x,quote="",header=TRUE,sep="\t")), use.names=TRUE) Thanks for any insights, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ELIF?
Thanks for your help! Joh Duncan Murdoch wrote: > On 2/14/2007 11:35 AM, Johannes Graumann wrote: >> Hello, >> >> Is there an elegant way to implement something like the elif function >> (e.g. python) and prevent multiple if-else contruct concatenation when >> coding in R? > > Why not just concatenate, using "else if"? For example, > > if (condition1) { > action 1 > } else if (condition2) { > action 2 > } else if (condition3) { > action 3 > } else { > default action > } > > There is a switch() function if the condition is something that can be > computed in advance, e.g. from the example on its man page: > > answer <- switch(type, > mean = mean(x), > median = median(x), > trimmed = mean(x, trim = .1)) > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] ELIF?
Hello, Is there an elegant way to implement something like the elif function (e.g. python) and prevent multiple if-else contruct concatenation when coding in R? Sorry for my newbieishness, Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dealing with Duplicates - How to count instances?
jim holtman wrote: > table(data[column]) > > will give you the number of items in each subgroup; that would be the > count you are after. Thanks for your Help! That rocks! I can do copynum <- table(data_6plus["Accession.number"]) data_6plus$"Repeats" <- sapply(data_6plus[["Accession.number"]], function(x) copynum[x][[1]]) now! But how about this: - do something along the lines of duplicity <- duplicated(data_6plus["Accession.number"]) data_6plus_unique <- subset(data_6plus,duplicity!=TRUE) - BUT: retain from each deleted row one field, append it to a vector and fill that into a new field of the remaining row of the set sharing data_6plus["Accession.number"]? How would you do something like that? Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Dealing with Duplicates - How to count instances?
Hi there, given a data.frame 'data' I managed to filter out entries (rows) that are identical with respect to one column like so: duplicity <- duplicated(data[column]) data_unique <- subset(data,duplicity!=TRUE) But I'm trying to extract how many duplicates each of the remaining rows had. Can someone please send me down the right path for this? Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Math expressions in pie chart labels?
On Wednesday 03 May 2006 09:05, Uwe Ligges wrote: > Ah, I see, this happens in pie()'s line: > >if (!is.na(lab <- labels[i]) && lab != "") { > > where lab is one element of the expression. > I'd like to propose to change that line to > >if (!is.na(lab <- labels[i]) && nchar(lab) > 0) { What's the canonical way of patching something like this in R? Redefining the function at the start of your script? Joh pgpgSSNWEOKo8.pgp Description: PGP signature __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Math expressions in pie chart labels?
Uwe Ligges wrote: > Johannes Graumann wrote: > >> On Tuesday 02 May 2006 23:33, Uwe Ligges wrote: >> >>>Then please read ?plotmath and use it: >>> >>>labels = expression("" >= 0.66, "" == 0.33, "" <= -0.33, "" <= -0.66) >> >> >> Error in lab != "" : comparison is not allowed for expressions >> In addition: Warning message: >> is.na() applied to non-(list or vector) in: is.na(lab <- labels[i]) >> >> I don't seem to be the only one having problems with this ;0) > > > Then please tell us the details, I just tried successfully: > > plot(1:10, xaxt="n") > axis(1, at = c(1,3,5,7), labels = > expression("" >= 0.66, "" == 0.33, "" <= -0.33, "" <= -0.66)) As I was mentioning in my first post (see subject): this is a pie chart. Try: pie( c(20,40,60,80), labels = expression(NULL>= 0.66,NULL>= 0.33,NULL<= -0.33,NULL<= -0.66) ) or the '""' equivalent. platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 3.0 year 2006 month 04 day24 svn rev37909 language R version.string Version 2.3.0 (2006-04-24) Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Math expressions in pie chart labels?
On Tuesday 02 May 2006 23:33, Uwe Ligges wrote: > Then please read ?plotmath and use it: > > labels = expression("" >= 0.66, "" == 0.33, "" <= -0.33, "" <= -0.66) Error in lab != "" : comparison is not allowed for expressions In addition: Warning message: is.na() applied to non-(list or vector) in: is.na(lab <- labels[i]) I don't seem to be the only one having problems with this ;0) Joh pgpPq74G3CxiE.pgp Description: PGP signature __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Math expressions in pie chart labels?
ronggui wrote: > I think you should use labels = c(">= 0.66", ">= 0.33", "<= -0.33", > "<= -0.66") . > Note the quote in each element of the vector. No. Am using that at the moment. Does not give me the nice plotmath 'greater-than' etc. signs ... Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Math expressions in pie chart labels?
Hello, trying to get something like this to work and am failing: pie( c(length(strongN14),length(weakN14),length(weakN15),length(strongN15),length(ambiguous)), labels = c(>= 0.66, >= 0.33, <= -0.33, <= -0.66), col = c("#FF","#CC","#009900","lightgreen","white") ) Can't figure out a way to display the 'greater or equal' ... signs properly. I'm thankful for any prodding into the right direction. Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] MASS: rlm, MM and errors in observations AND regressors
Hello, I need to perform a robust regression on data which contains errors in BOTH observations and regressors. Right now I am using rlm from the MASS package with 'method="MM"' and get visually very nice results. MASS is quite clear, however, that the described methodologies are only applicable to observation-error only data (p. 157, 4th Ed.). So here's the questions now: a) is there methodology for robust and resistant regression on data with errors in BOTH observations and regressors? b) if "yes" at a): does somebody know of an implementation in R? c) if "no" at b): would somebody reading this be open to implement this? If yes: please get in contact with me off list. Please excuse my unfamiliarity with terminology and subject - I'm very new to statistics. Joh -- +--+ | Johannes Graumann, Dipl. Biol. | | | | Graduate StudentTel.: ++1 (626) 395 6602| | Deshaies LabFax.: ++1 (626) 395 5739| | Department of Biology | | CALTECH, M/C 156-29 | | 1200 E. California Blvd.| | Pasadena, CA 91125 | | USA | +--+ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Robust M-Estimator Comparison
Hello, I'm learning about robust M-estimators right now and had settled on the "Huber Proposal 2" as implemented in MASS, but further reading made clear, that at least 2 further weighting functions (Hampel, Tukey bisquare) exist. In a post from B.D. Ripley going back to 1999 I found the following quote: >> 2) Would huber() give me results that are similar (i.e., close enough)? > > Not if you have lots of extreme outliers on just one side. Since this message seems to imply that the nature of the data described (and not just personal preference) should influence the choice among above M-estimators, I've been scouting around for a direct comparison among them - to no avail. Can anybody here point me to such a comparison (novice-suitability would be more than welcome ;0)? Thanks for any hint, Joh -- +------+ | Johannes Graumann, Dipl. Biol. | | | | Graduate StudentTel.: ++1 (626) 395 6602 | | Deshaies LabFax.: ++1 (626) 395 5739 | | Department of Biology | | CALTECH, M/C 156-29| | 1200 E. California Blvd. | | Pasadena, CA 91125 | | USA| +--+ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Linear regression with variation in x and y
Hello, According to my archive digging, this issue comes up again and again. I was just wondering whether somebody had code lying around for a Deming Regression or a MLFR method for this, which I might peruse. I came across a post from Brian Ripley stating that something like it was close to be included into MASS a couple of times and was wondering whether it made the cut there (or elsewhere) in the meantime ... Any hint is greatly appreciated. Joh __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] subset-analogue removing fed in indexes?
Jebus, you guys are fast! Thanks so much, Joh On Tue, 2005-05-31 at 17:38 -0400, Gabor Grothendieck wrote: > On 5/31/05, Johannes Graumann <[EMAIL PROTECTED]> wrote: > > Hello, > > > > Here's my issue: > > > > I want to plot the following vectors: > > > x <- c(0.0, 2.0, 15.0, 100.0, 105.0, 105.1, 110.0, 120.0, 120.1, > > 130.0) > > > data <- c(8.75, 8.75, 16.25, 38.75, 61.25, 8.75, NA, 8.75, NA, NA) > > > > and avoid the line discontinuations caused by 'NA'. > > > plot_data <- na.omit(data) > > will clean up 'data' for me, but now I need to get a 'plot_x' which > > omits the values indexed with what's spit out by 'na.exclude(data)'. > > > > Can anybody let me know a smooth way of how to delete entries with > > certain indexes from a vector? > > plot(approx(x,data)) > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] subset-analogue removing fed in indexes?
Hello, Here's my issue: I want to plot the following vectors: > x <- c(0.0, 2.0, 15.0, 100.0, 105.0, 105.1, 110.0, 120.0, 120.1, 130.0) > data <- c(8.75, 8.75, 16.25, 38.75, 61.25, 8.75, NA, 8.75, NA, NA) and avoid the line discontinuations caused by 'NA'. > plot_data <- na.omit(data) will clean up 'data' for me, but now I need to get a 'plot_x' which omits the values indexed with what's spit out by 'na.exclude(data)'. Can anybody let me know a smooth way of how to delete entries with certain indexes from a vector? Thanks, Joih __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] annotation problems (conditional text())
Thanks! Major knot in brain unraveled ... Joh On Sat, 20 Nov 2004 17:43:37 +0100 Uwe Ligges <[EMAIL PROTECTED]> wrote: > Johannes Graumann wrote: > > > Hello, > > > > I'm trying to annotate my plots nicely and am running into trouble. > > This example contains two problems: > > a) the 'text()' arguments do not show the conditional behavior I'm > > trying to give them. I try to test for the intercept of my > > regression and reformat the output accordingly ('+ intercept' in the > > >= 0 case and > > '- sqrt(intercept^2)' in the other case), which doesn't work this > > way. b) my pasted substitute commands yield jolted output, which > > overwrites itself ... > > > > Can anyone give this newbie a nudge into the right direction? > > 1. Multi-line mathematical annotation is not supported. You have to > add them line by line. > > 2. You want to use a construct such as >if(m >= 0){ > # code for text 1 >} else{ > # code for text 2 >} > rather than the one you speicfied below, which evaluates both text() > calls if m > 0. > > Uwe Ligges > > > > Thanks, Joh > > > > if(m >= 0){ > > text( > > 4,0.19, > > cex=0.75, > > adj=0, > > paste( > > substitute( > > y == m*x+b, > > list( > > m=round(m,digits=5), > > b=round(b,digits=5) > > ) > > ), > > "\n", > > substitute( > > R^2==rsquared, > > list( > > rsquared=round(summary(fit)$r.squared,digits=3) > > ) > > ) > > ) > > ); > > text( > > 4,0.19, > > cex=0.75, > > adj=0, > > paste( > > substitute( > > y == m*x-b, > > list( > > m=round(m,digits=5), > > b=round(sqrt(b^2),digits=5) > > ) > > ), > > "\n", > > substitute( > > R^2==rsquared, > > list( > > rsquared=round(summary(fit)$r.squared,digits=3) > > ) > > ) > > ) > > ) > > } > > > > __ > > [EMAIL PROTECTED] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] annotation problems (conditional text())
Hello, I'm trying to annotate my plots nicely and am running into trouble. This example contains two problems: a) the 'text()' arguments do not show the conditional behavior I'm trying to give them. I try to test for the intercept of my regression and reformat the output accordingly ('+ intercept' in the >= 0 case and '- sqrt(intercept^2)' in the other case), which doesn't work this way. b) my pasted substitute commands yield jolted output, which overwrites itself ... Can anyone give this newbie a nudge into the right direction? Thanks, Joh if(m >= 0){ text( 4,0.19, cex=0.75, adj=0, paste( substitute( y == m*x+b, list( m=round(m,digits=5), b=round(b,digits=5) ) ), "\n", substitute( R^2==rsquared, list( rsquared=round(summary(fit)$r.squared,digits=3) ) ) ) ); text( 4,0.19, cex=0.75, adj=0, paste( substitute( y == m*x-b, list( m=round(m,digits=5), b=round(sqrt(b^2),digits=5) ) ), "\n", substitute( R^2==rsquared, list( rsquared=round(summary(fit)$r.squared,digits=3) ) ) ) ) } __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] par("usr") trouble in multiplot axis scaling
You were right! 'ylim' does what I want! Thanks for deciphering my cryptic scribble and helping out! Joh On Mon, 25 Oct 2004 14:25:55 -0500 Marc Schwartz <[EMAIL PROTECTED]> wrote: > On Mon, 2004-10-25 at 13:19, Johannes Graumann wrote: > > Hello, > > > > I'm blotting a series of growth curves into a multiplot environment > > created with layout(). > > since I want the four plots to be easily visually comparable, I do > > the following: > > > > #first plot > > plot(x,y,) > > standarduser<-par()$usr > > ... > > > > ... > > lines(spline(x, )) > > > > #everything all right till here > > # second plot > > plot(x,y,) > > par(usr=standarduser) > > ... > > > > ... > > lines(spline(x, )) > > > > The problem here is, that the axis of the second plot seem to be > > scaled according to the parameters of the first, BUT the fitted > > curve in the second plot isn't! > > > > Any idea about what I'm doing wrong? > > > > Please help this newbie out of his misery! > > > > Joh > > If I am correctly understanding what you are doing and what you want, > you would like each of the four plots to have the same axis ranges? > > Part of the problem, I think, is that in your second plot(), the axis > ranges are automatically set based upon the ranges of your x and y > data in that call. These presumably are different than the x and y > values in your first plot? > > Thus, the initial plot region scales are going to be different for > each plot. By default, this will be range(x) +/- 4% and range(y) +/- > 4%. > > When you force the second plot region's values to be 'standarduser', > your underlying x,y plot, having already been drawn, and the new lines > to be added are then on different scales in the same plot. > > If my assumptions are correct, you would be better off calling plot() > each time using the 'xlim' and 'ylim' arguments to explicitly define > the axis ranges with known common values. > > For example, if you know that the range of all x values is r.x and the > range of all y values is r.y: > > #first plot > plot(x, y, , xlim = r.x, ylim = r.y) > ... > > ... > lines(spline(x, )) > > > # second plot > plot(x, y, , xlim = r.x, ylim = r.y) > ... > > ... > lines(spline(x, )) > > > This gets around the need to manipulate the pars directly and > hopefully less confusion in reading the code. The key is knowing the > common ranges of your x and y values in advance. > > Does that help? > > Marc Schwartz > > > __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] par("usr") trouble in multiplot axis scaling
Hello, I'm blotting a series of growth curves into a multiplot environment created with layout(). since I want the four plots to be easily visually comparable, I do the following: #first plot plot(x,y,) standarduser<-par()$usr ... ... lines(spline(x, )) #everything all right till here # second plot plot(x,y,) par(usr=standarduser) ... ... lines(spline(x, )) The problem here is, that the axis of the second plot seem to be scaled according to the parameters of the first, BUT the fitted curve in the second plot isn't! Any idea about what I'm doing wrong? Please help this newbie out of his misery! Joh __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Legend/Substitute/Plotmath problem
Thank you so much ... works now ... sooo much to learn ... Joh On Mon, 25 Oct 2004 09:56:35 +0200 Martin Maechler <[EMAIL PROTECTED]> wrote: > >>>>> "Johannes" == Johannes Graumann <[EMAIL PROTECTED]> > >>>>> on Sat, 23 Oct 2004 11:04:25 -0700 writes: > >>>>> "Johannes" == Johannes Graumann <[EMAIL PROTECTED]> > >>>>> on Sat, 23 Oct 2004 11:04:25 -0700 writes: > > Johannes> Hello, > > Johannes> I seem unable to construct a legend which contains > Johannes> a substitution as well as math symbols. I'm trying > Johannes> to do the following: > > >> strain2 <- "YJG48" > > >> legend.txt <- c( > >>substitute( > >>strain * > >>%==% * > >>"YJG45, rpn10" * > >>%Delta%, > >>list(strain=strain2) > >>), > >>"Verhulst/Logistic", > >>"Malthus" > >> ) > > > Johannes> . > > Do try to break down a problem into simple things -- > particularly when you have problems! > > This substitute() call is simply invalid: > > > ss <- substitute( strain * %==% * "YJG45, rpn10" * %Delta%, > > list(strain=strain2) ) > Error: syntax error > > and the 'syntax error' should give you a clue: > The first argument of substitute must be a syntactically correct > R expression. > > Now you try more and more simple things till you 'see it' : > > Why should I expect 'A * %==% B' to be valid syntax? > Both '*' and '%==%' are (diadic) operators: You can't juxtapose > them, as well as you can't write 'A * = B'. > Then, '%Delta%' (like any other '%foo%' !!) is a diadic operator > too and hence can't be juxtaposed to '*'. But I'm pretty sure > you rather mean (greek) 'Delta'. > > Hence: > ss <- substitute( strain %==% "YJG45, rpn10" * Delta, > list(strain=strain2) ) > > --- > > Once you have the expression you can go further; > still step by step : > > > c(ss, "Verhulst") > [[1]] > "YJG48" %==% "YJG45, rpn10" * Delta > > [[2]] > [1] "Verhulst" > > Hmm, a list; that won't work. > You do need to pass either a "character" vector or an > expression, i.e., an expression of length 3 in our case. > We must build the expression somewhat manually: > > > e <- expression(1, "Verhulst", "Malthus")# '1' is a place holder > expression(1, "Verhulst", "Malthus") > > e[[1]] <- ss ## that's the trick! > > > str(e) > expression("YJG48" %==% "YJG45, rpn10" * Delta, "Verhulst", > "Malthus") > > > plot(1); legend(1,1, leg = e) > > --- > > Maybe something to be added as an example to help(legend) or rather > to help(expression) ? > > HTH, > Martin Maechler, ETH Zurich > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Legend/Substitute/Plotmath problem
Hello, I seem unable to construct a legend which contains a substitution as well as math symbols. I'm trying to do the following: strain2 <- "YJG48" legend.txt <- c( substitute( strain * %==% * "YJG45, rpn10" * %Delta%, list(strain=strain2) ), "Verhulst/Logistic", "Malthus" ) legend( 100,2.5, legend.txt, cex=0.75, bty="n", pch=c(20,NA,NA), lty=c(NA,1,2) I derived this from the following "text" command which works, text( 160,2.2, cex=0.5, adj=0, substitute( OD[600][~nm] * " of 2 at " * time2_2 * " min" %~~% time2h_2 * " h", list( time2_2=round(time2_2,digits=0), time2h_2=round(time2_2/60,digits=1) ) ) ) But I can't get it to work in the context of "legend". Any hints/ideas? Thanks, Joh __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] text() with text, variables and math HOWTO?
Thanks everybody! Joh On Fri, 27 Aug 2004 09:37:12 +0200 Uwe Ligges <[EMAIL PROTECTED]> wrote: > Johannes Graumann wrote: > > > Hello, > > > > One more question from the 'abusing R for blotting - particularly > > anally' department: > > How can I in the expression below make the '%~~%' show up as the > > aprrox-sign I want it to be? > > > > Thanks for any hint, > > > > Joh > > > > text( > > 500,1.5, > > cex=0.75, > > substitute( > > paste( > > OD[600][~nm], > > " of 1 at ", > > time1, > > " min ", > > "%~~%", > > time1h, > > "h" > > ), > > list( > > time1=round(time1,digits=0), > > time1h=round(time1/60,digits=1) > > ) > > ) > > ) > > >substitute(OD[600][~nm] * " of 1 at " * > time1 * " min" %~~% time1h * h, >list(time1=round(time1,digits=0), > time1h=round(time1/60,digits=1)) >) > > > > Uwe Ligges > > > > > __ > > [EMAIL PROTECTED] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] text() with text, variables and math HOWTO?
Hello, One more question from the 'abusing R for blotting - particularly anally' department: How can I in the expression below make the '%~~%' show up as the aprrox-sign I want it to be? Thanks for any hint, Joh text( 500,1.5, cex=0.75, substitute( paste( OD[600][~nm], " of 1 at ", time1, " min ", "%~~%", time1h, "h" ), list( time1=round(time1,digits=0), time1h=round(time1/60,digits=1) ) ) ) __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to make lines() meet axis in autoscaled coordinate system?
Grand! Thanks so much! Joh On Thu, 26 Aug 2004 18:15:44 -0300 (ADT) Rolf Turner <[EMAIL PROTECTED]> wrote: > > Johannes Graumann wrote: > > > I have an auto-scaled coordinate system and would like to add some > > clarifying lines to the graph - which ares supposed to meet the > > axis. > > > > >lines(c(0,time1,time1), c(1,1,0),lty=3) > > > > does what I want, BUT the second leg does not touch the x-axis since > > the auto-scaling of the y-axis does not start at'0' but slightly > > negative. I could now adjust the line length by 'trial and error' to > > suit my needs, but I'd prefer a generalizable solution like > > > > >lines(c(,time1,time1), > > + c(1,1,),lty=3) > > lines(c(par()$usr[1],time1,time1), c(1,1,par()$usr[3]),lty=3) > > cheers, > > Rolf Turner > [EMAIL PROTECTED] > __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] how to make lines() meet axis in autoscaled coordinate system?
Hello, I have an auto-scaled coordinate system and would like to add some clarifying lines to the graph - which ares supposed to meet the axis. >lines(c(0,time1,time1), c(1,1,0),lty=3) does what I want, BUT the second leg does not touch the x-axis since the auto-scaling of the y-axis does not start at'0' but slightly negative. I could now adjust the line length by 'trial and error' to suit my needs, but I'd prefer a generalizable solution like >lines(c(,time1,time1), + c(1,1,),lty=3) Can somebody help me out with this? Thanks, Joh __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Beginners Question: Make nlm work
Thanks. Joh On 26 Aug 2004 21:28:56 +0200 Peter Dalgaard <[EMAIL PROTECTED]> wrote: > Johannes Graumann <[EMAIL PROTECTED]> writes: > > > > coef(fit)[1] > >a > > 4.216479 > > > > How now to extract just '4.216479'? > > That's what you have, it's just that is has a names attribute. Doesn't > usually matter, but you can feed it to as.vector() if you want to get > rid of it. > > > -- >O__ Peter Dalgaard Blegdamsvej 3 > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) > 35327918 > ~~ - ([EMAIL PROTECTED]) FAX: (+45) > 35327907 > __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Beginners Question: Make nlm work
Due to the combined nudging of the newsgroup I get it done VERY nicely now - thanks guys! The one problem remaining (similar to what Jim explained earlier) is: how to get to the fitted parameters? For the code below (were the nls was assigned to 'fit'), 'coef(fit)' gives me: > coef(fit) a b 4.216478980 0.004143935 and 'coef(fit)[1]' results in: > coef(fit)[1] a 4.216479 How now to extract just '4.216479'? Thanks for the help again, everybody! Joh Here is the code: setwd("~/Biology/R_versuch") mydata<-read.table("YJG45-7_Growth.dat") x<-mydata$V1 y<-mydata$V2 plot(x, y, axes=FALSE, type="p", xlab="Time (min)", ylab=expression(OD[600][~nm]), las=1, pch=20, # log="y", tck=0.015, mgp=c(1.5,0.25,0), ) axis(1,at=NULL,tick=TRUE,tck=0.015,mgp=c(1.5,0.25,0)) axis(2,at=NULL,tick=TRUE,tck=0.015,las=1,mgp=c(1.5,0.5,0)) axis(3,at=c(300,600,900,1200,1500,1800,2100),labels=c(5,10,15,20,25,30, 35),tick=TRUE,tck=0.015,mgp=c(1.5,0.25,0)) axis(4,labels=FALSE,at=NULL,tick=TRUE,tck=0.015,mgp=c(1.5,0.25,0)) box() fit <- nls(y ~ a/(1+((a-0.008)/0.008)*exp(-(b*x))), start = list(a = 3, b = 4e-3), # trace = TRUE ) yfit1 <- 4.216479/(1+((4.216479-0.008)/0.008)*exp(-(0.004143935*x))) lines(spline(x, yfit1)) And the data: # YJG45, YJG46, YJG47 Growth curves 08/12/-08/x/04 # Inoculation with an over night culture to OD600=0.008 # Inoculums: # YJG45 (A): 2.67 --> use 74.9 myl in 25 ml # YJG46 (B): 2.65 --> use 75.5 myl in 25 ml # YJG47 (C): 2.26 --> use 88.5 myl in 25 ml # # t OD600 # (min) YJG45 YJG46 YJG47 # A B C #0 0.008 0.008 0.008 94 0.011 0.013 0.012 188 0.013 0.016 0.018 281 0.018 0.020.023 376 0.027 0.026 0.028 454 0.037 0.041 0.039 599 0.078 0.076 0.075 695 0.113 0.121 0.113 814 0.204 0.210 0.197 914 0.3 0.330.3 10090.470.510.48 11360.750.8 0.77 12651.181.281.16 13941.781.741.73 15252.132.162.20 16522.642.642.67 17713.083.012.99 18973.383.433.41 20363.783.763.72 21644.1 4.144.17 On Wed, 25 Aug 2004 22:39:12 -0400 "Jim Brennan" <[EMAIL PROTECTED]> wrote: > I can't open your file it comes up missing or damaged. > Maybe you could send me your data as I am curious now to see the > result. :-) probably something still wrong if it is not fitting the > points properly... > > Jim > - Original Message - > From: "Johannes Graumann" <[EMAIL PROTECTED]> > To: "Jim Brennan" <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Wednesday, August 25, 2004 9:57 PM > Subject: Re: [R] Beginners Question: Make nlm work > > > > Aaaa - there was my conceptual problem ... Thanks! > > ... but 'Oh, God!'! R sucks at fitting (when directed to do so by > > the simple minded)! Or am I really that off? > > I attach a plot that contains my data as well as two modeled curves: > > - the nice one fitted by gnuplot (nonlinear least-squares (NLLS) > > Marquardt-Levenberg) > > - the nasty one fitted by the code below. > > > > Both algorithms were started with the same values for p[1] and p[2]. > > > > Comments? > > > > Is there any way to access the 2 elements of 'out$estimate' from the > > program? > > > > Joh > > > > setwd("~/Biology/R_versuch") > > mydata<-read.table("YJG45-7_Growth.dat") > > #plot(mydata$V1,mydata$V2,xlab="Time > > (h)",ylab=expression(OD[600][~nm]),las=1) x<-mydata$V1 > > y<-mydata$V2 > > VH <- function(p) sum( > > (y - p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x^2) > > plot(x, y, > > axes=FALSE, > > type="p", > > xlab="Time (min)", > > ylab=expression(OD[600][~nm]), > > las=1, > > pch=20, > > tck=0.015, > > mgp=c(1.5,0.25,0), > > ) > > axis(1, > > at=NULL, > > tick=TRUE, > > tck=0.015, > > mgp=c(1.5,0.25,0) > > ) > > axis(2, > > at=NULL, > > tick=TRUE, > > tck=0.015, > > mgp=c(1.5,0.25,0) > > ) > > axis(3, > > at=c(300,600,900,1200,1500,1800,2100), > > labels=c(5,10,15,20,25,30,35), > > tick=TRUE, > > tck=0.015, > > mgp=c(1.5,0.25,0)) > > axis(4, > > labels=FALSE, > > at=NULL, > > tick=TRUE, > > tck=0.015, > > mgp=c(1.5,0.25,0) > > ) > > box() > > out <- nlm(VH, p = c(3, 4e-3), hes
Re: [R] Beginners Question: Make nlm work
Aaaa - there was my conceptual problem ... Thanks! ... but 'Oh, God!'! R sucks at fitting (when directed to do so by the simple minded)! Or am I really that off? I attach a plot that contains my data as well as two modeled curves: - the nice one fitted by gnuplot (nonlinear least-squares (NLLS) Marquardt-Levenberg) - the nasty one fitted by the code below. Both algorithms were started with the same values for p[1] and p[2]. Comments? Is there any way to access the 2 elements of 'out$estimate' from the program? Joh setwd("~/Biology/R_versuch") mydata<-read.table("YJG45-7_Growth.dat") #plot(mydata$V1,mydata$V2,xlab="Time (h)",ylab=expression(OD[600][~nm]),las=1) x<-mydata$V1 y<-mydata$V2 VH <- function(p) sum( (y - p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x^2) plot(x, y, axes=FALSE, type="p", xlab="Time (min)", ylab=expression(OD[600][~nm]), las=1, pch=20, tck=0.015, mgp=c(1.5,0.25,0), ) axis(1, at=NULL, tick=TRUE, tck=0.015, mgp=c(1.5,0.25,0) ) axis(2, at=NULL, tick=TRUE, tck=0.015, mgp=c(1.5,0.25,0) ) axis(3, at=c(300,600,900,1200,1500,1800,2100), labels=c(5,10,15,20,25,30,35), tick=TRUE, tck=0.015, mgp=c(1.5,0.25,0)) axis(4, labels=FALSE, at=NULL, tick=TRUE, tck=0.015, mgp=c(1.5,0.25,0) ) box() out <- nlm(VH, p = c(3, 4e-3), hessian = TRUE) #Plot Results from Gnuplot fit yfit1 <- 4.21632/(1+((4.21632-0.008)/0.008)*exp(-(0.00414403*x))) lines(spline(x, yfit1)) #Plot Results from 'out' yfit2 <- 3.02050/(1+((3.02050-0.008)/0.008)*exp(-(0.004587924*x))) lines(spline(x,yfit2)) On Wed, 25 Aug 2004 21:06:24 -0400 "Jim Brennan" <[EMAIL PROTECTED]> wrote: > > - Original Message - > From: "Johannes Graumann" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Wednesday, August 25, 2004 7:07 PM > Subject: [R] Beginners Question: Make nlm work > > > > Hello, > > > > I'm new to this and am trying to teach myself some R by plotting > > biological data. The growth curve in question is supposed to be > > fitted to the Verhulst equation, which may be transcribed as > > follows: f(x)=a/(1+((a-0.008)/0.008)*exp(-(b*x))) > > - for a known population density (0.008) at t(0). > > > > I am trying to rework the example from "An Introduction to R" (p. > > 72) for my case and am failing miserably. Could somebody glance over > > the code below and nudge me into the right direction - I must have > > some major conceptual problem which can't be solved by me staring at > > it ... Since I'm repeating something I have done with gnuplot I know > > that 3 and 4e-3 as starting values for the fit are appropriate ... > > > > Thanks for any hint, > > > > Joh > > > > setwd("~/Biology/R_versuch") > > mydata<-read.table("YJG45-7_Growth.dat") > > x<-mydata$V1 > > y<-mydata$V2 > > VH <- function(p) y ~ p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x))) > > Shouldn't this be > VH <- function(p) sum((y - > p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x^2) Where you are > minimizing the squared deviations from what your given equation is > when you pass it to nlm? > > Maybe if you send some data that would make it more clear. > > Jim > > > > plot(x, y, xlab="Time (h)",ylab=expression(OD[600][~nm]),las=1) > > out <- nlm(VH, p = c(3, 4e-3), hessian = TRUE) > > > > __ > > [EMAIL PROTECTED] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > plot1.eps Description: PostScript document __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Beginners Question: Make nlm work
Hello, I'm new to this and am trying to teach myself some R by plotting biological data. The growth curve in question is supposed to be fitted to the Verhulst equation, which may be transcribed as follows: f(x)=a/(1+((a-0.008)/0.008)*exp(-(b*x))) - for a known population density (0.008) at t(0). I am trying to rework the example from "An Introduction to R" (p. 72) for my case and am failing miserably. Could somebody glance over the code below and nudge me into the right direction - I must have some major conceptual problem which can't be solved by me staring at it ... Since I'm repeating something I have done with gnuplot I know that 3 and 4e-3 as starting values for the fit are appropriate ... Thanks for any hint, Joh setwd("~/Biology/R_versuch") mydata<-read.table("YJG45-7_Growth.dat") x<-mydata$V1 y<-mydata$V2 VH <- function(p) y ~ p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x))) plot(x, y, xlab="Time (h)",ylab=expression(OD[600][~nm]),las=1) out <- nlm(VH, p = c(3, 4e-3), hessian = TRUE) __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html