[R] Loop struggle
Hi, I cannot get rid of this error message: Warning messages: 1: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 2: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 3: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used data$A5 [1] 1 1 1 The loop seems to be stuck within the first loop. I have data (in .csv format) witch contains one example of each SP within the data, so the output should look like 123 instead of 111. This example is simplified version just to give you the idea of the problem. What is wrong within my code? I have tried everything imaginable and cannot figure it out. for (i in 1:n) { if (data$SP==1){ data[1:n, A1]- data$A1 -1 data[1:n, A2]- data$A2 -1 data[1:n, A3]- data$A3 -1 data[1:n, A4]- data$A4 -1 data[1:n, A5]- data$A5 -1} else if(data$SP==2){ data[1:n, A1]- data$A1 -2 data[1:n, A2]- data$A2 -2 data[1:n, A3]- data$A3 -2 data[1:n, A4]- data$A4 -2 data[1:n, A5]- data$A5 -2} else if(data$SP==3){ data[1:n, A1]-data$A1 -3 data[1:n, A2]-data$A2 -3 data[1:n, A3]-data$A3 -3 data[1:n, A4]-data$A4 -3 data[1:n, A5]-data$A5 -3} } -Tiff [[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] Loop struggle
Hi Tiff data1 - data.frame(SP = c(2, 2, 1), A1 = 1:3) data1 SP A1 1 2 1 2 2 2 3 1 3 i - 1 data1$SP [1] 2 2 1 data1$SP[i] [1] 2 # a warning is generated when # the length of the argument is # greater than 1 if(c(TRUE, TRUE, TRUE)) print(TRUE) [1] TRUE Warning message: In if (c(TRUE, TRUE, TRUE)) print(TRUE) : the condition has length 1 and only the first element will be used # subset by i to select element of interest for(i in 1:3) { + if(data1$SP[i] == 1) + data1$A1[i] - 1 + } data1 SP A1 1 2 1 2 2 2 3 1 1 Hope this helps, Chris Chris Campbell MANGO SOLUTIONS Data Analysis that Delivers +44 1249 705450 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of titta majasalmi Sent: 09 March 2012 07:20 To: r-help@r-project.org Subject: [R] Loop struggle Hi, I cannot get rid of this error message: Warning messages: 1: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 2: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 3: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used data$A5 [1] 1 1 1 The loop seems to be stuck within the first loop. I have data (in .csv format) witch contains one example of each SP within the data, so the output should look like 123 instead of 111. This example is simplified version just to give you the idea of the problem. What is wrong within my code? I have tried everything imaginable and cannot figure it out. for (i in 1:n) { if (data$SP==1){ data[1:n, A1]- data$A1 -1 data[1:n, A2]- data$A2 -1 data[1:n, A3]- data$A3 -1 data[1:n, A4]- data$A4 -1 data[1:n, A5]- data$A5 -1} else if(data$SP==2){ data[1:n, A1]- data$A1 -2 data[1:n, A2]- data$A2 -2 data[1:n, A3]- data$A3 -2 data[1:n, A4]- data$A4 -2 data[1:n, A5]- data$A5 -2} else if(data$SP==3){ data[1:n, A1]-data$A1 -3 data[1:n, A2]-data$A2 -3 data[1:n, A3]-data$A3 -3 data[1:n, A4]-data$A4 -3 data[1:n, A5]-data$A5 -3} } -Tiff [[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. LEGAL NOTICE This message is intended for the use o...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop struggle
Hi you are coming from different language paradigm? Although you did not provide your data I presume you have data frame called data with columns SP, A1-A5 Your construction data[1:n, A1]- data$A1 -1 seems to me rather strange and basically your cycle shall do data$A1-data$A2-data$A3-data$A4-data$A5-data$SP or if your columns were suitably located data[,1:5] - data$SP If you want something else you shall provide some working example. Regards Petr Hi, I cannot get rid of this error message: Warning messages: 1: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 2: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 3: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used data$A5 [1] 1 1 1 The loop seems to be stuck within the first loop. I have data (in .csv format) witch contains one example of each SP within the data, so the output should look like 123 instead of 111. This example is simplified version just to give you the idea of the problem. What is wrong within my code? I have tried everything imaginable and cannot figure it out. for (i in 1:n) { if (data$SP==1){ data[1:n, A1]- data$A1 -1 data[1:n, A2]- data$A2 -1 data[1:n, A3]- data$A3 -1 data[1:n, A4]- data$A4 -1 data[1:n, A5]- data$A5 -1} else if(data$SP==2){ data[1:n, A1]- data$A1 -2 data[1:n, A2]- data$A2 -2 data[1:n, A3]- data$A3 -2 data[1:n, A4]- data$A4 -2 data[1:n, A5]- data$A5 -2} else if(data$SP==3){ data[1:n, A1]-data$A1 -3 data[1:n, A2]-data$A2 -3 data[1:n, A3]-data$A3 -3 data[1:n, A4]-data$A4 -3 data[1:n, A5]-data$A5 -3} } -Tiff [[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] time between two dates
Dear All, It may be a trivial question but how to determine the number of days between two dates? What I want to do is to subtract two dates by a function which returns the number of days between these two dates. 11.11.2008-11.11.2006 ~= 730 days Look forward to your reply, Carol __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 between two dates
On 09/03/12 10:04, carol white wrote: Dear All, It may be a trivial question but how to determine the number of days between two dates? What I want to do is to subtract two dates by a function which returns the number of days between these two dates. 11.11.2008-11.11.2006 ~= 730 days start - strptime(2006, format=%Y%m%d) end - strptime(2008, format=%Y%m%d) end-start Time difference of 731 days HTH Sebastian signature.asc Description: OpenPGP digital signature __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 between two dates
On 09-03-2012, at 10:04, carol white wrote: Dear All, It may be a trivial question but how to determine the number of days between two dates? What I want to do is to subtract two dates by a function which returns the number of days between these two dates. 11.11.2008-11.11.2006 ~= 730 days x - as.Date(c(11-11-2008,11-11-2006),format=%d-%m-%Y) difftime(x[1],x[2],units=days) Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] figure margins too large in RGtk2 drawing area as cairo device - why?
Thanks, Peter. I did the following: restart R and run the same code with and without a minimal system pause (Sys.sleep) after the line that adds the device to the GTK window. Adding a pause will make it work, though I do not understand what is happening here. Note the different settings of par(din). This is probably not the expected behavior, I guess. Any ideas why this is the case? It seems as if din is not adjusted on time? Might that be? library(RGtk2) library(cairoDevice) win = gtkWindow() da = gtkDrawingArea() asCairoDevice(da) [1] TRUE win$add(da) plot(1:10) Fehler in plot.new() : Grafikränder zu groß par(c(din, mai)) $din [1] 0.0139 0.0139 $mai [1] 0.7791667 0.6263889 0.6263889 0.3208333 win = gtkWindow() da = gtkDrawingArea() asCairoDevice(da) [1] TRUE win$add(da) Sys.sleep(.1) plot(1:10) par(c(din, mai)) $din [1] 2.78 2.78 $mai [1] 0.7791667 0.6263889 0.6263889 0.3208333 Thanks in advance --- Mark Am 09.03.2012 um 00:01 schrieb peter dalgaard: On Mar 8, 2012, at 23:25 , Mark Heckmann wrote: Peter, thanks for the answer! Indeed, it does work if I set par(mar=c(0,0,0,0)) but not when it is set to the default values mar=c(5.1, 4.1, 4.1, 2.1). The par settings returned in the example are the defaults, so no extraordinary big mar settings or char size (see below). Also, it does not matter what size the drawing area is set to (e.g. 1000x 1000). The error always occurs. Any idea? The other parameters... What about din and mai? The margin problem usually means that the sum of the relevant margins is bigger than the device size. E.g. quartz() par(mai=rep(4,4)) plot(0) Error in plot.new() : figure margins too large examples: win = gtkWindow() da = gtkDrawingArea() win$add(da) asCairoDevice(da) [1] TRUE par(c(mar, cra, oma)) $mar [1] 5.1 4.1 4.1 2.1 $cra [1] 7 11 $oma [1] 0 0 0 0 plot(1:10) Fehler in plot.new() : Grafikränder zu groß ###ERROR### Thanks Mark Am 08.03.2012 um 22:48 schrieb peter dalgaard: On Mar 8, 2012, at 20:27 , Mark Heckmann wrote: When using a gtkDrawingArea as a Cairo device I very often encounter the error: figure margins too large Even for the below getting started example from http://www.ggobi.org/rgtk2/ this is the case. win = gtkWindow() da = gtkDrawingArea() win$add(da) asCairoDevice(da) [1] TRUE plot(1:10) Fehler in plot.new() : Grafikränder zu groß Also enlarging the drawing area does not help. win = gtkWindow() da = gtkDrawingArea() win$add(da) asCairoDevice(da) [1] TRUE da$setSizeRequest(700, 700) plot(1:10) Fehler in plot.new() : Grafikränder zu groß Any ideas? I'd check the par() settings for the device. Especially mar/mai and cra/cin to see whether margins are set unusually large and/or character sizes are unusually big, but check help(par) yourself. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How do I force confint() for glm() to be quiet?
I need confint() for glm() to supress the messages Waiting for profiling to be done... because they mess up the caching mechanism of pgfSweave (see https://github.com/cameronbracken/pgfSweave/issues/40). I have read the help page of confint(), but I do not know how to get the help page for the glm() version, if any such help page exists. Is there a general way of turning of output from functions in R, that would help here? Below is an example of an intended usage scenario: x - 1 set.seed(42) a - rnorm(x) b - factor(LETTERS[sample(1:7, x, replace = TRUE)]) c - factor(LETTERS[sample(1:4, x, replace = TRUE)]) my.fit - glm(c ~ b + a, family = binomial) my.results - confint(my.fit) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rtags for VI(M)
Hi, according to the help file rtags does not support VI(M) yet. Is there any known hack to ctags to get tags for R in VI(M)? BW F -- Federico C. F. Calboli Neuroepidemiology and Ageing Research Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] 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] rpanel / list error
Yes, please upload some code / data (minimal working example). The easiest way to upload data is to use dput() for a plain text representation. Also remember that the majority of R-Helpers don't use Nabble (rather they use an email client directly) so it's easier for us if you put things in the body of your post rather than as attachments. Michael On Thu, Mar 8, 2012 at 1:46 PM, jism7690 james.jism.ca...@gmail.com wrote: Hi All, I have created a simulation that works perfect and I have the results been returned in a list as I have multiple values. I then decided to include some user interaction by using the package rpanel, I now get the error: object of type 'builtin' is not subsettable when I attempted to have the return my list with the results . Any help needed. I can also upload code if needs be. -- View this message in context: http://r.789695.n4.nabble.com/rpanel-list-error-tp4457308p4457308.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] From (common IDs different Names) To (common IDs common Names)
library(stringr) x$Name - str_trim(gsub([ABC] Branch, ,x$Name)) Michael On Fri, Mar 9, 2012 at 12:32 AM, Sichong Chen csc...@gmail.com wrote: Dear Community I have a large dataframe x as follows with common ids but different names: x - data.frame(ID = c(1,1,2,2,2,3,3), + Name = c(B Branch A Firm ,A Firm,B Firm,B Firm,B Firm C Branch,C Firm,C Firm A Branch) + ) x ID Name 1 1 B Branch A Firm 2 1 A Firm 3 2 B Firm 4 2 B Firm 5 2 B Firm C Branch 6 3 C Firm 7 3 C Firm A Branch Q: How can I turn it into a dataframe with common id and common names, like this: y - data.frame(ID = c(1,1,2,2,2,3,3), + Name = c(A Firm,A Firm,B Firm,B Firm,B Firm,C Firm,C Firm) + ) y ID Name 1 1 A Firm 2 1 A Firm 3 2 B Firm 4 2 B Firm 5 2 B Firm 6 3 C Firm 7 3 C Firm Although I searched a lot, I am still not able to find answers to my question. Please help. Thanks in advance. 2012-03-09 Chen [[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] R versus R Studio output differences
Hi Everyone, I ran the same code in R and in R-studio, but got two different results. Does anybody know why this is occurring, and if there is a fix for this? and which is the correct program to use ? Some information about the code I am running: I am running the fisher test and it seems that the p-values are similar but not same for example, for an event A the p-value coming from the R-Studio is around 10^-58 and with R it is 10^-135. Also, I am running the Rstudio on Mac and R through linux server. They both are 64 bit. I am finding it for the first time and I am really surprised by its weirdness. -Best, Aayush Raman [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R versus R Studio output differences
Reproducible code please. (I'm quite surprised this would happen -- are you sure there's no stochastic element to your calculation that explains the differences?) But the canonical answer is the CLI R and the CRAN binaries. Michael On Fri, Mar 9, 2012 at 7:11 AM, Aayush Raman ayushra...@gmail.com wrote: Hi Everyone, I ran the same code in R and in R-studio, but got two different results. Does anybody know why this is occurring, and if there is a fix for this? and which is the correct program to use ? Some information about the code I am running: I am running the fisher test and it seems that the p-values are similar but not same for example, for an event A the p-value coming from the R-Studio is around 10^-58 and with R it is 10^-135. Also, I am running the Rstudio on Mac and R through linux server. They both are 64 bit. I am finding it for the first time and I am really surprised by its weirdness. -Best, Aayush Raman [[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] Loop struggle
Hi Hi, Ok I think I have to be more precise. Here is some example: The data includes tree samples (one of each species: 1, 2, 3 ) with different properties that are on rows. It is difficult to reproduce your code as the data can not be easily transferred to R. Better to use dput(data) and copy a result to your mail. Further see in text data SP BAI_coef TPH BA N H R_canc_lauri R_jakob DBH 1 1 0.18 533.433 15.39472 0.05334331 16.7231.616 1.540559 19.169 2 2 0.10 2059.378 11.91140 0.20593779 7.3761.197 1.076917 8.582 3 3 0.15 1034.076 14.61637 0.10340759 14.7161.190 1.549067 13.415 CL Canc_lauri CC_lauri Canc_jakob OPT_LAIA1A2A3A4 A5 1 7.176 0.4373724 0.4373724 0.39772851.27 0.744 0.584 0.450 0.282 0.186 2 5.648 0.9270533 0.9270533 0.75032671.57 0.854 0.724 0.451 0.220 0.086 3 8.103 0.4601203 0.4601203 0.77954792.67 0.316 0.213 0.179 0.081 0.037 rad1 rad2 rad3 rad4 rad5 1 0.1308997 0.3926991 0.6544985 0.9162979 1.178097 2 0.1308997 0.3926991 0.6544985 0.9162979 1.178097 3 0.1308997 0.3926991 0.6544985 0.9162979 1.178097 clump_pine-0.98 clump_spruce-0.98 clump_birch-0.98 W_pine-0.15 W_spruce-0.15 W_birch-0.15 n-nrow(data) What I am about to do is to add new columns to which new values will be calculated. Here is an example on double loop that produces right results, although the error messages seem to disagree. for (i in 1:n) { + if (data$SP==1) data[1:n, NAI]- data$NAI -(1-W_pine)*data$OPT_LAI* ^ Why do you use double assignment to one varable? if (data$SP==1) data$NAI -(1-W_pine)*data$OPT_LAI* shall be enough. Basically you shall use ifelse instead of if for what you want to achieve see ?ifelse, ?if But I believe there could be better way if you do not use three different clump_ and W_variables but an appropriate set of variables. Maybe someone more clever could do better with lapply but I would use loop first prepare variable to loop over ss-sort(unique(data$SP)) and coefficients in correct order W_any - c(.98,.98,.98) clump_any - c(.15,.15,.15) denom- c(.56,.56,1) and a new column data$NAI-NA for (i in 1:length(ss)) { rows-which(data$SP==ss[i]) data$NAI[rows] - (1-W[i])*data$OPT_LAI[rows]*(1/denom[i])/cl[i] } Regards Petr (1/0.56)/clump_pine else + if (data$SP==2) data[1:n, NAI]- data$NAI -(1-W_spruce)*data $OPT_LAI*(1/0.56)/clump_spruce else + if (data$SP==3) data[1:n, NAI]- data$NAI -(1-W_birch)*data $OPT_LAI*(1/1)/clump_birch + } Warning messages: 1: In if (data$SP == 1) data[1:n, NAI] - data$NAI - (1 - W_pine) * : the condition has length 1 and only the first element will be used 2: In if (data$SP == 1) data[1:n, NAI] - data$NAI - (1 - W_pine) * : the condition has length 1 and only the first element will be used 3: In if (data$SP == 1) data[1:n, NAI] - data$NAI - (1 - W_pine) * : the condition has length 1 and only the first element will be used data$NAI [1] 1.967019 2.431669 4.135386 Next, I am trying to do basically same thing. I wish the program would loop true all samples and add five new colums (A1A5) to which new values are calculated by species specific values. Here is again the problem.. The equations are replaced by number 1 or 2 or 3 just to see if loop works properly (should give values 1,2,3 because the species 1,2,3 are in that order). Are you able to figure out why it does not work? for (i in 1:n) { if (data$SP==1){ data[1:n, A1]- data$A1 -1 data[1:n, A2]- data$A2 -1 data[1:n, A3]- data$A3 - 1 data[1:n, A4]- data$A4 -1 data[1:n, A5]- data$A5 -1} else if(data$SP==2){ data[1:n, A1]- data$A1 -2 data[1:n, A2]- data$A2 -2 data[1:n, A3]- data$A3 -2 data[1:n, A4]- data$A4 -2 data[1:n, A5]- data$A5 -2} else if(data$SP==3){ data[1:n, A1]-data$A1 -3 data[1:n, A2]-data$A2 -3 data[1:n, A3]-data$A3 -3 data[1:n, A4]-data$A4 -3 data[1:n, A5]-data$A5 -3} } -Tiff 9. maaliskuuta 2012 10.43 Petr PIKAL petr.pi...@precheza.cz kirjoitti: Hi you are coming from different language paradigm? Although you did not provide your data I presume you have data frame called data with columns SP, A1-A5 Your construction data[1:n, A1]- data$A1 -1 seems to me rather strange and basically your cycle shall do data$A1-data$A2-data$A3-data$A4-data$A5-data$SP or if your columns were suitably located data[,1:5] - data$SP If you want something else you shall provide some working example. Regards Petr Hi, I cannot get rid of this error message: Warning messages: 1: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 2: In if (data$SP == 1) { : the condition has length 1 and only the first element will be used 3: In if (data$SP == 1) { :
Re: [R] SSOAP and Chemspider: Security token?
Dear Duncan, thanks for the quick answer. However, I already sorted one error out - turned out that I was just stupid: The security token worked fine once I filled all the additional required information on the ChemSpider profile (which means the token showing up on your profile is non-functional as long as that information isn't complete - ChemSpider doesn't tell you that, or force you to fill in the information, however.) Best, -Michael Message: 114 Date: Wed, 07 Mar 2012 16:57:21 -0800 From: Duncan Temple Lang dun...@wald.ucdavis.edu To: r-help@r-project.org Subject: Re: [R] SSOAP and Chemspider: Security token? Message-ID: 4f5803f1.2080...@wald.ucdavis.edu Content-Type: text/plain; charset=ISO-8859-1 Hi Michael Thanks for the report and digging into the actual XML documents that are sent. It turns out that if I remove the redundant namespace definitions and just use a single one on the SimpleSearch node, all is apparently fine. I've put a pre-release version of the SSOAP package that does at http://www.omegahat.org/Prerelease/SSOAP_0.9-1.tar.gz You can try that. I'll release this version when I also fix the issue with XMLSchema that causes the error in genSOAPClientInterface() BTW, the if(!is.character(token)) in the example in chemSpider.R is an error - a mixture of !is.null() and then checking only if it is a character. Best, Duncan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R versus R Studio output differences
On Mar 9, 2012, at 13:15 , R. Michael Weylandt wrote: Reproducible code please. (I'm quite surprised this would happen -- are you sure there's no stochastic element to your calculation that explains the differences?) Notice that the code is running on two separate platforms. It's not particularly unusual to find minor discrepancies due to e.g. different compiler optimizations. Rstudio as such is probably not part of the issue. -pd But the canonical answer is the CLI R and the CRAN binaries. Michael On Fri, Mar 9, 2012 at 7:11 AM, Aayush Raman ayushra...@gmail.com wrote: Hi Everyone, I ran the same code in R and in R-studio, but got two different results. Does anybody know why this is occurring, and if there is a fix for this? and which is the correct program to use ? Some information about the code I am running: I am running the fisher test and it seems that the p-values are similar but not same for example, for an event A the p-value coming from the R-Studio is around 10^-58 and with R it is 10^-135. Also, I am running the Rstudio on Mac and R through linux server. They both are 64 bit. I am finding it for the first time and I am really surprised by its weirdness. -Best, Aayush Raman [[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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R versus R Studio output differences
Missed that...thank you. Michael On Fri, Mar 9, 2012 at 8:21 AM, peter dalgaard pda...@gmail.com wrote: On Mar 9, 2012, at 13:15 , R. Michael Weylandt wrote: Reproducible code please. (I'm quite surprised this would happen -- are you sure there's no stochastic element to your calculation that explains the differences?) Notice that the code is running on two separate platforms. It's not particularly unusual to find minor discrepancies due to e.g. different compiler optimizations. Rstudio as such is probably not part of the issue. -pd But the canonical answer is the CLI R and the CRAN binaries. Michael On Fri, Mar 9, 2012 at 7:11 AM, Aayush Raman ayushra...@gmail.com wrote: Hi Everyone, I ran the same code in R and in R-studio, but got two different results. Does anybody know why this is occurring, and if there is a fix for this? and which is the correct program to use ? Some information about the code I am running: I am running the fisher test and it seems that the p-values are similar but not same for example, for an event A the p-value coming from the R-Studio is around 10^-58 and with R it is 10^-135. Also, I am running the Rstudio on Mac and R through linux server. They both are 64 bit. I am finding it for the first time and I am really surprised by its weirdness. -Best, Aayush Raman [[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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extended Survival Plot Lines
... Is there a way to extend all the lines to make them end at a certain time point? (i.e outcome.[,1] is a time to event variable and I would like thesurvival lines on the plot to extend out to say 5(years) ) No, there is no option in the plot.survival function to do this. No one has ever asked for this feature before (the function was written in about 1988), so you are breaking new ground. It is standard practice to end a survival curve at the last observed time point; you are not likely to convince me to add this as an option. You can always plot the curves yourself: fit - survfit(Surv(1:5, c(1,0,1,0,0)) ~1) plot(fit$time, fit$surv, type='s') plot(c(0, fit$time), c(1, fit$surv), type='s') #Oops, add time 0 on The key is using type='s' for a step function. You can now tack on an extra time point of your choice, 6 say, with c(0, fit$time, 6) for x and c(1, fit$surv, min(fit$surv)) for y. For multiple curves look more closely at help(survfit.object) Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Copy dataframe for another
Hello, the idea is to copy the d for df, with new results. x-data.frame(name=x1,pos=4,age=20) x-rbind(x,data.frame(name=x2,pos=5,age=20)) x-rbind(x,data.frame(name=x3,pos=6,age=21)) x-rbind(x,data.frame(name=x4,pos=7,age=24)) x-rbind(x,data.frame(name=x5,pos=8,age=27)) x-rbind(x,data.frame(name=x6,pos=9,age=26)) View(x) d-NULL df-NULL for(r in 2: nrow(x)) { val_user-x$name[[r]] pos-x$pos[[r]] -4 age -x$age[[r]] d-data.frame(val_user,pos,age) print(d) } df-rbind(df,d) View(df) in df only have the last result, the ideia is have the new results calculated in the for loop thanks -- View this message in context: http://r.789695.n4.nabble.com/Copy-dataframe-for-another-tp4456893p4459068.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] find points on a graph
May i please update my question, and I understand now something that i did not yesterday. In this example: table - structure(c(4, 7, 0.2, 3, .1, 7, 222, 3, 10, 5, 11, 8, 8, 10, 7), .Dim = c(5L, 3L), .Dimnames = list(c(gene1, gene2, gene3, gene4, gene5), c(codon1, codon2, codon3))) Library(ca) list -scan(test_list, what=list(gene=)) ### where test_list is a file containing the words gene4, gene5 plot(ca(table, suprow=c(4, 5))) *Question 1: is it possible to change:* plot(ca(table, suprow=c(4, 5))) to either: plot(ca(table, suprow=c(0-100)) ## e.g. a range of numbers (i have about 100 rows that i need to highlight, so i'd rather not do manually) or: plot(ca(table, suprow=c(test_list))) ### where i've given it a file with list of nodes, and R can find the rows that these nodes are on and highlight these. And then my second question is the same as previous regarding the plot output, is it possible to shade rather than have open circles. Many thanks. -- View this message in context: http://r.789695.n4.nabble.com/find-points-on-a-graph-tp4452746p4459001.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] For loop and using its index
Dear All, I have a data set with variables x1, x2, x3, ..., x20 and I want to create z1, z2, z3, ..., z20 with the following formula: z1 = 200 - x1 z2 = 200 - x2 z3 = 200 - x3 . . . z20 = 200 - x20. I tried using a for loop and its index as: for (i in 1:20) { z(i) = 200 - x(i) } But R gives the following error message: Error: could not find function x. Is there any other way for a simple coding of my 20 lines of code? Alohas, Hassan Eini-Zinab __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting shaded areas
May I ask, is it possible using plotrix to shade a group of variables differentially from the rest of a graph, eg so the output looks similar to this, where the nodes of open circles are my nodes of interest: http://r.789695.n4.nabble.com/file/n4459137/Screen_shot_2012-03-08_at_12.18.34.png Many thanks -- View this message in context: http://r.789695.n4.nabble.com/Plotting-shaded-areas-tp896558p4459137.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] rpanel / list error
Hi Michael, Thank you for your reply. I have uploaded the minimum, I have left out the formulas for calculating the amounts as they are not important to the loop. Basically I have a while loop running that adds to the list of values and then outside this loop I have a list called sis, this is the list that is causing the error. I would like this list to return the values with panel, before I used rpanel it was returning values perfectly. Thanks main - function(panel) { with(panel,{ LAST = 1100 START = 0 index = 0 Starting Conditions revenue = 0 minStock = panel$minStock maxStock = 100 inventory = 100 order_costs = 0 storage_costs = 0 orderlevel =panel$k sum = list(ninventory=inventory,order_costs=0,storage_costs=0,revenue = 0) # initial list containing values while(index LAST inventory 0) { sum$order_costs = sum$order_costs + order_costs sum$storage_costs = sum$storage_costs + storage_costs sum$ninventory = sum$ninvenotry + inventory index = index + 1 } }) sis = list(Time = index,StorageCosts=sum$storage_costs,OrderCosts= sum$order_cost,fInventory = sum$ninventory) return(sis) } panel - rp.control(title=Stochastic Case, size=panel.size) rp.button(panel,action=main,title=Calculate,pos=pos.go.button) rp.slider(panel,k,from=10,to=90,resolution=10,showvalue=TRUE,title=Select Order Size,pos=pos.order.slider,initval=70) rp.slider(panel,minStock,from=10,to=90,resolution=10,pos=pos.minstock.slider,initval = 50,title=Minimum Stock Level,showvalue=TRUE) -- View this message in context: http://r.789695.n4.nabble.com/rpanel-list-error-tp4457308p4459254.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] Calculating length of consecutive sequences within a vector
Thanks, rle is what I was looking for. Jorge From: R. Michael Weylandt [michael.weyla...@gmail.com] Sent: 08 March 2012 16:29 To: Jorge Molinos Cc: r-help@R-project.org Subject: Re: [R] Calculating length of consecutive sequences within a vector rle should get you started. Michael On Thu, Mar 8, 2012 at 9:35 AM, Jorge Molinos jgarc...@tcd.ie wrote: Hi all, I have a nx1 logical array of zeros and ones and I want to calculate the individual lengths of all 1-consecutive sequences contained in it. Is there an easy quick way to do this in R? So, if I have a vector such as 1110011011110 I would like to get (1) 3, (2) 2, (3) 1, (4) 7 Any help would be appreciated! thanks! Jorge [[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 do I force confint() for glm() to be quiet?
In stats:::confint.glm (actually it is MASS:::confint.glm) you see that the message() function is used to produce waiting for To avoid this message you can just use suppressMessages(confint(my.fit)) At least in R it works, hope it works with Sweave as well. Regards, Sina -- View this message in context: http://r.789695.n4.nabble.com/How-do-I-force-confint-for-glm-to-be-quiet-tp4459152p4459227.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] parsing text files
Here is one way of doing it; it reads the file and create a 'long' version. ## input - file(/temp/ClinicalReports.txt, 'r') outFile - '/temp/output.txt' # tempfile() output - file(outFile, 'w') writeLines(ID, Date, variable, value, output) ID - NULL dataSw - NULL repeat{ line - readLines(input, n = 1) if (length(line) == 0) break if (!is.null(dataSw)){ if (line == ''){ # end of data ID - NULL dataSw - NULL next } # now write CSV output file cat(ID , ',' , Date , ',' , substring(line, 1, 31) , ',' , substring(line, 32, 43) , '\n' , sep = '' , file = output ) next } if (grepl(Acc.ne, line)){ ID - (substring(line, 29,35)) Date - (substring(line, 52,61)) next } if (!is.null(ID)){ # looking for Esame if (grepl(Esame, line)){ # skip two lines readLines(input, n = 2) dataSw - 1 next } } } # now read in the data in a long format close(output) result - read.csv(outFile, as.is = TRUE) the results from your test data is: str(result) 'data.frame': 43 obs. of 4 variables: $ ID : int 185 185 185 185 185 185 185 185 185 185 ... $ Date: chr 05/12/2011 05/12/2011 05/12/2011 05/12/2011 ... $ variable: chr AZOTEMIACREATININEMIA SODIEMIAPOTASSIEMIA ... $ value : num 33.6 0.99 136 4.22 94.2 8.68 1.87 1.79 189 118 ... head(result) ID Datevariable value 1 185 05/12/2011 AZOTEMIA 33.60 2 185 05/12/2011 CREATININEMIA 0.99 3 185 05/12/2011 SODIEMIA136.00 4 185 05/12/2011 POTASSIEMIA 4.22 5 185 05/12/2011 CLOREMIA 94.20 6 185 05/12/2011 CALCEMIA 8.68 On Thu, Mar 8, 2012 at 8:24 AM, ginger bi...@igm.cnr.it wrote: Ooops, I forgot to specify that for each raw, containing records of the clinical reports , the values of the 22 parameter measurement have to be reported. For example, first raw, first 5 columns: ID DATE GLICEMIA AZOTEMIA CREATININEMIA SODIEMIA ... ... ... 185 05/12/2011 115 33.6 0.99 136 ... ... ... -- View this message in context: http://r.789695.n4.nabble.com/parsing-text-files-tp4456355p4456389.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] figure margins too large in RGtk2 drawing area as cairo device - why?
Hi Mark, This comes down to the way that GTK+ allocates size to its widgets. The allocation of a widget is initialized to have a width and height of 1. When a child is added to a visible parent, the parent will execute its lay out algorithm and allocate a certain amount of space to the widget. The widget is notified of this change via an event that arrives after an iteration of the event loop. An event loop iteration may be forced in a number of ways; you've discovered the Sys.sleep() method. However, it is generally not good practice to show a container before adding its children, unless widgets are being added in the middle of a session, which is rare. If you were to instead do something like this: win = gtkWindow(show = FALSE) win$setDefaultSize(500, 500) da = gtkDrawingArea() asCairoDevice(da) win$add(da) win$showAll() plot(1:10) Then GTK+ will correctly initialize the allocation of the widget, I think even before a configure event is received. The above approach is my recommended solution to your problem. Thanks, Michael On Fri, Mar 9, 2012 at 1:39 AM, Mark Heckmann mark.heckm...@gmx.de wrote: Thanks, Peter. I did the following: restart R and run the same code with and without a minimal system pause (Sys.sleep) after the line that adds the device to the GTK window. Adding a pause will make it work, though I do not understand what is happening here. Note the different settings of par(din). This is probably not the expected behavior, I guess. Any ideas why this is the case? It seems as if din is not adjusted on time? Might that be? library(RGtk2) library(cairoDevice) win = gtkWindow() da = gtkDrawingArea() asCairoDevice(da) [1] TRUE win$add(da) plot(1:10) Fehler in plot.new() : Grafikränder zu groß par(c(din, mai)) $din [1] 0.0139 0.0139 $mai [1] 0.7791667 0.6263889 0.6263889 0.3208333 win = gtkWindow() da = gtkDrawingArea() asCairoDevice(da) [1] TRUE win$add(da) Sys.sleep(.1) plot(1:10) par(c(din, mai)) $din [1] 2.78 2.78 $mai [1] 0.7791667 0.6263889 0.6263889 0.3208333 Thanks in advance --- Mark Am 09.03.2012 um 00:01 schrieb peter dalgaard: On Mar 8, 2012, at 23:25 , Mark Heckmann wrote: Peter, thanks for the answer! Indeed, it does work if I set par(mar=c(0,0,0,0)) but not when it is set to the default values mar=c(5.1, 4.1, 4.1, 2.1). The par settings returned in the example are the defaults, so no extraordinary big mar settings or char size (see below). Also, it does not matter what size the drawing area is set to (e.g. 1000x 1000). The error always occurs. Any idea? The other parameters... What about din and mai? The margin problem usually means that the sum of the relevant margins is bigger than the device size. E.g. quartz() par(mai=rep(4,4)) plot(0) Error in plot.new() : figure margins too large examples: win = gtkWindow() da = gtkDrawingArea() win$add(da) asCairoDevice(da) [1] TRUE par(c(mar, cra, oma)) $mar [1] 5.1 4.1 4.1 2.1 $cra [1] 7 11 $oma [1] 0 0 0 0 plot(1:10) Fehler in plot.new() : Grafikränder zu groß ###ERROR### Thanks Mark Am 08.03.2012 um 22:48 schrieb peter dalgaard: On Mar 8, 2012, at 20:27 , Mark Heckmann wrote: When using a gtkDrawingArea as a Cairo device I very often encounter the error: figure margins too large Even for the below getting started example from http://www.ggobi.org/rgtk2/ this is the case. win = gtkWindow() da = gtkDrawingArea() win$add(da) asCairoDevice(da) [1] TRUE plot(1:10) Fehler in plot.new() : Grafikränder zu groß Also enlarging the drawing area does not help. win = gtkWindow() da = gtkDrawingArea() win$add(da) asCairoDevice(da) [1] TRUE da$setSizeRequest(700, 700) plot(1:10) Fehler in plot.new() : Grafikränder zu groß Any ideas? I'd check the par() settings for the device. Especially mar/mai and cra/cin to see whether margins are set unusually large and/or character sizes are unusually big, but check help(par) yourself. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help
[R] sort dates
Hello, How is it possible to sort dates in R? Cheers, Carol __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Copy dataframe for another
Hi Hello, the idea is to copy the d for df, with new results. x-data.frame(name=x1,pos=4,age=20) x-rbind(x,data.frame(name=x2,pos=5,age=20)) x-rbind(x,data.frame(name=x3,pos=6,age=21)) x-rbind(x,data.frame(name=x4,pos=7,age=24)) x-rbind(x,data.frame(name=x5,pos=8,age=27)) x-rbind(x,data.frame(name=x6,pos=9,age=26)) View(x) d-NULL df-NULL for(r in 2: nrow(x)) { val_user-x$name[[r]] x$name[r] is enough x$name shall be plain vector pos-x$pos[[r]] -4 age -x$age[[r]] d-data.frame(val_user,pos,age) print(d) } df-rbind(df,d) View(df) in df only have the last result, the ideia is have the new results calculated in the for loop It is not very efficient way of doing things in R, but if you insist. d is overwritten in each iteration therefore only last value is stored. You need to put values from each cycle to separate slot. So you shall put df-rbind(df,d) into the cycle. As I said it is not very convenient and effective way, but if you want to shoot yourself to your leg Regards Petr thanks -- View this message in context: http://r.789695.n4.nabble.com/Copy- dataframe-for-another-tp4456893p4459068.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] For loop and using its index
Hi Dear All, I have a data set with variables x1, x2, x3, ..., x20 and I want to create z1, z2, z3, ..., z20 with the following formula: z1 = 200 - x1 z2 = 200 - x2 z3 = 200 - x3 . . . z20 = 200 - x20. I tried using a for loop and its index as: for (i in 1:20) { z(i) = 200 - x(i) } But R gives the following error message: Error: could not find function x. You probably did not define any such function. Is there any other way for a simple coding of my 20 lines of code? No. Preferable is to do it in one line z - x-200 But it depends what is a set of variables. There is no such object in R AFAIK. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Regards Petr Alohas, Hassan Eini-Zinab __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sort dates
? sort x - c(Sys.Date(), Sys.Date() + 1, Sys.Date() - 1) print(x) print(sort(x)) Michael On Fri, Mar 9, 2012 at 8:35 AM, carol white wht_...@yahoo.com wrote: Hello, How is it possible to sort dates in R? Cheers, Carol __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sort dates
Hi Hello, How is it possible to sort dates in R? You mean sort? Or order? Something like: dd -sample(Sys.Date()-1:10) dd [1] 2012-03-04 2012-03-05 2012-02-29 2012-03-01 2012-03-02 [6] 2012-03-08 2012-03-03 2012-02-28 2012-03-06 2012-03-07 sort(dd) [1] 2012-02-28 2012-02-29 2012-03-01 2012-03-02 2012-03-03 [6] 2012-03-04 2012-03-05 2012-03-06 2012-03-07 2012-03-08 dd[order(dd)] [1] 2012-02-28 2012-02-29 2012-03-01 2012-03-02 2012-03-03 [6] 2012-03-04 2012-03-05 2012-03-06 2012-03-07 2012-03-08 Regards Petr Cheers, Carol __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sort dates
How is it possible to sort dates in R? Try this: a = sample(as.Date(1:100, origin = '2012-01-01'),15) a [1] 2012-01-31 2012-01-22 2012-03-18 2012-03-05 2012-03-17 [6] 2012-03-08 2012-01-08 2012-01-20 2012-03-01 2012-03-21 [11] 2012-02-17 2012-01-17 2012-02-12 2012-02-28 2012-04-01 sort(a) [1] 2012-01-08 2012-01-17 2012-01-20 2012-01-22 2012-01-31 [6] 2012-02-12 2012-02-17 2012-02-28 2012-03-01 2012-03-05 [11] 2012-03-08 2012-03-17 2012-03-18 2012-03-21 2012-04-01 Cheers, Carol __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A. T. Still University of Health Sciences 800 W. Jefferson St. Kirksville, MO 63501 660-626-2322 FAX 660-626-2965 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] For loop and using its index
Le vendredi 09 mars 2012 à 13:24 +0330, Hassan Eini Zinab a écrit : Dear All, I have a data set with variables x1, x2, x3, ..., x20 and I want to create z1, z2, z3, ..., z20 with the following formula: z1 = 200 - x1 z2 = 200 - x2 z3 = 200 - x3 . . . z20 = 200 - x20. I tried using a for loop and its index as: for (i in 1:20) { z(i) = 200 - x(i) } But R gives the following error message: Error: could not find function x. Is there any other way for a simple coding of my 20 lines of code? This is very basic, please read the R intro. The problem is that x(i) means call function x with argument i, and no function x exists (nor z, BTW). You need x1 - 1:10 x2 - 11:20 for (i in 1:2) { assign(paste(z, i, sep=), 200 - get(paste(x, i, sep=))) } But you'd better use a data frame to store these variables, in which case you can do: df - data.frame(x1=1:10, x2=11:20) for (i in 1:2) { df[[paste(z, i, sep=)]] - 200 - df[[paste(x, i, sep=)]] } You can also create a new data frame: xdf - data.frame(x1=1:10, x2=11:20) zdf - 200 - xdf colnames(zdf) - paste(z, 1:2, sep=) df - cbind(xdf, zdf) Regards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sort dates
On Fri, Mar 9, 2012 at 8:35 AM, carol white wht_...@yahoo.com wrote: Hello, How is it possible to sort dates in R? Your question has already been answered but note that if your data is a time series and you represent it using zoo it will automatically be sorted. Here dates is in reverse chronological order whereas z, the zoo time series object, is in chronological order: values - 13:10 dates - as.Date(2000-01-01) + 3:0; dates library(zoo) z - zoo(values, dates); z -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] Plotting shaded areas
Perhaps ?polygon Michael On Fri, Mar 9, 2012 at 6:10 AM, aoife aoife.m.dohe...@gmail.com wrote: May I ask, is it possible using plotrix to shade a group of variables differentially from the rest of a graph, eg so the output looks similar to this, where the nodes of open circles are my nodes of interest: http://r.789695.n4.nabble.com/file/n4459137/Screen_shot_2012-03-08_at_12.18.34.png Many thanks -- View this message in context: http://r.789695.n4.nabble.com/Plotting-shaded-areas-tp896558p4459137.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R versus R Studio output differences
First, be sure your R and the R associated with Rstudio are the same R versions. In Rstudio, check Tools - Options - R version. It looks as if your R-studio is running the 32-bit version of R. Aayush Raman ayushra...@gmail.com Sent by: r-help-boun...@r-project.org 03/09/2012 07:11 AM To r-help@r-project.org cc Subject [R] R versus R Studio output differences Hi Everyone, I ran the same code in R and in R-studio, but got two different results. Does anybody know why this is occurring, and if there is a fix for this? and which is the correct program to use ? Some information about the code I am running: I am running the fisher test and it seems that the p-values are similar but not same for example, for an event A the p-value coming from the R-Studio is around 10^-58 and with R it is 10^-135. Also, I am running the Rstudio on Mac and R through linux server. They both are 64 bit. I am finding it for the first time and I am really surprised by its weirdness. -Best, Aayush Raman [[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] Boxplot Fill Pattern
On 3/8/2012 1:08 PM, Gabriel Yospin wrote: I would like to make a legible boxplot of tree growth rates for each of seven tree species at each of seven different sites. It's a lot of data to put on one figure, I know. I made a beautiful, interpretable figure using color, but my target journal can't deal with color figures. I can use seven shades of grey to fill the boxes, but the figure then becomes If you print your original figure (with the legend) in B/W, you'll see that the shading levels are not too bad -- they are relatively distinguishable except for Acer and Pinus/ Thus, one thing I often do in this situation is design a graph so that it will render reasonably well also in B/W and suggest to the journal to make a color version available online (or I put it on my own web). Your final version using ggplot2 is a far worse graph, IMHO because the labels are illegible, and using no fill in the boxplots makes it impossible to distinguish the same species across sites. You could make it better by (a) only labeling the species in alternate site panels (b) rotating those labels by 45^o (c) using some fill for the boxes My .05 -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] binning dates by decade for simulated data
On Mar 8, 2012, at 7:37 PM, Jeff Garcia wrote: I have a simulated matrix of dates that I generated from a probability function. Each column represents a single iteration. I would like to bin each run _separately_ by decades and dump them into a new matrix where each column is the length of all decades a single run with the number dates binned by decade. I have successfully done this for a single vector of dates, but not for a matrix: dates is a vector of observed data representing when certain trees established in a population #-find min and max decade -# minDecade - min(dates) maxDecade - max(dates) #-create vector of decades -# allDecades - seq(minDecade, 2001, by=10) #-make empty vector of same length as decade vector-# bin.vec - rep(0,length(allDecades)) #-populate bin.vec (empty vector) with the number of trees in each decade-# for (i in 1:length(allDecades)) { bin.vec[i] - length(which(dates==allDecades[i])) } bin.vec : [1]0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 2 0 1 [19] 3 0 1 3 8 5 9 8 5 5 4 10 3 6 9 17 32 37 [37] 35 25 31 41 41 44 45 40 50 43 59 42 46 28 16 18 20 16 [55] 11 4 7 1 My matrix looks like this (it actually had 835 rows, I used head (x) just to demonstrate). head(bin.mat) [,1] [,2] [,3] [,4] [,5][,6][,7] [,8][, 9] [,10] [1,] 1831 1811 1841 1881 1851 1871 1921 1821 1781 1561 [2,] 1851 1931 1821 1701 1841 1961 1941 1931 1891 1841 [3,] 1751 1861 1861 1751 1841 1841 1771 1971 1811 1871 [4,] 1831 1871 1741 1881 1871 1771 1821 1901 1901 1851 [5,] 1681 1861 1871 1811 1711 1931 1891 1771 1811 1821 [6,] 1931 1841 1841 1861 1831 1881 1601 1861 1891 1891 After setting up your allDecades vector to your liking perhaps something like: apply( dates, 2, function(colm){ 1 + max(findInterval(colm, allDecades)) - min(findInterval(colm, allDecades) ) } ) With that data (although changing its name to years): years - scan() 1: 1831 1811 1841 1881 1851 1871 1921 1821 1781 1561 11: 1851 1931 1821 1701 1841 1961 1941 1931 1891 1841 21: 1751 1861 1861 1751 1841 1841 1771 1971 1811 1871 31: 1831 1871 1741 1881 1871 1771 1821 1901 1901 1851 41: 1681 1861 1871 1811 1711 1931 1891 1771 1811 1821 51: 1931 1841 1841 1861 1831 1881 1601 1861 1891 1891 61: Read 60 items years - matrix(years, nrow=6, byrow=TRUE) minDecade - min(years) maxDecade - max(years) allDecades - seq(minDecade, 2001, by=10) apply( years, 2, function(colm){ + 1 + max(findInterval(colm, allDecades)) - + min(findInterval(colm, allDecades) ) + } ) [1] 26 13 14 19 17 20 35 21 13 34 You have not offered the requested correct answer with your data , so I leave it to you to decide whether the rules the 'findInterval' uses for determining boundaries with you interval-vector are to your requirements. Each column is a separate run (runs - 10 ) . How can I bin each column into decades separately? That is not a good description of what I did but following that wording would have constructed a result that only a list object could have accepted because of the irregular lengths. I decided from your sample output that you just wanted a single number to describe the span of years. I'll bet this is super easy, but my R-skills are seriously limited!!! Thanks for any help! ~Jeff [[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. 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] R-help Digest, Vol 109, Issue 9
On Fri, 2012-03-09 at 12:00 +0100, r-help-requ...@r-project.org wrote: A note on standard errors: ?S(t) +- std is a terrible confidence interval. ?You will be much more accurate if you use log scale. ?(Some argue for logit or log-log, in truth they all work well.) ? If n is large enough, however, you should be ok. Very true, but if one really wants a confidence interval for S_1(t)-S_2(t) (not for S_1(t)/S_2(t)) then one is pretty much forced to use the raw probability scale. -thomas I agree, and stand corrected. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Copy dataframe for another
Hello Thanks for the reply. As yet I have not much experience in r, although I make some mistakes. Any tips to solve the problem of a more effective way. Regards -- View this message in context: http://r.789695.n4.nabble.com/Copy-dataframe-for-another-tp4456893p4459526.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 Correspondence Analysis
You should send this to r-h...@stat.math.ethz.ch. On 03/09/2012 09:21 AM, Andrea Sica wrote: Hello everybody, I'm looking for someone who is able with MCA and would like to gives some help. If what I'm doing is not wrong, according to the purpose I have, I need to understand how to create a dependence matrix, where I can analyze the dependence between all my variables. Till now this is what I was able to do: /p - length(spain)/ #this is the number of the variables (91) /chisquare - matrix(spain, nrow=(p-1), ncol=p)/ #it creates a squared-matrix with all the variables (if I'm not already wrong) /for(i in (1:(p-1))){/ /chisquare[i, (1:(p-1))] - chisq.test(spain[,i], spain[, i+1])$statistic/ /chisquare[i, p] - chisq.test(spain[,i], spain[, i+1])$p.value/ /} /#it should have related the p variables to analyze whether in pairs they are dependents, but it seems like it just related two of them and repeated the relations for all the number of columns (since it gives the same values in each cell by row) /chisquare/ #all the cells have the same values by row Anyway, I think is also the way I'm proceeding which is wrong, since I want to relate all the variables in pairs thus to be able to calculate the dependence between all of them. That's why I am going for a dependence matrix. Where am I wrong? After that I can proceed with the MCA. Of course, I would also need help there. I used the following codes to do it: /spain.mca - mjca(spain) /#it makes the mca for all the data /spain.mca/ /plot(spain.mca)/ #it shows the plot But the plot was overcrowded. Anyway, I must first complete the first step, this was just to make some practice on it. As you can see, until now I didn't succeed. I hope someone will be so gentle to give it a try. Attached you are the data-set Thank you Best -- Kevin E. Thorpe Biostatistician/Trialist, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 [[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] Reading in 9.6GB .DAT File - OK with 64-bit R?
You could also have a look at the LaF package which is written to handle large text files: http://cran.r-project.org/web/packages/LaF/index.html Under the vignettes you'll find a manual. Note: LaF does not help you to fit 9GB of data in 4GB of memory, but it could help you reading your file block by block and filtering it. Jan RHelpPlease rrum...@trghcsolutions.com schreef: Hi Barry, You could do a similar thing in R by opening a text connection to your file and reading one line at a time, writing the modified or selected lines to a new file. Great! I'm aware of this existing, but don't know the commands for R. I have a variable [560,1] to use to pare down the incoming large data set (I'm sure of millions of rows). With other data sets they've been small enough where I've been able to use the merge function after data has been read in. Obviously I'm having trouble reading in this large data set in in the first place. Any additional help would be great! -- View this message in context: http://r.789695.n4.nabble.com/Reading-in-9-6GB-DAT-File-OK-with-64-bit-R-tp4457220p4458074.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I force confint() for glm() to be quiet?
On Mar 9, 2012, at 6:14 AM, Hans Ekbrand wrote: I need confint() for glm() to supress the messages I'm wondering if suppressMessages would be helpful? Which in turn suggests that you do not know how to use ??, so firt you should get in the habit of doing a helpSearch before posting. ??suppress messages Waiting for profiling to be done... because they mess up the caching mechanism of pgfSweave (see https://github.com/cameronbracken/pgfSweave/issues/40). I have read the help page of confint(), but I do not know how to get the help page for the glm() version, if any such help page exists. When I type ?confint.glm at my console I get this help page: confint-MASS {MASS} Is there a general way of turning of output from functions in R, that would help here? If suppressMessages is not effective then look at: ?sink Below is an example of an intended usage scenario: x - 1 set.seed(42) a - rnorm(x) b - factor(LETTERS[sample(1:7, x, replace = TRUE)]) c - factor(LETTERS[sample(1:4, x, replace = TRUE)]) my.fit - glm(c ~ b + a, family = binomial) my.results - confint(my.fit) G. A _minimal_ example would have had fewer iterations, but this does seem to be effective: suppressMessages(my.results - confint(my.fit)) -- 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] Moving average with loess
Hi Robert, If you type ?loess It pulls up the documentation. What about that function do you not like? As you said, it needs two variables, but typically the second is just your time index. Try this: n - 50 x - rep(0,n) for(i in 2:n){ x[i] - rnorm(1,x[i-1]) } loess(x ~ seq(1,n)) plot(1:n,x,type='l') lines(predict(loess(x ~ seq(1,n))),col=4,type='l') This might also help: http://research.stowers-institute.org/efg/R/Statistics/loess.htm -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Faryabi, Robert (NIH/NCI) [F] Sent: Thursday, March 08, 2012 6:43 PM To: r-help@r-project.org Subject: [R] Moving average with loess Hello All, I just have a very simple question. I recently switching from Matlab to R, so cannot figure out some of the easy tasks in the new environment. Is there any weighted local regression smoothing in R? Basically, I want to have weighted moving average. All the functions that I know of need two variables for fitting. Best, Robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Multiple Correspondence Analysis
Hello everybody, I'm looking for someone who is able with MCA and would like to gives some help. If what I'm doing is not wrong, according to the purpose I have, I need to understand how to create a dependence matrix, where I can analyze the dependence between all my variables. Till now this is what I was able to do: *p - length(spain)* #this is the number of the variables (91) *chisquare - matrix(spain, nrow=(p-1), ncol=p)* #it creates a squared-matrix with all the variables (if I'm not already wrong) *for(i in (1:(p-1))){* *chisquare[i, (1:(p-1))] - chisq.test(spain[,i], spain[, i+1])$statistic* *chisquare[i, p] - chisq.test(spain[,i], spain[, i+1])$p.value* *} *#it should have related the p variables to analyze whether in pairs they are dependents, but it seems like it just related two of them and repeated the relations for all the number of columns (since it gives the same values in each cell by row) *chisquare* #all the cells have the same values by row Anyway, I think is also the way I'm proceeding which is wrong, since I want to relate all the variables in pairs thus to be able to calculate the dependence between all of them. That's why I am going for a dependence matrix. Where am I wrong? After that I can proceed with the MCA. Of course, I would also need help there. I used the following codes to do it: *spain.mca - mjca(spain) *#it makes the mca for all the data *spain.mca* *plot(spain.mca)* #it shows the plot But the plot was overcrowded. Anyway, I must first complete the first step, this was just to make some practice on it. As you can see, until now I didn't succeed. I hope someone will be so gentle to give it a try. Attached you are the data-set Thank you Best A.1 A.2 A.3_1 A.3_2 A.3_3 A.3_4 A.3_5 A.3_6 A.3_7 A.3_8 A.3_9 A.3_10 A.3_11 A.3_12 A.4 A.4_1.1 A.4_1.2 A.4_1.3 A.4_1.4 A.4_1.5 A.4_1.6 A.4_1.7 A.4_1.8 A.4_2.1_1 A.4_2.1_2 A.4_2.1_3 A.4_2.2_1 A.4_2.2_2 A.4_2.2_3 A.5_1 A.5_2 A.5_3 A.5_4 A.5_5 A.5_6 A.5_7 A.5_8 A.5_9 A.5_10 A.5_11 A.5_12 A.6_1 A.6_2 A.6_3 A.6_4 A.6_5 A.6_6 A.6_7 A.6_8 A.6_9 A.6_10 A.6_11 A.6_12 A.6_13 A.6_14 A.6_15 A.6_16 A.6_17 A.6_18 A.6_19 A.6_20 A.6_21 A.6_22 A.6_23 A.7 A.8_1 A.8_2 A.8_3 A.8_4 A.8_5 B.1_1 B.1_2 B.1_3 B.1_4 B.1_5 B.2_1 B.2_2 B.2_3 B.3_1 B.3_2 B.3_3 B.3_4 B.3_5 B.3_6 B.3_7 B.3_8 C.1 C.3 C.4 C.5_1 C.5_2 1 1 7 6 -2 5 4 5 1 5 4 3 5 5 1 -2 -2 1 -2 2 -2 -2 -2 -1 -1 -1 -1 -1 -1 2 2 1 2 2 2 2 2 2 2 1 1 5 4 4 5 4 5 5 6 5 3 6 5 4 4 5 4 4 5 -2 4 5 6 5 3 5 6 6 3 7 3 4 6 -1 -1 2 1 2 6 5 4 5 1 4 4 6 1 1 4 1 -1 1 1 7 4 -2 6 3 4 7 3 5 2 5 3 1 2 1 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 1 1 1 1 2 2 2 2 2 2 1 5 6 4 4 -2 4 4 5 4 -2 3 6 4 -2 7 -2 3 7 5 3 7 5 3 3 6 2 5 1 4 1 4 6 7 8 1 1 1 7 7 7 7 1 4 4 1 1 1 4 1 2 1 1 5 4 3 4 4 5 6 5 5 4 4 4 2 -1 -1 -1 -1 -1 -1 -1 -1 1 -2 -2 1 -2 -2 2 2 1 1 1 1 1 1 2 1 1 2 5 6 4 5 2 5 4 5 4 -2 4 5 4 3 6 4 5 5 -2 4 6 4 5 2 4 4 4 5 5 1 -1 -1 -1 -1 5 4 5 6 1 1 3 4 4 3 4 1 1 4 1 -1 2 1 4 4 2 5 2 5 6 5 4 6 -2 -2 1 -2 -2 x -2 -2 -2 -2 -2 -1 -1 -1 -1 -1 -1 1 1 2 1 2 2 2 1 2
Re: [R] For loop and using its index
On Fri, Mar 09, 2012 at 01:24:00PM +0330, Hassan Eini Zinab wrote: Dear All, I have a data set with variables x1, x2, x3, ..., x20 and I want to create z1, z2, z3, ..., z20 with the following formula: z1 = 200 - x1 z2 = 200 - x2 z3 = 200 - x3 . . . z20 = 200 - x20. I tried using a for loop and its index as: for (i in 1:20) { z(i) = 200 - x(i) } Hi. Try this. x - 21:40 z - 200 - x x[1] # [1] 21 x[2] # [1] 22 z[1] # [1] 179 z[2] # [1] 178 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I force confint() for glm() to be quiet?
On 2012-03-09 15:30, David Winsemius wrote: On Mar 9, 2012, at 6:14 AM, Hans Ekbrand wrote: I need confint() for glm() to supress the messages I'm wondering if suppressMessages would be helpful? Which in turn suggests that you do not know how to use ??, so firt you should get in the habit of doing a helpSearch before posting. ??suppress messages OK, noted. Waiting for profiling to be done... because they mess up the caching mechanism of pgfSweave (see https://github.com/cameronbracken/pgfSweave/issues/40). I have read the help page of confint(), but I do not know how to get the help page for the glm() version, if any such help page exists. When I type ?confint.glm at my console I get this help page: Ah, I tried ?confint.lm without success and didn't go further. If suppressMessages is not effective then look at: ?sink OK, but since suppressMessages works, I'll stick to that. G. A _minimal_ example would have had fewer iterations, Sorry. but this does seem to be effective: suppressMessages(my.results - confint(my.fit)) 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] Simulating n 2x2 tables with the same odds ratio
Hello. I'm looking for a method to simulate n different 2x2 tables having all the same odds ratio. For example. I need 100 tables with odds ratio 1 100 tables with odds ratio 2 100 tables with odds ratio 3 and so on. All tables should have the same marginal frequencies. Thank you -- View this message in context: http://r.789695.n4.nabble.com/Simulating-n-2x2-tables-with-the-same-odds-ratio-tp4459457p4459457.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] Re : Moving average with loess
Thanks Pascal, The good new is the code works, but it doesn't produce the result that I expected, or at least it doesn't match what matlab does. I did a bit of search myself and came across the following post on stackoverflow http://stackoverflow.com/questions/7746529/smoothing-with-lowess Which I cannot decipher it. Do you have any suggestion? On 3/9/12 1:42 AM, Pascal Oettli kri...@ymail.com wrote: Hi Robert, You can try ?lowess Regards, Pascal - Mail original - De : Faryabi, Robert (NIH/NCI) [F] babak.fary...@nih.gov À : r-help@r-project.org r-help@r-project.org Cc : Envoyé le : Vendredi 9 mars 2012 8h43 Objet : [R] Moving average with loess Hello All, I just have a very simple question. I recently switching from Matlab to R, so cannot figure out some of the easy tasks in the new environment. Is there any weighted local regression smoothing in R? Basically, I want to have weighted moving average. All the functions that I know of need two variables for fitting. Best, Robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulating n 2x2 tables with the same odds ratio
On Fri, Mar 09, 2012 at 05:37:42AM -0800, hubinho wrote: Hello. I'm looking for a method to simulate n different 2x2 tables having all the same odds ratio. For example. I need 100 tables with odds ratio 1 100 tables with odds ratio 2 100 tables with odds ratio 3 and so on. All tables should have the same marginal frequencies. Hi. Marginal frequencies together with the odds ratio determine the matrix uniquely. So, some of the requirements should be relaxed. If we start with a matrix (a, b) (c, d) then all matrices with the same marginal frequencies have the form (a + t, b - t) (c - t, d + t) The odds ratio is (a+t)(d+t)/(c-t)/(b-t) which is a strictly increasing function of t and so the equation (a+t)(d+t)/(c-t)/(b-y) = odds for a given odds has a unique solution t. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] extracting the i-th row of a matrix in a list of lists
Hi, what is the proper of of passing a missing value so I can extract the entire i-th row of a matrix (in a list of lists) without pre-computing the number of cols? For example, if I know that the matrices have 2 columns, I can do the following: set.seed(1) x0 - lapply(1:10, function(i) replicate(4, list(matrix(rnorm(10), nc=2 lapply(lapply(x0, '[[', 3), '[', i=2, j=1:2) (given that if I don't specify j, I only get the first element) but if the number of columns are variable: x1 - lapply(1:10, function(i) replicate(4, list(matrix(rnorm(100), nc=sample(c(2, 4, 5, 10), 1) what would be the value of J below? lapply(lapply(x1, '[[', 3), '[', i=2, j=J) or should I really stick with: lapply(lapply(x1, '[[', 3), function(x) x[2,]) ? Thank you very much, benilton __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Time series and logs.
Folks, This is more of a stat question than an R question. Apologies in advance! Suppose I fit an AR(1) to a time-series and also fit an AR(1) to the logs of the same time-series and then simulate future paths. In my case I see a big difference in the resulting paths. If I simulate thousands of paths under each scenario (exponentiating the results from the log-fit) and take the mean path for each I see a divergence. The average path from log-fit is increasing relative to the average path of the base fit. My guess is that there is a simple computation that would allow me to compare the two analytically but I just haven't been able to find it. Thanks for your time, KW -- [[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] rtags for VI(M)
Dear Federico, I am using the r-plugin provided for VIM on unix. This has an option of building tag files. http://www.vim.org/scripts/script.php?script_id=2628 I 've just tried the command, and albeit some error messages showed up, a tag file for the current dir was build. Not sure how the capabilities of this part of the plugin are and how useful it might be for you, but I think it is worth it to give it a shot. Hope that helps!? Cheers, STefan On Fri, 2012-03-09 at 11:33 +, Federico Calboli wrote: Hi, according to the help file rtags does not support VI(M) yet. Is there any known hack to ctags to get tags for R in VI(M)? BW F -- Federico C. F. Calboli Neuroepidemiology and Ageing Research Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] 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. [[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] join 2 .sav
Dear R-users, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Copy dataframe for another
On Mar 9, 2012, at 5:31 AM, RMSOPS wrote: Hello, the idea is to copy the d for df, with new results. x-data.frame(name=x1,pos=4,age=20) x-rbind(x,data.frame(name=x2,pos=5,age=20)) x-rbind(x,data.frame(name=x3,pos=6,age=21)) x-rbind(x,data.frame(name=x4,pos=7,age=24)) x-rbind(x,data.frame(name=x5,pos=8,age=27)) x-rbind(x,data.frame(name=x6,pos=9,age=26)) x - data.frame(name=paste(x, 1:6, sep=), pos=3+1:6 age=c(20,20, 21,24,27,26) View(x) d-NULL df-NULL for(r in 2: nrow(x)) { val_user-x$name[[r]] pos-x$pos[[r]] -4 age -x$age[[r]] d-data.frame(val_user,pos,age) print(d) } df-rbind(df,d) View(df) It is generally better to spend more time describing the problem. Attempting to read the mind of new R users who come from other programming paradigms is often unrewarding. -- David. in df only have the last result, the ideia is have the new results calculated in the for loop thanks -- View this message in context: http://r.789695.n4.nabble.com/Copy-dataframe-for-another-tp4456893p4459068.html Sent from the R help mailing list archive at Nabble.com. PLEASE: Include context. We are NOT reading this on Nabble. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] layer plots.
Hello. I have 2 plots. plot1 -plot(table1) plot2 -plot(table2) How may i plot these both on the same graph, i.e. layer one graph on top of the other one. The result should look similar to this the image below, where the black lines indicate one plot, and the red dots indicate the second plot. http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png Aaral. -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.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] reading HDF5 or H5 files
I would like to read hdf5 or h5 files in R . I found two packages hdf5 and h5r , but in both packages they have information how to get attribute from data. In my case I would like see what kind of parameters are saved in every file. I have tried h5 - hdf5load(GOSATTFTS20090601_02C02SV0002R101202000F0.h5, load = TRUE, verbosity = 0, tidy = FALSE) ls() # list available data ls() [1] Data Gcan Globalaet ancillary [6] driverevalStats gpp h5h5t [11] i nam nee obs r.1 [16] r.2 r.3 r.4 r.5 r.6 [21] scanAttribute swc1 swc2 t ter [26] x y z but these are major classes and I would like see the names of attributes which are stored in this major groups? how to deal with these major parameters ? -- View this message in context: http://r.789695.n4.nabble.com/reading-HDF5-or-H5-files-tp4459803p4459803.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] Create a list object in a loop
Dear all, I'm trying to create a list of point patterns ppp.object {spatstat} in a loop. My dataset looks like this: names(OT1);head(OT1);dim(OT1) [1] EID latitude longitude month year CPUE TSUM [8] fTSUM EID latitude longitude month year CPUE TSUM fTSUM 1 167-1-1996-1135 67.7 -61.81667 9 199600 F 2 167-10-1996-1135 67.71667 -59.18333 9 199600 F 3 167-100-1996-1135 67.86667 -59.410 199600 F 4 167-101-1996-1135 67.95000 -59.5833310 199600 F 5 167-102-1996-1135 68.1 -59.7666710 199600 F 6 167-103-1996-1135 67.81667 -59.3833310 199600 F [1] 27078 What I would like to do is to select data for each of my month and create a ppp.object. sort(unique(OT1$month)) [1] 7 8 9 10 11 12 The following loop works and I can see each of my figures: for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b,main=i) } How can I access each of my ppp.objects? I've tried adding a list() in the loop command such that I can access the data but without any success... Any help would be much appreciated! Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Copy dataframe for another
On Mar 9, 2012, at 10:41 AM, David Winsemius wrote: On Mar 9, 2012, at 5:31 AM, RMSOPS wrote: Hello, the idea is to copy the d for df, with new results. x-data.frame(name=x1,pos=4,age=20) x-rbind(x,data.frame(name=x2,pos=5,age=20)) x-rbind(x,data.frame(name=x3,pos=6,age=21)) x-rbind(x,data.frame(name=x4,pos=7,age=24)) x-rbind(x,data.frame(name=x5,pos=8,age=27)) x-rbind(x,data.frame(name=x6,pos=9,age=26)) x - data.frame(name=paste(x, 1:6, sep=), pos=3+1:6, age=c(20,20, 21,24,27,26)) Added the missing comma and paren: Is this what you were attempting? df - x df$pos[2:nrow(df)] - df$pos[2:nrow(df)]-4 names(df) - c(val_user, pos, age) df val_user pos age 1 x1 4 20 2 x2 1 20 3 x3 2 21 4 x4 3 24 5 x5 4 27 6 x6 5 26 View(x) d-NULL df-NULL for(r in 2: nrow(x)) { val_user-x$name[[r]] pos-x$pos[[r]] -4 age -x$age[[r]] d-data.frame(val_user,pos,age) print(d) } df-rbind(df,d) View(df) It is generally better to spend more time describing the problem. Attempting to read the mind of new R users who come from other programming paradigms is often unrewarding. -- David. in df only have the last result, the ideia is have the new results calculated in the for loop thanks -- View this message in context: http://r.789695.n4.nabble.com/Copy-dataframe-for-another-tp4456893p4459068.html Sent from the R help mailing list archive at Nabble.com. PLEASE: Include context. We are NOT reading this on Nabble. -- 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] layer plots.
No idea what table1, table2 are plot(1:5, type = l) points(5:1, col = 2) should get you started. Michael On Fri, Mar 9, 2012 at 10:17 AM, aaral singh aaral.si...@gmail.com wrote: Hello. I have 2 plots. plot1 -plot(table1) plot2 -plot(table2) How may i plot these both on the same graph, i.e. layer one graph on top of the other one. The result should look similar to this the image below, where the black lines indicate one plot, and the red dots indicate the second plot. http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png Aaral. -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Create a list object in a loop
Hi Aurelie, Please give this a look: http://www.nealgroothuis.name/introduction-to-data-types-and-objects-in-r/ And see if this resolves most, or all, of your questions... Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Mar 9, 2012 at 5:48 PM, Aurelie Cosandey Godin god...@dal.cawrote: Dear all, I'm trying to create a list of point patterns ppp.object {spatstat} in a loop. My dataset looks like this: names(OT1);head(OT1);dim(OT1) [1] EID latitude longitude month year CPUE TSUM [8] fTSUM EID latitude longitude month year CPUE TSUM fTSUM 1 167-1-1996-1135 67.7 -61.81667 9 199600 F 2 167-10-1996-1135 67.71667 -59.18333 9 199600 F 3 167-100-1996-1135 67.86667 -59.410 199600 F 4 167-101-1996-1135 67.95000 -59.5833310 199600 F 5 167-102-1996-1135 68.1 -59.7666710 199600 F 6 167-103-1996-1135 67.81667 -59.3833310 199600 F [1] 27078 What I would like to do is to select data for each of my month and create a ppp.object. sort(unique(OT1$month)) [1] 7 8 9 10 11 12 The following loop works and I can see each of my figures: for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b,main=i) } How can I access each of my ppp.objects? I've tried adding a list() in the loop command such that I can access the data but without any success... Any help would be much appreciated! Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Create a list object in a loop
You are overriding b at each loop iteration and consequently only keeping the last one. Perhaps b - list() for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b[[i]]-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b[[i]],main=i) } Generally it's bad practice to have a dynamically growing object in R but I think the performance penalty for lists isn't too bad. (Not verified, I just think I saw that somewhere) What might be even better: months - sort(unique(OT1$month)) b - vector(list, length(months)) names(b) - months for(i in months){ a-OT1[OT1$month==i,] b[[i]]-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b[[i]],main=i) } Michael On Fri, Mar 9, 2012 at 10:48 AM, Aurelie Cosandey Godin god...@dal.ca wrote: Dear all, I'm trying to create a list of point patterns ppp.object {spatstat} in a loop. My dataset looks like this: names(OT1);head(OT1);dim(OT1) [1] EID latitude longitude month year CPUE TSUM [8] fTSUM EID latitude longitude month year CPUE TSUM fTSUM 1 167-1-1996-1135 67.7 -61.81667 9 1996 0 0 F 2 167-10-1996-1135 67.71667 -59.18333 9 1996 0 0 F 3 167-100-1996-1135 67.86667 -59.4 10 1996 0 0 F 4 167-101-1996-1135 67.95000 -59.58333 10 1996 0 0 F 5 167-102-1996-1135 68.1 -59.76667 10 1996 0 0 F 6 167-103-1996-1135 67.81667 -59.38333 10 1996 0 0 F [1] 2707 8 What I would like to do is to select data for each of my month and create a ppp.object. sort(unique(OT1$month)) [1] 7 8 9 10 11 12 The following loop works and I can see each of my figures: for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b,main=i) } How can I access each of my ppp.objects? I've tried adding a list() in the loop command such that I can access the data but without any success... Any help would be much appreciated! Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] layer plots.
Many thanks for reply. I have trouble understanding how to use response, i am sorry. My question is i have two matrices. I then plot two matrices. Then I have 2 seperate plots. I can color the nodes in the plots in two different colors. Then, how do i merge the two plots to view one overlapping the other? i.e. to view two sets of data in one 2D space? Many thanks On Fri, Mar 9, 2012 at 3:51 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: No idea what table1, table2 are plot(1:5, type = l) points(5:1, col = 2) should get you started. Michael On Fri, Mar 9, 2012 at 10:17 AM, aaral singh aaral.si...@gmail.com wrote: Hello. I have 2 plots. plot1 -plot(table1) plot2 -plot(table2) How may i plot these both on the same graph, i.e. layer one graph on top of the other one. The result should look similar to this the image below, where the black lines indicate one plot, and the red dots indicate the second plot. http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png Aaral. -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Create a list object in a loop
Thank you Tal, useful link. Best, Aurelie On 2012-03-09, at 11:53 AM, Tal Galili wrote: Hi Aurelie, Please give this a look: http://www.nealgroothuis.name/introduction-to-data-types-and-objects-in-r/ And see if this resolves most, or all, of your questions... Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Mar 9, 2012 at 5:48 PM, Aurelie Cosandey Godin god...@dal.ca wrote: Dear all, I'm trying to create a list of point patterns ppp.object {spatstat} in a loop. My dataset looks like this: names(OT1);head(OT1);dim(OT1) [1] EID latitude longitude month year CPUE TSUM [8] fTSUM EID latitude longitude month year CPUE TSUM fTSUM 1 167-1-1996-1135 67.7 -61.81667 9 199600 F 2 167-10-1996-1135 67.71667 -59.18333 9 199600 F 3 167-100-1996-1135 67.86667 -59.410 199600 F 4 167-101-1996-1135 67.95000 -59.5833310 199600 F 5 167-102-1996-1135 68.1 -59.7666710 199600 F 6 167-103-1996-1135 67.81667 -59.3833310 199600 F [1] 27078 What I would like to do is to select data for each of my month and create a ppp.object. sort(unique(OT1$month)) [1] 7 8 9 10 11 12 The following loop works and I can see each of my figures: for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b,main=i) } How can I access each of my ppp.objects? I've tried adding a list() in the loop command such that I can access the data but without any success... Any help would be much appreciated! Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Create a list object in a loop
Thank you very much Michael! Best, Aurelie On 2012-03-09, at 11:56 AM, R. Michael Weylandt wrote: You are overriding b at each loop iteration and consequently only keeping the last one. Perhaps b - list() for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b[[i]]-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b[[i]],main=i) } Generally it's bad practice to have a dynamically growing object in R but I think the performance penalty for lists isn't too bad. (Not verified, I just think I saw that somewhere) What might be even better: months - sort(unique(OT1$month)) b - vector(list, length(months)) names(b) - months for(i in months){ a-OT1[OT1$month==i,] b[[i]]-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b[[i]],main=i) } Michael On Fri, Mar 9, 2012 at 10:48 AM, Aurelie Cosandey Godin god...@dal.ca wrote: Dear all, I'm trying to create a list of point patterns ppp.object {spatstat} in a loop. My dataset looks like this: names(OT1);head(OT1);dim(OT1) [1] EID latitude longitude month year CPUE TSUM [8] fTSUM EID latitude longitude month year CPUE TSUM fTSUM 1 167-1-1996-1135 67.7 -61.81667 9 199600 F 2 167-10-1996-1135 67.71667 -59.18333 9 199600 F 3 167-100-1996-1135 67.86667 -59.410 199600 F 4 167-101-1996-1135 67.95000 -59.5833310 199600 F 5 167-102-1996-1135 68.1 -59.7666710 199600 F 6 167-103-1996-1135 67.81667 -59.3833310 199600 F [1] 27078 What I would like to do is to select data for each of my month and create a ppp.object. sort(unique(OT1$month)) [1] 7 8 9 10 11 12 The following loop works and I can see each of my figures: for(i in sort(unique(OT1$month))){ a-OT1[OT1$month==i,] b-ppp(a$longitude,a$latitude,marks=a$fTSUM,window=newW) plot(b,main=i) } How can I access each of my ppp.objects? I've tried adding a list() in the loop command such that I can access the data but without any success... Any help would be much appreciated! Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help please. 2 tables, which test?
The chi-squared test is one option (and seems reasonable to me if it the the proportions/patterns that you want to test). One way to do the test is to combine your 2 matrices into a 3 dimensional array (the abind package may help here) and test using the loglin function. On Thu, Mar 8, 2012 at 5:46 AM, aaral singh aaral.si...@gmail.com wrote: Hi.Please help if someone can. Problem: I have 2 matrices Eg matrix 1: Freq None Some Heavy 3 2 5 Never 8 13 8 Occas 1 4 4 Regul 9 5 7 matrix 2: Freq None Some Heavy 7 1 3 Never 87 18 84 Occas 12 3 4 Regul 9 1 7 I want to see if matrix 1 is significantly different from matrix 2. I consider using a chi-squared test. Is this appropriate? Could anyone advise? Many thank you. Aaral Singh -- View this message in context: http://r.789695.n4.nabble.com/help-please-2-tables-which-test-tp4456312p4456312.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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] xyplot without external box
Why do you want to do this? Lattice was not really designed to put just part of the graph up, but rather to create the entire graph using one command. If you want to show a process, putting up part of a graph at a time, it may be better to create the whole graph as a vector graphics file (pdf, postscript, svg, pgf, emf, etc.) then use an external program to remove those parts that you don't want for a given step. On Thu, Mar 8, 2012 at 6:02 AM, Mauricio Zambrano-Bigiarini hzambran.newsgro...@gmail.com wrote: Dear list members, Within a loop, I need to create an xyplot with only a legend, not even with the default external box drawn by lattice. I already managed to remove the axis labels and tick marks, but I couldn't find in the documentation of xyplot how to remove the external box. I would really appreciate any help with this - START --- library(lattice) x-1:100 cuts - unique( quantile( as.numeric(x), probs=c(0, 0.25, 0.5, 0.75, 0.9, 0.95, 1), na.rm=TRUE) ) gof.levels - cut(x, cuts) nlevels - length(levels(gof.levels)) xyplot(1~1, groups=gof.levels, type=n, xlab=, ylab=, scales=list(draw=FALSE), key = list(x = .5, y = .5, corner = c(0.5, 0.5), title=legend, points = list(pch=16, col=c(2,4,3), cex=1.5), text = list(levels(gof.levels)) ) ) - END --- Thanks in advance, Mauricio Zambrano-Bigiarini -- FLOODS Action Water Resources Unit (H01) Institute for Environment and Sustainability (IES) European Commission, Joint Research Centre (JRC) webinfo : http://floods.jrc.ec.europa.eu/ DISCLAIMER: The views expressed are purely those of the writer and may not in any circumstances be regarded as stating an official position of the European Commission. Linux user #454569 -- Ubuntu user #17469 There is only one pretty child in the world, and every mother has it. (Chinese Proverb) http://c2.com/cgi/wiki?HowToAskQuestionsTheSmartWay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] help please. 2 tables, which test?
Thank you. Can the chi-squared test compare two matrices that are not the same size, eg if matrix 1 is a 2 X 4 table, and matrix 2 is a 3 X 5 matrix? On Fri, Mar 9, 2012 at 4:37 PM, Greg Snow 538...@gmail.com wrote: The chi-squared test is one option (and seems reasonable to me if it the the proportions/patterns that you want to test). One way to do the test is to combine your 2 matrices into a 3 dimensional array (the abind package may help here) and test using the loglin function. On Thu, Mar 8, 2012 at 5:46 AM, aaral singh aaral.si...@gmail.com wrote: Hi.Please help if someone can. Problem: I have 2 matrices Eg matrix 1: Freq None Some Heavy32 5 Never8 13 8 Occas14 4 Regul 95 7 matrix 2: Freq None Some Heavy7 1 3 Never 87 18 84 Occas 12 34 Regul917 I want to see if matrix 1 is significantly different from matrix 2. I consider using a chi-squared test. Is this appropriate? Could anyone advise? Many thank you. Aaral Singh -- View this message in context: http://r.789695.n4.nabble.com/help-please-2-tables-which-test-tp4456312p4456312.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. -- Gregory (Greg) L. Snow Ph.D. 538...@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. [[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 sort frequency distribution table?
R tends to see the ordering of factor levels as a property of the data rather than a property of the table/graph. So it is generally best to modify the data object (factor) to represent what you want rather than look for an option in the table/plot function (this will also be more efficient in the long run). Here is a simple example using the reorder function: tmp - factor(sample( letters[1:5], 100, TRUE )) table(tmp) tmp a b c d e 20 20 19 18 23 tmp2 - reorder(tmp, rep(1,length(tmp)), sum) table(tmp2) tmp2 d c a b e 18 19 20 20 23 tmp2 - reorder(tmp, rep(-1,length(tmp)), sum) table(tmp2) tmp2 e a b c d 23 20 20 19 18 On Wed, Mar 7, 2012 at 9:46 PM, Manish Gupta mandecent.gu...@gmail.com wrote: Hi, I am working on categorical data with column as disease name(categaory). My input data is [1] Acute lymphoblastic leukemia (childhood) [2] Adiponectin levels [3] Adiponectin levels [4] Adiponectin levels [5] Adiponectin levels [6] Adiponectin levels [7] Adiposity [8] Adiposity [9] Adiposity [10] Adiposity [11] Age-related macular degeneration [12] Age-related macular degeneration [13] Aging (time to death) [14] Aging (time to event) [15] Aging (time to event) [16] Aging (time to event) [17] Aging (time to event) [18] AIDS [19] AIDS [20] AIDS . when i use table command, i get [,1] Acute lymphoblastic leukemia (childhood) 1 Adiponectin levels 5 Adiposity 4 Age-related macular degeneration 2 Aging (time to death) 1 .. But i need to sort this table by frequency and need to plot a histogram with lable first column (e.g. Adiposity , Age-related macular degeneration as bar name). How can i do it? Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-sort-frequency-distribution-table-tp4455595p4455595.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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] xyplot without external box
On Mar 8, 2012, at 8:02 AM, Mauricio Zambrano-Bigiarini wrote: Dear list members, Within a loop, I need to create an xyplot with only a legend, not even with the default external box drawn by lattice. I already managed to remove the axis labels and tick marks, but I couldn't find in the documentation of xyplot how to remove the external box. I found it by searching rhelp at the Newcastle site: From: Jerome Asselin Date: Fri 25 Jul 2003 - 07:54:15 EST trellis.par.set(axis.line,list(col=NA,lty=1,lwd=1)) You can restore the earlier behavior with: trellis.par.set(axis.line,list(col=black,lty=1,lwd=1)) -- David I would really appreciate any help with this - START --- library(lattice) x-1:100 cuts - unique( quantile( as.numeric(x), probs=c(0, 0.25, 0.5, 0.75, 0.9, 0.95, 1), na.rm=TRUE) ) gof.levels - cut(x, cuts) nlevels - length(levels(gof.levels)) xyplot(1~1, groups=gof.levels, type=n, xlab=, ylab=, scales=list(draw=FALSE), key = list(x = .5, y = .5, corner = c(0.5, 0.5), title=legend, points = list(pch=16, col=c(2,4,3), cex=1.5), text = list(levels(gof.levels)) ) ) - END --- 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] xyplot without external box
On Mar 9, 2012, at 12:10 PM, David Winsemius wrote: On Mar 8, 2012, at 8:02 AM, Mauricio Zambrano-Bigiarini wrote: Dear list members, Within a loop, I need to create an xyplot with only a legend, not even with the default external box drawn by lattice. I already managed to remove the axis labels and tick marks, but I couldn't find in the documentation of xyplot how to remove the external box. I found it by searching rhelp at the Newcastle site: From: Jerome Asselin Date: Fri 25 Jul 2003 - 07:54:15 EST trellis.par.set(axis.line,list(col=NA,lty=1,lwd=1)) You can restore the earlier behavior with: trellis.par.set(axis.line,list(col=black,lty=1,lwd=1)) And this is what Sarkar demonstraates in the help page for wireframe: wirfrm ## transparent axes wirfrm wirfrm par.set - wirfrm+ list(axis.line = list(col = transparent), wirfrm+ clip = list(panel = off)) wirfrm print(cloud(Sepal.Length ~ Petal.Length * Petal.Width, wirfrm+ data = iris, cex = .8, wirfrm+ groups = Species, wirfrm+ main = Stereo, wirfrm+ screen = list(z = 20, x = -70, y = 3), wirfrm+ par.settings = par.set, wirfrm+ scales = list(col = black)), wirfrm+ split = c(1,1,2,1), more = TRUE) -- David I would really appreciate any help with this - START --- library(lattice) x-1:100 cuts - unique( quantile( as.numeric(x), probs=c(0, 0.25, 0.5, 0.75, 0.9, 0.95, 1), na.rm=TRUE) ) gof.levels - cut(x, cuts) nlevels - length(levels(gof.levels)) xyplot(1~1, groups=gof.levels, type=n, xlab=, ylab=, scales=list(draw=FALSE), key = list(x = .5, y = .5, corner = c(0.5, 0.5), title=legend, points = list(pch=16, col=c(2,4,3), cex=1.5), text = list(levels(gof.levels)) ) ) - END --- 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. 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] help please. 2 tables, which test?
You should probably read up on what the chi-squared test actually tests: in one form, it asks whether some set of observations could have come from a given multinomial distribution. Concretely, it asks whether it is reasonable to get 3 blues, 4 reds, and 2 whites from a uniform distribution over read white and blue. (Real statisticians will have all sorts of problems with that over-simplification) What you seem to be asking is whether it is reasonable to get 3 blues 4 reds, 2 whites, and 6 greens from a uniform distribution over red white and blue -- obviously something doesn't fit here. Caveat: if matrix1 matches matrix2 but there were null observations that got dropped, then this can be done. https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test The website http://stats.stackexchange.com/ can (and will) provide more statistically oriented help. Michael On Fri, Mar 9, 2012 at 11:46 AM, aoife doherty aaral.si...@gmail.com wrote: Thank you. Can the chi-squared test compare two matrices that are not the same size, eg if matrix 1 is a 2 X 4 table, and matrix 2 is a 3 X 5 matrix? On Fri, Mar 9, 2012 at 4:37 PM, Greg Snow 538...@gmail.com wrote: The chi-squared test is one option (and seems reasonable to me if it the the proportions/patterns that you want to test). One way to do the test is to combine your 2 matrices into a 3 dimensional array (the abind package may help here) and test using the loglin function. On Thu, Mar 8, 2012 at 5:46 AM, aaral singh aaral.si...@gmail.com wrote: Hi.Please help if someone can. Problem: I have 2 matrices Eg matrix 1: Freq None Some Heavy 3 2 5 Never 8 13 8 Occas 1 4 4 Regul 9 5 7 matrix 2: Freq None Some Heavy 7 1 3 Never 87 18 84 Occas 12 3 4 Regul 9 1 7 I want to see if matrix 1 is significantly different from matrix 2. I consider using a chi-squared test. Is this appropriate? Could anyone advise? Many thank you. Aaral Singh -- View this message in context: http://r.789695.n4.nabble.com/help-please-2-tables-which-test-tp4456312p4456312.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. -- Gregory (Greg) L. Snow Ph.D. 538...@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. [[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] layer plots.
Do your matrices match up with each other in any meaningful way or do you just want two independent plots on a single page? You should probably provide the dput() output of each table object so we can see what you've got. Michael On Fri, Mar 9, 2012 at 11:07 AM, aoife doherty aaral.si...@gmail.com wrote: Many thanks for reply. I have trouble understanding how to use response, i am sorry. My question is i have two matrices. I then plot two matrices. Then I have 2 seperate plots. I can color the nodes in the plots in two different colors. Then, how do i merge the two plots to view one overlapping the other? i.e. to view two sets of data in one 2D space? Many thanks On Fri, Mar 9, 2012 at 3:51 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: No idea what table1, table2 are plot(1:5, type = l) points(5:1, col = 2) should get you started. Michael On Fri, Mar 9, 2012 at 10:17 AM, aaral singh aaral.si...@gmail.com wrote: Hello. I have 2 plots. plot1 -plot(table1) plot2 -plot(table2) How may i plot these both on the same graph, i.e. layer one graph on top of the other one. The result should look similar to this the image below, where the black lines indicate one plot, and the red dots indicate the second plot. http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png Aaral. -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help please. 2 tables, which test?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of aoife doherty Thank you. Can the chi-squared test compare two matrices that are not the same size, eg if matrix 1 is a 2 X 4 table, and matrix 2 is a 3 X 5 matrix? No. S*** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] what does rlm do if it fails to converge within iteration limits?
Hi all, In using rlm I've got a bunch of warnings... failed to converge in 20 steps, etc. My question is: what are the results then after the failure? Will rlm automatically downgrade back to lm upon failure? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Removing Values from Summary after Survival Curve
Hi All, s = Surv(outcome.[,1], outcome.[,2]) survplot= (survfit(s ~ person.list[,1])) summary(survplot) This prints a summary of all the curves at specified time intervals of events. Is there a way to suppress this summary to only display a summary of the values above a certain time point? (i.e summary(survplot, ONLY survplot$time 3) ) Thanks, M -- View this message in context: http://r.789695.n4.nabble.com/Removing-Values-from-Summary-after-Survival-Curve-tp4459816p4459816.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] layer plots.
The response much appreciated. They do match up, one is a small subset of the other. I have this: dput(table1) structure(list(var1 = c(2L, 4L, 4L, 1L, 423L), var2 = c(3L, 5L, 6L, 342L, 3L)), .Names = c(var1, var2), class = data.frame, row.names = c(node1, node2, node3, node4, node5)) dput(list1) structure(list(node = c(node1, node2)), .Names = node) so one table is a 2 X 5 matrix (called table1) and one table is 1 X 2 table (called list1). i then type this: plot1 -plot(table,suprow=c(list1$node),passive) to give me a plot of list1 and this: plot2 -plot(table,suprow=c(list1$node),active) to give me a plot of table1 i want to combine plot 1 and 2. BUT i know i can do this: plot2 -plot(table,suprow=c(list1$node),all) to plot both on the same graph, but in my actual dataset, the points in list1 are obscured from sight by table1, because in reality table 1 may contain 20,000 points and list1 may contain 10 points, so i cannot see where my 10 specific nodes of interest are on the graph. So i want to plot the graph so that any nodes in list1 are seen on top of the plot of table 1. On Fri, Mar 9, 2012 at 5:36 PM, Michael Weylandt [via R] ml-node+s789695n4460118...@n4.nabble.com wrote: Do your matrices match up with each other in any meaningful way or do you just want two independent plots on a single page? You should probably provide the dput() output of each table object so we can see what you've got. Michael On Fri, Mar 9, 2012 at 11:07 AM, aoife doherty [hidden email]http://user/SendEmail.jtp?type=nodenode=4460118i=0 wrote: Many thanks for reply. I have trouble understanding how to use response, i am sorry. My question is i have two matrices. I then plot two matrices. Then I have 2 seperate plots. I can color the nodes in the plots in two different colors. Then, how do i merge the two plots to view one overlapping the other? i.e. to view two sets of data in one 2D space? Many thanks On Fri, Mar 9, 2012 at 3:51 PM, R. Michael Weylandt [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=1 wrote: No idea what table1, table2 are plot(1:5, type = l) points(5:1, col = 2) should get you started. Michael On Fri, Mar 9, 2012 at 10:17 AM, aaral singh [hidden email]http://user/SendEmail.jtp?type=nodenode=4460118i=2 wrote: Hello. I have 2 plots. plot1 -plot(table1) plot2 -plot(table2) How may i plot these both on the same graph, i.e. layer one graph on top of the other one. The result should look similar to this the image below, where the black lines indicate one plot, and the red dots indicate the second plot. http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png Aaral. -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=3mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=4mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=5mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4460118.html To unsubscribe from layer plots., click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4459732code=YWFyYWwuc2luZ2hAZ21haWwuY29tfDQ0NTk3MzJ8LTE5NjQxNjQyNTM= . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4460207.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list
Re: [R] For loop and using its index
Hassan, Others have provided you with better solutions, but I hope this allows you to see why yours didn't work. # first (going with your code) you needed a data.frame called x # here is an example: x - structure(list(x1 = c(0.0986048226696643, -0.445652024980979, 0.0893989676314604, -3.02656448303247, -0.966125836458264, -1.49916656636977, -1.43173455089552, 0.370528111260298, -1.16980816517156, -0.808744946153693 ), x2 = c(-0.765406771195136, -0.37933377428095, 1.38846324586498, -1.70043724374807, -0.71331175577977, 1.44597103991061, 1.31674350467787, -0.954578441470943, -1.30637013925954, 0.551870274117374), x3 = c(-0.122350075070145, 1.6217818199546, -0.824570718637696, -0.0341988842898353, 1.03924814479596, 0.898533448980663, 0.68074228601446, 0.296251937506574, -0.698501590358135, -0.0533564535030227)), .Names = c(x1, x2, x3), row.names = c(NA, -10L), class = data.frame) # you then need an empty vector to hold the results of your for loop (called z here) # note the square brackets as opposed to your parentheses z - vector(list) for (i in 1:ncol(x)) { z[i] = 200 - x[i] } # finally, this will reassemble the output of the for loop z - do.call(cbind, z) colnames(z) - c(z1, z2, z3) # Finally, do read what the others sent you as they provide more efficient solutions HTH Chuck Hassan Eini Zinab wrote Dear All, I have a data set with variables x1, x2, x3, ..., x20 and I want to create z1, z2, z3, ..., z20 with the following formula: z1 = 200 - x1 z2 = 200 - x2 z3 = 200 - x3 . . . z20 = 200 - x20. I tried using a for loop and its index as: for (i in 1:20) { z(i) = 200 - x(i) } But R gives the following error message: Error: could not find function x. Is there any other way for a simple coding of my 20 lines of code? Alohas, Hassan Eini-Zinab __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/For-loop-and-using-its-index-tp4459454p4460277.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] socket connection in while(TRUE) loop the best way?
I'm accessing R via a socket connection. I set up a connection using socketConnection and then use readLines inside of a while(TRUE) loop to listen for activity. Is that the best way of doing this sort of activity? It works, that's not the issue, I am just wondering if there's a better way. Thanks [[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] extracting the i-th row of a matrix in a list of lists
Benilton Carvalho beniltoncarva...@gmail.com writes: Hi, what is the proper of of passing a missing value so I can extract the entire i-th row of a matrix (in a list of lists) without pre-computing the number of cols? For example, if I know that the matrices have 2 columns, I can do the following: set.seed(1) x0 - lapply(1:10, function(i) replicate(4, list(matrix(rnorm(10), nc=2 lapply(lapply(x0, '[[', 3), '[', i=2, j=1:2) (given that if I don't specify j, I only get the first element) but if the number of columns are variable: x1 - lapply(1:10, function(i) replicate(4, list(matrix(rnorm(100), nc=sample(c(2, 4, 5, 10), 1) what would be the value of J below? lapply(lapply(x1, '[[', 3), '[', i=2, j=J) I think you want 'j=TRUE'. Note: all.equal( lapply(lapply(x0, '[[', 3), '[', i=2,j=TRUE), lapply(lapply(x0, '[[', 3), '[', i=2, j=1:2) ) HTH, Chuck or should I really stick with: lapply(lapply(x1, '[[', 3), function(x) x[2,]) ? Thank you very much, benilton -- Charles C. BerryDept of Family/Preventive Medicine cberry at 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] what does rlm do if it fails to converge within iteration limits?
On 09-03-2012, at 20:00, Michael wrote: Hi all, In using rlm I've got a bunch of warnings... failed to converge in 20 steps, etc. My question is: what are the results then after the failure? They haven't converged. So inaccurate. Maybe your model is badly formulated or ill conditioned. Will rlm automatically downgrade back to lm upon failure? Help says nothing about that so most likely no. Why don't you try and raise maxit? Use maxit=40 in the call of rlm. And see what happens. Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rgl: cylinder3d() with elliptical cross-section
For a paper dealing with generalized ellipsoids, I want to illustrate in 3D an ellipsoid that is unbounded in one dimension, having the shape of an infinite cylinder along, say, z, but whose cross-section in (x,y) is an ellipse, say, given by the 2x2 matrix cov(x,y). I've looked at rgl:::cylinder3d, but don't see any way to make it accomplish this. Does anyone have any ideas? thx, -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] No announcement of version 2.14.2
Thanks, we will try to get it updated soon. Uwe On 08.03.2012 09:40, Caitlin wrote: Hi all. I just noticed that the release of version 2.14.2 was not announced on the R home page. Thanks, ~Caitlin [[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] hierarchical clustering of large dataset
I think the main issue of the OP is that he geneartes a 55000x55000 distance matrix and has to calculate on it. Beside immense main memory consumption this may take ages to complete with hierarchical clustering. Uwe Ligges On 08.03.2012 15:02, Sarah Goslee wrote: See inline: On Thu, Mar 8, 2012 at 7:41 AM, Massimo Di Stefano massimodisa...@gmail.com wrote: Hello All, i've a set of observations that is in the form : a,b,c,d,e,f 67.12,4.28,1.7825,30,3,16001 67.12,4.28,1.7825,30,3,16001 66.57,4.28,1.355,30,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 63.64,9.726,1.3004,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 … …. 55.000 observation in total. where : a,b,c,d,e are environmental parameters and f is a label. as you can see some rows are duplicated, this means that the observation occurred more times If you use dput() for the first 10 or 20 rows of your data, then you will have provided the requested reproducible example. (in my use cases the observation is the presence of a specific biological specie in a photo, if in the photo there are more than one individual of the same species i have a duplicated row ) i'm trying to learn how to use R in order to build a dendrogram that will help me to 'group' several species in communities, based on the similarity of the env. parameters. i tried with d- diet(as.matrix(my data)) hc- hclust(d) but it doesn't works. I'm assuming you mean dist() instead of diet() ? I don't know of any function named diet(). What doesn't work? We can't answer your question unless we know what it is. is the 'redundancy' of my data (multiple rows with same information) a problem? should i remove all the rows that are exactly the same ? Yes. Identical rows have a distance of 0, so they're clustered together immediately, so a dendrogram that includes them is identical to one that has only unique rows. in this way how to take care about the fact that for the same environmental parameters i've multiple observation ? maybe this information is not relevant in order to build the dendrogram ? Please, can you suggest me a valid approach in order to cluster a such dataset ? forgive me, i've an evident lack of statistic knowledge, thank you very mach for you help! Perhaps some reading in one of the many excellent ecologically-based multivariate statistics books is called for? Sarah __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Where do I report CRAN mirror problems?
Seems to be fine for me. Uwe Ligges On 07.03.2012 03:24, Robert King wrote: Where should I report mirror problems? There doesn't seem to be anywhere on http://cran.r-project.org/mirrors.html listing contact emails for mirror admins. There is some problem with the debian binaries on http://cran.ms.unimelb.edu.au output from my apt-get update says: W: Failed to fetch http://cran.ms.unimelb.edu.au/bin/linux/debian/squeeze-cran/Packages.gz Hash Sum mismatch [[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] qbeta function in R
HI All: Does anyone know the code behind the qbeta function in R? I am using it to calculate exact confidence intervals and I am getting 'NaN' at places I shouldnt be. Heres the simple code I am using: k-3 x-NULL p-rbeta(k,3,3)# so that the mean nausea rate is alpha/(alpha+beta) min-10 max-60 n-as.integer(runif(3,min,max)) for(i in 1:k) + x-cbind(x,rbinom(5,n[i],p[i])) # Exact Confidence Interval l_cl_exact-qbeta(.025, x, n-x+1) Warning message: In qbeta(p, shape1, shape2, lower.tail, log.p) : NaNs produced u_cl_exact-qbeta(.975, x+1, n-x) Warning message: In qbeta(p, shape1, shape2, lower.tail, log.p) : NaNs produced x [,1] [,2] [,3] [1,]8 12 14 [2,]5 15 13 [3,]5 12 12 [4,]8 21 12 [5,]8 14 12 n [1] 10 36 31 l_cl_exact [,1] [,2] [,3] [1,] 0.44390454 0.2184996 0.2314244 [2,] 0.04667766 NaN 0.2454760 [3,] 0.05452433 0.1855618 NaN [4,] 0.44390454 0.4862702 0.1855618 [5,] 0.10115053 NaN 0.2184996 Thanks for your help. Anamika [[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] qbeta function in R
On Mar 9, 2012, at 2:48 PM, Anamika Chaudhuri wrote: HI All: Does anyone know the code behind the qbeta function in R? Well, yes, but don't you think it would be wise to question whether your code might be the problem rather than the R code? I am using it to calculate exact confidence intervals and I am getting 'NaN' at places I shouldnt be. Heres the simple code I am using: k-3 x-NULL p-rbeta(k,3,3)# so that the mean nausea rate is alpha/(alpha+beta) min-10 max-60 n-as.integer(runif(3,min,max)) for(i in 1:k) + x-cbind(x,rbinom(5,n[i],p[i])) Isn't this going to make x get longer with each pass through the loop? I think your parameter are then going to be interpreted as values of x. Looks like user error to me. -- David # Exact Confidence Interval l_cl_exact-qbeta(.025, x, n-x+1) Warning message: In qbeta(p, shape1, shape2, lower.tail, log.p) : NaNs produced u_cl_exact-qbeta(.975, x+1, n-x) Warning message: In qbeta(p, shape1, shape2, lower.tail, log.p) : NaNs produced x [,1] [,2] [,3] [1,]8 12 14 [2,]5 15 13 [3,]5 12 12 [4,]8 21 12 [5,]8 14 12 n [1] 10 36 31 l_cl_exact [,1] [,2] [,3] [1,] 0.44390454 0.2184996 0.2314244 [2,] 0.04667766 NaN 0.2454760 [3,] 0.05452433 0.1855618 NaN [4,] 0.44390454 0.4862702 0.1855618 [5,] 0.10115053 NaN 0.2184996 Thanks for your help. Anamika [[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. 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] qbeta function in R
Take a look at n-x+1, the second parameter to the beta distribution: n - c(10, 45, 38) x - rbind(c( 7, 45, 31), +c(10, 40, 35), +c( 9, 44, 33), +c( 8, 44, 31), +c( 8, 45, 36)) n - x + 1 [,1] [,2] [,3] [1,]4 -6 15 [2,] 36 -294 [3,] 302 -22 [4,]3 -5 15 [5,] 38 -343 You probably intended sweep(1-x, MAR=2, n, `+`) [,1] [,2] [,3] [1,]418 [2,]164 [3,]226 [4,]328 [5,]313 If you had been unlucky, none of the entries in n-x+1 would have been negative and you would have received no warning from qbeta to give a hint that n-x+1 was not working as expected. 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 Anamika Chaudhuri Sent: Friday, March 09, 2012 11:48 AM To: r-help@r-project.org Subject: [R] qbeta function in R HI All: Does anyone know the code behind the qbeta function in R? I am using it to calculate exact confidence intervals and I am getting 'NaN' at places I shouldnt be. Heres the simple code I am using: k-3 x-NULL p-rbeta(k,3,3)# so that the mean nausea rate is alpha/(alpha+beta) min-10 max-60 n-as.integer(runif(3,min,max)) for(i in 1:k) + x-cbind(x,rbinom(5,n[i],p[i])) # Exact Confidence Interval l_cl_exact-qbeta(.025, x, n-x+1) Warning message: In qbeta(p, shape1, shape2, lower.tail, log.p) : NaNs produced u_cl_exact-qbeta(.975, x+1, n-x) Warning message: In qbeta(p, shape1, shape2, lower.tail, log.p) : NaNs produced x [,1] [,2] [,3] [1,]8 12 14 [2,]5 15 13 [3,]5 12 12 [4,]8 21 12 [5,]8 14 12 n [1] 10 36 31 l_cl_exact [,1] [,2] [,3] [1,] 0.44390454 0.2184996 0.2314244 [2,] 0.04667766 NaN 0.2454760 [3,] 0.05452433 0.1855618 NaN [4,] 0.44390454 0.4862702 0.1855618 [5,] 0.10115053 NaN 0.2184996 Thanks for your help. Anamika [[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] index instead of loop?
Here is my latest. I kind of changed the problem (for speed). In real life I have over 300 uadata type matrices, each having over 20 rows and over 11,000 columns. However the rddata file is valid for all of the uadata matrices that I have (300). What I am doing now: I'm creating a matrix of row indices which will either lag the row values or not based on the report data (rddata). Then I apply that matrix of row indices to each uadata data item (300 times) to create a matrix of the correctly row adjusted data items for the correct columns of the dimensions and periodicity that I want (weekly in this case). The key being, I only do the 'adjustment' once (which is comparatively slow) and I apply those results to the data matrix (fast!). I'm open to ideas. I put this together quickly so hopefully all is well. #sample data zdates = c(2007-03-31,2007-06-30,2007-09-30,2007-12-31,2008-03-31,2008-06-30,2008-09-30,2008-12-31) nms = c(A,B,C,D) # these are the report dates that are the real days the data was available rddata = matrix(c(20070514,20070814,20071115,20080213,20080514,20080814,20081114,20090217, 20070410,20070709,20071009,20080109,20080407,20080708,20081007,20090112, 20070426,--,--,--,--,--,--,20090319, --,--,--,--,--,--,--,--), nrow=8,ncol=4) dimnames(rddata) = list(zdates,nms) # this is the unadjusted raw data, that always has the same dimensions, rownames, and colnames as the report dates uadata = matrix(c(640.35,636.16,655.91,657.41,682.06,702.90,736.15,667.65, 2625.050,2625.050,2645.000,2302.000,1972.000,1805.000,1547.000,1025.000, NaN, NaN,-98.426,190.304,180.894,183.220,172.520, 144.138, NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN), nrow=8,ncol=4) dimnames(uadata) = list(zdates,nms) I do this once fix = function(x) { year = substring(x, 1, 4) mo = substring(x, 5, 6) day = substring(x, 7, 8) ifelse(year==--, --, paste(year, mo, day, sep = -)) } rd = apply(rddata, 2, fix) dimnames(rd) = dimnames(rd) wd1 - seq(from =as.Date(min(zdates)), to = Sys.Date(), by = day) wd1 = wd1[weekdays(wd1) == Friday] # uncomment to go weekly wd = sapply(wd1, as.character) mat = matrix(NA,nrow=length(wd),ncol=ncol(uadata)) rownames(mat) = wd nms = as.Date(rownames(uadata)) for(i in 1:length(wd)){ d = as.Date(wd[i]) diff = abs(nms - d) rd_row_idx = max(which(diff == min(diff))) rd_row_idx_lag = rd_row_idx - 1 rd_row_idx_lag2 = rd_row_idx - 2 rd_col_idx = which(as.Date(rd[rd_row_idx,], format=%Y-%m-%d) d) rd_col_idx_lag = which(as.Date(rd[rd_row_idx_lag,], format=%Y-%m-%d) d) rd_col_idx_lag2 = which(as.Date(rd[rd_row_idx_lag2,], format=%Y-%m-%d) d) ## if(length(rd_col_idx_lag2) (rd_row_idx - 2) 0){ if(rd_row_idx_lag2 0){ # mat[i,rd_col_idx_lag2] = ua[rd_row_idx_lag2,rd_col_idx_lag2] mat[i,rd_col_idx_lag2] = rd_row_idx_lag2 } #if(length(rd_col_idx_lag)){ mat[i,rd_col_idx_lag] = rd_row_idx_lag #} #if( length(rd_col_idx)){ mat[i,rd_col_idx] = rd_row_idx #} } indx = mat vals = uadata ## I do this 300 times x = matrix(vals[cbind(c(indx),rep(1:ncol(indx),each=nrow(indx)))],nrow=nrow(indx),ncol=ncol(indx)) Regards, ben On Thu, Mar 8, 2012 at 11:40 AM, Rui Barradas rui1...@sapo.pt wrote: Hello, Humm If I understand what you are saying, you are correct. I get 144.138 for 2009-03-20 for column C. Maybe I posted the wrong code? If so, sorry. I think I have the fastest so far solution, and it checks with your corrected,last one. I've made just a change: to transform it into a function I renamed the parameters (only for use inside the function) 'zdates', without the period, 'rddata' and 'uadata'. 'fun1' is yours, 'fun2', mine. Here it goes. fun1 - function(zdates, rddata, uadata){ fix = function(x) { year = substring(x, 1, 4) mo = substring(x, 5, 6) day = substring(x, 7, 8) ifelse(year==--, --, paste(year, mo, day, sep = -)) } rd = apply(rddata, 2, fix) dimnames(rd) = dimnames(rd) wd1 - seq(from =as.Date(min(zdates)), to = Sys.Date(), by = day) #wd1 = wd1[weekdays(wd1) == Friday] # uncomment to go weekly wd = sapply(wd1, as.character) mat = matrix(NA,nrow=length(wd),ncol=ncol(uadata)) rownames(mat) = wd nms = as.Date(rownames(uadata)) for(i in 1:length(wd)){ d = as.Date(wd[i]) diff = abs(nms - d) rd_row_idx = max(which(diff == min(diff))) rd_col_idx = which(as.Date(rd[rd_row_idx,], format=%Y-%m-%d) d) rd_col_idx_lag = which(as.Date(rd[rd_row_idx - 1,], format=%Y-%m-%d) d) rd_col_idx_lag2 = which(as.Date(rd[rd_row_idx - 2,], format=%Y-%m-%d) d) if(length(rd_col_idx_lag2) (rd_row_idx - 2) 0){ mat[i,rd_col_idx_lag2] = uadata[rd_row_idx - 2,rd_col_idx_lag2] } if(length(rd_col_idx_lag)){ mat[i,rd_col_idx_lag] =
Re: [R] hierarchical clustering of large dataset
2012/3/9 Uwe Ligges lig...@statistik.tu-dortmund.de: I think the main issue of the OP is that he geneartes a 55000x55000 distance matrix and has to calculate on it. Beside immense main memory consumption this may take ages to complete with hierarchical clustering. Indeed. I missed that in the original email. If a non-hierarchical clustering is acceptable, clara() from the cluster package may be of use. Sarah Uwe Ligges On 08.03.2012 15:02, Sarah Goslee wrote: See inline: On Thu, Mar 8, 2012 at 7:41 AM, Massimo Di Stefano massimodisa...@gmail.com wrote: Hello All, i've a set of observations that is in the form : a, b, c, d, e, f 67.12, 4.28, 1.7825, 30, 3, 16001 67.12, 4.28, 1.7825, 30, 3, 16001 66.57, 4.28, 1.355, 30, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 63.64, 9.726, 1.3004, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 … …. 55.000 observation in total. where : a, b, c, d, e are environmental parameters and f is a label. as you can see some rows are duplicated, this means that the observation occurred more times If you use dput() for the first 10 or 20 rows of your data, then you will have provided the requested reproducible example. (in my use cases the observation is the presence of a specific biological specie in a photo, if in the photo there are more than one individual of the same species i have a duplicated row ) i'm trying to learn how to use R in order to build a dendrogram that will help me to 'group' several species in communities, based on the similarity of the env. parameters. i tried with d- diet(as.matrix(my data)) hc- hclust(d) but it doesn't works. I'm assuming you mean dist() instead of diet() ? I don't know of any function named diet(). What doesn't work? We can't answer your question unless we know what it is. is the 'redundancy' of my data (multiple rows with same information) a problem? should i remove all the rows that are exactly the same ? Yes. Identical rows have a distance of 0, so they're clustered together immediately, so a dendrogram that includes them is identical to one that has only unique rows. in this way how to take care about the fact that for the same environmental parameters i've multiple observation ? maybe this information is not relevant in order to build the dendrogram ? Please, can you suggest me a valid approach in order to cluster a such dataset ? forgive me, i've an evident lack of statistic knowledge, thank you very mach for you help! Perhaps some reading in one of the many excellent ecologically-based multivariate statistics books is called for? -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] hierarchical clustering of large dataset
On Thu, Mar 8, 2012 at 4:41 AM, Massimo Di Stefano massimodisa...@gmail.com wrote: Hello All, i've a set of observations that is in the form : a, b, c, d, e, f 67.12, 4.28, 1.7825, 30, 3, 16001 67.12, 4.28, 1.7825, 30, 3, 16001 66.57, 4.28, 1.355, 30, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 66.2, 4.28, 1.3459, 13, 3, 16001 63.64, 9.726, 1.3004, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 63.28, 9.725, 1.2755, 6, 3, 11012 … …. 55.000 observation in total. Hi Massimo, you don't want to use the entire matrix to calculate the distance. You will want to select the environmental columns and you may want to standardize them to prevent one of them having more influence than others. Second, if you want to cluster such a huge data set using hierarchical clustering, you need a lot of memory, at least 32GB but preferably 64GB. If you don't have that much, you cannot use hierarchical clustering. Third, if you do have enough memory, use package flashClust or fastcluster (I am the maintainer of flashClust.) For flashClust, you can install it using install.packages(flashClust) and load it using library(flashClust). The standard R implementation of hclust is unnecessarily slow (order n^3). flashClust provides a replacement (function hclust) that is approximately n^2. I have clustered data sets of 3 variables in a minute or two, so 55000 shouldn't take more than 4-5 minutes, again assuming your computer has enough memory. HTH, Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] layer plots.
It's hard to help if you keep changing the framework of your problem, first two matrices - now it's a data.frame and a list of subset row names in a plotting method from whatever package suprow comes from. Regardless, Michael's original answer already gave you a solution: plot(table1,type='l',lwd=2) points(table1[list1$node,],col=2,pch=19) The points are overlayed on the line plot, so they are not obscured if you have 20 or 20M values. On Fri, Mar 9, 2012 at 11:09 AM, aaral singh aaral.si...@gmail.com wrote: The response much appreciated. They do match up, one is a small subset of the other. I have this: dput(table1) structure(list(var1 = c(2L, 4L, 4L, 1L, 423L), var2 = c(3L, 5L, 6L, 342L, 3L)), .Names = c(var1, var2), class = data.frame, row.names = c(node1, node2, node3, node4, node5)) dput(list1) structure(list(node = c(node1, node2)), .Names = node) so one table is a 2 X 5 matrix (called table1) and one table is 1 X 2 table (called list1). i then type this: plot1 -plot(table,suprow=c(list1$node),passive) to give me a plot of list1 and this: plot2 -plot(table,suprow=c(list1$node),active) to give me a plot of table1 i want to combine plot 1 and 2. BUT i know i can do this: plot2 -plot(table,suprow=c(list1$node),all) to plot both on the same graph, but in my actual dataset, the points in list1 are obscured from sight by table1, because in reality table 1 may contain 20,000 points and list1 may contain 10 points, so i cannot see where my 10 specific nodes of interest are on the graph. So i want to plot the graph so that any nodes in list1 are seen on top of the plot of table 1. On Fri, Mar 9, 2012 at 5:36 PM, Michael Weylandt [via R] ml-node+s789695n4460118...@n4.nabble.com wrote: Do your matrices match up with each other in any meaningful way or do you just want two independent plots on a single page? You should probably provide the dput() output of each table object so we can see what you've got. Michael On Fri, Mar 9, 2012 at 11:07 AM, aoife doherty [hidden email]http://user/SendEmail.jtp?type=nodenode=4460118i=0 wrote: Many thanks for reply. I have trouble understanding how to use response, i am sorry. My question is i have two matrices. I then plot two matrices. Then I have 2 seperate plots. I can color the nodes in the plots in two different colors. Then, how do i merge the two plots to view one overlapping the other? i.e. to view two sets of data in one 2D space? Many thanks On Fri, Mar 9, 2012 at 3:51 PM, R. Michael Weylandt [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=1 wrote: No idea what table1, table2 are plot(1:5, type = l) points(5:1, col = 2) should get you started. Michael On Fri, Mar 9, 2012 at 10:17 AM, aaral singh [hidden email]http://user/SendEmail.jtp?type=nodenode=4460118i=2 wrote: Hello. I have 2 plots. plot1 -plot(table1) plot2 -plot(table2) How may i plot these both on the same graph, i.e. layer one graph on top of the other one. The result should look similar to this the image below, where the black lines indicate one plot, and the red dots indicate the second plot. http://r.789695.n4.nabble.com/file/n4459732/R_screen_shot.png Aaral. -- View this message in context: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4459732.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=3mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=4mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4460118i=5mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/layer-plots-tp4459732p4460118.html To unsubscribe from layer plots., click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4459732code=YWFyYWwuc2luZ2hAZ21haWwuY29tfDQ0NTk3MzJ8LTE5NjQxNjQyNTM= .
Re: [R] Siegel-Tukey test for equal variability (code)
#The code of rank 1 in the previous post should have read #rank1-apply(iterator1,1,function(x) x+base1) #corrected code below siegel.tukey=function(x,y,id.col=TRUE,adjust.median=F,rnd=-1,alternative=two.sided,mu=0,paired=FALSE,exact=FALSE,correct=TRUE,conf.int=FALSE,conf.level=0.95){ if(id.col==FALSE){ data=data.frame(c(x,y),rep(c(0,1),c(length(x),length(y } else { data=data.frame(x,y) } names(data)=c(x,y) data=data[order(data$x),] if(rnd-1){data$x=round(data$x,rnd)} if(adjust.median==T){ cat(\n,Adjusting medians...,\n,sep=) data$x[data$y==0]=data$x[data$y==0]-(median(data$x[data$y==0])) data$x[data$y==1]=data$x[data$y==1]-(median(data$x[data$y==1])) } cat(\n,Median of group 1 = ,median(data$x[data$y==0]),\n,sep=) cat(Median of group 2 = ,median(data$x[data$y==1]),\n,\n,sep=) cat(Testing median differences...,\n) print(wilcox.test(data$x[data$y==0],data$x[data$y==1])) cat(Performing Siegel-Tukey rank transformation...,\n,\n) sort.x-sort(data$x) sort.id-data$y[order(data$x)] data.matrix-data.frame(sort.x,sort.id) base1-c(1,4) iterator1-matrix(seq(from=1,to=length(x),by=4))-1 rank1-apply(iterator1,1,function(x) x+base1) iterator2-matrix(seq(from=2,to=length(x),by=4)) base2-c(0,1) rank2-apply(iterator2,1,function(x) x+base2) #print(rank1) #print(rank2) if(length(rank1)==length(rank2)){ rank-c(rank1[1:floor(length(x)/2)],rev(rank2[1:ceiling(length(x)/2)])) } else{ rank-c(rank1[1:ceiling(length(x)/2)],rev(rank2[1:floor(length(x)/2)])) } unique.ranks-tapply(rank,sort.x,mean) unique.x-as.numeric(as.character(names(unique.ranks))) rank.matrix-data.frame(unique.x,unique.ranks) ST.matrix-merge(data.matrix,rank.matrix,by.x=sort.x,by.y=unique.x) print(ST.matrix) cat(\n,Performing Siegel-Tukey test...,\n,sep=) ranks0-ST.matrix$unique.ranks[ST.matrix$sort.id==0] ranks1-ST.matrix$unique.ranks[ST.matrix$sort.id==1] cat(\n,Mean rank of group 0: ,mean(ranks0),\n,sep=) cat(Mean rank of group 1: ,mean(ranks1),\n,sep=) print(wilcox.test(ranks0,ranks1,alternative=alternative,mu=mu,paired=paired,exact=exact,correct=correct,conf.int=conf.int,conf.level=conf.level)) } Examples: x - c(33, 62, 84, 85, 88, 93, 97, 4, 16, 48, 51, 66, 98) id - c(0,0,0,0,0,0,0,1,1,1,1,1,1) siegel.tukey(x,id,adjust.median=F,exact=T) x-c(0,0,1,4,4,5,5,6,6,9,10,10) id-c(0,0,0,1,1,1,1,1,1,0,0,0) siegel.tukey(x,id) x - c(85,106,96, 105, 104, 108, 86) id-c(0,0,1,1,1,1,1) siegel.tukey(x,id) x-c(177,200,227,230,232,268,272,297,47,105,126,142,158,172,197,220,225,230,262,270) id-c(rep(0,8),rep(1,12)) siegel.tukey(x,id,adjust.median=T) -- View this message in context: http://r.789695.n4.nabble.com/Siegel-Tukey-test-for-equal-variability-code-tp1565053p4460705.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] extracting the i-th row of a matrix in a list of lists
Hi Chuck, thank you *very* much! That really helped! b On 9 March 2012 17:15, cbe...@tajo.ucsd.edu wrote: Benilton Carvalho beniltoncarva...@gmail.com writes: Hi, what is the proper of of passing a missing value so I can extract the entire i-th row of a matrix (in a list of lists) without pre-computing the number of cols? For example, if I know that the matrices have 2 columns, I can do the following: set.seed(1) x0 - lapply(1:10, function(i) replicate(4, list(matrix(rnorm(10), nc=2 lapply(lapply(x0, '[[', 3), '[', i=2, j=1:2) (given that if I don't specify j, I only get the first element) but if the number of columns are variable: x1 - lapply(1:10, function(i) replicate(4, list(matrix(rnorm(100), nc=sample(c(2, 4, 5, 10), 1) what would be the value of J below? lapply(lapply(x1, '[[', 3), '[', i=2, j=J) I think you want 'j=TRUE'. Note: all.equal( lapply(lapply(x0, '[[', 3), '[', i=2,j=TRUE), lapply(lapply(x0, '[[', 3), '[', i=2, j=1:2) ) HTH, Chuck or should I really stick with: lapply(lapply(x1, '[[', 3), function(x) x[2,]) ? Thank you very much, benilton -- Charles C. Berry Dept of Family/Preventive Medicine cberry at 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] round giving different results on Windows and Mac
Dear all, I have been running some tests of my package RSiena on different platforms and trying to reconcile the results. With Mac, the commands options(digits=4) round(1.81652, digits=4) print 1.817 With Windows, the same commands print 1.816 I am not bothered which answer I get, but it would be nice if they were the same. A linux box agreed with the Mac. Mac sessionInfo(): R version 2.14.2 (2012-02-29) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RSiena_1.0.12.205 loaded via a namespace (and not attached): [1] grid_2.14.2lattice_0.20-0 Matrix_1.0-4 tools_2.14.2 Windows (but 2.14.1patched was the same) sessionInfo(): R version 2.15.0 alpha (2012-03-08 r58640) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base Any enlightenment would be gratefully received. Ruth -- Ruth M. Ripley, Email:r...@stats.ox.ac.uk Dept. of Statistics,http://www.stats.ox.ac.uk/~ruth/ University of Oxford, Tel: 01865 282857 1 South Parks Road, Oxford OX1 3TG, UK Fax: 01865 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.
[R] nonparametric densities for bounded distributions
Can anyone recommend a good nonparametric density approach for data bounded (say between 0 and 1)? For example, using the basic Gaussian density approach doesn't generate a very realistic shape (nor should it): set.seed(1) dat - rbeta(100, 1, 2) plot(density(dat)) (note the area outside of 0/1) The data I have may be bimodal or have other odd properties (e.g. point mass at zero). I've tried transforming via the logit, estimating the density then plotting the curve in the original units, but this seems to do poorly in the tails (and I have data are absolute zero and one). Thanks, Max [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] hierarchical clustering of large dataset
Peter, really thanks for your answer. install.packages(flashClust) library(flashClust) data - read.csv('/Users/epifanio/Desktop/cluster/x.txt') data - na.omit(data) data - scale(data) mydata a bc d e 1 -0.207709346 -6.618558e-01 0.481413046 0.7761133 0.96473124 2 -0.207709346 -6.618558e-01 0.481413046 0.7761133 0.96473124 3 -0.256330843 -6.618558e-01 -0.352285877 0.7761133 0.96473124 4 -0.289039851 -6.618558e-01 -0.370032451 -0.2838308 0.96473124 my target is to group my observation by 'speciesID' the speciesID is the last column : 'e' Before to go ahead, i should understand how to tell R that the he has to generate the groups using the column 'e' as variable, so to have the groups by speciesID. using this instruction : d - dist(data) clust - hclust(d) is not clear to me how R will understand to use the column 'e' as label. Sarah said : Yes. Identical rows have a distance of 0, so they're clustered together immediately, so a dendrogram that includes them is identical to one that has only unique rows. in this way i will lose a lot informations! seems relevant for me that a species is found 4 times instead of 1 with a specific combination of environmental parameters. no? Maybe a way to Try to decrease the size of my dataset can be : convert my multiple rows to abundance values, i means : if a species occurs four times with exactly the same environmental parameters i'll add a column for abundance and fill in a 4. and then remove three rows ? in this way i can decrease the size of my dataset (in rows) but i'll add a column. make sense ? Thanks a lot for your help (and patience), Massimo. Il giorno Mar 9, 2012, alle ore 3:54 PM, Peter Langfelder ha scritto: On Thu, Mar 8, 2012 at 4:41 AM, Massimo Di Stefano massimodisa...@gmail.com wrote: Hello All, i've a set of observations that is in the form : a,b,c,d,e,f 67.12,4.28,1.7825,30,3,16001 67.12,4.28,1.7825,30,3,16001 66.57,4.28,1.355,30,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 66.2,4.28,1.3459,13,3,16001 63.64,9.726,1.3004,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 63.28,9.725,1.2755,6,3,11012 … …. 55.000 observation in total. Hi Massimo, you don't want to use the entire matrix to calculate the distance. You will want to select the environmental columns and you may want to standardize them to prevent one of them having more influence than others. Second, if you want to cluster such a huge data set using hierarchical clustering, you need a lot of memory, at least 32GB but preferably 64GB. If you don't have that much, you cannot use hierarchical clustering. Third, if you do have enough memory, use package flashClust or fastcluster (I am the maintainer of flashClust.) For flashClust, you can install it using install.packages(flashClust) and load it using library(flashClust). The standard R implementation of hclust is unnecessarily slow (order n^3). flashClust provides a replacement (function hclust) that is approximately n^2. I have clustered data sets of 3 variables in a minute or two, so 55000 shouldn't take more than 4-5 minutes, again assuming your computer has enough memory. HTH, Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Siegel-Tukey test for equal variability (code)
With coordination with the code's author (Daniel), The updated code has been uploaded to github here: https://github.com/talgalili/R-code-snippets/blob/master/siegel.tukey.r And also the following post was updated with the code: http://www.r-statistics.com/2010/02/siegel-tukey-a-non-parametric-test-for-equality-in-variability-r-code/ I suspect that the code still needs some tweaks so it will be able to take care of two vectors of different lengths. Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Mar 9, 2012 at 11:11 PM, Daniel Malter dan...@umd.edu wrote: #The code of rank 1 in the previous post should have read #rank1-apply(iterator1,1,function(x) x+base1) #corrected code below siegel.tukey=function(x,y,id.col=TRUE,adjust.median=F,rnd=-1,alternative=two.sided,mu=0,paired=FALSE,exact=FALSE,correct=TRUE, conf.int=FALSE,conf.level=0.95){ if(id.col==FALSE){ data=data.frame(c(x,y),rep(c(0,1),c(length(x),length(y } else { data=data.frame(x,y) } names(data)=c(x,y) data=data[order(data$x),] if(rnd-1){data$x=round(data$x,rnd)} if(adjust.median==T){ cat(\n,Adjusting medians...,\n,sep=) data$x[data$y==0]=data$x[data$y==0]-(median(data$x[data$y==0])) data$x[data$y==1]=data$x[data$y==1]-(median(data$x[data$y==1])) } cat(\n,Median of group 1 = ,median(data$x[data$y==0]),\n,sep=) cat(Median of group 2 = ,median(data$x[data$y==1]),\n,\n,sep=) cat(Testing median differences...,\n) print(wilcox.test(data$x[data$y==0],data$x[data$y==1])) cat(Performing Siegel-Tukey rank transformation...,\n,\n) sort.x-sort(data$x) sort.id-data$y[order(data$x)] data.matrix-data.frame(sort.x,sort.id) base1-c(1,4) iterator1-matrix(seq(from=1,to=length(x),by=4))-1 rank1-apply(iterator1,1,function(x) x+base1) iterator2-matrix(seq(from=2,to=length(x),by=4)) base2-c(0,1) rank2-apply(iterator2,1,function(x) x+base2) #print(rank1) #print(rank2) if(length(rank1)==length(rank2)){ rank-c(rank1[1:floor(length(x)/2)],rev(rank2[1:ceiling(length(x)/2)])) } else{ rank-c(rank1[1:ceiling(length(x)/2)],rev(rank2[1:floor(length(x)/2)])) } unique.ranks-tapply(rank,sort.x,mean) unique.x-as.numeric(as.character(names(unique.ranks))) rank.matrix-data.frame(unique.x,unique.ranks) ST.matrix-merge(data.matrix,rank.matrix,by.x=sort.x,by.y=unique.x) print(ST.matrix) cat(\n,Performing Siegel-Tukey test...,\n,sep=) ranks0-ST.matrix$unique.ranks[ST.matrix$sort.id==0] ranks1-ST.matrix$unique.ranks[ST.matrix$sort.id==1] cat(\n,Mean rank of group 0: ,mean(ranks0),\n,sep=) cat(Mean rank of group 1: ,mean(ranks1),\n,sep=) print(wilcox.test(ranks0,ranks1,alternative=alternative,mu=mu,paired=paired,exact=exact,correct=correct, conf.int=conf.int,conf.level=conf.level)) } Examples: x - c(33, 62, 84, 85, 88, 93, 97, 4, 16, 48, 51, 66, 98) id - c(0,0,0,0,0,0,0,1,1,1,1,1,1) siegel.tukey(x,id,adjust.median=F,exact=T) x-c(0,0,1,4,4,5,5,6,6,9,10,10) id-c(0,0,0,1,1,1,1,1,1,0,0,0) siegel.tukey(x,id) x - c(85,106,96, 105, 104, 108, 86) id-c(0,0,1,1,1,1,1) siegel.tukey(x,id) x-c(177,200,227,230,232,268,272,297,47,105,126,142,158,172,197,220,225,230,262,270) id-c(rep(0,8),rep(1,12)) siegel.tukey(x,id,adjust.median=T) -- View this message in context: http://r.789695.n4.nabble.com/Siegel-Tukey-test-for-equal-variability-code-tp1565053p4460705.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.
[R] Interacting with the Operating System
Is there any way to issue operating system commands and geting back the results, in R? I mean, for instance, in Linux, to execute from R the 'ls' command and getting back a list of files in the current directory, or, equivalently, in Windows/DOS, the 'dir' command? I'm not interested in the 'ls' or 'dir' commands it is just an example. Do you have any comments on this matter? Thanks, --Sergio. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.