Re: [R] Automatic placement of Legends
Many thanks. Still, if anyone knows of an automated way of achieving this result, I would appreciate hearing about it. Tolga Boks, M.P.M. [EMAIL PROTECTED] 08/07/2008 20:45 To [EMAIL PROTECTED], r-help@r-project.org cc Subject RE: [R] Automatic placement of Legends You may want to look at locator(1) for manual placements; legend(locator(),...) BW Marco -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] namens [EMAIL PROTECTED] Verzonden: di 8-7-2008 20:31 Aan: r-help@r-project.org Onderwerp: [R] Automatic placement of Legends Dear R-Users, I am looking for a way to get legends placed automagically in an empty spot on a graph. Additional complication comes through my useage of multiple graphs on the same plot through mfrow. Is there a way to achieve this in R ? I have legends for each of the sub-plots. Many thanks in advance, Tolga Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[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. Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[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
Re: [R] cex.axis for the x axis
Hi Pavel, First, annonations should have the same cex-size on each axis. That said, the way that this is implemented is not too cexy (ouch!). You need to plot without axes, e.g. plot(obj, axes=F), then you add your axes afterwards using your own specifications. ?axes Also see ?par (sub ann) HTH, Mark. Pavel77 wrote: Hello, I would like to change the font size of the x axis annotations. cex.axis changes the y axis annotations only. Does anyone know how to change the x axis annotations? With thanks, Pavel. -- View this message in context: http://www.nabble.com/cex.axis-for-the-x-axis-tp18353453p18355827.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] cex.axis for the x axis
Hi Pavel, And perhaps read the entry for cex.axis a little more carefully. And bear in mind that labels, main, and sub are distinct, having their own cex.- settings. HTH, Mark. Mark Difford wrote: Hi Pavel, First, annonations should have the same cex-size on each axis. That said, the way that this is implemented is not too cexy (ouch!). You need to plot without axes, e.g. plot(obj, axes=F), then you add your axes afterwards using your own specifications. ?axes Also see ?par (sub ann) HTH, Mark. Pavel77 wrote: Hello, I would like to change the font size of the x axis annotations. cex.axis changes the y axis annotations only. Does anyone know how to change the x axis annotations? With thanks, Pavel. -- View this message in context: http://www.nabble.com/cex.axis-for-the-x-axis-tp18353453p18355914.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with installing add-on packages
Dear R users. Recently I wanted to update my R distribution to the current one (R-2.7.1). I am running a Fedora core 8 distirbution. The installation went fine, but when I tried to add some additional packages the majority made an exit with an error. Only a few least demanding (e.g. RColorBrewer) managed to get through the installation process. What happened between the versions 2.6.x and 2.7.x to impede the installation of add-on packages that previously went smooth? Thank you for your suggestions and best regards. Miha Example: install.packages(akima,repos=http://cran.r-project.org,depend=T) * Installing to library '/usr/lib/R/library' * Installing *source* package 'akima' ... ** libs gfortran -m32 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c akima433.f -o akima433.o In file akima433.f:49 IF(X(I-1)-X(I)) 11,95,96 1 Warning: Obsolete: arithmetic IF statement at (1) In file akima433.f:38 10 L0=L 1 Warning: Label 1 at (1) defined but not used In file akima433.f:56 20 IF(LM2.EQ.0) GO TO 27 1 Warning: Label 20 at (1) defined but not used In file akima433.f:63 22 IMX=I 1 Warning: Label 22 at (1) defined but not used In file akima433.f:79 40 J=I 1 Warning: Label 40 at (1) defined but not used In file akima433.f:166 99 ERR = 10 1 Warning: Label 99 at (1) defined but not used gfortran -m32 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c akima697.f -o akima697.o In file akima697.f:88 10 IF (ND.LE.1) GO TO 90 1 Warning: Label 10 at (1) defined but not used In file akima697.f:97 20 NP0=MAX(3,NP) 1 Warning: Label 20 at (1) defined but not used In file akima697.f:103 30 DO 39 II=1,NI 1 Warning: Label 30 at (1) defined but not used In file akima697.f:398 99 ERR=10 1 Warning: Label 99 at (1) defined but not used gfortran -m32 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c akima.new.f -o akima.new.o akima.new.f: In function ‘sdplnl’: akima.new.f:1904: warning: ‘zii1’ may be used uninitialized in this function akima.new.f:1903: warning: ‘y0’ may be used uninitialized in this function akima.new.f:1903: warning: ‘wt2’ may be used uninitialized in this function akima.new.f:1903: warning: ‘p50’ may be used uninitialized in this function akima.new.f:1903: warning: ‘p41’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p40’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p31’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p32’ may be used uninitialized in this function akima.new.f:1903: warning: ‘x0’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p22’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p21’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p23’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p13’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p14’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p12’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p20’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p10’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p04’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p02’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p03’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p05’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p11’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p30’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p00’ may be used uninitialized in this function akima.new.f:1900: warning: ‘cp’ may be used uninitialized in this function akima.new.f:1899: warning: ‘bp’ may be used uninitialized in this function akima.new.f:1898: warning: ‘ap’ may be used uninitialized in this
[R] building experimental paradigm with R as Brainard/Pelli Psych Toolbox
Hi R users, I would known if any attempt of building psychological experimental paradigm with R as Brainard/Pelli Psych Toolbox on Matlab or e-prime was done. [[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] building experimental paradigm with R as Brainard/Pelli PsychToolbox
guillaume chaumet guillaumechaumet at gmail.com writes: Hi R users, I would known if any attempt of building psychological experimental paradigm with R as Brainard/Pelli Psych Toolbox on Matlab or e-prime was done. As far as I know, the answer is no. I think that someone would have to write the equivalent of their SCREEN function for R. SCREEN is in C the last time I looked and compiled as a .mex so perhaps it would not be too difficult to modify it to be compiled into R. There are a few packages that are directed toward analysing psychophysical data (for example, my own psyphy and MLDS). Ken -- Ken Knoblauch Inserm U846 Institut Cellule Souche et Cerveau Département Neurosciences Intégratives 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replacing value in column of data frame
Dear all, Probably a very basic question but I need some help. I have a data frame (made by read.table from a text file) of microarray data, of which the first column is a factor and the rest of the columns are numeric. The factor column contains chromosome names, so values 1 through 22 plus X, Y and XY. The numeric columns contain positions or intensity measurements. What I need to do is change the X's in the first column to a value of 23. This is what I thought I would do: BAF_temp - read.table(BAF_all.txt, sep=\t, header=T) #to read in the table BAF_temp[,1][BAF_temp[,1]==X] - 23 #in rows where the first column of BAF_temp is X, change the first column of BAF_temp to 23 However with this last line I get an error: Invalid factor level, NAs generated in '[-.factor'('*tmp*', BAF_temp[,1]==X, value=23) (I tested if my syntax for selecting the rows of chromosome X was correct by trying BAF_X - BAF_temp[BAF_temp[,1]==X,] which worked to give me a data frame with only the rows of the X chromosome.) I then thought it might work better if I changed the data frame to a matrix. When I change the BAF_temp data frame into a matrix (by BAF_matrix - as.matrix(BAF_temp)), then the command I used above: BAF_temp[,1][BAF_temp[,1]==X] - 23 works fine and the end result is as I meant it to be, with all the X's changed into 23's. However, by using as.matrix all columns are changed to 'character' including the numeric measurements (I understand this is because one of the columns of the data frame is 'factor') I would like some help on what is the best option to solve this. I have thought of a few options myself and would like your comment/help: 1. Is there another syntax I can use on the data frame to change the X's to 23's, so I don't have to change the data frame into a matrix first? 2. I could change the data frame into a matrix and run the syntax as I described, resulting in all columns becoming 'character'; is there then an easy way to turn the columns with measurements (columns 2 and further) back into 'numeric' while leaving the first column with the chromosome numbers as 'character'? 3. I thought of using data.matrix(BAF_temp) and making use of the fact that the first column of factors would be changed to the underlying numbers (because X being the 23rd level in the list would automaticly be changed to 23). However because the levels (chromosome names) of the factor column are ordered as 1, 10, 11, 12,,19, 2, 20, 21, 3, 4, etc. (I see this when using str(BAF_temp)) , this results in chromosome 10 being changed into a value of 2, chromosome 11 into 3, chromosome 2 into 12 etc. For info: the chromosome names in the text file that is imported are ordered just 1, 2, 3, etc. If anyone has some tips for me I would greatly appreciate it. Best wishes, Marije De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de geadresseerde(n). Anderen dan de geadresseerde(n) mogen geen gebruik maken van dit bericht, het niet openbaar maken of op enige wijze verspreiden of vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een incomplete aankomst of vertraging van dit verzonden bericht. The contents of this message are confidential and only intended for the eyes of the addressee(s). Others than the addressee(s) are not allowed to use this message, to make it public or to distribute or multiply this message in any way. The UMCG cannot be held responsible for incomplete reception or delay of this transferred message. [[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] Expression in axis
Hello, I am creating a plot and I would like to know how to put this expression to the y axis µmol/10^6 cells I've tried some combinations using the expression() function, but none of them worked. Any idea? Best, Dani -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Centro de Investigación Biomédica en Red en Bioingeniería, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biomèdiques de la RMN Facultat de Biociències Universitat Autònoma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vallès- SPAIN +34 93 5814126 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replacing value in column of data frame
x=c(1:25) x[23]=X x x.new=ifelse(x==X,23,x) x.new=as.numeric(x.new) Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Booman, M Gesendet: Wednesday, July 09, 2008 5:14 AM An: r-help@r-project.org Betreff: [R] replacing value in column of data frame Dear all, Probably a very basic question but I need some help. I have a data frame (made by read.table from a text file) of microarray data, of which the first column is a factor and the rest of the columns are numeric. The factor column contains chromosome names, so values 1 through 22 plus X, Y and XY. The numeric columns contain positions or intensity measurements. What I need to do is change the X's in the first column to a value of 23. This is what I thought I would do: BAF_temp - read.table(BAF_all.txt, sep=\t, header=T) #to read in the table BAF_temp[,1][BAF_temp[,1]==X] - 23 #in rows where the first column of BAF_temp is X, change the first column of BAF_temp to 23 However with this last line I get an error: Invalid factor level, NAs generated in '[-.factor'('*tmp*', BAF_temp[,1]==X, value=23) (I tested if my syntax for selecting the rows of chromosome X was correct by trying BAF_X - BAF_temp[BAF_temp[,1]==X,] which worked to give me a data frame with only the rows of the X chromosome.) I then thought it might work better if I changed the data frame to a matrix. When I change the BAF_temp data frame into a matrix (by BAF_matrix - as.matrix(BAF_temp)), then the command I used above: BAF_temp[,1][BAF_temp[,1]==X] - 23 works fine and the end result is as I meant it to be, with all the X's changed into 23's. However, by using as.matrix all columns are changed to 'character' including the numeric measurements (I understand this is because one of the columns of the data frame is 'factor') I would like some help on what is the best option to solve this. I have thought of a few options myself and would like your comment/help: 1. Is there another syntax I can use on the data frame to change the X's to 23's, so I don't have to change the data frame into a matrix first? 2. I could change the data frame into a matrix and run the syntax as I described, resulting in all columns becoming 'character'; is there then an easy way to turn the columns with measurements (columns 2 and further) back into 'numeric' while leaving the first column with the chromosome numbers as 'character'? 3. I thought of using data.matrix(BAF_temp) and making use of the fact that the first column of factors would be changed to the underlying numbers (because X being the 23rd level in the list would automaticly be changed to 23). However because the levels (chromosome names) of the factor column are ordered as 1, 10, 11, 12,,19, 2, 20, 21, 3, 4, etc. (I see this when using str(BAF_temp)) , this results in chromosome 10 being changed into a value of 2, chromosome 11 into 3, chromosome 2 into 12 etc. For info: the chromosome names in the text file that is imported are ordered just 1, 2, 3, etc. If anyone has some tips for me I would greatly appreciate it. Best wishes, Marije De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de geadresseerde(n). Anderen dan de geadresseerde(n) mogen geen gebruik maken van dit bericht, het niet openbaar maken of op enige wijze verspreiden of vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een incomplete aankomst of vertraging van dit verzonden bericht. The contents of this message are confidential and only intended for the eyes of the addressee(s). Others than the addressee(s) are not allowed to use this message, to make it public or to distribute or multiply this message in any way. The UMCG cannot be held responsible for incomplete reception or delay of this transferred message. [[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] Expression in axis
x=rnorm(100,0,10) y=rnorm(100,0,10) plot(y~x,xlab=µmol/10^6) Is that it? Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Dani Valverde Gesendet: Wednesday, July 09, 2008 5:22 AM An: R Help Betreff: [R] Expression in axis Hello, I am creating a plot and I would like to know how to put this expression to the y axis µmol/10^6 cells I've tried some combinations using the expression() function, but none of them worked. Any idea? Best, Dani -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Centro de Investigación Biomédica en Red en Bioingeniería, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biomèdiques de la RMN Facultat de Biociències Universitat Autònoma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vallès- SPAIN +34 93 5814126 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Expression in axis
E.g. plot(1:10,1:10,xlab=NA) title(xlab=expression(mu*mol/10^6* cells)) Gabor On Wed, Jul 09, 2008 at 11:21:46AM +0200, Dani Valverde wrote: Hello, I am creating a plot and I would like to know how to put this expression to the y axis µmol/10^6 cells I've tried some combinations using the expression() function, but none of them worked. Any idea? Best, Dani -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Centro de Investigación Biomédica en Red en Bioingeniería, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biomèdiques de la RMN Facultat de Biociències Universitat Autònoma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vallès- SPAIN +34 93 5814126 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Csardi Gabor [EMAIL PROTECTED]UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Parsing
Dear R users, I have a big text file formatted like this: x x_string y y_string id1id1_string id2id2_string z z_string w w_string stuff stuff stuff stuff stuff stuff stuff stuff stuff // x x_string1 y y_string1 z z_string1 w w_string1 stuff stuff stuff stuff stuff stuff stuff stuff stuff // x x_string2 y y_string2 id1id1_string1 id2id2_string1 z z_string2 w w_string2 stuff stuff stuff stuff stuff stuff stuff stuff stuff // ... ... I'd like to parse this file and retrieve the x, y, id1, id2, z, w fields and save them into a a matrix object: xy id1 id2 z w x_string y_string id1_string id2_string z_string w_string x_string1 y_string1 NA NA z_string1 w_string1 x_string2 y_string2 id1_string1 id2_string1 z_string2 w_string2 ... ... id1, id2 fields are not always present within a section (the interval between x and the last stuff) and I'd like to insert a NA when they are absent (see above) so that length(x)==length(y)==length(id1)==... . Without the id1, id2 fields the task is easily solvable importing the text file with readLines and retrieving the single fields with grep: input = readLines(file.txt) x = grep(^x\\s, input, value = T) id1 = grep(^id1\\s, input, value = T) ... I'd like to accomplish this task entirely in R (no SQL, no perl script), possibly without using loops. Any suggestions are quite welcome! Regards, Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] non-sample standard-deviation
Hi, R seems to use the 1/n-1-factor calculating the standard-deviation sd(). If i wat to get the non-sample standard-deviation i use sqrt(sd(x)^2*((n-1)/n)) Is there a parameter to get the sd()-function using the 1/n factor directly? Or is there any other function to do so? Thank you in advance :-) Best, Eli __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Change in behaviour of sd()
On Tue, 2008-07-08 at 17:38 +1000, Fiona Johnson wrote: Hi I have just upgraded from R2.6.0 to R2.7.1 (running on Windows) and a part of my code that previously ran ok now gives an error. The following is a simple example to demonstrate my problem. a - array(c(1,2,3,4,5,6,rep(NA,6)),dim=c(6,2)) apply(a,2,sd,na.rm=T) In R2.6.0 this gives (which is what I would like) [1] 1.870829 NA In R2.7.1 it gives the following error Error in var(x, na.rm = na.rm) : no complete element pairs As my columns are always either all NA or all numbers, I could get around it by replacing the NA's with 0's but if someone could shed some light on why the behaviour has changed in the new version or a better work around it would be much appreciated. I want to keep the columns of NA's because ultimately I am plotting the results with contour and the NA's refer to grid cells not on land where I don't want to have contours. Hi Fiona, I get the same behavior on Linux. You can get around it like this: mysd-function(x,...) if(!all(is.na(x))) sd(x,...) apply(sd,2,mysd,) While I haven't looked at the changes for 2.7.1 on this, I think is it probably to avoid a problem with trying to calculate the covariance of a NULL object. If I remember, I'll test it tomorrow at work where I have access to Windows and email you again. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] recursively divide a value to get a sequence
Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] non-sample standard-deviation
I don't think so, but you can easily write a function for that: vec=c(1,2) pop.sd=function(x)(sqrt(var(x)*(length(x)-1)/length(x))) pop.sd(vec) ##as compared to sd(vec) Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von [EMAIL PROTECTED] Gesendet: Wednesday, July 09, 2008 5:35 AM An: R-help@r-project.org Betreff: [R] non-sample standard-deviation Hi, R seems to use the 1/n-1-factor calculating the standard-deviation sd(). If i wat to get the non-sample standard-deviation i use sqrt(sd(x)^2*((n-1)/n)) Is there a parameter to get the sd()-function using the 1/n factor directly? Or is there any other function to do so? Thank you in advance :-) Best, Eli __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Expression in axis
Sorry, you want it in the y-axis. So put ylab instead of xlab. Generally, type ?plot in the R-prompt and hit enter. Click the little par link in the middle of the page. There you see all the options (or at least very many) that you can pass to your plot command. Best, Da. Daniel Malter wrote: x=rnorm(100,0,10) y=rnorm(100,0,10) plot(y~x,xlab=µmol/10^6) Is that it? Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Dani Valverde Gesendet: Wednesday, July 09, 2008 5:22 AM An: R Help Betreff: [R] Expression in axis Hello, I am creating a plot and I would like to know how to put this expression to the y axis µmol/10^6 cells I've tried some combinations using the expression() function, but none of them worked. Any idea? Best, Dani -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Centro de Investigación Biomédica en Red en Bioingeniería, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biomèdiques de la RMN Facultat de Biociències Universitat Autònoma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vallès- SPAIN +34 93 5814126 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- View this message in context: http://www.nabble.com/Expression-in-axis-tp18357570p18357802.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] problems using mice()
R 2.7.2 PPC Mac OS X 10.4.11 library mice 1.13.1 I try to use mice for multivariate data imputation. My variables are numeric, factors, count data, ordered factors. First I created a vector for the methods to use with each variable ImpMethMice-c(rep(logreg, 62), rep(polyreg,1), rep(norm,12), rep(polyreg,12)) next step was Test-mice(df, im=ImpMethMice) I got the following error message: iter imp variable 1 1 variablenameFehler in impute.logreg(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, : Dimensionen [Produkt 119] passen nicht zur Länge des Objektes [122] Zusätzlich: Es gab 50 oder mehr Warnungen (Anzeige der ersten 50 mit warnings()) 1 1 variablenameError in impute.logreg(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, : dimensions [product 119] don`t match lenght of object [122] Additional: 50 or more warnings (show first 50 with warnings()) warnings() 1: In any(predictorMatrix[j, ]) ... : wandle Argument des Typs 'double' nach boolesch 1: In any(predictorMatrix[j, ]) ... : transform argument of type 'double' to boolesch I would be very happy if somebody could help me to fix this. Thanks in advance. B. - The art of living is more like wrestling than dancing. (Marcus Aurelius) -- View this message in context: http://www.nabble.com/problems-using-mice%28%29-tp18358093p18358093.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] recursively divide a value to get a sequence
your.number=15000 your.denominator=5 your.favorite.n=9 your.vector=NULL for(i in 0:your.favorite.n){ your.vector[i+1]=your.number/your.denominator^i your.vector[your.favorite.n+1]=0 } your.vector ##check Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Anne-Marie Ternes Gesendet: Wednesday, July 09, 2008 5:40 AM An: r-help@r-project.org Betreff: [R] recursively divide a value to get a sequence Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Automatic placement of Legends
On Tue, 2008-07-08 at 19:31 +0100, [EMAIL PROTECTED] wrote: Dear R-Users, I am looking for a way to get legends placed automagically in an empty spot on a graph. Additional complication comes through my useage of multiple graphs on the same plot through mfrow. Is there a way to achieve this in R ? I have legends for each of the sub-plots. Hi Tolga, Have a look at emptyspace in the plotrix package. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recursively divide a value to get a sequence
a.start - 15000 a.step - 5 a.length - 9 c(a.start*a.step^-(0:(a.length-2)),0) Anne-Marie Ternes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] version problems of rkward in ubuntu hardy repository
Hi I tried to install rkward under ubuntu hardy heron, but it tried to use the one from the cran repository which was newer, but it did not install. To be able to install rkward, I had to disable the cran repository, install rkward, lock it's version and enable the repository again. I have the feeling, that the dependencies are not correct (it is looking for libqt4GUI, but I have a libqt4-GUI from the ubuntu repository). Just for information, Rainer -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recursively divide a value to get a sequence
On Wed, 2008-07-09 at 11:40 +0200, Anne-Marie Ternes wrote: Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Well, if you really want to do it recursively (and maybe loopy as well) recursivdiv-function(x,denom,lendiv,firstpass=TRUE) { if(firstpass) lendiv-lendiv-1 if(lendiv 1) { divvec-c(x/denom,recursivdiv(x/denom,denom,lendiv-1,FALSE)) cat(divvec,ndiv,\n) } else divvec-0 if(firstpass) divvec-c(x,divvec) return(divvec) } Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] re cursively divide a value to get a sequence
Maybe something like this: f1 with loop, f2 without. f1 - function(start,len, div) { x - rep(start,len) for (i in 2 : (len-1)) { x[i] - x[i-1]/div } x[len] - 0 return(x) } f2 - function(start,len, div) { x - rep(start,len) y - div^(0:(len-1)) x - x/y x[length(x)] - 0 return(x) } system.time(f1(1,10,0.5)) system.time(f2(1,10,0.5)) Best regards Bart Anne-Marie Ternes wrote: Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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://www.nabble.com/recursively-divide-a-value-to-get-a-sequence-tp18358046p18358674.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] childNames for xaxis grob (grid package)
Dear list, Can someone explain why the childNames below gives character(0) instead of the (canonical) names of the children grobs of the xaxis gTree ? [1] major ticks labels Many thanks in advance, Tobias ### minimal example code ### library(grid) pushViewport(plotViewport(c(5,4,4,2))) pushViewport(dataViewport(1:5, 1:5)) grid.points(1:5, 1:5) grid.xaxis(name = xa) grid.get(xa) childNames(grid.get(xa)) ### sessionInfo() ### sessionInfo() R version 2.7.1 (2008-06-23) i486-pc-linux-gnu locale: en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Automatic placement of Legends
Jim Lemon wrote: On Tue, 2008-07-08 at 19:31 +0100, [EMAIL PROTECTED] wrote: Dear R-Users, I am looking for a way to get legends placed automagically in an empty spot on a graph. Additional complication comes through my useage of multiple graphs on the same plot through mfrow. Is there a way to achieve this in R ? I have legends for each of the sub-plots. Hi Tolga, Have a look at emptyspace in the plotrix package. Jim Also see the labcurve function in the Hmisc package. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recursively divide a value to get a sequence
Keith, I am simply baffled! Didn't think a second about doing it this way, tsss - Great! Thanks also for Daniel, Jim's and Bart's proposals! R is cool, I realise it every day again :-) Thanks!! On Wed, Jul 9, 2008 at 12:33 PM, Jim Lemon [EMAIL PROTECTED] wrote: On Wed, 2008-07-09 at 11:40 +0200, Anne-Marie Ternes wrote: Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Well, if you really want to do it recursively (and maybe loopy as well) recursivdiv-function(x,denom,lendiv,firstpass=TRUE) { if(firstpass) lendiv-lendiv-1 if(lendiv 1) { divvec-c(x/denom,recursivdiv(x/denom,denom,lendiv-1,FALSE)) cat(divvec,ndiv,\n) } else divvec-0 if(firstpass) divvec-c(x,divvec) return(divvec) } Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recursively divide a value to get a sequence
See ?Reduce Reduce(/, rep(5, 9), 15000, acc = TRUE) On Wed, Jul 9, 2008 at 5:40 AM, Anne-Marie Ternes [EMAIL PROTECTED] wrote: Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recursively divide a value to get a sequence
G'day all, On Wed, 09 Jul 2008 20:33:39 +1000 Jim Lemon [EMAIL PROTECTED] wrote: On Wed, 2008-07-09 at 11:40 +0200, Anne-Marie Ternes wrote: Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Well, if you really want to do it recursively (and maybe loopy as well) recursivdiv-function(x,denom,lendiv,firstpass=TRUE) { if(firstpass) lendiv-lendiv-1 if(lendiv 1) { divvec-c(x/denom,recursivdiv(x/denom,denom,lendiv-1,FALSE)) cat(divvec,ndiv,\n) } else divvec-0 if(firstpass) divvec-c(x,divvec) return(divvec) } Or, a bit more compactly: recursivdiv - function(x,denom,lendiv) { if(lendiv 1) { divvec-c(x, Recall(x/denom,denom,lendiv-1)) } else divvec-0 return(divvec) } which will continue to work if the function is renamed (say, rcd - recursivdiv) due to the use of Recall() Cheers, Berwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Automatic placement of Legends
Many thanks all, Tolga Frank E Harrell Jr [EMAIL PROTECTED] 09/07/2008 12:03 To Jim Lemon [EMAIL PROTECTED] cc [EMAIL PROTECTED], r-help@r-project.org Subject Re: [R] Automatic placement of Legends Jim Lemon wrote: On Tue, 2008-07-08 at 19:31 +0100, [EMAIL PROTECTED] wrote: Dear R-Users, I am looking for a way to get legends placed automagically in an empty spot on a graph. Additional complication comes through my useage of multiple graphs on the same plot through mfrow. Is there a way to achieve this in R ? I have legends for each of the sub-plots. Hi Tolga, Have a look at emptyspace in the plotrix package. Jim Also see the labcurve function in the Hmisc package. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[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] replacing value in column of data frame
Try this; what you want to do is to change the 'levels' of the factor. x - factor(c(1:10,'x','y','xy')) str(x) Factor w/ 13 levels 1,10,2,3,..: 1 3 4 5 6 7 8 9 10 2 ... x [1] 1 2 3 4 5 6 7 8 9 10 x y xy Levels: 1 10 2 3 4 5 6 7 8 9 x xy y # your error x[x == 'x'] - 23 Warning message: In `[-.factor`(`*tmp*`, x == x, value = 23) : invalid factor level, NAs generated x [1] 12345678910 NA yxy Levels: 1 10 2 3 4 5 6 7 8 9 x xy y # work with the levels which is what you want to change x - factor(c(1:10,'x','y','xy')) levels(x)[x == 'x'] - '23' x [1] 1 2 3 4 5 6 7 8 9 10 23 y xy Levels: 1 10 2 3 4 5 6 7 8 9 23 xy y On Wed, Jul 9, 2008 at 5:13 AM, Booman, M [EMAIL PROTECTED] wrote: Dear all, Probably a very basic question but I need some help. I have a data frame (made by read.table from a text file) of microarray data, of which the first column is a factor and the rest of the columns are numeric. The factor column contains chromosome names, so values 1 through 22 plus X, Y and XY. The numeric columns contain positions or intensity measurements. What I need to do is change the X's in the first column to a value of 23. This is what I thought I would do: BAF_temp - read.table(BAF_all.txt, sep=\t, header=T) #to read in the table BAF_temp[,1][BAF_temp[,1]==X] - 23 #in rows where the first column of BAF_temp is X, change the first column of BAF_temp to 23 However with this last line I get an error: Invalid factor level, NAs generated in '[-.factor'('*tmp*', BAF_temp[,1]==X, value=23) (I tested if my syntax for selecting the rows of chromosome X was correct by trying BAF_X - BAF_temp[BAF_temp[,1]==X,] which worked to give me a data frame with only the rows of the X chromosome.) I then thought it might work better if I changed the data frame to a matrix. When I change the BAF_temp data frame into a matrix (by BAF_matrix - as.matrix(BAF_temp)), then the command I used above: BAF_temp[,1][BAF_temp[,1]==X] - 23 works fine and the end result is as I meant it to be, with all the X's changed into 23's. However, by using as.matrix all columns are changed to 'character' including the numeric measurements (I understand this is because one of the columns of the data frame is 'factor') I would like some help on what is the best option to solve this. I have thought of a few options myself and would like your comment/help: 1. Is there another syntax I can use on the data frame to change the X's to 23's, so I don't have to change the data frame into a matrix first? 2. I could change the data frame into a matrix and run the syntax as I described, resulting in all columns becoming 'character'; is there then an easy way to turn the columns with measurements (columns 2 and further) back into 'numeric' while leaving the first column with the chromosome numbers as 'character'? 3. I thought of using data.matrix(BAF_temp) and making use of the fact that the first column of factors would be changed to the underlying numbers (because X being the 23rd level in the list would automaticly be changed to 23). However because the levels (chromosome names) of the factor column are ordered as 1, 10, 11, 12,,19, 2, 20, 21, 3, 4, etc. (I see this when using str(BAF_temp)) , this results in chromosome 10 being changed into a value of 2, chromosome 11 into 3, chromosome 2 into 12 etc. For info: the chromosome names in the text file that is imported are ordered just 1, 2, 3, etc. If anyone has some tips for me I would greatly appreciate it. Best wishes, Marije De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de geadresseerde(n). Anderen dan de geadresseerde(n) mogen geen gebruik maken van dit bericht, het niet openbaar maken of op enige wijze verspreiden of vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een incomplete aankomst of vertraging van dit verzonden bericht. The contents of this message are confidential and only intended for the eyes of the addressee(s). Others than the addressee(s) are not allowed to use this message, to make it public or to distribute or multiply this message in any way. The UMCG cannot be held responsible for incomplete reception or delay of this transferred message. [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] Parsing
This should do what you want: (it uses loops; you can work at replacing those with 'lapply' and such -- it all depends on if it is going to take you more time to rewrite the code than to process a set of data; you never did say how large the data was). This also grows a data.frame, but you have not indicated how efficient is has to be. So this could be used as a model. x - readLines(textConnection(x x_string + y y_string + id1id1_string + id2id2_string + z z_string + w w_string + stuff stuff stuff + stuff stuff stuff + stuff stuff stuff + // + x x_string1 + y y_string1 + z z_string1 + w w_string1 + stuff stuff stuff + stuff stuff stuff + stuff stuff stuff + // + x x_string2 + y y_string2 + id1id1_string1 + id2id2_string1 + z z_string2 + w w_string2 + stuff stuff stuff + stuff stuff stuff + stuff stuff stuff + //)) # I assume that each group is delimited by // # initialize data.frame with desired values .keys - data.frame(x=NA, y=NA, id1=NA, id2=NA, w=NA) .out - .keys # for the first pass .save - NULL for (i in seq_along(x)){ + if (x[i] == //){ # output the current data + .save - rbind(.save, .out) + .out - .keys# setup for the next pass + } else { + .split - strsplit(x[i], \\s+) + if (.split[[1]][1] %in% names(.out)){ + .out[[.split[[1]][1]]] - .split[[1]][2] + } + } + } .save x y id1 id2 w 1 x_string y_string id1_string id2_string w_string 2 x_string1 y_string1NANA w_string1 3 x_string2 y_string2 id1_string1 id2_string1 w_string2 On Wed, Jul 9, 2008 at 5:33 AM, Paolo Sonego [EMAIL PROTECTED] wrote: Dear R users, I have a big text file formatted like this: x x_string y y_string id1id1_string id2id2_string z z_string w w_string stuff stuff stuff stuff stuff stuff stuff stuff stuff // x x_string1 y y_string1 z z_string1 w w_string1 stuff stuff stuff stuff stuff stuff stuff stuff stuff // x x_string2 y y_string2 id1id1_string1 id2id2_string1 z z_string2 w w_string2 stuff stuff stuff stuff stuff stuff stuff stuff stuff // ... ... I'd like to parse this file and retrieve the x, y, id1, id2, z, w fields and save them into a a matrix object: xy id1 id2 z w x_string y_string id1_string id2_string z_string w_string x_string1 y_string1 NA NA z_string1 w_string1 x_string2 y_string2 id1_string1 id2_string1 z_string2 w_string2 ... ... id1, id2 fields are not always present within a section (the interval between x and the last stuff) and I'd like to insert a NA when they are absent (see above) so that length(x)==length(y)==length(id1)==... . Without the id1, id2 fields the task is easily solvable importing the text file with readLines and retrieving the single fields with grep: input = readLines(file.txt) x = grep(^x\\s, input, value = T) id1 = grep(^id1\\s, input, value = T) ... I'd like to accomplish this task entirely in R (no SQL, no perl script), possibly without using loops. Any suggestions are quite welcome! Regards, Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] netCDF to TIFF
Greetings R users! I am working with the ENSEMBLE climate data (10 min resolution daily temperatures images for all of Europe 1950-2006). The data comes packaged in a single netCDF file. I would like to read the data in and export a subset (2002-2006) as geotiffs (one image per day). So far, I can successfully read in the data and view the images within an R display window. However, I have yet to figure out how to export the images as tiffs or geotiffs. Does anyone out there have experience converting netCDF grids to TIFFs? After reading the data into R, I have it stored in a dataframe with longitude values as the column names, latitude values as the row names, and temperatures as the actual values. Below is my code thus far that I adapted from an example on the UCAR website. Thanks in advance! -Dan -- # Set working directory and load library setwd('C:/Users/steinber/Documents/DATA/ENSEMBLES/') library(ncdf) library(rgdal) library(chron) library(fields) # Read netCDF file tg.ncdf = open.ncdf('tg_0.25deg_CRU_version1.0.nc') tg.ncdf lonmat = get.var.ncdf(nc=tg.ncdf,varid=longitude) # reads entire matrix latmat = get.var.ncdf(nc=tg.ncdf,varid=latitude)# ditto timearr = get.var.ncdf(nc=tg.ncdf,varid=time)# reads entire time array targettime = julian(x=1, d=1, y=2002, origin=c(month = 1, day = 1, year = 1950)) inds = (1:dim(timearr)) tind = inds[targettime == timearr] ndims= tg.ncdf$var[['data']]$ndims varsize = tg.ncdf$var[['data']]$varsize start = c(1, 1, tind) count = c(varsize[1], varsize[2],1) # Read in data slice: tg.data = get.var.ncdf(nc=tg.ncdf,varid=data,start,count) tg.data[tg.data == -] = NA tg.data = tg.data/100.0 x = 1:nrow(tg.data) # R plots rows along X axis! y = 1:ncol(tg.data) image.plot(x,y,tg.data,col=tim.colors()) test.data = data.frame(tg.data, row.names = lonmat) colnames(test.data) = latmat __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with installing add-on packages
Dear R users. Recently I wanted to update my R distribution to the current one (R-2.7.1). I am running a Fedora core 8 distirbution. The installation went fine, but when I tried to add some additional packages the majority made an exit with an error. Only a few least demanding (e.g. RColorBrewer) managed to get through the installation process. What happened between the versions 2.6.x and 2.7.x to impede the installation of add-on packages that previously went smooth? Thank you for your suggestions and best regards. Miha Example: install.packages(akima,repos=http://cran.r-project.org,depend=T) * Installing to library '/usr/lib/R/library' * Installing *source* package 'akima' ... ** libs gfortran -m32 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c akima433.f -o akima433.o In file akima433.f:49 IF(X(I-1)-X(I)) 11,95,96 1 Warning: Obsolete: arithmetic IF statement at (1) In file akima433.f:38 10 L0=L 1 Warning: Label 1 at (1) defined but not used In file akima433.f:56 20 IF(LM2.EQ.0) GO TO 27 1 Warning: Label 20 at (1) defined but not used In file akima433.f:63 22 IMX=I 1 Warning: Label 22 at (1) defined but not used In file akima433.f:79 40 J=I 1 Warning: Label 40 at (1) defined but not used In file akima433.f:166 99 ERR = 10 1 Warning: Label 99 at (1) defined but not used gfortran -m32 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c akima697.f -o akima697.o In file akima697.f:88 10 IF (ND.LE.1) GO TO 90 1 Warning: Label 10 at (1) defined but not used In file akima697.f:97 20 NP0=MAX(3,NP) 1 Warning: Label 20 at (1) defined but not used In file akima697.f:103 30 DO 39 II=1,NI 1 Warning: Label 30 at (1) defined but not used In file akima697.f:398 99 ERR=10 1 Warning: Label 99 at (1) defined but not used gfortran -m32 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -c akima.new.f -o akima.new.o akima.new.f: In function ‘sdplnl’: akima.new.f:1904: warning: ‘zii1’ may be used uninitialized in this function akima.new.f:1903: warning: ‘y0’ may be used uninitialized in this function akima.new.f:1903: warning: ‘wt2’ may be used uninitialized in this function akima.new.f:1903: warning: ‘p50’ may be used uninitialized in this function akima.new.f:1903: warning: ‘p41’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p40’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p31’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p32’ may be used uninitialized in this function akima.new.f:1903: warning: ‘x0’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p22’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p21’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p23’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p13’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p14’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p12’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p20’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p10’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p04’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p02’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p03’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p05’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p11’ may be used uninitialized in this function akima.new.f:1902: warning: ‘p30’ may be used uninitialized in this function akima.new.f:1901: warning: ‘p00’ may be used uninitialized in this function akima.new.f:1900: warning: ‘cp’ may be used uninitialized in this function akima.new.f:1899: warning: ‘bp’ may be used uninitialized in this function akima.new.f:1898: warning: ‘ap’ may be used uninitialized in this function
Re: [R] recursively divide a value to get a sequence
Hi Anne-Marie, maybe its not particularly elegant, but this function does the trick: dilute-function(val,div,len){ + res-rep(val,len) + res-res/div^c(0:(len-1)) + res[len]-0 + res + } dilute(15000,5,9) Cheers, René -Ursprüngliche Nachricht- Von: Anne-Marie Ternes [EMAIL PROTECTED] Gesendet: 09.07.08 14:12:16 An: r-help@r-project.org Betreff: [R] recursively divide a value to get a sequence Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ WEB.DE schenkt Ihnen jeden Monat einen hochkarätigen Blockbuster von maxdome! Jetzt anmelden unter http://www.blockbuster.web.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] making zoo objects with zoo without format argument?
n - c(f,m,a,m,j,j,a,s,o,n,d,j,f,m,a,m,j,j,a,s,o,n,d,j) plot(x.zoo[, 95], xaxt = n, ylim=c(1,2)) rng - range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = n, tcl = -0.3) #why do I have to put in the y-lim explicitly? If you try the below code I get a warning- Error in plot.window(...) : invalid 'ylim' value plot(x.zoo[, 95], xaxt = n) rng - range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = n, tcl = -0.3) #thanks Stephen On Tue, Jul 8, 2008 at 4:13 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: Its a bug in axis.zoo. I have just fixed it in the svn repository so try this: source( http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/R/yearmon.R?rev=485root=zoo ) plot(x.zoo[, 25]) axis.zoo uses the same algorithm as axis.Date in R and so it gives similar results: # uses axis.Date plot(aggregate(x.zoo[, 25], as.Date, force)) You may wish to try a custom axis: plot(x.zoo[, 25], xaxt = n) rng - range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = FALSE, tcl = -0.3) axis(1, at = seq(floor(rng[1]), floor(rng[2]))) On Tue, Jul 8, 2008 at 3:34 PM, stephen sefick [EMAIL PROTECTED] wrote: That worked fine- now one more question- plot(x.zoo[,25]) produces a graph with True as the first label on the x-axis 1. why? 2. is it wrong to assume this is february 2006? thanks stephen R2.7.1 Windows XP (I updated zoo last week when I installed 2.7.1) On Tue, Jul 8, 2008 at 3:17 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: On Tue, Jul 8, 2008 at 2:59 PM, stephen sefick [EMAIL PROTECTED] wrote: x.zoo - zoo(x,as.yearmon(as.character(x$Yearmonth), %Y-%m)) plot(x.zoo[,25]) 1. You are trying to pass data frame to zoo whereas it must be a numeric vector, matrix or a factor. See ?zoo and try this: x.zoo - zoo(data.matrix(x), as.yearmon(x$Yearmonth, format = %Y-%m)) 2. You don't need as.character (it won't hurt but its unnecessary) since as.yearmon has a factor method. You only need as.character in the situation cited in the last post. #Error in plot.window(...) : invalid 'ylim' value #there are values On Tue, Jul 8, 2008 at 2:55 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: There is no data in your data frame, just index info, so I assume you want a zero width time series: zoo(, as.yearmon(x$Yearmonth, %Y-%m)) This also works but then you are left with a character date which you may not want: zoo(, x$Yearmonth) This last one should have been: zoo(, as.character(x$Yearmon)) since your data frame holds a factor rather than character column. On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick [EMAIL PROTECTED] wrote: #this is a subset of a larger data frame and I am okay with subsetting it as there are redundant time stamps, but I would like to create a zoo object out of this and I am having a hard #time figuring out how to do this the date structure is year and then month x - structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, 10L, 22L, 11L, 23L), .Label = c(2006-02, 2006-03, 2006-04, 2006-05, 2006-06, 2006-07, 2006-08, 2006-09, 2006-10, 2006-11, 2006-12, 2007-01, 2007-02, 2007-03, 2007-04, 2007-05, 2007-06, 2007-07, 2007-08, 2007-09, 2007-10, 2007-11, 2007-12, 2008-01), class = factor), Month = c(1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c(Yearmonth, Month ), class = data.frame, row.names = c(NA, 23L)) #thanks Stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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. -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are
[R] plot gam main effect functions in one graph
Dear R users, I have a question about the plot with the package gam. I need to plot different main effect functions, related to different gam models, in the same graphics (i.e. the same covariate about different models). I used the plot.gam e preplot.gam documentations. Using preplot.gam I can plot the single function but I'm not able to put all the functions together. Does anybody can help me. Thank you in advance. Pancrazio Bertaccini, PhD student, Università di Torino - Department of Statistics and Applied Mathematics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question concerning Furness iteration subprogram/modules
Dear all, I have basically two questions were some help would be very useful. The first question is whether there exists a package that performs Furness iterations. In the field of transportation, growth factor models are estimated using this iterative procedure. It encompasses and iterative procedure of multiplying matrix elements by the ration of the sum over all columns divided by a goal target, and multiplying all matrix elements by the ratio of the sum over all rows divided by a goal target. Does such procedure exists already in R? The second question I have is whether it is possible to store subprograms (modules) in a name, to reduce line of code, and make code more readable. I use r-code to generate activity-travel patterns, and afterwards I have a loop were I regenerate those patterns using the same code. Any idea how I could store subprograms (not functions?). If anyone has some answers for me I would greatly appreciate it. Best wishes, Mario [[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] Strptime/ date time classes
Dear all, I've come across a problem using strptime, can anyone explain what's going on? I'm using version 2.7.0 on Windows XP. Thank you Caroline First read in a data file using read.table alldata = read.table(file, header=F, skip=4, colClasses = c(character,numeric)) dim(alldata) [1] 223960 2 # inefficient, safe way of sorting out missing or dodgy data alldata[,2][alldata[,2] 0] = NA # first ten lines of the data alldata[1:10,] V1V2 1 19800604062759NA 2 19800604062800 0.271 3 19800604111900 0.286 4 19800604134300 0.362 5 19800604144400 0.465 6 19800604163300 0.510 7 19800604175400 0.518 8 19800604185100 0.526 9 1980060900NA 10 1980060959NA #Then convert the first column using strptime datetimes = strptime(alldata[,1],format=%Y%m%d%H%M%S) #Then I want to get minimum and maximum, but some seem to be missing when they aren't. length(as.POSIXlt(datetimes)) #also equal to length(datetimes) [1] 9 # Why isn't this 223960? Is it something to do with the class? # This is the really puzzling bit (to me anyway) a =(1:223960)[is.na(datetimes)] # which gives 1462 14295 18744 50499 50500 92472 92473 92474 92475 92476 137525 137526 137527 171066 171067 192353 # 16 values alldata[a,] V1V2 1462 19810329012000 0.983 14295 19900325014300 0.219 18744 19920329014300 0.246 50499 19960331013000 0.564 50500 19960331015700 0.563 92472 19970330010200 0.173 92473 19970330011400 0.172 92474 19970330012700 0.172 92475 19970330014400 0.172 92476 19970330015500 0.172 137525 19980329011600 0.427 137526 19980329014100 0.427 137527 19980329015600 0.427 171066 19990328010300 0.223 171067 19990328011800 0.223 192353 2326012800 0.189 datetimes[a] [1] 1981-03-29 01:20:00 1990-03-25 01:43:00 1992-03-29 01:43:00 1996-03-31 01:30:00 1996-03-31 01:57:00 [6] 1997-03-30 01:02:00 1997-03-30 01:14:00 1997-03-30 01:27:00 1997-03-30 01:44:00 1997-03-30 01:55:00 [11] 1998-03-29 01:16:00 1998-03-29 01:41:00 1998-03-29 01:56:00 1999-03-28 01:03:00 1999-03-28 01:18:00 [16] 2000-03-26 01:28:00 # They're all around the end of March! I've looked at the data file and I can't see anything funny in it around these dates. The first few lines of the data file look like #TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELVIN|*|CNR98808|*| #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| #RTYPEinstantaneous values|*| 19800604062759 -777.0 19800604062800 0.271 19800604111900 0.286 19800604134300 0.362 19800604144400 0.465 19800604163300 0.510 19800604175400 0.518 19800604185100 0.526 1980060900 -777.0 1980060959 -777.0 1980061000 0.100 19800611211400 0.096 1980061200 0.096 19800612065000 0.098 19800612133400 0.100 Caroline KeefJBA Consulting South Barn, Broughton Hall, Skipton, North Yorkshire, BD23 3AE, UK t: +44 (0)1756 799919 f: +44 (0)1756 799449 JBA Consulting now incorporates Maslen Environmental, the award winning environmental regeneration consultancy. http://www.maslen-environmental.com. JBA is a Carbon Neutral Company. Please don't print this e-mail unless you really need to. This email is covered by JBA Consulting's email disclaimer at www.jbaconsulting.co.uk/emaildisclaimer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 index list when using tapply()
jholtman wrote: Working code would help. I would probably use 'lapply' since it appears that you want to return a variable number of items for each condition. On Tue, Jul 8, 2008 at 2:23 PM, hesicaia [EMAIL PROTECTED] wrote: Hello, The quick version of my question is how can I extract a matrix instead of a vector using tapply()? I would like to be able to access both the results of tapply() and also the index variables. In case further explanation would help: I am analyzing a large (3million rows x 9 columns) spatial/temporal dataset and am attempting to calculate the number of unique years containing any data within each geographic area (10 degree cells in this case). I can do this, but I also want to extract a subset vector of the index variable (area). My script to calculate the number of unique years containing any data for each area is: x-tapply(years, area, function(x) length(unique(x))) Now, I want to extract the vector of areas where the number of unique years containing any data is 20, but tapply() only returns a vector of unique years and I was a matrix. I could use a looping function to do this, but tapply() is much faster with large datasets and so I would like to use it if possible. Any help is appreciated. Thanks. -- View this message in context: http://www.nabble.com/extracting-index-list-when-using-tapply%28%29-tp18345794p18345794.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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thanks very much to all who replied. Post #2 (Charles Berry) did the trick. I will be sure to give more relevant information and a small sample of data in future posts. Thanks again, your time is much appreciated. Dan. -- View this message in context: http://www.nabble.com/extracting-index-list-when-using-tapply%28%29-tp18345794p18360686.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] RJDBC and OracleDriver: unable to connect
Hi there, I'm trying to connect in an Oracle database. I am able to do it with Java, but when trying this code in R: library(DBI) library(RJDBC) drv = JDBC(oracle.jdbc.driver.OracleDriver, C:\\Documents and Settings\\rodri\\workspace\\AtlasQueryingTest\\lib\\ojdbc14.jar, identifier.quote=`) con=dbConnect(drv,url=jdbc:oracle:thin:@apu.ebi.ac.uk:1521:AEDWT,uid=rodri, pwd=rodri) The JDBC() call seems to work fine but dbConnect() returns: Error in .verify.JDBC.result(jc, Unable to connect JDBC to , url) : Unable to connect JDBC to jdbc:oracle:thin:@apu.ebi.ac.uk:1521:AEDWT (invalid arguments in call) I guess it should be a problem with the driver, because the other parameters are simple and work ok in Java-equivalent code I've tried to find info in the forums, and i've found the same question but with no response My environment is -R 2.7.0 With -RJDBC -DBI -rJava -Java 1.6.0_03 -ojdbc14.jar with OracleDriver (working fine in java code) -Windows XP Thanks in advance! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recursively divide a value to get a sequence
two alternative solutions with a more functional-style taste: dilute = function(init, div, count) sapply(1:count, function(i) init/div^(i-1)) dilute = function(init, div, count) if (count == 1) init else c(init, dilute(init/div, div, count-1)) vQ René Capell wrote: Hi Anne-Marie, maybe its not particularly elegant, but this function does the trick: dilute-function(val,div,len){ + res-rep(val,len) + res-res/div^c(0:(len-1)) + res[len]-0 + res + } dilute(15000,5,9) Cheers, René -Ursprüngliche Nachricht- Von: Anne-Marie Ternes [EMAIL PROTECTED] Gesendet: 09.07.08 14:12:16 An: r-help@r-project.org Betreff: [R] recursively divide a value to get a sequence Hi, if given the value of, say, 15000, I would like to be able to divide that value recursively by, say, 5, and to get a vector of a determined length, say 9, the last value being (set to) zero- i.e. like this: 15000 3000 600 120 24 4.8 0.96 0.192 0 These are in fact concentration values from an experiment. For my script, I get only the starting value (here 15000), and the factor by which concentration is divided for each well, the last one having, by definition, no antagonist at all. I have tried to use seq, but it can only do positive or negative increment. I didn't either find a way with rep, sweep etc. These function normally start from an existing vector, which is not the case here, I have only got a single value to start with. I suppose I could do something loopy, but I'm sure there is a better way to do it. Thanks a lot for your help, hope the question is not too dumb... Anne-Marie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ WEB.DE schenkt Ihnen jeden Monat einen hochkarätigen Blockbuster von maxdome! Jetzt anmelden unter http://www.blockbuster.web.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- --- Wacek Kusnierczyk, MD PhD Email: [EMAIL PROTECTED] Phone: +47 73591875, +47 72574609 Department of Computer and Information Science (IDI) Faculty of Information Technology, Mathematics and Electrical Engineering (IME) Norwegian University of Science and Technology (NTNU) Sem Saelands vei 7, 7491 Trondheim, Norway Room itv303 Bioinformatics Gene Regulation Group Department of Cancer Research and Molecular Medicine (IKM) Faculty of Medicine (DMF) Norwegian University of Science and Technology (NTNU) Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway Room 231.05.060 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] making zoo objects with zoo without format argument?
BB - structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, 10L, 22L, 11L, 23L), .Label = c(2006-02, 2006-03, 2006-04, 2006-05, 2006-06, 2006-07, 2006-08, 2006-09, 2006-10, 2006-11, 2006-12, 2007-01, 2007-02, 2007-03, 2007-04, 2007-05, 2007-06, 2007-07, 2007-08, 2007-09, 2007-10, 2007-11, 2007-12, 2008-01), class = factor), Site = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(301, 520, Betty's Branch, Butler Creek, CLYO, Downstream, Horse Creek, IP, North Augusta, Stan's, Stevens Creek, Vogtle), class = factor), River.Mile = c(215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215), Lagrangian = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(No, Yes), class = factor), EventType = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(Regular, Stormwater), class = factor), Month = c(1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L), Year = c(2007L, 2008L, 2006L, 2007L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L), DCAA = c(87, NA, 95, NA, 96, NA, NA, NA, 93, NA, NA, NA, NA, NA, NA, 79, 82, NA, NA, NA, NA, NA, 86), Decachlorobiphenyl = c(79, NA, 65, NA, 83, NA, NA, NA, 74, NA, NA, NA, NA, NA, NA, 93, 76, NA, NA, NA, NA, NA, 74), Tetrachloro.m.xylene = c(90, NA, 86, NA, 83, NA, NA, NA, 96, NA, NA, NA, NA, NA, NA, 95, 91, NA, NA, NA, NA, NA, 85), Alkalinity = c(15, 13, 12, 14, 13, 16, 13, 16, 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), BOD..5.day = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Carbonaceous.BOD..5.day = c(NA, NA, NA, NA, NA, 0.3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Chloride = c(2.6, 2.7, 3, 2.9, 2.8, 2.6, 2.7, 2.5, 3, 2.4, 2.8, 2.5, 2.7, 2.3, 2.7, 2.5, 2.7, 3, 2.7, 2.6, 2.8, 2.6, 2.7), COD = c(NA, 8.8, NA, NA, NA, 13, NA, NA, 7.9, 5.9, NA, NA, NA, NA, NA, NA, NA, 6.6, 6.5, NA, NA, NA, 12), Dissolved.Ammonia...N..phenate. = c(NA, 0.095, NA, NA, 0.072, 0.1, 0.17, 0.11, 0.12, NA, 0.055, NA, NA, 0.11, NA, NA, 0.1, 0.15, 0.072, 0.078, 0.073, NA, 0.065 ), Dissolved.Chloride = c(2.7, 2.7, NA, 2.9, 3.4, 2.6, 2.7, 2.5, 2.9, 2.5, NA, 2.5, 2.7, 2.5, 2.7, 2.4, 2.7, 2.4, 2.8, 2.7, 2.8, 2.6, 2.8), Dissolved.Mercury = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.00013, NA, NA, NA, NA, NA, NA, NA, NA, NA), Dissolved.Nitrate.Nitrite...N = c(0.092, 0.16, 0.13, 0.14, 0.16, 1.4, 0.15, 0.18, 0.17, 0.21, 0.17, 0.2, 0.19, 0.16, 0.18, 0.069, 0.048, 0.022, 0.2, 0.056, 0.068, 0.082, 0.051), Dissolved.Nitrite...N = c(NA, 0.0097, NA, 0.015, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.0046, NA, 0.0051, 0.0034, NA, 0.009, 0.0066, 0.016, NA, NA), Dissolved.Sulfate = c(2.7, 3.3, NA, 3, 3, 2.5, 2.8, 1.7, 3.1, 2.1, 0.18, 2.5, 3, 2.3, 2.9, 2.2, 2.8, 2.3, 2.7, 2.6, 5.8, 2.5, 2.8), DOC = c(2.1, 2, 2.5, 2.1, 2.8, 2.4, 2.3, 2.3, 3.5, 2.1, 2.8, 2, 2.5, 1.9, 2.4, 2, 2.2, 2.1, 2.2, 2.9, 2.2, 2.6, 2.2), Hardness..total. = c(NA, NA, 9.6, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Mercury = c(NA, NA, 9.1e-05, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Ortho.phosphorus = c(NA, NA, 0.057, 0.008, 0.016, 0.009, 0.028, 0.04, 0.039, 0.044, 0.01, 0.038, NA, 0.089, NA, 0.046, 0.023, 0.019, 0.03, 0.074, NA, 0.027, NA), Phosphorus = c(NA, 0.011, 0.042, 0.013, 0.0092, 0.015, 0.0085, 0.0057, 0.01, 0.01, 0.0068, 0.0099, 0.0073, 0.0085, 0.008, 0.0072, 0.01, NA, 0.0086, NA, 0.014, 0.011, 0.011), Silica..calculation. = c(NA, NA, 9.4, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA ), Sulfate = c(2.5, 2.3, 2.5, 2.7, 3, 0.26, 2.9, 2.4, 3.5, 2.4, 3.1, 2.4, 3.1, 2.2, 3, 2.5, 2.8, 2.4, 2.6, 4.1, 2.8, 2.4, 3.4), TDS = c(38, NA, 21, 25, 46, 32, 46, 38, 27, 34, 64, 39, 57, 24, 33, NA, 39, 37, 40, 29, 44, 32, 28), TIC = c(1.1, 3.6, 1.2, 0.99, 1.6, 3.4, 2.4, 4.6, 1.2, 2.7, 2.2, 0.73, 3.5, 1.9, 1.6, 2.2, 2.3, 2.4, 2, 2.2, 0.78, 2, 3.8), TKN = c(0.86, 0.42, 0.42, 0.17, 0.12, 0.2, NA, 0.32, 0.2, 0.46, 0.24, NA, 0.35, 0.2, 0.37, 0.54, 0.2, 0.18, 0.1, 0.25, NA, NA, 0.39 ), TOC = c(2, 1.9, 2.2, 2, 2.3, 2.2, 2.3, 2.4, 2.8, 2.2, 2.6, 1.8, 2.7, 2.2, 2.2, 2, 2.2, 1.9, 2.5, 2, 2.2, 2, 2.1 ), TSS = c(0.8, 5.7, NA, 1, 1.8, NA,
Re: [R] making zoo objects with zoo without format argument?
This was fixed in the zoo devel version (to be zoo 1.5-4) just last week. See: http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/NEWS?rev=487root=zoo You can either wait for that, use the workaround you found or source the fixed version of plot.zoo: source(http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/R/plot.zoo.R?rev=472root=zoo;) On Wed, Jul 9, 2008 at 9:37 AM, stephen sefick [EMAIL PROTECTED] wrote: n - c(f,m,a,m,j,j,a,s,o,n,d,j,f,m,a,m,j,j,a,s,o,n,d,j) plot(x.zoo[, 95], xaxt = n, ylim=c(1,2)) rng - range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = n, tcl = -0.3) #why do I have to put in the y-lim explicitly? If you try the below code I get a warning- Error in plot.window(...) : invalid 'ylim' value plot(x.zoo[, 95], xaxt = n) rng - range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = n, tcl = -0.3) #thanks Stephen On Tue, Jul 8, 2008 at 4:13 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: Its a bug in axis.zoo. I have just fixed it in the svn repository so try this: source(http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/R/yearmon.R?rev=485root=zoo;) plot(x.zoo[, 25]) axis.zoo uses the same algorithm as axis.Date in R and so it gives similar results: # uses axis.Date plot(aggregate(x.zoo[, 25], as.Date, force)) You may wish to try a custom axis: plot(x.zoo[, 25], xaxt = n) rng - range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = FALSE, tcl = -0.3) axis(1, at = seq(floor(rng[1]), floor(rng[2]))) On Tue, Jul 8, 2008 at 3:34 PM, stephen sefick [EMAIL PROTECTED] wrote: That worked fine- now one more question- plot(x.zoo[,25]) produces a graph with True as the first label on the x-axis 1. why? 2. is it wrong to assume this is february 2006? thanks stephen R2.7.1 Windows XP (I updated zoo last week when I installed 2.7.1) On Tue, Jul 8, 2008 at 3:17 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: On Tue, Jul 8, 2008 at 2:59 PM, stephen sefick [EMAIL PROTECTED] wrote: x.zoo - zoo(x,as.yearmon(as.character(x$Yearmonth), %Y-%m)) plot(x.zoo[,25]) 1. You are trying to pass data frame to zoo whereas it must be a numeric vector, matrix or a factor. See ?zoo and try this: x.zoo - zoo(data.matrix(x), as.yearmon(x$Yearmonth, format = %Y-%m)) 2. You don't need as.character (it won't hurt but its unnecessary) since as.yearmon has a factor method. You only need as.character in the situation cited in the last post. #Error in plot.window(...) : invalid 'ylim' value #there are values On Tue, Jul 8, 2008 at 2:55 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: There is no data in your data frame, just index info, so I assume you want a zero width time series: zoo(, as.yearmon(x$Yearmonth, %Y-%m)) This also works but then you are left with a character date which you may not want: zoo(, x$Yearmonth) This last one should have been: zoo(, as.character(x$Yearmon)) since your data frame holds a factor rather than character column. On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick [EMAIL PROTECTED] wrote: #this is a subset of a larger data frame and I am okay with subsetting it as there are redundant time stamps, but I would like to create a zoo object out of this and I am having a hard #time figuring out how to do this the date structure is year and then month x - structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, 10L, 22L, 11L, 23L), .Label = c(2006-02, 2006-03, 2006-04, 2006-05, 2006-06, 2006-07, 2006-08, 2006-09, 2006-10, 2006-11, 2006-12, 2007-01, 2007-02, 2007-03, 2007-04, 2007-05, 2007-06, 2007-07, 2007-08, 2007-09, 2007-10, 2007-11, 2007-12, 2008-01), class = factor), Month = c(1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c(Yearmonth, Month ), class = data.frame, row.names = c(NA, 23L)) #thanks Stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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] Auto.key colors maintained when subsetting
All, I'm plotting points and lines for various groups. I'd like subsequent plots done on subsets to maintain the color assignments from the original plot. This works fine, but the key for the subset doesn't maintain the correspondence. One solution is to reprint the entire key, but this is undesirable since then the key has more elements than the groups in the plot. Reproducible example below. Cheers, David dat = data.frame( Y = c(rnorm(4,0), rnorm(4,2), rnorm(4,6), rnorm(4,8)), Group = factor(c(rep(A, 4), rep(B, 4), rep(C, 4), rep(D, 4))), Hour = rep(c(1:4), 4) ) ## plots colors and key correctly: xyplot(Y ~ Hour, data = dat, pch = 16, groups=Group, type=b, auto.key = list(space = top, text = levels(Group), points = FALSE, lines = TRUE, columns=4), par.settings = list(superpose.line = list(lty = c(1,2,3,4) ) ) ) dev.new() ## does not plot colors and key correctly: xyplot(Y ~ Hour, data = dat, pch = 16, subset = (Group != A), groups=Group, type=b, auto.key = list(space = top, text = levels(Group)[2:4], points = FALSE, lines = TRUE, columns=3), par.settings = list(superpose.line = list(lty = c(1,2,3,4) ) ) ) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loglikelihood for x factorial?
ctu at bigred.unl.edu writes: I have a silly question. I don't know how to express the loglikelihood function of 1/(x!) where x=x1,x2,xn in R. Not clear what you mean. If you just want the log of the factorial, just use lfactorial(x) ... Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Summary Stats (not summary(x))
I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363275.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] lapply
hi Can i use a for loop with in the lapply..if so could u plz let me know the syntax. Ramya -- View this message in context: http://www.nabble.com/lapply-tp18363288p18363288.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] Summary Stats (not summary(x))
There are describe functions in prettyR and Hmisc packages and doSummary in doBy. On Wed, Jul 9, 2008 at 11:15 AM, nmarti [EMAIL PROTECTED] wrote: I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363275.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] Summary Stats (not summary(x))
Dear nmarti, See ?basicStats in fBasics. HTH, Jorge On Wed, Jul 9, 2008 at 11:15 AM, nmarti [EMAIL PROTECTED] wrote: I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363275.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lapply
Yes. It is the same syntax. Can you provide an example of what you want to do. lapply(1:5, function(num){ + .ret - numeric(num) + for (i in 1:num) .ret[i] - i*i + .ret + }) [[1]] [1] 1 [[2]] [1] 1 4 [[3]] [1] 1 4 9 [[4]] [1] 1 4 9 16 [[5]] [1] 1 4 9 16 25 On Wed, Jul 9, 2008 at 11:26 AM, Rajasekaramya [EMAIL PROTECTED] wrote: hi Can i use a for loop with in the lapply..if so could u plz let me know the syntax. Ramya -- View this message in context: http://www.nabble.com/lapply-tp18363288p18363288.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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Summary Stats (not summary(x))
Why don't you write it for yourself, it takes less time than writing an email: mysummary - function(x) { require(plotrix) require(e1071) c(Mean=mean(x), Std.Error=std.error(x), Std.Deviation=sd(x), Kurtosis=kurtosis(x)) } Gabor On Wed, Jul 09, 2008 at 08:15:00AM -0700, nmarti wrote: I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363275.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. -- Csardi Gabor [EMAIL PROTECTED]UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Summary Stats (not summary(x))
I think the function describe() in the package psych will give you want you want. There are other similar functions in the library Simple as well. Harold nmarti wrote: I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363387.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] gsub and \
This is hopefully a simple question. I am trying to escape single quotes like so: abc'sabc\'s However, I cannot find an easy way to do that with gsub: gsub(',',abc's) # returns abc\\'s How can I get a single \ in the output? Thanks, Sean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Summary Stats (not summary(x))
At 11:26 AM -0400 7/9/08, Gabor Grothendieck wrote: There are describe functions in prettyR and Hmisc packages and doSummary in doBy. As well as describe and describe.by in the psych package. On Wed, Jul 9, 2008 at 11:15 AM, nmarti [EMAIL PROTECTED] wrote: I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363275.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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rJava crashes jvm
Dear List I tried using rJava respectively JRI to run R code from within Java but got an error message reproducible. I have broken down the problem to this simple piece of code: import org.rosuda.JRI.*; public class rtest { public static void main(String[] args) { Rengine re=new Rengine(); re.assign(x, Peter); } } Compiling is ok, but when I try to run it the jvm crashes with the following error message: # An unexpected error has been detected by Java Runtime Environment: # # SIGSEGV (0xb) at pc=0xb54763fd, pid=5716, tid=3085089680 # # Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode, sharing linux-x86) # Problematic frame: # C [libR.so+0xe63fd] # # An error report file with more information is saved as: # /home/cruckert/workspace/OWL-Test/src/hs_err_pid5716.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. Greetings Christian PS: The hs_err_pid5716.log: # An unexpected error has been detected by Java Runtime Environment: # # SIGSEGV (0xb) at pc=0xb54763fd, pid=5716, tid=3085089680 # # Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode, sharing linux-x86) # Problematic frame: # C [libR.so+0xe63fd] # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # --- T H R E A D --- Current thread (0x08058800): JavaThread main [_thread_in_native, id=5717, stack(0xb7ddb000,0xb7e2c000)] siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x000c Registers: EAX=0x, EBX=0xb55dd51c, ECX=0x0001, EDX=0xb5612c78 ESP=0xb7e2aed0, EBP=0xb7e2af38, ESI=0x08141da8, EDI=0x EIP=0xb54763fd, CR2=0x000c, EFLAGS=0x00210202 Top of Stack: (sp=0xb7e2aed0) 0xb7e2aed0: 07cc 0003 b7e2af60 0xb7e2aee0: 08141cf0 b7e2af18 08141468 0xb7e2aef0: b5612c78 00b8 0xb7e2af00: b5612b20 b5612bd8 00b8 08141da0 0xb7e2af10: 0001 08058ca0 b7e2af38 0020 0xb7e2af20: 003e 0001 b55dd51c 0xb7e2af30: 00b8 b5612b20 b7e2afa8 b5479d19 0xb7e2af40: 049393b2 b7ff3ff4 b567dc2c 0813fb28 Instructions: (pc=0xb54763fd) 0xb54763ed: 08 83 e0 10 88 45 bb 88 55 ba 8b 55 bc 83 c1 01 0xb54763fd: 8b 47 0c 89 75 dc 89 77 0c 83 42 0c 01 0f b6 55 Stack: [0xb7ddb000,0xb7e2c000], sp=0xb7e2aed0, free space=319k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [libR.so+0xe63fd] C [libR.so+0xe9d19] Rf_allocVector+0xa89 C [libjri.so+0x475f] jri_getString+0x5f C [libjri.so+0x35f4] Java_org_rosuda_JRI_Rengine_rniPutString+0x24 v ~BufferBlob::Interpreter v ~BufferBlob::Interpreter v ~BufferBlob::Interpreter v ~BufferBlob::StubRoutines (1) V [libjvm.so+0x21c5cd] V [libjvm.so+0x310748] V [libjvm.so+0x21c460] V [libjvm.so+0x245a86] V [libjvm.so+0x237288] C [java+0x1b98] JavaMain+0x2c8 C [libpthread.so.0+0x54fb] Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) v ~BufferBlob::Interpreter v ~BufferBlob::Interpreter v ~BufferBlob::Interpreter v ~BufferBlob::StubRoutines (1) --- P R O C E S S --- Java Threads: ( = current thread ) 0x08096000 JavaThread Low Memory Detector daemon [_thread_blocked, id=5723, stack(0xb58c4000,0xb5915000)] 0x0808b400 JavaThread CompilerThread0 daemon [_thread_blocked, id=5722, stack(0xb5915000,0xb5996000)] 0x0808a000 JavaThread Signal Dispatcher daemon [_thread_blocked, id=5721, stack(0xb5996000,0xb59e7000)] 0x08081c00 JavaThread Finalizer daemon [_thread_blocked, id=5720, stack(0xb5b21000,0xb5b72000)] 0x08080800 JavaThread Reference Handler daemon [_thread_blocked, id=5719, stack(0xb5b72000,0xb5bc3000)] =0x08058800 JavaThread main [_thread_in_native, id=5717, stack(0xb7ddb000,0xb7e2c000)] Other Threads: 0x0807f400 VMThread [stack: 0xb5bc3000,0xb5c44000] [id=5718] 0x080a9800 WatcherThread [stack: 0xb5843000,0xb58c4000] [id=5724] VM state:not at safepoint (normal execution) VM Mutex/Monitor currently owned by a thread: None Heap def new generation total 960K, used 315K [0x8c0c, 0x8c1c, 0x8c5a) eden space 896K, 35% used [0x8c0c, 0x8c10ed50, 0x8c1a) from space 64K, 0% used [0x8c1a, 0x8c1a, 0x8c1b) to space 64K, 0% used [0x8c1b, 0x8c1b, 0x8c1c) tenured generation total 4096K, used 0K [0x8c5a, 0x8c9a, 0x900c) the space 4096K, 0% used [0x8c5a, 0x8c5a, 0x8c5a0200, 0x8c9a) compacting perm gen total 12288K, used 46K [0x900c, 0x90cc, 0x940c) the space 12288K, 0% used [0x900c, 0x900cba78, 0x900cbc00, 0x90cc) ro space 8192K, 73%
Re: [R] Parsing
How much time is it taking on the files and how many files do you have to process? I tried it with your data duplicated so that I had 57K lines and it took 27 seconds to process. How much faster to you want? On Wed, Jul 9, 2008 at 10:57 AM, Paolo Sonego [EMAIL PROTECTED] wrote: Thanks so much Jim! It works without a glitch! My only problem is that the text files to be parsed are quite big, up to several thousands rows (my apologies for the incomplete informations in my former post), so loops are not my first choice. I'll take a look at 'lapply' using your code as a model. Thanks again! Sincerely, Paolo jim holtman ha scritto: This should do what you want: (it uses loops; you can work at replacing those with 'lapply' and such -- it all depends on if it is going to take you more time to rewrite the code than to process a set of data; you never did say how large the data was). This also grows a data.frame, but you have not indicated how efficient is has to be. So this could be used as a model. x - readLines(textConnection(x x_string + y y_string + id1id1_string + id2id2_string + z z_string + w w_string + stuff stuff stuff + stuff stuff stuff + stuff stuff stuff + // + x x_string1 + y y_string1 + z z_string1 + w w_string1 + stuff stuff stuff + stuff stuff stuff + stuff stuff stuff + // + x x_string2 + y y_string2 + id1id1_string1 + id2id2_string1 + z z_string2 + w w_string2 + stuff stuff stuff + stuff stuff stuff + stuff stuff stuff + //)) # I assume that each group is delimited by // # initialize data.frame with desired values .keys - data.frame(x=NA, y=NA, id1=NA, id2=NA, w=NA) .out - .keys # for the first pass .save - NULL for (i in seq_along(x)){ + if (x[i] == //){ # output the current data + .save - rbind(.save, .out) + .out - .keys# setup for the next pass + } else { + .split - strsplit(x[i], \\s+) + if (.split[[1]][1] %in% names(.out)){ + .out[[.split[[1]][1]]] - .split[[1]][2] + } + } + } .save x y id1 id2 w 1 x_string y_string id1_string id2_string w_string 2 x_string1 y_string1NANA w_string1 3 x_string2 y_string2 id1_string1 id2_string1 w_string2 On Wed, Jul 9, 2008 at 5:33 AM, Paolo Sonego [EMAIL PROTECTED] wrote: Dear R users, I have a big text file formatted like this: x x_string y y_string id1id1_string id2id2_string z z_string w w_string stuff stuff stuff stuff stuff stuff stuff stuff stuff // x x_string1 y y_string1 z z_string1 w w_string1 stuff stuff stuff stuff stuff stuff stuff stuff stuff // x x_string2 y y_string2 id1id1_string1 id2id2_string1 z z_string2 w w_string2 stuff stuff stuff stuff stuff stuff stuff stuff stuff // ... ... I'd like to parse this file and retrieve the x, y, id1, id2, z, w fields and save them into a a matrix object: xy id1 id2 z w x_string y_string id1_string id2_string z_string w_string x_string1 y_string1 NA NA z_string1 w_string1 x_string2 y_string2 id1_string1 id2_string1 z_string2 w_string2 ... ... id1, id2 fields are not always present within a section (the interval between x and the last stuff) and I'd like to insert a NA when they are absent (see above) so that length(x)==length(y)==length(id1)==... . Without the id1, id2 fields the task is easily solvable importing the text file with readLines and retrieving the single fields with grep: input = readLines(file.txt) x = grep(^x\\s, input, value = T) id1 = grep(^id1\\s, input, value = T) ... I'd like to accomplish this task entirely in R (no SQL, no perl script), possibly without using loops. Any suggestions are quite welcome! Regards, Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] gsub and \
It does have a single \; the printing just shows that it is escaped. If you 'cat' it to output, you will see: gsub(',',abc's) [1] abc\\'s cat(gsub(',',abc's)) abc\'s Which I think is what you were thinking it would be. So when you write it out to a file, it will be correct. On Wed, Jul 9, 2008 at 11:49 AM, Sean Davis [EMAIL PROTECTED] wrote: This is hopefully a simple question. I am trying to escape single quotes like so: abc'sabc\'s However, I cannot find an easy way to do that with gsub: gsub(',',abc's) # returns abc\\'s How can I get a single \ in the output? Thanks, Sean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] gsub and \
On Wed, Jul 9, 2008 at 11:57 AM, jim holtman [EMAIL PROTECTED] wrote: It does have a single \; the printing just shows that it is escaped. If you 'cat' it to output, you will see: gsub(',',abc's) [1] abc\\'s cat(gsub(',',abc's)) abc\'s Which I think is what you were thinking it would be. So when you write it out to a file, it will be correct. Thanks, Jim. That does it. Sean On Wed, Jul 9, 2008 at 11:49 AM, Sean Davis [EMAIL PROTECTED] wrote: This is hopefully a simple question. I am trying to escape single quotes like so: abc'sabc\'s However, I cannot find an easy way to do that with gsub: gsub(',',abc's) # returns abc\\'s How can I get a single \ in the output? Thanks, Sean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Strptime/ date time classes
You probably want POSIXct instead of POSIXlt: x - read.table(textConnection(#TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELVIN|*|CNR98808|*| + #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| + #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| + #RTYPEinstantaneous values|*| + 19800604062759 -777.0 + 19800604062800 0.271 + 19800604111900 0.286 + 19800604134300 0.362 + 19800604144400 0.465 + 19800604163300 0.510 + 19800604175400 0.518 + 19800604185100 0.526 + 1980060900 -777.0 + 1980060959 -777.0 + 1980061000 0.100 + 19800611211400 0.096 + 1980061200 0.096 + 19800612065000 0.098 + 19800612133400 0.100),colClasses=c('character','numeric')) closeAllConnections() # you probably want POSIXct not POSIXlt datetimes - as.POSIXct(strptime(x[,1], %Y%m%d%H%M%S)) str(datetimes) POSIXct[1:15], format: 1980-06-04 06:27:59 1980-06-04 06:28:00 1980-06-04 11:19:00 ... length(datetimes) [1] 15 On Wed, Jul 9, 2008 at 6:09 AM, Caroline Keef [EMAIL PROTECTED] wrote: Dear all, I've come across a problem using strptime, can anyone explain what's going on? I'm using version 2.7.0 on Windows XP. Thank you Caroline First read in a data file using read.table alldata = read.table(file, header=F, skip=4, colClasses = c(character,numeric)) dim(alldata) [1] 223960 2 # inefficient, safe way of sorting out missing or dodgy data alldata[,2][alldata[,2] 0] = NA # first ten lines of the data alldata[1:10,] V1V2 1 19800604062759NA 2 19800604062800 0.271 3 19800604111900 0.286 4 19800604134300 0.362 5 19800604144400 0.465 6 19800604163300 0.510 7 19800604175400 0.518 8 19800604185100 0.526 9 1980060900NA 10 1980060959NA #Then convert the first column using strptime datetimes = strptime(alldata[,1],format=%Y%m%d%H%M%S) #Then I want to get minimum and maximum, but some seem to be missing when they aren't. length(as.POSIXlt(datetimes)) #also equal to length(datetimes) [1] 9 # Why isn't this 223960? Is it something to do with the class? # This is the really puzzling bit (to me anyway) a =(1:223960)[is.na(datetimes)] # which gives 1462 14295 18744 50499 50500 92472 92473 92474 92475 92476 137525 137526 137527 171066 171067 192353 # 16 values alldata[a,] V1V2 1462 19810329012000 0.983 14295 19900325014300 0.219 18744 19920329014300 0.246 50499 19960331013000 0.564 50500 19960331015700 0.563 92472 19970330010200 0.173 92473 19970330011400 0.172 92474 19970330012700 0.172 92475 19970330014400 0.172 92476 19970330015500 0.172 137525 19980329011600 0.427 137526 19980329014100 0.427 137527 19980329015600 0.427 171066 19990328010300 0.223 171067 19990328011800 0.223 192353 2326012800 0.189 datetimes[a] [1] 1981-03-29 01:20:00 1990-03-25 01:43:00 1992-03-29 01:43:00 1996-03-31 01:30:00 1996-03-31 01:57:00 [6] 1997-03-30 01:02:00 1997-03-30 01:14:00 1997-03-30 01:27:00 1997-03-30 01:44:00 1997-03-30 01:55:00 [11] 1998-03-29 01:16:00 1998-03-29 01:41:00 1998-03-29 01:56:00 1999-03-28 01:03:00 1999-03-28 01:18:00 [16] 2000-03-26 01:28:00 # They're all around the end of March! I've looked at the data file and I can't see anything funny in it around these dates. The first few lines of the data file look like #TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELVIN|*|CNR98808|*| #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| #RTYPEinstantaneous values|*| 19800604062759 -777.0 19800604062800 0.271 19800604111900 0.286 19800604134300 0.362 19800604144400 0.465 19800604163300 0.510 19800604175400 0.518 19800604185100 0.526 1980060900 -777.0 1980060959 -777.0 1980061000 0.100 19800611211400 0.096 1980061200 0.096 19800612065000 0.098 19800612133400 0.100 Caroline KeefJBA Consulting South Barn, Broughton Hall, Skipton, North Yorkshire, BD23 3AE, UK t: +44 (0)1756 799919 f: +44 (0)1756 799449 JBA Consulting now incorporates Maslen Environmental, the award winning environmental regeneration consultancy. http://www.maslen-environmental.com. JBA is a Carbon Neutral Company. Please don't print this e-mail unless you really need to. This email is covered by JBA Consulting's email disclaimer at www.jbaconsulting.co.uk/emaildisclaimer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented,
Re: [R] gsub and \
On 09-Jul-08 15:49:54, Sean Davis wrote: This is hopefully a simple question. I am trying to escape single quotes like so: abc'sabc\'s However, I cannot find an easy way to do that with gsub: gsub(',',abc's) # returns abc\\'s How can I get a single \ in the output? Thanks, Sean In terms of the internal representation, I think you have in fact got what you want. It's just that when it's prented on the screen, the internal \ is printed as \\: nchar(abc\\'s) # [1] 6 nchar(abc's) # [1] 5 Quite how you get it to be displayed as abc\'s is another matter, and I don't have an answer to it! Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 09-Jul-08 Time: 17:06:40 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
I apologize for giving wrong information again ... :-[ The number of files is not a problem (30/40). The real deal is that some of my files have ~10^6 lines (file size ~ 300/400M) :'( Thanks again for your help and advices! Regards, Paolo jim holtman ha scritto: How much time is it taking on the files and how many files do you have to process? I tried it with your data duplicated so that I had 57K lines and it took 27 seconds to process. How much faster to you want? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
It might be best to use Perl for this processing since it is better equipped to work with text files of this nature. On Wed, Jul 9, 2008 at 12:18 PM, Paolo Sonego [EMAIL PROTECTED] wrote: I apologize for giving wrong information again ... :-[ The number of files is not a problem (30/40). The real deal is that some of my files have ~10^6 lines (file size ~ 300/400M) :'( Thanks again for your help and advices! Regards, Paolo jim holtman ha scritto: How much time is it taking on the files and how many files do you have to process? I tried it with your data duplicated so that I had 57K lines and it took 27 seconds to process. How much faster to you want? -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Port package
Hi When I type: ?nls I come across this section: algorithm: character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm. Other possible values are 'plinear' for the Golub-Pereyra algorithm for partially linear least-squares models and 'port' for the 'nl2sol' algorithm from the Port package. The simple question is: where's the Port package? I can't find it on cran. Thanks, Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Strptime/ date time classes
Hi Caroline, Because POSIXlt is a complicated structure: you are dealing with a list, not with what you think you are. Maybe this will help you to see more clearly. strptime(19800604062759, format=%Y%m%d%H%M%S) [1] 1980-06-04 06:27:59 str(strptime(19800604062759, format=%Y%m%d%H%M%S)) POSIXlt[1:9], format: 1980-06-04 06:27:59 ## length == 9 strptime(c(19800604062759,19800604062800), format=%Y%m%d%H%M%S) [1] 1980-06-04 06:27:59 1980-06-04 06:28:00 str(strptime(c(19800604062759,19800604062800), format=%Y%m%d%H%M%S)) POSIXlt[1:9], format: 1980-06-04 06:27:59 1980-06-04 06:28:00 ## length == 9 typeof(strptime(c(19800604062759,19800604062800), format=%Y%m%d%H%M%S)) [1] list length(unlist(strptime(c(19800604062759,19800604062800), format=%Y%m%d%H%M%S))) [1] 18 ## 9 * 2 == 18 HTH you on your way, Mark. Caroline Keef wrote: Dear all, I've come across a problem using strptime, can anyone explain what's going on? I'm using version 2.7.0 on Windows XP. Thank you Caroline First read in a data file using read.table alldata = read.table(file, header=F, skip=4, colClasses = c(character,numeric)) dim(alldata) [1] 223960 2 # inefficient, safe way of sorting out missing or dodgy data alldata[,2][alldata[,2] 0] = NA # first ten lines of the data alldata[1:10,] V1V2 1 19800604062759NA 2 19800604062800 0.271 3 19800604111900 0.286 4 19800604134300 0.362 5 19800604144400 0.465 6 19800604163300 0.510 7 19800604175400 0.518 8 19800604185100 0.526 9 1980060900NA 10 1980060959NA #Then convert the first column using strptime datetimes = strptime(alldata[,1],format=%Y%m%d%H%M%S) #Then I want to get minimum and maximum, but some seem to be missing when they aren't. length(as.POSIXlt(datetimes)) #also equal to length(datetimes) [1] 9 # Why isn't this 223960? Is it something to do with the class? # This is the really puzzling bit (to me anyway) a =(1:223960)[is.na(datetimes)] # which gives 1462 14295 18744 50499 50500 92472 92473 92474 92475 92476 137525 137526 137527 171066 171067 192353 # 16 values alldata[a,] V1V2 1462 19810329012000 0.983 14295 19900325014300 0.219 18744 19920329014300 0.246 50499 19960331013000 0.564 50500 19960331015700 0.563 92472 19970330010200 0.173 92473 19970330011400 0.172 92474 19970330012700 0.172 92475 19970330014400 0.172 92476 19970330015500 0.172 137525 19980329011600 0.427 137526 19980329014100 0.427 137527 19980329015600 0.427 171066 19990328010300 0.223 171067 19990328011800 0.223 192353 2326012800 0.189 datetimes[a] [1] 1981-03-29 01:20:00 1990-03-25 01:43:00 1992-03-29 01:43:00 1996-03-31 01:30:00 1996-03-31 01:57:00 [6] 1997-03-30 01:02:00 1997-03-30 01:14:00 1997-03-30 01:27:00 1997-03-30 01:44:00 1997-03-30 01:55:00 [11] 1998-03-29 01:16:00 1998-03-29 01:41:00 1998-03-29 01:56:00 1999-03-28 01:03:00 1999-03-28 01:18:00 [16] 2000-03-26 01:28:00 # They're all around the end of March! I've looked at the data file and I can't see anything funny in it around these dates. The first few lines of the data file look like #TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELVIN|*|CNR98808|*| #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| #RTYPEinstantaneous values|*| 19800604062759 -777.0 19800604062800 0.271 19800604111900 0.286 19800604134300 0.362 19800604144400 0.465 19800604163300 0.510 19800604175400 0.518 19800604185100 0.526 1980060900 -777.0 1980060959 -777.0 1980061000 0.100 19800611211400 0.096 1980061200 0.096 19800612065000 0.098 19800612133400 0.100 Caroline KeefJBA Consulting South Barn, Broughton Hall, Skipton, North Yorkshire, BD23 3AE, UK t: +44 (0)1756 799919 f: +44 (0)1756 799449 JBA Consulting now incorporates Maslen Environmental, the award winning environmental regeneration consultancy. http://www.maslen-environmental.com. JBA is a Carbon Neutral Company. Please don't print this e-mail unless you really need to. This email is covered by JBA Consulting's email disclaimer at www.jbaconsulting.co.uk/emaildisclaimer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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://www.nabble.com/Strptime--date-time-classes-tp18362221p18365531.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,
Re: [R] Port package
A more accurate wording, I believe, would be Port Library see: http://www.bell-labs.com/project/PORT/ Martin will correct me if there really is a package!! Unfortunately, the licensing link is broken on the URL above and it would be interesting to know what the status of licensing really is, since there were/are lots of useful things in this library. url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Jul 9, 2008, at 11:42 AM, Jos Kaefer wrote: Hi When I type: ?nls I come across this section: algorithm: character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm. Other possible values are 'plinear' for the Golub-Pereyra algorithm for partially linear least-squares models and 'port' for the 'nl2sol' algorithm from the Port package. The simple question is: where's the Port package? I can't find it on cran. Thanks, Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question regarding lu in package Matrix
Dear R-helpers, I have a question regarding LU-decomposition with function lu in package Matrix. The following simple example confuses me: Why is as.matrix(elu$U) not an upper triangular matrix? u3 - matrix(c(1,1,1,1,1,1,-1,1,0,0,0,0,0,-1,1,0,0,0,-1,0,1,0,0,0,0,0,-1,1,0,0),5,6,byrow=T) elu - expand(lu(Matrix(u3,sparse=F))) as.matrix(elu$U) I only have very limited experience with the package and its different types of matrices, and I am lost where to start looking for a reason. Regards, Ulrike Grömping -- View this message in context: http://www.nabble.com/Question-regarding-lu-in-package-Matrix-tp18366291p18366291.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] Port package
It is not an R package, but rather a collection of Fortran functions that R uses from netlib: http://www.netlib.org/port/ On Wed, 9 Jul 2008, Jos Kaefer wrote: Hi When I type: ?nls I come across this section: algorithm: character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm. Other possible values are 'plinear' for the Golub-Pereyra algorithm for partially linear least-squares models and 'port' for the 'nl2sol' algorithm from the Port package. The simple question is: where's the Port package? I can't find it on cran. Thanks, Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Port package
A little more googling reveals: The Port 3 Library is now available via netlib and licensing arrangements are specified here: http://www.netlib.org/port/readme url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Jul 9, 2008, at 11:55 AM, roger koenker wrote: A more accurate wording, I believe, would be Port Library see: http://www.bell-labs.com/project/PORT/ Martin will correct me if there really is a package!! Unfortunately, the licensing link is broken on the URL above and it would be interesting to know what the status of licensing really is, since there were/are lots of useful things in this library. url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Jul 9, 2008, at 11:42 AM, Jos Kaefer wrote: Hi When I type: ?nls I come across this section: algorithm: character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm. Other possible values are 'plinear' for the Golub-Pereyra algorithm for partially linear least-squares models and 'port' for the 'nl2sol' algorithm from the Port package. The simple question is: where's the Port package? I can't find it on cran. Thanks, Jos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] package segmented problem
Hi Alan How your lm model looks like? Are your data stored on a data.frame ? Case yes, send us a str(df). Send us a short sample of the code and a short subset of the data. Cheers, miltinho astronauta brazil On Tue, Jul 8, 2008 at 5:36 AM, Alan Kelly [EMAIL PROTECTED] wrote: Hi, while using package segmented (version 0.2-4) by Vita Muggeo to investigate a possible change point (around time = 222) in admissions for a specific medical condition I had the following error message: fit2.seg-segmented(fit2, seg.Z=~time,psi=222) Error in segmented.lm(fit2, seg.Z = ~time, psi = 222) : (Some) estimated psi out of its range fit2 is a simple lm fit to time. I have used this package successfully for related analyses without this error. Having tried many alternatives to psi=222 but with the same error, I wondered if anyone can assist? Many thanks, Alan Kelly __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] outlining symbol in legend with blackline
# I would like to outline the squares in the legend with a black line. Does anyone know how to do this? x.t - structure(c(5987.387, 4354.516, 3685.789, 6478.592, 5924.315, NA, 8386, 5559.468, NA, 4651.273, 3967.5, NA, 4339.167, 5053.56, NA, 4631.978, 4808.694, NA, 5217.306, 4017.632, NA, 5846.903, 3969.883, NA, 3867.825, 3910.236, NA, 3886.434, 3782.094, NA, 3959.668, 3961.286, NA, 3848.853, 3711.262, NA), .Dim = c(3L, 12L), .Dimnames = list(c(Year.2006, Year.2007, Year.2008 ), c(January, February, March, April, May, June, July, August, September, October, November, December ))) library(IDPmisc) barplot(x.t, beside=T, ylim=c(0, 4), yaxt=n, ylab=Discharge(cfs), col=grey.colors(3, gamma=4)) axis(side=2, at=c(0,4000 ,7000, 1,15000, 2,25000,3,35000,4)) legend(x=topright, legend=c(2006 mean, 2007 mean, 2008 mean, 1964-2005 mean \n max and min flows ), pch=c(15, 15, 15, 19), col=c(grey.colors(3, gamma=4),black), cex=1.5) box(which=plot, lty=solid) points(2.5, 8313, pch=19, lwd=4) points(6, 9665, pch=19, lwd=4) points(10, 10675, pch=19, lwd=4) points(14, 10303, pch=19, lwd=4) points(18, 7926, pch=19, lwd=4) points(22, 7278, pch=19, lwd=4) points(26, 6472, pch=19, lwd=4) points(30, 6719, pch=19, lwd=4) points(34, 6123, pch=19, lwd=4) points(38, 6280, pch=19, lwd=4) points(42, 6334, pch=19, lwd=4) points(46, 7707, pch=19, lwd=4) #max thurmond flow bar Arrows(2.5, 8229, 2.5, 25580, size=0, sh.lwd=4) Arrows(6, 9555, 6, 28571, size=0, sh.lwd=4) Arrows(10, 10547, 10, 23153, size=0, sh.lwd=4) Arrows(14, 10182, 14, 37591, size=0, sh.lwd=4) Arrows(18, 7847, 18, 22521, size=0, sh.lwd=4) Arrows(22, 7206, 22, 18384, size=0, sh.lwd=4) Arrows(26, 6472, 26, 15489, size=0, sh.lwd=4) Arrows(30, 6719, 30, 16659, size=0, sh.lwd=4) Arrows(34, 6123, 34, 11841, size=0, sh.lwd=4) Arrows(38, 6280, 38, 14282, size=0, sh.lwd=4) Arrows(42, 6334, 42, 17364, size=0, sh.lwd=4) Arrows(46, 7707, 46, 25877, size=0, sh.lwd=4) #min thurmond flow bar Arrows(2.5, 8229, 2.5, 3602, size=0, sh.lwd=4) Arrows(6, 9555, 6, 3377, size=0, sh.lwd=4) Arrows(10, 10547, 10, 3490, size=0, sh.lwd=4) Arrows(14, 10182, 14, 3278, size=0, sh.lwd=4) Arrows(18, 7847, 18, 3579, size=0, sh.lwd=4) Arrows(22, 7206, 22, 3605, size=0, sh.lwd=4) Arrows(26, 6472, 26, 3579, size=0, sh.lwd=4) Arrows(30, 6719, 30, 3734, size=0, sh.lwd=4) Arrows(34, 6123, 34, 3694, size=0, sh.lwd=4) Arrows(38, 6280, 38, 3657, size=0, sh.lwd=4) Arrows(42, 6334, 42, 3287, size=0, sh.lwd=4) Arrows(46, 7707, 46, 3345, size=0, sh.lwd=4) -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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] Question regarding lu in package Matrix
On Wed, Jul 9, 2008 at 12:01 PM, Ulrike Grömping [EMAIL PROTECTED] wrote: Dear R-helpers, I have a question regarding LU-decomposition with function lu in package Matrix. The following simple example confuses me: Why is as.matrix(elu$U) not an upper triangular matrix? u3 - matrix(c(1,1,1,1,1,1,-1,1,0,0,0,0,0,-1,1,0,0,0,-1,0,1,0,0,0,0,0,-1,1,0,0),5,6,byrow=T) elu - expand(lu(Matrix(u3,sparse=F))) as.matrix(elu$U) I get elu$U 5 x 6 Matrix of class dtrMatrix [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1.000 0.000 0.000 0.000 1.000 1.000 [2,] . 2.000 0.000 0.000 1.000 1.000 [3,] . . 1.500 0.000 0.000 0.500 [4,] . . . 1.333 0.000 0.333 [5,] . . . . 0.000 0.000 which is about as upper-triangular as it can be, considering that the original matrix is not square. The help page for 'lu' does say that it gives the triangular decomposition of a square matrix, although the decomposition is defined for non-square. It's just not as useful as it would be for square matrices. Are you suggesting that we should check the argument to lu and report an error if it is not square? I only have very limited experience with the package and its different types of matrices, and I am lost where to start looking for a reason. Regards, Ulrike Grömping -- View this message in context: http://www.nabble.com/Question-regarding-lu-in-package-Matrix-tp18366291p18366291.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] Find the closest value in a list or matrix
I have a long list of numbers [3.4,5.4,3.67,], and I basically want to find the index of the number closest to this number that I have, let's say 5.43. How would I do this without writing a for loop (I have to do this many times for several lists)? Is there a lookup function in R? Thanks! -- View this message in context: http://www.nabble.com/Find-the-closest-value-in-a-list-or-matrix-tp18363290p18363290.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] rollmean()
Hello, I am trying to calculate a 31 day running mean in some temperature data along ROWS. Rollmean() works great along columns, but how do I perform this same action on my rows? The data is a matrix of 365 columns (days of the year) by 5,000 rows (lat/long coordinates). I would like to perform a 31 day running mean along the 365 days. I am new to R so any help would be greatly appreciated! Thanks alot, Rheannon -- View this message in context: http://www.nabble.com/rollmean%28%29-tp18366044p18366044.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] Summary Stats (not summary(x))
Thanks for your replies. basicStats(x) in fBasics is exactly what I was looking for. nmarti wrote: I'm looking for a function that lists a few summary stats for a column (or row) of data. I'm aware of summary(x), but that does not give me what I'm looking for. I'm actually looking for something that is very similar to the descriptive statistics tool in excel; i.e. Mean, Std. Error, Std. Deviation, Kurtosis. I'm positive that I came across a function that did this (possibly in Rmetrics), but now I can't find it. I lost it in the endless mass of R functions. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Summary-Stats-%28not-summary%28x%29%29-tp18363275p18363415.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] build matrix with the content of one column of a data frame in function of two factors
Seems that the following makes what I want : attach(votesredac) tapply(value, list(name, content_id), mean) Only thing is, I don't need to make a mean - there is only one or no value. VinceD wrote: Hello, First, thanks for your help (and sorry for my english !) I have a data frame in which each row represents a vote (in percent, only 20,40, 60,80,100) of one person on one content, with three columns : name (the name of the voters), content_id, vote : str(votesredac) 'data.frame': 1000 obs. of 3 variables: $ name : chr Guillemette Faure Guillemette Faure Guillemette Faure Pascal Rich\xe9 ... $ content_id: num 385241 384926 384635 383266 384814 ... $ value : num 100 100 100 20 100 100 20 100 100 100 ... I want to build a matrix with one column for each content and one line for each user, containing the votes. This matrix can content NAs (each person hasn't voted on all contents). If each row and column was labelled, would be better. Thanks again ! -- View this message in context: http://www.nabble.com/build-matrix-with-the-content-of-one-column-of-a-data-frame-in-function-of-two-factors-tp18364752p18366233.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] build matrix with the content of one column of a data frame in function of two factors
Hello, First, thanks for your help (and sorry for my english !) I have a data frame in which each row represents a vote (in percent, only 20,40, 60,80,100) of one person on one content, with three columns : name (the name of the voters), content_id, vote : str(votesredac) 'data.frame': 1000 obs. of 3 variables: $ name : chr Guillemette Faure Guillemette Faure Guillemette Faure Pascal Rich\xe9 ... $ content_id: num 385241 384926 384635 383266 384814 ... $ value : num 100 100 100 20 100 100 20 100 100 100 ... I want to build a matrix with one column for each content and one line for each user, containing the votes. This matrix can content NAs (each person hasn't voted on all contents). If each row and column was labelled, would be better. Thanks again ! -- View this message in context: http://www.nabble.com/build-matrix-with-the-content-of-one-column-of-a-data-frame-in-function-of-two-factors-tp18364752p18364752.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 the closest value in a list or matrix
Try this: which.min(abs(x - 5.43)) where x is your vector of numbers. On Wed, Jul 9, 2008 at 12:28 PM, R_Learner [EMAIL PROTECTED] wrote: I have a long list of numbers [3.4,5.4,3.67,], and I basically want to find the index of the number closest to this number that I have, let's say 5.43. How would I do this without writing a for loop (I have to do this many times for several lists)? Is there a lookup function in R? Thanks! -- View this message in context: http://www.nabble.com/Find-the-closest-value-in-a-list-or-matrix-tp18363290p18363290.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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Strptime/ date time classes
Thank you, but why does this happen? a =(1:223960)[is.na(datetimes)] datetimes[a] [1] 1981-03-29 01:20:00 1990-03-25 01:43:00 1992-03-29 01:43:00 1996-03-31 01:30:00 1996-03-31 01:57:00 [6] 1997-03-30 01:02:00 1997-03-30 01:14:00 1997-03-30 01:27:00 1997-03-30 01:44:00 1997-03-30 01:55:00 [11] 1998-03-29 01:16:00 1998-03-29 01:41:00 1998-03-29 01:56:00 1999-03-28 01:03:00 1999-03-28 01:18:00 [16] 2000-03-26 01:28:00 Which obviously aren't missing. I do want POSIXlt as I need to extract the day of the month (I'm extracting daily maxima from irregulrly observed time series). This seems like a bug to me, I just thought I'd check with people who know more than I do. Caroline -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: 09 July 2008 17:24 To: Caroline Keef Cc: r-help@r-project.org Subject: Re: [R] Strptime/ date time classes You probably want POSIXct instead of POSIXlt: x - read.table(textConnection(#TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELV IN|*|CNR98808|*| + #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| + #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| + #RTYPEinstantaneous values|*| + 19800604062759 -777.0 + 19800604062800 0.271 + 19800604111900 0.286 + 19800604134300 0.362 + 19800604144400 0.465 + 19800604163300 0.510 + 19800604175400 0.518 + 19800604185100 0.526 + 1980060900 -777.0 + 1980060959 -777.0 + 1980061000 0.100 + 19800611211400 0.096 + 1980061200 0.096 + 19800612065000 0.098 + 19800612133400 0.100),colClasses=c('character','numeric')) closeAllConnections() # you probably want POSIXct not POSIXlt datetimes - as.POSIXct(strptime(x[,1], %Y%m%d%H%M%S)) str(datetimes) POSIXct[1:15], format: 1980-06-04 06:27:59 1980-06-04 06:28:00 1980-06-04 11:19:00 ... length(datetimes) [1] 15 On Wed, Jul 9, 2008 at 6:09 AM, Caroline Keef [EMAIL PROTECTED] wrote: Dear all, I've come across a problem using strptime, can anyone explain what's going on? I'm using version 2.7.0 on Windows XP. Thank you Caroline First read in a data file using read.table alldata = read.table(file, header=F, skip=4, colClasses = c(character,numeric)) dim(alldata) [1] 223960 2 # inefficient, safe way of sorting out missing or dodgy data alldata[,2][alldata[,2] 0] = NA # first ten lines of the data alldata[1:10,] V1V2 1 19800604062759NA 2 19800604062800 0.271 3 19800604111900 0.286 4 19800604134300 0.362 5 19800604144400 0.465 6 19800604163300 0.510 7 19800604175400 0.518 8 19800604185100 0.526 9 1980060900NA 10 1980060959NA #Then convert the first column using strptime datetimes = strptime(alldata[,1],format=%Y%m%d%H%M%S) #Then I want to get minimum and maximum, but some seem to be missing when they aren't. length(as.POSIXlt(datetimes)) #also equal to length(datetimes) [1] 9 # Why isn't this 223960? Is it something to do with the class? # This is the really puzzling bit (to me anyway) a =(1:223960)[is.na(datetimes)] # which gives 1462 14295 18744 50499 50500 92472 92473 92474 92475 92476 137525 137526 137527 171066 171067 192353 # 16 values alldata[a,] V1V2 1462 19810329012000 0.983 14295 19900325014300 0.219 18744 19920329014300 0.246 50499 19960331013000 0.564 50500 19960331015700 0.563 92472 19970330010200 0.173 92473 19970330011400 0.172 92474 19970330012700 0.172 92475 19970330014400 0.172 92476 19970330015500 0.172 137525 19980329011600 0.427 137526 19980329014100 0.427 137527 19980329015600 0.427 171066 19990328010300 0.223 171067 19990328011800 0.223 192353 2326012800 0.189 datetimes[a] [1] 1981-03-29 01:20:00 1990-03-25 01:43:00 1992-03-29 01:43:00 1996-03-31 01:30:00 1996-03-31 01:57:00 [6] 1997-03-30 01:02:00 1997-03-30 01:14:00 1997-03-30 01:27:00 1997-03-30 01:44:00 1997-03-30 01:55:00 [11] 1998-03-29 01:16:00 1998-03-29 01:41:00 1998-03-29 01:56:00 1999-03-28 01:03:00 1999-03-28 01:18:00 [16] 2000-03-26 01:28:00 # They're all around the end of March! I've looked at the data file and I can't see anything funny in it around these dates. The first few lines of the data file look like #TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELVIN|*|CNR98808|*| #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| #RTYPEinstantaneous values|*| 19800604062759 -777.0 19800604062800 0.271 19800604111900 0.286 19800604134300 0.362 19800604144400 0.465 19800604163300 0.510 19800604175400 0.518 19800604185100 0.526 1980060900 -777.0 1980060959 -777.0 1980061000 0.100 19800611211400 0.096 1980061200 0.096 19800612065000 0.098 19800612133400 0.100 Caroline KeefJBA Consulting South Barn, Broughton Hall, Skipton, North Yorkshire, BD23 3AE, UK t: +44 (0)1756 799919 f: +44 (0)1756 799449 JBA Consulting now incorporates Maslen Environmental,
Re: [R] Find the closest value in a list or matrix
x=c(1:100) your.number=5.43 which(abs(x-your.number)==min(abs(x-your.number))) Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von R_Learner Gesendet: Wednesday, July 09, 2008 11:28 AM An: r-help@r-project.org Betreff: [R] Find the closest value in a list or matrix I have a long list of numbers [3.4,5.4,3.67,], and I basically want to find the index of the number closest to this number that I have, let's say 5.43. How would I do this without writing a for loop (I have to do this many times for several lists)? Is there a lookup function in R? Thanks! -- View this message in context: http://www.nabble.com/Find-the-closest-value-in-a-list-or-matrix-tp18363290p 18363290.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] rbinom for a matrix
I have a large matrix full of probabilities; I would like to convert each probability to a 1 or a 0 using rbinom. How can I do this on the entire matrix? The matrix was converted from a raster ArcMap dataset, so the matrix is essentially a map. Because of this, I have no column headings. Thanks! -- View this message in context: http://www.nabble.com/rbinom-for-a-matrix-tp18366867p18366867.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] rollmean()
See ?t On Wed, Jul 9, 2008 at 12:50 PM, Rheannon [EMAIL PROTECTED] wrote: Hello, I am trying to calculate a 31 day running mean in some temperature data along ROWS. Rollmean() works great along columns, but how do I perform this same action on my rows? The data is a matrix of 365 columns (days of the year) by 5,000 rows (lat/long coordinates). I would like to perform a 31 day running mean along the 365 days. I am new to R so any help would be greatly appreciated! Thanks alot, Rheannon -- View this message in context: http://www.nabble.com/rollmean%28%29-tp18366044p18366044.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] rollmean()
I am going to assume your data.frame is called x #this transposes the matrix x.t - t(x) rollmean(x.t) On Wed, Jul 9, 2008 at 12:50 PM, Rheannon [EMAIL PROTECTED] wrote: Hello, I am trying to calculate a 31 day running mean in some temperature data along ROWS. Rollmean() works great along columns, but how do I perform this same action on my rows? The data is a matrix of 365 columns (days of the year) by 5,000 rows (lat/long coordinates). I would like to perform a 31 day running mean along the 365 days. I am new to R so any help would be greatly appreciated! Thanks alot, Rheannon -- View this message in context: http://www.nabble.com/rollmean%28%29-tp18366044p18366044.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. -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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] garchFit problem
Hi, I have a problem using garchFit, when I use : x-model$resid fit = garchFit(~garch(1, 1), data = x, cond.dist=dst) [EMAIL PROTECTED] it gives me error : object fit not found Why it doesn't recognize fit? Thanks, Shirin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] question on FARIMA innovations
Hello everyone - I am currently modeling some data with ARIMA(p,d,q), and have successfully used the fracdiff package to obtain estimates for d and the ARMA parameters. However, I don't know how to get fracdiff to obtain innovations for me. Can fracdiff even do this? Can any other package? Please help me if you can, and thank you for your time. Respectfully, Ferebee Tunno __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sweave figure
Hi, I have a problem using figures in Sweave: To save my figures, I use \SweaveOpts{prefix.string=figures/figure} I adjust the figure size for my pdf document using graphicsFun, fig=TRUE, echo=FALSE, height=10, width=5, eval=TRUE= this works fine. The file figures/figure-graphicsFun.pdf has the right size, and so has the figure in the final pdf document. The problem is, that during Sweave'ing, the plot is printed also to the active x11 device, which has default size settings. In some cases, this results in an error, because some parameters (e.g. margins) might not be compatible with the default size. I think the best solution would be to supress printing to the x11 device by that code chunk, since I do not really need this side effect, but I have not found how to do this and do not know if this is possible. Any hints? Best, Georg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot gam main effect functions in one graph
Hi, there may be a more elegant way of doing this, but at least it works. You have to be careful about putting the same axis limits in both graphs and to use axis-labels in only one of them. ##generate data x1=c(1:100) e1=rnorm(100,0,10) e2=rnorm(100,0,30) x1=x1+e1 x2=x1+e2 y1=100+x1+0.025*x1^2+e1 y2=100+x1+0.025*x1^2+e2 ##run gam library(mgcv) reg1=gam(y1~s(x1)) reg2=gam(y2~s(x2)) ##plot plot(reg1,col=blue,xlim=c(-70,200),ylim=c(-300,400),xlab=x,ylab=y) par(new=TRUE) plot(reg2,col=red,xlim=c(-70,200),ylim=c(-300,400),xlab=NA,ylab=NA) Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Pancrazio Bertaccini Gesendet: Wednesday, July 09, 2008 6:37 AM An: R-help@r-project.org Betreff: [R] plot gam main effect functions in one graph Dear R users, I have a question about the plot with the package gam. I need to plot different main effect functions, related to different gam models, in the same graphics (i.e. the same covariate about different models). I used the plot.gam e preplot.gam documentations. Using preplot.gam I can plot the single function but I'm not able to put all the functions together. Does anybody can help me. Thank you in advance. Pancrazio Bertaccini, PhD student, Università di Torino - Department of Statistics and Applied Mathematics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rotated Lat-Lon projection in mapproj
Hi, I'm trying to plot a field obtained from the atmospheric model WRF-NMM which uses a Rotated Lat-Lon¨ map projection. The WRF documentation mentions that: · Rotates the earth's lat/lon grid such that the intersection of the equator and prime meridian is at the center of the model domain. · Within the rotated framework the grid spacing is constant, but in an earth-relative sense, the scale varies slightly. I haven't identified a projection in library mapproj that can handle this. Any ideas on how to plot this field on a map? A typical R script to plot other outputs in a lambert projection would be: ##Read lat/lon data lat-as.numeric(system(paste(pycmd,'control',20010815,LATITCRS,1,0,sep= ),intern=TRUE)) lon-as.numeric(system(paste(pycmd,'control',20010815,LONGICRS,1,0,sep= ),intern=TRUE)) ## Projected coordinates coords_lamb-mapproject(lon,lat,projection=lambert,parameters=c(60.,30.)) xs-t(matrix(coords_lamb$x,ncol=NCC,nrow=NRC))[,1] ys-t(matrix(coords_lamb$y,ncol=NCC,nrow=NRC))[1,]} ## Plot map filled.contour(xs,ys,Tsd[,,tstep],levels=fillevs,col=cpal,plot.axes={ map('world',projection=lambert,parameter=c(60.,30.),add=TRUE,col=grey); contour(xs,ys,Tm[,,tstep]-273.15,levels=c(-20:20)*3,add=TRUE); axis(1,labels=F,tick=F);axis(2,labels=F,tick=F)},main=title) #,asp=1.) Appreciate your help in advance, Víctor. -- --- Víctor Homar Santaner Grup de Meteorologia Edif. Mateu Orfila Tel: +34 971 17 1376 Universitat de les Illes BalearsFax: +34 971 17 3426 07122 Palma de Mallorca (SPAIN) Email: [EMAIL PROTECTED] Knowledge is contagious. Infect truth. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rbinom for a matrix
ACroske Audy3272 at yahoo.com writes: I have a large matrix full of probabilities; I would like to convert each probability to a 1 or a 0 using rbinom. How can I do this on the entire matrix? The matrix was converted from a raster ArcMap dataset, so the matrix is essentially a map. Because of this, I have no column headings. Thanks! How about matrix(rbinom(length(m),prob=m,size=1),nrow=nrow(m)) or (perhaps marginally more efficiently?) y - (runif(m)m) storage.mode(y) - double Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] outlining symbol in legend with blackline
yes use plotting chars 22, 21 replace your legend statement with: legend(x=topright, legend=c(2006 mean, 2007 mean, 2008 mean, 1964-2005 mean \n max and min flows ), pch=c(22, 22, 22, 21), col=c(1,1,1,1), pt.bg=c(grey.colors(3, gamma=4),black), cex=1.5) box(which=plot, lty=solid) thnaks y stephen sefick wrote: # I would like to outline the squares in the legend with a black line. Does anyone know how to do this? x.t - structure(c(5987.387, 4354.516, 3685.789, 6478.592, 5924.315, NA, 8386, 5559.468, NA, 4651.273, 3967.5, NA, 4339.167, 5053.56, NA, 4631.978, 4808.694, NA, 5217.306, 4017.632, NA, 5846.903, 3969.883, NA, 3867.825, 3910.236, NA, 3886.434, 3782.094, NA, 3959.668, 3961.286, NA, 3848.853, 3711.262, NA), .Dim = c(3L, 12L), .Dimnames = list(c(Year.2006, Year.2007, Year.2008 ), c(January, February, March, April, May, June, July, August, September, October, November, December ))) library(IDPmisc) barplot(x.t, beside=T, ylim=c(0, 4), yaxt=n, ylab=Discharge(cfs), col=grey.colors(3, gamma=4)) axis(side=2, at=c(0,4000 ,7000, 1,15000, 2,25000,3,35000,4)) legend(x=topright, legend=c(2006 mean, 2007 mean, 2008 mean, 1964-2005 mean \n max and min flows ), pch=c(15, 15, 15, 19), col=c(grey.colors(3, gamma=4),black), cex=1.5) box(which=plot, lty=solid) points(2.5, 8313, pch=19, lwd=4) points(6, 9665, pch=19, lwd=4) points(10, 10675, pch=19, lwd=4) points(14, 10303, pch=19, lwd=4) points(18, 7926, pch=19, lwd=4) points(22, 7278, pch=19, lwd=4) points(26, 6472, pch=19, lwd=4) points(30, 6719, pch=19, lwd=4) points(34, 6123, pch=19, lwd=4) points(38, 6280, pch=19, lwd=4) points(42, 6334, pch=19, lwd=4) points(46, 7707, pch=19, lwd=4) #max thurmond flow bar Arrows(2.5, 8229, 2.5, 25580, size=0, sh.lwd=4) Arrows(6, 9555, 6, 28571, size=0, sh.lwd=4) Arrows(10, 10547, 10, 23153, size=0, sh.lwd=4) Arrows(14, 10182, 14, 37591, size=0, sh.lwd=4) Arrows(18, 7847, 18, 22521, size=0, sh.lwd=4) Arrows(22, 7206, 22, 18384, size=0, sh.lwd=4) Arrows(26, 6472, 26, 15489, size=0, sh.lwd=4) Arrows(30, 6719, 30, 16659, size=0, sh.lwd=4) Arrows(34, 6123, 34, 11841, size=0, sh.lwd=4) Arrows(38, 6280, 38, 14282, size=0, sh.lwd=4) Arrows(42, 6334, 42, 17364, size=0, sh.lwd=4) Arrows(46, 7707, 46, 25877, size=0, sh.lwd=4) #min thurmond flow bar Arrows(2.5, 8229, 2.5, 3602, size=0, sh.lwd=4) Arrows(6, 9555, 6, 3377, size=0, sh.lwd=4) Arrows(10, 10547, 10, 3490, size=0, sh.lwd=4) Arrows(14, 10182, 14, 3278, size=0, sh.lwd=4) Arrows(18, 7847, 18, 3579, size=0, sh.lwd=4) Arrows(22, 7206, 22, 3605, size=0, sh.lwd=4) Arrows(26, 6472, 26, 3579, size=0, sh.lwd=4) Arrows(30, 6719, 30, 3734, size=0, sh.lwd=4) Arrows(34, 6123, 34, 3694, size=0, sh.lwd=4) Arrows(38, 6280, 38, 3657, size=0, sh.lwd=4) Arrows(42, 6334, 42, 3287, size=0, sh.lwd=4) Arrows(46, 7707, 46, 3345, size=0, sh.lwd=4) -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/outlining-symbol-in-legend-with-blackline-tp18367274p18368074.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] Read.table - Less rows than original data
Dear all, I have problem when reading a table into R. The total row of read in table has is much less than the original saved table. I built a 1,273,230 by 6 data set named mydata2, it was saved in the following command, write.table(mydata2, mydata2.txt, row.name=F,col.name=T,quote=F,sep=\t) The next day I read in above saved text file into R, temp-read.table(mydata2.txt,header=T,sep=\t,na.strings=NA) However, the dimension of temp is 636,615 X 6. Do yo know why? Thanks for your attention. Sityee [[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] rbinom for a matrix
Is this what you're looking for? test - matrix(runif(100, 0, 1), nrow = 20) nr - nrow(test) matrix(sapply(test, rbinom, n = 1, size = 1), nrow = nr) ACroske wrote: I have a large matrix full of probabilities; I would like to convert each probability to a 1 or a 0 using rbinom. How can I do this on the entire matrix? The matrix was converted from a raster ArcMap dataset, so the matrix is essentially a map. Because of this, I have no column headings. Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Strptime/ date time classes
Even using POSIXlt it seems to work fine when you are looking for NAs in the dates (ones that did not convert correctly. So you must be doing something different or your data is different from the example you have in the mail. You are always requested to provide commented, minimal, self-contained, reproducible code. x - read.table(textConnection(#TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELVIN|*|CNR98808|*| + #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| + #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| + #RTYPEinstantaneous values|*| + 19800604062759 -777.0 + 19800604062800 0.271 + 19800604111900 0.286 + 19800604134300 0.362 + 19800604144400 0.465 + 19800604163300 0.510 + 19800604175400 0.518 + 19800604185100 0.526 + 060900 -777.0 + 1980060959 -777.0 + 1980061000 0.100 + 19800611211400 0.096 + 1980061200 0.096 + 19800612065000 0.098 + 19800612133400 0.100),colClasses=c('character','numeric')) closeAllConnections() # you probably want POSIXct not POSIXlt datetimes - (strptime(x[,1], %Y%m%d%H%M%S)) str(datetimes) POSIXlt[1:9], format: 1980-06-04 06:27:59 1980-06-04 06:28:00 1980-06-04 11:19:00 ... length(datetimes) [1] 9 a - (1:15)[is.na(datetimes)] datetimes[a] [1] NA On Wed, Jul 9, 2008 at 1:18 PM, Caroline Keef [EMAIL PROTECTED] wrote: Thank you, but why does this happen? a =(1:223960)[is.na(datetimes)] datetimes[a] [1] 1981-03-29 01:20:00 1990-03-25 01:43:00 1992-03-29 01:43:00 1996-03-31 01:30:00 1996-03-31 01:57:00 [6] 1997-03-30 01:02:00 1997-03-30 01:14:00 1997-03-30 01:27:00 1997-03-30 01:44:00 1997-03-30 01:55:00 [11] 1998-03-29 01:16:00 1998-03-29 01:41:00 1998-03-29 01:56:00 1999-03-28 01:03:00 1999-03-28 01:18:00 [16] 2000-03-26 01:28:00 Which obviously aren't missing. I do want POSIXlt as I need to extract the day of the month (I'm extracting daily maxima from irregulrly observed time series). This seems like a bug to me, I just thought I'd check with people who know more than I do. Caroline -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: 09 July 2008 17:24 To: Caroline Keef Cc: r-help@r-project.org Subject: Re: [R] Strptime/ date time classes You probably want POSIXct instead of POSIXlt: x - read.table(textConnection(#TZUTC+0|*|SANR08002|*|SNAMENAUL|*|SWATERDELV IN|*|CNR98808|*| + #CNAMEQ|*|CTYPEn-min-ip|*|CMW1440|*|RTIMELVLhigh-resolution|*| + #CUNITm3/s|*|RINVAL-777|*|RNR-1|*|REXCHANGE98913|*| + #RTYPEinstantaneous values|*| + 19800604062759 -777.0 + 19800604062800 0.271 + 19800604111900 0.286 + 19800604134300 0.362 + 19800604144400 0.465 + 19800604163300 0.510 + 19800604175400 0.518 + 19800604185100 0.526 + 1980060900 -777.0 + 1980060959 -777.0 + 1980061000 0.100 + 19800611211400 0.096 + 1980061200 0.096 + 19800612065000 0.098 + 19800612133400 0.100),colClasses=c('character','numeric')) closeAllConnections() # you probably want POSIXct not POSIXlt datetimes - as.POSIXct(strptime(x[,1], %Y%m%d%H%M%S)) str(datetimes) POSIXct[1:15], format: 1980-06-04 06:27:59 1980-06-04 06:28:00 1980-06-04 11:19:00 ... length(datetimes) [1] 15 On Wed, Jul 9, 2008 at 6:09 AM, Caroline Keef [EMAIL PROTECTED] wrote: Dear all, I've come across a problem using strptime, can anyone explain what's going on? I'm using version 2.7.0 on Windows XP. Thank you Caroline First read in a data file using read.table alldata = read.table(file, header=F, skip=4, colClasses = c(character,numeric)) dim(alldata) [1] 223960 2 # inefficient, safe way of sorting out missing or dodgy data alldata[,2][alldata[,2] 0] = NA # first ten lines of the data alldata[1:10,] V1V2 1 19800604062759NA 2 19800604062800 0.271 3 19800604111900 0.286 4 19800604134300 0.362 5 19800604144400 0.465 6 19800604163300 0.510 7 19800604175400 0.518 8 19800604185100 0.526 9 1980060900NA 10 1980060959NA #Then convert the first column using strptime datetimes = strptime(alldata[,1],format=%Y%m%d%H%M%S) #Then I want to get minimum and maximum, but some seem to be missing when they aren't. length(as.POSIXlt(datetimes)) #also equal to length(datetimes) [1] 9 # Why isn't this 223960? Is it something to do with the class? # This is the really puzzling bit (to me anyway) a =(1:223960)[is.na(datetimes)] # which gives 1462 14295 18744 50499 50500 92472 92473 92474 92475 92476 137525 137526 137527 171066 171067 192353 # 16 values alldata[a,] V1V2 1462 19810329012000 0.983 14295 19900325014300 0.219 18744 19920329014300 0.246 50499 19960331013000 0.564 50500 19960331015700 0.563 92472 19970330010200 0.173 92473 19970330011400 0.172 92474 19970330012700 0.172 92475 19970330014400 0.172 92476 19970330015500 0.172 137525 19980329011600 0.427 137526 19980329014100 0.427 137527 19980329015600 0.427 171066 19990328010300 0.223 171067
Re: [R] rbinom for a matrix
On Wednesday 09 July 2008, Ben Bolker wrote: ACroske Audy3272 at yahoo.com writes: I have a large matrix full of probabilities; I would like to convert each probability to a 1 or a 0 using rbinom. How can I do this on the entire matrix? The matrix was converted from a raster ArcMap dataset, so the matrix is essentially a map. Because of this, I have no column headings. Thanks! How about matrix(rbinom(length(m),prob=m,size=1),nrow=nrow(m)) or (perhaps marginally more efficiently?) y - (runif(m)m) storage.mode(y) - double Ben Bolker Wait a second. Are you trying to convert each probability into the most likely '1' or '0' through rounding? The code example above will give you a different answer every time you run it. Is that what you are looking for? Just curious, Dylan -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 the closest value in a list or matrix
Daniel Malter wrote: x=c(1:100) your.number=5.43 which(abs(x-your.number)==min(abs(x-your.number))) or [depending on the problem]: which.min(abs(x-your.number)) HTH, Tobias - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von R_Learner Gesendet: Wednesday, July 09, 2008 11:28 AM An: r-help@r-project.org Betreff: [R] Find the closest value in a list or matrix I have a long list of numbers [3.4,5.4,3.67,], and I basically want to find the index of the number closest to this number that I have, let's say 5.43. How would I do this without writing a for loop (I have to do this many times for several lists)? Is there a lookup function in R? Thanks! -- View this message in context: http://www.nabble.com/Find-the-closest-value-in-a-list-or-matrix-tp18363290p 18363290.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] netCDF to TIFF
the function is there in grDevices http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/png.html type ? png if tiff() is not listed, you need to update R to get the new base with new grDevices. thanks y Daniel Steinberg wrote: Greetings R users! I am working with the ENSEMBLE climate data (10 min resolution daily temperatures images for all of Europe 1950-2006). The data comes packaged in a single netCDF file. I would like to read the data in and export a subset (2002-2006) as geotiffs (one image per day). So far, I can successfully read in the data and view the images within an R display window. However, I have yet to figure out how to export the images as tiffs or geotiffs. Does anyone out there have experience converting netCDF grids to TIFFs? After reading the data into R, I have it stored in a dataframe with longitude values as the column names, latitude values as the row names, and temperatures as the actual values. Below is my code thus far that I adapted from an example on the UCAR website. Thanks in advance! -Dan -- # Set working directory and load library setwd('C:/Users/steinber/Documents/DATA/ENSEMBLES/') library(ncdf) library(rgdal) library(chron) library(fields) # Read netCDF file tg.ncdf = open.ncdf('tg_0.25deg_CRU_version1.0.nc') tg.ncdf lonmat = get.var.ncdf(nc=tg.ncdf,varid=longitude) # reads entire matrix latmat = get.var.ncdf(nc=tg.ncdf,varid=latitude)# ditto timearr = get.var.ncdf(nc=tg.ncdf,varid=time)# reads entire time array targettime = julian(x=1, d=1, y=2002, origin=c(month = 1, day = 1, year = 1950)) inds = (1:dim(timearr)) tind = inds[targettime == timearr] ndims= tg.ncdf$var[['data']]$ndims varsize = tg.ncdf$var[['data']]$varsize start = c(1, 1, tind) count = c(varsize[1], varsize[2],1) # Read in data slice: tg.data = get.var.ncdf(nc=tg.ncdf,varid=data,start,count) tg.data[tg.data == -] = NA tg.data = tg.data/100.0 x = 1:nrow(tg.data) # R plots rows along X axis! y = 1:ncol(tg.data) image.plot(x,y,tg.data,col=tim.colors()) test.data = data.frame(tg.data, row.names = lonmat) colnames(test.data) = latmat __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/netCDF-to-TIFF-tp18360688p18368372.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] rbinom for a matrix
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dylan Beaudette wrote: | On Wednesday 09 July 2008, Ben Bolker wrote: | ACroske Audy3272 at yahoo.com writes: | I have a large matrix full of probabilities; I would like to convert each | probability to a 1 or a 0 using rbinom. | How can I do this on the entire matrix? The matrix was converted from a | raster ArcMap dataset, so the matrix is essentially a map. Because of | this, I have no column headings. | Thanks! | How about | | matrix(rbinom(length(m),prob=m,size=1),nrow=nrow(m)) | | or (perhaps marginally more efficiently?) | | y - (runif(m)m) | storage.mode(y) - double | | Ben Bolker | | | Wait a second. Are you trying to convert each probability into the most | likely '1' or '0' through rounding? The code example above will give you a | different answer every time you run it. Is that what you are looking for? | | Just curious, | | Dylan | ~ I assumed that since the original poster said convert each probability to a 1 or 0 using rbinom that they did indeed want a random assignment, rather than rounding ... -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFIdRiZc5UpGjwzenMRAuLkAKCA6ZhjrVsg5RJGYFGwq+6vz2pWxgCfetYk 9V/ZPGi2jfVGV5jx+LGPs8s= =d8c9 -END PGP 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] Auto.key colors maintained when subsetting
On 7/9/08 1:07 PM, Deepayan Sarkar [EMAIL PROTECTED] wrote: On 7/9/08, David Afshartous [EMAIL PROTECTED] wrote: All, I'm plotting points and lines for various groups. I'd like subsequent plots done on subsets to maintain the color assignments from the original plot. This works fine, but the key for the subset doesn't maintain the correspondence. One solution is to reprint the entire key, but this is undesirable since then the key has more elements than the groups in the plot. Reproducible example below. Well, the ideal solution would have been for auto.key to magically omit the levels of 'groups' that are omitted by the application of 'subset', but there is not enough information available to it for this to happen. One option is to 1. subset the data beforehand, and drop unsed levels with Group[drop=TRUE] This will work, but unfortunately the color correspondence across plots will be lost. Leading to a preference for your second suggestion: 2. supply colors, etc. explicitly through 'par.settings'. The code below works, but when extended to include error bars (panel.ci, and prepanel.ci), it works for the full data but not the subset. ## full data w/ colors supplied, this works: xyplot(Y ~ Hour, data = dat, pch = 16, groups=Group, col=c('red', 'black', 'green', 'blue'), type=b, auto.key = list(space = top, text = levels(Group), points = FALSE, lines = TRUE, columns=4), par.settings = list(superpose.line = list(lty = c(1,2,3,4), col=c('red', 'black', 'green', 'blue') ) ) ) ## subset of data; this works: dev.new() xyplot(Y ~ Hour, data = dat, pch = 16, subset = (Group != A), groups=Group, col=c('red', 'black', 'green', 'blue'), lty = c(1,2,3,4), type=b, auto.key = list(space = top, text = levels(Group)[2:4], points = FALSE, lines = TRUE, columns=3), par.settings = list(superpose.line = list(lty = c(2,3,4), col=c('black', 'green', 'blue') ) ) ) ## full data w/ error bars, this works: xyplot(Y ~ Hour, data = dat, pch = 16, groups=Group, col=c('red', 'black', 'green', 'blue'), lty = c(1,2,3,4), ly = dat$lower.bound , uy = dat$upper.bound , prepanel = prepanel.ci, panel = panel.superpose, panel.groups = panel.ci, type=b, auto.key = list(space = top, text = levels(Group), points = FALSE, lines = TRUE, columns=4), par.settings = list(superpose.line = list(lty = c(1,2,3,4), col=c('red','black', 'green', 'blue') ) ) ) ## subset of data w/ error bars produces error message: Error using packet ## 1, Invalid Line Type: xyplot(Y ~ Hour, data = dat, pch = 16, subset = (Group != A), groups=Group, col=c('red', 'black', 'green', 'blue'), lty = c(1,2,3,4), ly = dat$lower.bound , uy = dat$upper.bound , prepanel = prepanel.ci, panel = panel.superpose, panel.groups = panel.ci, type=b, auto.key = list(space = top, text = levels(Group)[2:4], points = FALSE, lines = TRUE, columns=3), par.settings = list(superpose.line = list(lty = c(2,3,4), col=c('black', 'green', 'blue') ) ) ) The other option is to construct your own key (i.e., use the 'key' argument, not 'auto.key', to specify the legend). Below is an attempt to use key; although the plot is correct, in the key the color is applied to the text instead of the line and the line type isn't drawn: xyplot(Y ~ Hour, data = dat, pch = 16, subset = (Group != A), groups=Group, col=c('red', 'black', 'green', 'blue'), type=b, key = simpleKey(text = levels(Group)[2:4], lty = c(2,3,4), space = top, columns = 3, points = FALSE, lines = TRUE, col = c('black', 'green', 'blue')) par.settings = list(superpose.line = list(lty = c(1,2,3,4), col=c('red', 'black', 'green', 'blue') ) ) ) # Data and necessary functions: set.seed(101) Y = c(rnorm(4,0), rnorm(4,2), rnorm(4,6), rnorm(4,8)) dat = data.frame( Y , lower.bound = Y - .5, upper.bound = Y + .5, Group = factor(c(rep(A, 4), rep(B, 4), rep(C, 4), rep(D, 4))), Hour = rep(c(1:4), 4) ) prepanel.ci - function(x, y, ly, uy, subscripts, ...) { x - as.numeric(x) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) panel.arrows(x, ly, x, uy, col = black, length = 0.25, unit = native, angle = 90, code = 3) panel.xyplot(x, y, pch = 16, ...)} It should be simple to write a function that constructs a suitable 'key' argument
Re: [R] Question regarding lu in package Matrix
No, not at all, I'm glad that I do get the decomposition for non-square matrices. My problem is not with elu$U but with as.matrix(elu$U), which is not an upper diagonal matrix. Can I do something to fix this ? Regards, Ulrike Douglas Bates-2 wrote: On Wed, Jul 9, 2008 at 12:01 PM, Ulrike Grömping [EMAIL PROTECTED] wrote: Dear R-helpers, I have a question regarding LU-decomposition with function lu in package Matrix. The following simple example confuses me: Why is as.matrix(elu$U) not an upper triangular matrix? u3 - matrix(c(1,1,1,1,1,1,-1,1,0,0,0,0,0,-1,1,0,0,0,-1,0,1,0,0,0,0,0,-1,1,0,0),5,6,byrow=T) elu - expand(lu(Matrix(u3,sparse=F))) as.matrix(elu$U) I get elu$U 5 x 6 Matrix of class dtrMatrix [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1.000 0.000 0.000 0.000 1.000 1.000 [2,] . 2.000 0.000 0.000 1.000 1.000 [3,] . . 1.500 0.000 0.000 0.500 [4,] . . . 1.333 0.000 0.333 [5,] . . . . 0.000 0.000 which is about as upper-triangular as it can be, considering that the original matrix is not square. The help page for 'lu' does say that it gives the triangular decomposition of a square matrix, although the decomposition is defined for non-square. It's just not as useful as it would be for square matrices. Are you suggesting that we should check the argument to lu and report an error if it is not square I only have very limited experience with the package and its different types of matrices, and I am lost where to start looking for a reason. Regards, Ulrike Grömping -- View this message in context: http://www.nabble.com/Question-regarding-lu-in-package-Matrix-tp18366291p18366291.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. -- View this message in context: http://www.nabble.com/Question-regarding-lu-in-package-Matrix-tp18366291p18369646.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 the closest value in a list or matrix
Hi there, Is this what you want? your.number=5.43 # For a vector x=c(1,2,4,3,2,5,6,7,5.42,6) which.min(abs(x-your.number)) [1] 9 # For a matrix set.seed(123) X=matrix(rpois(100,4.5),ncol=10) apply(X,2,function(x) which.min(abs(x-your.number))) [1] 9 3 2 3 2 5 1 2 2 2 HTH, Jorge On Wed, Jul 9, 2008 at 11:28 AM, R_Learner [EMAIL PROTECTED] wrote: I have a long list of numbers [3.4,5.4,3.67,], and I basically want to find the index of the number closest to this number that I have, let's say 5.43. How would I do this without writing a for loop (I have to do this many times for several lists)? Is there a lookup function in R? Thanks! -- View this message in context: http://www.nabble.com/Find-the-closest-value-in-a-list-or-matrix-tp18363290p18363290.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.