Re: [R] prblem with NA
Hi r-help-boun...@r-project.org napsal dne 06.01.2009 02:29:18: Hello - kayj wrote: Hi all I have a data set with the total number of columns =ncol, and the total number of rows=nrow. I am trying to loop over the values and id the value is less than or equal to 100 to be changed to 1. if the value is greater than 100 , to be changed to 0. if NA , let X[i,j]=NA. I ran into a problem where if one row in my data set had all values =NA, then the program does not continue working past that row! At some point I get the following error message: “Error in if (data [i, j] = 100) { : missing value where TRUE/FALSE needed” Here is the program data-read.table(fileName.txt, header=F, sep='\t') X=data for(i in ncol) { for(j in nrow) { if(data[i,j]=100) {X[i,j]=1} if(data[i,j]100) {X[i,j]=0} if(is.na(data[i,j])) {X[i,j]=NA} } } An alternate, vectorized solution may be: X - ifelse(data = 100, 1, 0) Another one X -(da=100)*1 Logical vectors can be treated like numeric with TRUE=1 and FALSE=0, I learned that somewhere but it is not mentioned in help page for ?logical so it is not so easy to find. Regards Petr And as 'data' is a function in the utils package include with R, you might consider not naming your variables 'data'. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] prblem with NA
Wacek Kusnierczyk wrote: Prof Brian Ripley wrote: On Tue, 6 Jan 2009, Petr PIKAL wrote: [...] Logical vectors can be treated like numeric with TRUE=1 and FALSE=0, More accurately, 'like integer' ('numeric' often means 'double'). why would this be more accurate? is(TRUE+0) # numeric, not integer is.integer(TRUE+0) # FALSE ah, that was about literals again: is(TRUE+0L) # integer, not numeric is.integer(TRUE+0L) # TRUE anyway, is.integer(TRUE) # FALSE so how logical vectors will be treated depends on the context, though integer is (or it seems so) closer in the type hierarchy than double. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] hi I have a problem with implementing R-project
Hi, This is Kiran I tried to work on r-project through C#.Net While calling the r-project I got an error that *System.Runtime.InteropServices.COMException(0x80040013):Exception from HRESULT:0x80040013 at STATCONNECTORSRVLib.StatConnectorClass.Init(String bstrConnectorName) at IAG.RD.RcomWrapper.Rcom..ctor() at demo.DemoForm.RcomExecute()* Can any one suggest how can I salve this problem Thanks regards; Kiran. [[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] hi i have a problem with implementing R-Project in C#
Hi, This is Kiran I tried to work on r-project through C#.Net While calling the r-project I got an error that *System.Runtime.InteropServices.COMException(0x80040013):Exception from HRESULT:0x80040013 at STATCONNECTORSRVLib.StatConnectorClass.Init(String bstrConnectorName) at IAG.RD.RcomWrapper.Rcom..ctor() at demo.DemoForm.RcomExecute()* Can any one suggest how can I salve this problem Thanks regards; Kiran. [[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] Changing Matrix Header
Dear all, I have the following matrix. dat A A A A A A A A A A [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 0 2 How can I change it into: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 02 I tried: as.matrix(x) But failed. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing Matrix Header
Hi Gundala, try chopping off the top row like newx-as.matrix(x[2:dim(x)[1],]) OR try changing it to a data frame... new x-data.frame(x,row.names=NULL) #pretty sure its not row.names but there is probably an equivalent for col.names OR look into ?read.table and specify header = F Cheers, Si. - Original Message - From: Gundala Viswanath gunda...@gmail.com To: r-h...@stat.math.ethz.ch Sent: Tuesday, January 06, 2009 8:14 AM Subject: [R] Changing Matrix Header Dear all, I have the following matrix. dat A A A A A A A A A A [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 0 2 How can I change it into: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 02 I tried: as.matrix(x) But failed. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing Matrix Header
Hello, colnames( dat ) - NULL will do the trick. Carlos J. Gil Bellosta http://www.datanalytics.com On Tue, 2009-01-06 at 17:14 +0900, Gundala Viswanath wrote: Dear all, I have the following matrix. dat A A A A A A A A A A [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 0 2 How can I change it into: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 02 I tried: as.matrix(x) But failed. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] problems with ace (ape-package)
Hi everyone I am trying to reconstruct ancestral character states with R. I used the ace function of the package ape. I have discrete characters and tried to use the ER and ARD model. The problem is, that I get negative lik$anc values. Does anybody by chance have an idea what might be wrong? Thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C dll compilation + S Poetry example
On 05/01/2009 11:26 PM, Pedro Mardones wrote: Dear all; Working with the following code extracted from the document S Poetry by Patrick Burns (from CRAN), I haven't been able to load the resulting dll into R. The code is basically the calculation of the quadratic form x'Qx: static double quad_form(double *Q, double *x, long n) { long i, j, ij; double ans = 0.0; for(i=0; i n; i++) { for(j=0, ij = i * n; j n; j++, ij++) { ans = ans + x[i] * Q[ij] * x[j]; } } return(ans); } void quad_form_Sp(double *Q, double *x, long *xdim, double *ans) { long i, ii, n; double quad_form(double*, double*, long); n = xdim[0]; for(i=0, ii=0; i xdim[1]; i++, ii += n) { ans[i] = quad_form(Q, x + ii, n); } } The dll was compiled (in Win XP, R-2.8.1) using the command: rcmd SHLIB qform.c. Then in R I typed: dyn.load(qform.dll) and some other variants but is.loaded(qform) it always returns FALSE. Now I followed the same steps using the convolution example provided by Venables (S Programming book) and it works fine. is.loaded is looking for a symbol name, not a DLL name: you want is.loaded(quad_form_Sp). Duncan Murdoch Can anyone point me out to where could be the problem with the quadratic form example? Thanks PM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Converting data frame to symmetric matrix
Try this: reshape(d, timevar = x, idvar = y, direction = wide) On Tue, Jan 6, 2009 at 6:29 AM, poas...@umich.edu wrote: Dear Sir or Madam, I have the following data frame (which is just a toy example of my larger dataset) L3 - LETTERS[1:3] x=c(1,1,2,2,3,3,4,4,5,5) y=1:10 d - data.frame(cbind(x,y), fac=sample(L3, 10, replace=TRUE)) This data frame produces the following output x y fac 1 1 1 C 2 1 2 C 3 2 3 B 4 2 4 B 5 3 5 C 6 3 6 B 7 4 7 B 8 4 8 C 9 5 9 B 10 5 10 A Is there a command I can use to convert data frame d into a 10 X 10 symmetric matrix where the columns are labeled 1 through 10, the rows are labeled 1 through 10, and the entries in each cell are the corresponding values of fac? For example, the first two columns and rows should have the following entries: 1 2 1 C C 2 C NA Any suggestions will be greatly appreciated. Many thanks, Paul Poast __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 [[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] RODBC connection die - using more than 1 Rgui/Rcmdr
On 05/01/2009 9:26 PM, jaey.ahn wrote: Yes, I am aware of that. RODBC connection is automatically shutting down without any warnings or error message. (That's why I jotted down Oracle error message when trying to reconnect). I don't think it's a matter of Oracle since I've tested many query works simultaneously with multiple windows. I suspect RODBC's stability with multiple windows. That would be a bug, so you should put together a simple example to reproduce it. Avoid Rcmdr, try to just use Rgui and RODBC. The big problem will be the database: if your example requires Oracle, only someone with Oracle will be able to debug it, so try to put together a generic example that works with any database with an ODBC driver. I still suspect Oracle here (it did say internal error after all), so please do demonstrate it on some other database before you conclude it's an RODBC problem. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Trouble using ohlcPlot
Hi, I'm trying to create a time series that will work with ohlcPlot: mts-ts(data=c(results$OpenPrice,results$HighPrice,results$LowPrice, results$ClosePrice),c=mts,names=c(Open, High, Low,Close)) ohlcPlot(mts) fails with: Error in if ((!is.mts(x)) || (colnames(x)[1] != Open) || (colnames(x)[2] != : ... is.mts(mts) returns true but colnames(mts) returns NULL. I've trawled the archive for an example of using this function to no avail and it's not apparent from the docs what the data needs to look like. Does anyone have an example of code that will work with this function? Thanks Neil . This message is intended only for the use of the person(s) to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any unauthorised use is strictly prohibited. If you are not the intended recipient, please contact the sender as soon as possible. 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, unless specifically agreed otherwise. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any opinions or advice contained in this Internet email are subject to the terms and conditions expressed in any applicable governing Marble Bar Asset Management LLP's terms and conditions of business or client agreement letter. Any comments or statements made herein do not necessarily reflect those of Marble Bar Asset Management LLP. Marble Bar Asset Management LLP is regulated and authorised by the FSA. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] prblem with NA
Hi r-help-boun...@r-project.org napsal dne 06.01.2009 10:02:12: On Tue, 6 Jan 2009, Petr PIKAL wrote: [...] Logical vectors can be treated like numeric with TRUE=1 and FALSE=0, More accurately, 'like integer' ('numeric' often means 'double'). I learned that somewhere but it is not mentioned in help page for ?logical so it is not so easy to find. Hmm: it *is* in 'An Introduction to R'. Well, I have read it about 10 years ago so I remember the fact but not the source. However spending few hours by reading introduction can prevent many question from novice user (I mean that the beginner shall spend it, not yoursef :-). Petr -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Warning message:In pt(q, df, lower.tail, log.p) : NaNs produced
Hi friends, Any idea why do i get this warning?And also why all computed p-values are NaN. Have shown below what i did in Windows r-console.:-- df c1 c2 1 1 50 2 NA NA 3 4 NA 4 7 6 5 NA 7 6 10 10 r-cor(x=df,y=NULL,use=complete.obs,method=c(pearson)) r c1 c2 c1 1.000 -0.9148074 c2 -0.9148074 1.000 cor.p.values- function(r, n) + { + df - n - 2 + ESTIMATE - c(cor = r) + PARAMETER - c(df = df) + STATISTIC - c(sqrt(df) * r / sqrt(1 - r^2)) + p - pt(STATISTIC, df) + return(2 * pmin(p, 1 - p)) + } cor.p.values(r,2) [1] NaN NaN NaN NaN *Warning message: In pt(q, df, lower.tail, log.p) : NaNs produced * Any help will be appreciated.. :) -- Thanks Moumita [[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] [R-pkgs] pmml 1.2.0 (predictive modelling markup language)
Version 1.2.0 of pmml has been released and is available from CRAN. The pmml package (http://rattle.togaware.com/pmml.html) is part of the Rattle data mining suite http://rattle.togaware.com. It generates representations of analytic models built in R using the open standard predictive modelling markup language (http://www.dmg.org/). PMML represents analytic models in an application independent way so that models developed in R can be loaded into other applications. Supported models include: arules, hclust, kmeans, ksvm, lm (and glm), nnet, rpart, and rsf. PMML consumers include Information Builders' C code generator (for deployment of R generated models within Web Focus on all of their supported platforms), Zementis' scoring engine or cloud computing application (ADAPA), Teradata's Warehouse Miner and IBM's DB2. A key update is the incorporation of a framework for dealing with data transformations. This is ongoing work. The pmml package is regularly updated and intermediate releases (between the more stable CRAN releases) are always available using: install.packages(pmml, repos=http://rattle.togaware.com;) Comments, bugs, suggestions are always welcome. Regards, Graham ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Large Dataset
Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Large Dataset
type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Warning message:In pt(q, df, lower.tail, log.p) : NaNs produced
Obviously your df=0 in pt(STATISTIC, df). Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China On Tue, Jan 6, 2009 at 7:26 PM, Moumita Das das.moumita.onl...@gmail.com wrote: Hi friends, Any idea why do i get this warning?And also why all computed p-values are NaN. Have shown below what i did in Windows r-console.:-- df c1 c2 1 1 50 2 NA NA 3 4 NA 4 7 6 5 NA 7 6 10 10 r-cor(x=df,y=NULL,use=complete.obs,method=c(pearson)) r c1 c2 c1 1.000 -0.9148074 c2 -0.9148074 1.000 cor.p.values- function(r, n) + { + df - n - 2 + ESTIMATE - c(cor = r) + PARAMETER - c(df = df) + STATISTIC - c(sqrt(df) * r / sqrt(1 - r^2)) + p - pt(STATISTIC, df) + return(2 * pmin(p, 1 - p)) + } cor.p.values(r,2) [1] NaN NaN NaN NaN *Warning message: In pt(q, df, lower.tail, log.p) : NaNs produced * Any help will be appreciated.. :) -- Thanks Moumita [[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] Large Dataset
Hi Simon, Thank for your reply. I have read ?Memory but I dont understand how to use. I am not sure if that can solve my problem. Can you tell me more detail? Thanks, Edwin type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Warning message:In pt(q, df, lower.tail, log.p) : NaNs produced
Yihui Xie wrote: Obviously your df=0 in pt(STATISTIC, df). However, there are 3 complete observation pairs, not 2, and he wants r as the off-diagonal element and not the whole correlation matrix. (and df denotes two different things, but that is just aesthetics.) Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China On Tue, Jan 6, 2009 at 7:26 PM, Moumita Das das.moumita.onl...@gmail.com wrote: Hi friends, Any idea why do i get this warning?And also why all computed p-values are NaN. Have shown below what i did in Windows r-console.:-- df c1 c2 1 1 50 2 NA NA 3 4 NA 4 7 6 5 NA 7 6 10 10 r-cor(x=df,y=NULL,use=complete.obs,method=c(pearson)) r c1 c2 c1 1.000 -0.9148074 c2 -0.9148074 1.000 cor.p.values- function(r, n) + { + df - n - 2 + ESTIMATE - c(cor = r) + PARAMETER - c(df = df) + STATISTIC - c(sqrt(df) * r / sqrt(1 - r^2)) + p - pt(STATISTIC, df) + return(2 * pmin(p, 1 - p)) + } cor.p.values(r,2) [1] NaN NaN NaN NaN *Warning message: In pt(q, df, lower.tail, log.p) : NaNs produced * Any help will be appreciated.. :) -- Thanks Moumita [[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. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Large Dataset
When I do it on a Mac installation I get: Help for the topic memory was not found. Is that a Linux-specific function? Or perhaps you meant to type: ?Memory Which does produce useful information. -- David Winsemius sessionInfo() R version 2.8.0 Patched (2008-11-14 r46932) i386-apple-darwin9.5.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] vcd_1.2-1colorspace_1.0-0 MASS_7.2-45 rattle_2.4.0 loaded via a namespace (and not attached): [1] tools_2.8.0 On Jan 6, 2009, at 6:43 AM, Simon Pickett wrote: type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Large Dataset
I think he meant: ?Memory edwin When I do it on a Mac installation I get: Help for the topic memory was not found. Is that a Linux-specific function? Or perhaps you meant to type: ?Memory Which does produce useful information. -- David Winsemius sessionInfo() R version 2.8.0 Patched (2008-11-14 r46932) i386-apple-darwin9.5.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] vcd_1.2-1colorspace_1.0-0 MASS_7.2-45 rattle_2.4.0 loaded via a namespace (and not attached): [1] tools_2.8.0 On Jan 6, 2009, at 6:43 AM, Simon Pickett wrote: type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] adding a curve with xaxs=i
Unfortunately, I need add=T because there are many other things in the graph. I could swear that it worked 2 years ago. Maybe there's something wrong with an update. Original-Nachricht See if this gets you closer to what you want. curve (hm,lty=1,xaxs=i, xlim=c(0,1), yaxs=i, xlab=, xaxt=n ) Seemed as though the , add=TRUE, parameter was getting in the way of the other par settings working as expected. On Jan 5, 2009, at 6:23 PM, Valentina Kraus wrote: I want the curve to touch the y axis like the curve touches the upper boundary. How can I eliminate the margin between axis and curve on the left side? x1 - c(1,2,3,4,5) x2 - c(2,4,6,8,10) mod - lm (x2~x1) hm - function (x) (mod$coe[1]+x*mod$coe[2]) plot.new() # ... box() curve (hm,lty=1,add=T,xaxs=i,yaxs=i) (R 2.8.1) -- Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] adding a curve with xaxs=i
Valentina Kraus wrote: Unfortunately, I need add=T because there are many other things in the graph. I could swear that it worked 2 years ago. It can't have worked. Axis settings are fixed before you start adding things. Presumably you used xlim, xaxs et al. on one of the previous commands. Maybe there's something wrong with an update. Original-Nachricht See if this gets you closer to what you want. curve (hm,lty=1,xaxs=i, xlim=c(0,1), yaxs=i, xlab=, xaxt=n ) Seemed as though the , add=TRUE, parameter was getting in the way of the other par settings working as expected. On Jan 5, 2009, at 6:23 PM, Valentina Kraus wrote: I want the curve to touch the y axis like the curve touches the upper boundary. How can I eliminate the margin between axis and curve on the left side? x1 - c(1,2,3,4,5) x2 - c(2,4,6,8,10) mod - lm (x2~x1) hm - function (x) (mod$coe[1]+x*mod$coe[2]) plot.new() # ... box() curve (hm,lty=1,add=T,xaxs=i,yaxs=i) (R 2.8.1) -- Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting variables from a list of data.frames
I have a simulation program that generates a data frame for each run. I aggregate the data.frames into a list (df.list). The structure of all data frames is the same, only the values are different. I then want to aggregate the various runs. Currently I use the following method (for three runs): means = (df.list[[1]]$variable + df.list[[2]]$variable + df.list[[3]]$variable)/3 I would like to do this in a more parsimonious way, for example using lapply or related commands, but I can't seem to figure out the magic touch. Any thoughts on the best way to accomplish this? Thanks and regards, Magnus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Large Dataset
Only a couple of weeks ago I had to deal with this. adjust the memory limit as follows, although you might not want 4000, that is quite high memory.limit(size = 4000) Simon. - Original Message - From: Edwin Sendjaja edw...@web.de To: Simon Pickett simon.pick...@bto.org Cc: r-help@r-project.org Sent: Tuesday, January 06, 2009 12:24 PM Subject: Re: [R] Large Dataset Hi Simon, Thank for your reply. I have read ?Memory but I dont understand how to use. I am not sure if that can solve my problem. Can you tell me more detail? Thanks, Edwin type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing Matrix Header
Try this: unname(dat) On Tue, Jan 6, 2009 at 6:14 AM, Gundala Viswanath gunda...@gmail.comwrote: Dear all, I have the following matrix. dat A A A A A A A A A A [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 0 2 How can I change it into: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 1 [3,] 0 0 0 0 0 0 0 0 02 I tried: as.matrix(x) But failed. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 [[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] Large Dataset
Yup, it was a typo. But I always try capital if lower case doesnt work, Sorry. - Original Message - From: David Winsemius dwinsem...@comcast.net To: Simon Pickett simon.pick...@bto.org Cc: Edwin Sendjaja edw...@web.de; r-help@r-project.org Sent: Tuesday, January 06, 2009 12:40 PM Subject: Re: [R] Large Dataset When I do it on a Mac installation I get: Help for the topic memory was not found. Is that a Linux-specific function? Or perhaps you meant to type: ?Memory Which does produce useful information. -- David Winsemius sessionInfo() R version 2.8.0 Patched (2008-11-14 r46932) i386-apple-darwin9.5.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] vcd_1.2-1colorspace_1.0-0 MASS_7.2-45 rattle_2.4.0 loaded via a namespace (and not attached): [1] tools_2.8.0 On Jan 6, 2009, at 6:43 AM, Simon Pickett wrote: type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sweave in LATEX
On 1/6/2009 6:44 AM, Mr Derik wrote: Hello I have been setting up my computer to run Sweave. I have got the whole thing working on example files, except that my MikTex returns an Undefined Control Sequence error for \Sexpr and my output file contains verbatim code sequences at the apropriate point in the text rather than the R output. The rest of the output file is fine with tables, R code sequences and figures in the right place and correctly formatted. I have searched everywhere for advice on what to do about this, any ideas would be gratefully received. You need to give more details. Which version of R are you running? How are you running Sweave? Are you including \usepackage{Sweave} in your Sweave document? (This is not always necessary, but is usually a good idea). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting variables from a list of data.frames
Magnus account at zulutime.net writes: I have a simulation program that generates a data frame for each run. I aggregate the data.frames into a list (df.list). The structure of all data frames is the same, only the values are different. I then want to aggregate the various runs. Currently I use the following method (for three runs): means = (df.list[[1]]$variable + df.list[[2]]$variable + df.list[[3]]$variable)/3 I would like to do this in a more parsimonious way, for example using lapply or related commands, but I can't seem to figure out the magic touch. Any thoughts on the best way to accomplish this? x - sapply(df.list,[[,variable) will extract the variables as a matrix. If the variables are all vectors of the same length then you might follow this with rowSums(x)/ncol(x) or apply(x,1,mean) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] for loop and if problem
Hi, I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each gene in my dataset. Attached is the dataset: http://www.nabble.com/file/p21312449/genlistchrompos.csv genlistchrompos.csv Column 'B' is the gene name, 'G' is the starting position and 'H' is the stop position. You can load the dataset by using: data-read.csv(genlistchrompos.csv, sep=;) I hope someone can help me, it's giving me headaches for a week now:-((. Thanks! -- View this message in context: http://www.nabble.com/for-loop-and-if-problem-tp21312449p21312449.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] Error : unused arguments in pairs()
Dear Sarah, Thank you a lot, It does exactly what I need. By the way, I tried doing what Prof. Ripley suggested I just was not able to get it right - I am pretty new to this after all. Thank again, Herwig Sarah Goslee wrote: You didn't do what Prof. Ripley suggested - adding a ... argument. Here's a crude version of what you want; I'm sure there's a more elegant solution for passing the needed data to the panel function. panel.cor - function(x, y, digits=2, prefix=, splitvar, col.cor, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r - abs(cor(x, y)) if(!missing(splitvar)) { r - c(r, abs(sapply(lapply(split(cbind.data.frame(x, y), splitvar), cor), function(x)x[1,2]))) } txt - format(c(r, 0.123456789), digits=digits)[1:4] txt - paste(prefix, txt, sep=) if(missing(col.cor)) col.cor - c(black, red, green3, blue) for(i in 1:length(txt)) { text(0.5, (1/(length(txt)+1))*i, txt[i], col = col.cor[i]) } } pairs(iris[1:4], main = Anderson's Iris Data -- 3 species, pch = 21, bg = c(red, green3, blue)[unclass(iris$Species)], lower.panel=panel.cor, splitvar=iris$Species) On Mon, Jan 5, 2009 at 5:32 PM, herwig bachmannher...@hotmail.com wrote: Dear Prof. Ripley, thanks for your reply. Unfortunately I still was not able to solve the problem. I tried it with the Iris data and you can find the code below: panel.cor - function(x, y, digits=2, prefix=, cex.cor) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r - abs(cor(x, y)) txt - format(c(r, 0.123456789), digits=digits)[1] txt - paste(prefix, txt, sep=) if(missing(cex.cor)) cex.cor - 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex.cor * r) } pairs(iris[1:4], main = Anderson's Iris Data -- 3 species, pch = 21, bg = c(red, green3, blue)[unclass(iris$Species)], lower.panel=panel.cor ) What I would ideally like to have is that the upper panel shows the plot with the iris$Species color coded and the lower panel showing the correlation coefficients for the total data in the plot, but also for the each iris$Species with the same color code as in the upper panels. So the lower panel should therefore actually show 4 correlation coefficients in each panel (color coded); It does not need to be sized according to the value of the correlation coefficient as shown in the example above. Any help with this would be appreciated a lot, Kind regards, Herwig -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Error-%3A-unused-arguments-in---pairs%28%29-tp21283398p21312270.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] history: recording
Hi, I'm using windows xp and R 2.8.0 - I wonder what is the command to put in a script that has the same effect as when in a plot you choose menu History and Recording. Best wishes Troels -- Troels Ring - - Department of nephrology - - Aalborg Hospital 9100 Aalborg, Denmark - - +45 99326629 - - tr...@gvdnet.dk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave in LATEX
Thanks for replying. I'm working on a windows XP sp3 PC. I am trying to run the test file provided by R at the moment: % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \SweaveOpts{echo=FALSE} \usepackage{a4wide} \begin{document} \maketitle A simple example that will run in any S engine: The integers from 1 to 10 are print=TRUE= 1:10 results=hide= print(1:20) @ % the above is just to ensure that 2 code chunks can follow each other We can also emulate a simple calculator: echo=TRUE,print=TRUE= 1 + 1 1 + pi sin(pi/2) @ Now we look at Gaussian data: = library(stats) x - rnorm(20) print(x) print(t1 - t.test(x)) @ Note that we can easily integrate some numbers into standard text: The third element of vector \texttt{x} is \Sexpr{x[3]}, the $p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $ Now we look at a summary of the famous iris data set, and we want to see the commands in the code chunks: \SweaveOpts{echo=true} % the following code is R-specific, as data(iris) will not run in Splus. % Hence, we mark it as R code. engine=R= data(iris) summary(iris) @ %def \begin{figure}[htbp] \begin{center} fig=TRUE= library(graphics) pairs(iris) @ \caption{Pairs plot of the iris data.} \end{center} \end{figure} \begin{figure}[htbp] \begin{center} fig=true= boxplot(Sepal.Length~Species, data=iris) @ \caption{Boxplot of sepal length grouped by species.} \end{center} \end{figure} % R is not S-PLUS, hence this chunk will be ignored: engine=S4= function.that.comes.only.with.Splus(x) @ \end{document} ## I open in Tinn-R 2.1.1.6. I save it, change the working directory in R to the one I have the file saved in. Then execute Sweave from R with: Sweave(C:\\R_folder\\sweave_Test\\Sweave-test-1.rnw) Which produces the following .tex file: ## % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \usepackage{a4wide} \usepackage{Sweave} \begin{document} \maketitle A simple example that will run in any S engine: The integers from 1 to 10 are \begin{Schunk} \begin{Soutput} [1] 1 2 3 4 5 6 7 8 9 10 \end{Soutput} \end{Schunk} We can also emulate a simple calculator: \begin{Schunk} \begin{Sinput} 1 + 1 \end{Sinput} \begin{Soutput} [1] 2 \end{Soutput} \begin{Sinput} 1 + pi \end{Sinput} \begin{Soutput} [1] 4.141593 \end{Soutput} \begin{Sinput} sin(pi/2) \end{Sinput} \begin{Soutput} [1] 1 \end{Soutput} \end{Schunk} Now we look at Gaussian data: \begin{Schunk} \begin{Soutput} [1] -2.45376344 0.88169202 0.60153415 -0.34419029 -2.13665627 -0.06469998 0.02702410 0.73846812 -0.49656363 [10] -0.77085572 -0.64614048 0.31631767 -0.52449644 -0.15666901 1.00128172 -1.42788545 0.94008626 1.76111249 [19] -1.38254184 -0.34449613 \end{Soutput} \begin{Soutput} One Sample t-test data: x t = -0.929, df = 19, p-value = 0.3645 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.7288798 0.2807356 sample estimates: mean of x -0.2240721 \end{Soutput} \end{Schunk} Note that we can easily integrate some numbers into standard text: The third element of vector \texttt{x} is \Sexpr{x[3]}, the $p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $ Now we look at a summary of the famous iris data set, and we want to see the commands in the code chunks: % the following code is R-specific, as data(iris) will not run in Splus. % Hence, we mark it as R code. \begin{Schunk} \begin{Sinput} data(iris) summary(iris) \end{Sinput} \begin{Soutput} Sepal.LengthSepal.Width Petal.LengthPetal.Width Species Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50 Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50 Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 \end{Soutput} \end{Schunk} \begin{figure}[htbp] \begin{center} \begin{Schunk} \begin{Sinput} library(graphics) pairs(iris) \end{Sinput} \end{Schunk} \includegraphics{Sweave-test-1-006} \caption{Pairs plot of the iris data.} \end{center} \end{figure} \begin{figure}[htbp] \begin{center} \begin{Schunk} \begin{Sinput} boxplot(Sepal.Length ~ Species, data = iris) \end{Sinput} \end{Schunk} \includegraphics{Sweave-test-1-007} \caption{Boxplot of sepal length grouped by species.} \end{center} \end{figure} % R is not S-PLUS, hence this chunk will be ignored: \end{document}
[R] Semi-definite quadratic programming
Hi, I am currently using solve.QP from the quadprog package to solve some quadratic optimization problems of the form: min[ -d'b + (1/2) b'Db ] under constraints A'b = b_0 solve.QP appears to use an implementation of the Goldfarb and Idnani algorithm. I now have a problem of this form where the matrix D is positive semi-definite which breaks solve.QP. It looks like there is a modified Goldfarb and Idnani algorithm that handles the semi-definite case (see: http://www.springerlink.com/content/h8154g18w87x47g0/). Is there a quadratic solver in R that handles this case? Or, is there another approach to this problem someone can suggest? Thanks, Kyle [[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] Alternate looping
R-help, I'm using the for control flow to graph plots continuously: par(mfrow=c(3,5), mar=c(0.6,.2,1.2,.2),yaxt=n,xaxt=n) for(j in 1:11) { for(i in 1:15) { species - spAldur[spAldur$ar == 1993+i spAldur$aldur == j,] plot(spec...@coords[,1], spec...@coords[,2], xlim=c(-10,-3.5), ylim=c(60.1,63) , col=3,type=n,xlab=,ylab=) points(geoFeatures[[dyp100]],pch=.,cex=1.2,col=blue) . . . }} This will plot a map of something in the following way: (j=1, i=1), (j=1, i=2),(i=1, i=3),,, (j=2, i=1), (j=2, i=2),(i=2, i=3),,, (j=3, i=1), (j=3, i=2),(i=3, i=3),,, and so on but I wish to have it like this: (j=1, i=1), (j=2,i=2),(i=3,i=3),,, 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] for loop and if problem
I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each gene in my dataset. Attached is the dataset: http://www.nabble.com/file/p21312449/genlistchrompos.csv genlistchrompos.csv Column 'B' is the gene name, 'G' is the starting position and 'H' is the stop position. You can load the dataset by using: data-read.csv(genlistchrompos.csv, sep=;) I hope someone can help me, it's giving me headaches for a week now:-((. which(diff(as.numeric(data$Gene))!=0) will give you a vector of the last row in each gene. The start position is obviously the next row after the previous end. Also take a look at split(data, data$Gene) Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] for loop and if problem
On Tue, Jan 06, 2009 at 07:21:48AM -0800, Sake wrote: I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each gene in my dataset. Attached is the dataset: http://www.nabble.com/file/p21312449/genlistchrompos.csv genlistchrompos.csv Column 'B' is the gene name, 'G' is the starting position and 'H' is the stop position. I don't really see how 'if' and 'for loops' are involved in the question. You may want to give us a little more detail on what exactly you need and what you tried unsuccessfully. (By the way -- there are no columns labeled 'B', 'G' or 'H' in the file). Anyway - I believe this is what you are after: # get minimum start position by gene aggregate(dat[, c('Exon_Start.Chr.')], by=list(dat$Gene), min) # get maximum stop position by gene aggregate(dat[, c('Exon_Stop.Chr.')], by=list(dat$Gene), max) Of course, these will only reflect the real start and stop coordinates of the gene if ALL exons are given in the file. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave in LATEX
Your example works for me. I'd guess there's a problem with the way you handled Sweave.sty, but I don't really know what it would be. Can't you tell MikTex to use the Sweave file from its original location, using -include_directory? Duncan Murdoch On 1/6/2009 10:48 AM, Mr Derik wrote: Thanks for replying. I'm working on a windows XP sp3 PC. I am trying to run the test file provided by R at the moment: % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \SweaveOpts{echo=FALSE} \usepackage{a4wide} \begin{document} \maketitle A simple example that will run in any S engine: The integers from 1 to 10 are print=TRUE= 1:10 results=hide= print(1:20) @ % the above is just to ensure that 2 code chunks can follow each other We can also emulate a simple calculator: echo=TRUE,print=TRUE= 1 + 1 1 + pi sin(pi/2) @ Now we look at Gaussian data: = library(stats) x - rnorm(20) print(x) print(t1 - t.test(x)) @ Note that we can easily integrate some numbers into standard text: The third element of vector \texttt{x} is \Sexpr{x[3]}, the $p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $ Now we look at a summary of the famous iris data set, and we want to see the commands in the code chunks: \SweaveOpts{echo=true} % the following code is R-specific, as data(iris) will not run in Splus. % Hence, we mark it as R code. engine=R= data(iris) summary(iris) @ %def \begin{figure}[htbp] \begin{center} fig=TRUE= library(graphics) pairs(iris) @ \caption{Pairs plot of the iris data.} \end{center} \end{figure} \begin{figure}[htbp] \begin{center} fig=true= boxplot(Sepal.Length~Species, data=iris) @ \caption{Boxplot of sepal length grouped by species.} \end{center} \end{figure} % R is not S-PLUS, hence this chunk will be ignored: engine=S4= function.that.comes.only.with.Splus(x) @ \end{document} ## I open in Tinn-R 2.1.1.6. I save it, change the working directory in R to the one I have the file saved in. Then execute Sweave from R with: Sweave(C:\\R_folder\\sweave_Test\\Sweave-test-1.rnw) Which produces the following .tex file: ## % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \usepackage{a4wide} \usepackage{Sweave} \begin{document} \maketitle A simple example that will run in any S engine: The integers from 1 to 10 are \begin{Schunk} \begin{Soutput} [1] 1 2 3 4 5 6 7 8 9 10 \end{Soutput} \end{Schunk} We can also emulate a simple calculator: \begin{Schunk} \begin{Sinput} 1 + 1 \end{Sinput} \begin{Soutput} [1] 2 \end{Soutput} \begin{Sinput} 1 + pi \end{Sinput} \begin{Soutput} [1] 4.141593 \end{Soutput} \begin{Sinput} sin(pi/2) \end{Sinput} \begin{Soutput} [1] 1 \end{Soutput} \end{Schunk} Now we look at Gaussian data: \begin{Schunk} \begin{Soutput} [1] -2.45376344 0.88169202 0.60153415 -0.34419029 -2.13665627 -0.06469998 0.02702410 0.73846812 -0.49656363 [10] -0.77085572 -0.64614048 0.31631767 -0.52449644 -0.15666901 1.00128172 -1.42788545 0.94008626 1.76111249 [19] -1.38254184 -0.34449613 \end{Soutput} \begin{Soutput} One Sample t-test data: x t = -0.929, df = 19, p-value = 0.3645 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.7288798 0.2807356 sample estimates: mean of x -0.2240721 \end{Soutput} \end{Schunk} Note that we can easily integrate some numbers into standard text: The third element of vector \texttt{x} is \Sexpr{x[3]}, the $p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $ Now we look at a summary of the famous iris data set, and we want to see the commands in the code chunks: % the following code is R-specific, as data(iris) will not run in Splus. % Hence, we mark it as R code. \begin{Schunk} \begin{Sinput} data(iris) summary(iris) \end{Sinput} \begin{Soutput} Sepal.LengthSepal.Width Petal.LengthPetal.Width Species Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50 Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50 Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 \end{Soutput} \end{Schunk} \begin{figure}[htbp] \begin{center} \begin{Schunk} \begin{Sinput} library(graphics) pairs(iris) \end{Sinput} \end{Schunk} \includegraphics{Sweave-test-1-006} \caption{Pairs plot of the iris data.} \end{center} \end{figure} \begin{figure}[htbp] \begin{center} \begin{Schunk}
Re: [R] Interval censored Data in survreg() with zero values!
Terry Therneau schrieb: Apologies -- you are being more subtle than I thought. Nevertheless, I think that the censoring language isn't quite right. You are thinking of a hierarchical model: z ~ N(Xb, sigma), where Xb is the linear predictor, whatever covariates you think belong in the model. Whether the distribution should be Gaussian or somthing else depends not on the overall distribution of z, but on distribution of (z | Xb). We could have a skewed predictor leading to skewed z, even if the distribution about any given expectation is symmetric. y = F(z) is what you observe. The classic tobin model is y= max(0,z), which does lead to censored data. In your case y_i = Binomial(n_i, p_i = H(z)). Note a binomial is k heads out of n tries with a coin of probability p, a Bernouli is a binomial restricted to a single coin flip. From the way you wrote the problem I assumed that there is some number of n looks at the subject and then you count them up. Note that var(y) = n p (1-p) H describes how the probability changes with z. In biology we very rarely use H(z)= max(min(z,1),0) because it gives a hard threshold, and the probability of nearly anything doesn't go all the way to zero or one. If H were as above and var(y) = constant and n is sufficiently large so that Binomial dist is approx Gaussian and var(y |p) var(z| Xb) then your y will fit a censored Gaussian. Since at least the second is false, it doesn't. A censored model may still be an ok first cut at fitting the data, but I would be suspicious of variance estimates and particularly of any p-values. The bootstrap could help that. Terry T. @ Terry: thank you very much for the extended explanation. I will try out your suggestion. Geraldine __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Large Dataset
Hi, I am not very knowledgeable about this kind of stuff but my guess is that if you have a fairly slow computer and massive data sets there isnt alot you can do except get a better computer, buy more RAM or use something like SAS instead? Hopefully someone else will chip in Edwin, best of luck. Simon. - Original Message - From: Edwin Sendjaja edw...@web.de To: Simon Pickett simon.pick...@bto.org Cc: r-help@r-project.org Sent: Tuesday, January 06, 2009 2:53 PM Subject: Re: [R] Large Dataset Hi Simon, My RAM is only 3.2 GB (actually it should be 4 GB, but my Motherboard doesnt support it. R use almost of all my RAM and half of my swap. I think memory.limit will not solve my problem. It seems that I need RAM. Unfortunately, I can't buy more RAM. Why R is slow reading big data set? Edwin Only a couple of weeks ago I had to deal with this. adjust the memory limit as follows, although you might not want 4000, that is quite high memory.limit(size = 4000) Simon. - Original Message - From: Edwin Sendjaja edw...@web.de To: Simon Pickett simon.pick...@bto.org Cc: r-help@r-project.org Sent: Tuesday, January 06, 2009 12:24 PM Subject: Re: [R] Large Dataset Hi Simon, Thank for your reply. I have read ?Memory but I dont understand how to use. I am not sure if that can solve my problem. Can you tell me more detail? Thanks, Edwin type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave in LATEX
One other suggestion: use the SweavePDFMikTex function from patchDVI (available on http://r-forge.r-project.org/projects/sweavesearch) to handle both the Sweave call, and the pdflatex call. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave in LATEX
Another thing to try is placing Sweave.sty in the same directory as your .Rnw file and experiment with and without \usepackage{Sweave} in your .Rnw file. On Tue, Jan 6, 2009 at 11:39 AM, Duncan Murdoch murd...@stats.uwo.ca wrote: Your example works for me. I'd guess there's a problem with the way you handled Sweave.sty, but I don't really know what it would be. Can't you tell MikTex to use the Sweave file from its original location, using -include_directory? Duncan Murdoch On 1/6/2009 10:48 AM, Mr Derik wrote: Thanks for replying. I'm working on a windows XP sp3 PC. I am trying to run the test file provided by R at the moment: % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \SweaveOpts{echo=FALSE} \usepackage{a4wide} \begin{document} \maketitle A simple example that will run in any S engine: The integers from 1 to 10 are print=TRUE= 1:10 results=hide= print(1:20) @ % the above is just to ensure that 2 code chunks can follow each other We can also emulate a simple calculator: echo=TRUE,print=TRUE= 1 + 1 1 + pi sin(pi/2) @ Now we look at Gaussian data: = library(stats) x - rnorm(20) print(x) print(t1 - t.test(x)) @ Note that we can easily integrate some numbers into standard text: The third element of vector \texttt{x} is \Sexpr{x[3]}, the $p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $ Now we look at a summary of the famous iris data set, and we want to see the commands in the code chunks: \SweaveOpts{echo=true} % the following code is R-specific, as data(iris) will not run in Splus. % Hence, we mark it as R code. engine=R= data(iris) summary(iris) @ %def \begin{figure}[htbp] \begin{center} fig=TRUE= library(graphics) pairs(iris) @ \caption{Pairs plot of the iris data.} \end{center} \end{figure} \begin{figure}[htbp] \begin{center} fig=true= boxplot(Sepal.Length~Species, data=iris) @ \caption{Boxplot of sepal length grouped by species.} \end{center} \end{figure} % R is not S-PLUS, hence this chunk will be ignored: engine=S4= function.that.comes.only.with.Splus(x) @ \end{document} ## I open in Tinn-R 2.1.1.6. I save it, change the working directory in R to the one I have the file saved in. Then execute Sweave from R with: Sweave(C:\\R_folder\\sweave_Test\\Sweave-test-1.rnw) Which produces the following .tex file: ## % -*- mode: noweb; noweb-default-code-mode: R-mode; -*- \documentclass[a4paper]{article} \title{A Test File} \author{Friedrich Leisch} \usepackage{a4wide} \usepackage{Sweave} \begin{document} \maketitle A simple example that will run in any S engine: The integers from 1 to 10 are \begin{Schunk} \begin{Soutput} [1] 1 2 3 4 5 6 7 8 9 10 \end{Soutput} \end{Schunk} We can also emulate a simple calculator: \begin{Schunk} \begin{Sinput} 1 + 1 \end{Sinput} \begin{Soutput} [1] 2 \end{Soutput} \begin{Sinput} 1 + pi \end{Sinput} \begin{Soutput} [1] 4.141593 \end{Soutput} \begin{Sinput} sin(pi/2) \end{Sinput} \begin{Soutput} [1] 1 \end{Soutput} \end{Schunk} Now we look at Gaussian data: \begin{Schunk} \begin{Soutput} [1] -2.45376344 0.88169202 0.60153415 -0.34419029 -2.13665627 -0.06469998 0.02702410 0.73846812 -0.49656363 [10] -0.77085572 -0.64614048 0.31631767 -0.52449644 -0.15666901 1.00128172 -1.42788545 0.94008626 1.76111249 [19] -1.38254184 -0.34449613 \end{Soutput} \begin{Soutput} One Sample t-test data: x t = -0.929, df = 19, p-value = 0.3645 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.7288798 0.2807356 sample estimates: mean of x -0.2240721 \end{Soutput} \end{Schunk} Note that we can easily integrate some numbers into standard text: The third element of vector \texttt{x} is \Sexpr{x[3]}, the $p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $ Now we look at a summary of the famous iris data set, and we want to see the commands in the code chunks: % the following code is R-specific, as data(iris) will not run in Splus. % Hence, we mark it as R code. \begin{Schunk} \begin{Sinput} data(iris) summary(iris) \end{Sinput} \begin{Soutput} Sepal.LengthSepal.Width Petal.LengthPetal.Width Species Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50 Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50 Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
[R] smoothed contour lines
Hi all, I'm trying to draw a contour plot with rounded (smoothed) contour lines instead of sharp angles; when the grid consists of only a few points in x- and y- axis, the resulting contour is in facts rather ugly since very sharp angles may appear. I did not find any way to do it, by using either contour or contourplot (from the lattice package), I wonder if there exist a way for smoothing the angles, apart from artificially increasing the grid resolution, Thanks in advance Andrea __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] history: recording
Thanks a lot - windows(record=TRUE) seems to do the job. Sorry not to have found it. Troels jim holtman skrev: ?windows On Tue, Jan 6, 2009 at 10:44 AM, Troels Ring tr...@gvdnet.dk wrote: Hi, I'm using windows xp and R 2.8.0 - I wonder what is the command to put in a script that has the same effect as when in a plot you choose menu History and Recording. Best wishes Troels -- Troels Ring - - Department of nephrology - - Aalborg Hospital 9100 Aalborg, Denmark - - +45 99326629 - - tr...@gvdnet.dk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Troels Ring - - Department of nephrology - - Aalborg Hospital 9100 Aalborg, Denmark - - +45 99326629 - - tr...@gvdnet.dk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] the first and last observation for each subject
Just in case anyone is still interested, here are some comparisons of the time it says to compute grouped medians via sapply(split(x,group),median) and gm(x,group), which uses the trick used by rle() to find the first and last entries in each group. Which method is fastest depends on the nature of your data: the number of groups, k, the length of the data vector, n, and probably the distribution of group size (which I didn't look into). If the overhead involved in calling a function were to go down we would expect sapply() to look better in the cases where k/n is close to 1. Bill From: William Dunlap Sent: Monday, January 05, 2009 4:01 PM To: 'Kingsford Jones' Subject: RE: [R] the first and last observation for each subject -Original Message- From: Kingsford Jones [mailto:kingsfordjo...@gmail.com] Sent: Monday, January 05, 2009 3:19 PM To: William Dunlap Subject: Re: [R] the first and last observation for each subject Thanks for the explanation -- it's much more satisfying to have some theory rather than 'just trying things out'... Kingsford Trying things out helps sort out the constants in those 'order of' assertions. Here are times for various n and k (both ranging over 4^(3:10), with k=n) for gm and sapply: time.gm k n 64 256 1024 4096 16384 65536 262144 1048576 64 0.00 NA NA NANANA NA NA 256 0.00 0.00 NA NANANA NA NA 10240.00 0.00 0.00 NANANA NA NA 40960.00 0.00 0.00 0.00NANA NA NA 16384 0.00 0.01 0.02 0.02 0.04NA NA NA 65536 0.08 0.06 0.07 0.06 0.05 0.09 NA NA 262144 0.36 0.36 0.33 0.34 0.28 0.26 0.42 NA 1048576 3.46 2.83 1.88 1.91 1.96 1.39 1.17 2.2 time.sapply k n 64 256 1024 4096 16384 65536 262144 1048576 64 0.01 NA NA NANANA NA NA 256 0.01 0.03 NA NANANA NA NA 10240.02 0.03 0.09 NANANA NA NA 40960.00 0.03 0.14 0.41NANA NA NA 16384 0.02 0.05 0.14 0.55 1.61NA NA NA 65536 0.02 0.03 0.14 0.55 2.22 6.54 NA NA 262144 0.03 0.05 0.17 0.60 2.28 8.93 27.44 NA 1048576 0.27 0.16 0.27 0.71 2.41 9.22 37.56 121.55 time.gmtime.sapply k n64 256 1024 4096 16384 65536 262144 1048576 64 TRUENANANANANA NA NA 256 TRUE TRUENANANANA NA NA 1024 TRUE TRUE TRUENANANA NA NA 4096FALSE TRUE TRUE TRUENANA NA NA 16384TRUE TRUE TRUE TRUE TRUENA NA NA 65536 FALSE FALSE TRUE TRUE TRUE TRUE NA NA 262144 FALSE FALSE FALSE TRUE TRUE TRUE TRUE NA 1048576 FALSE FALSE FALSE FALSE TRUE TRUE TRUETRUE round(time.gm/time.sapply,3) k n 64256 1024 4096 16384 65536 262144 1048576 64 0.000 NANANANANA NA NA 256 0.000 0.000NANANANA NA NA 1024 0.000 0.000 0.000NANANA NA NA 4096 NaN 0.000 0.000 0.000NANA NA NA 163840.000 0.200 0.143 0.036 0.025NA NA NA 655364.000 2.000 0.500 0.109 0.023 0.014 NA NA 262144 12.000 7.200 1.941 0.567 0.123 0.029 0.015 NA 1048576 12.815 17.688 6.963 2.690 0.813 0.151 0.031 0.018 On Mon, Jan 5, 2009 at 4:00 PM, William Dunlap wdun...@tibco.com wrote: Note that gm fully sorts the whole vector, taking order n*log(n) time, then does an order n subscripting operation, then some order k stuff. The sapply approach does k calls to median, each of which takes order n/k time to partially sort its short input (assuming all groups are about the same size), resulting in order n total sorting time (I think the partial sort is order n, if not it is pretty close to that for n up to 2^25). It also involves some other order n and order k time operations. Thus for a fixed k, as n grows the sapply approach ought to do better, but for a fixed n, as k grows gm ought to do better. gm() only does better in some cases (when k/n is close to 1) because it avoids the function call overhead involved in calling median() many times. Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com -Original Message- From: Kingsford Jones [mailto:kingsfordjo...@gmail.com] Sent: Monday, January 05, 2009 2:20 PM To: William Dunlap Cc: hadley wickham; R help Subject: Re: [R] the first and last observation for each subject whoops -- I left the group size unchanged so k became greather than the length of the group vector. When I increase the size to 1e7, sapply is faster until it gets to k = 1e6. warning: this takes awhile (particularly on my machine which seems to be using just
Re: [R] Large Dataset
Hi Ben, Using colClasses doensnt improve the performace much. With the data, I will calculate the mean, min, max, and standard deviance. I have also failed to import the data in a Mysql Database. I dont have much knowledge in Mysql. Edwin Edwin Sendjaja edwin7 at web.de writes: Hi Simon, My RAM is only 3.2 GB (actually it should be 4 GB, but my Motherboard doesnt support it. R use almost of all my RAM and half of my swap. I think memory.limit will not solve my problem. It seems that I need RAM. Unfortunately, I can't buy more RAM. Why R is slow reading big data set? Edwin Start with FAQ 7.28 , http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-is-read_002etable_0028_002 9-so-inefficient_003f However, I think you're going to have much bigger problems if you have a 3.1G data set and a total of 3.2G of RAM: what do you expect to be able to do with this data set once you've read it in? Have you considered storing it in a database and accessing just the bits you need at any one time? 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Large Dataset
The sqldf R package can import a file into an sqlite database and extract a portion of it. You basically need two statements: one to specify the name and format of the file and one to specify what you want to extract. See home page at: http://sqldf.googlecode.com On Tue, Jan 6, 2009 at 12:10 PM, Edwin Sendjaja edw...@web.de wrote: Hi Ben, Using colClasses doensnt improve the performace much. With the data, I will calculate the mean, min, max, and standard deviance. I have also failed to import the data in a Mysql Database. I dont have much knowledge in Mysql. Edwin Edwin Sendjaja edwin7 at web.de writes: Hi Simon, My RAM is only 3.2 GB (actually it should be 4 GB, but my Motherboard doesnt support it. R use almost of all my RAM and half of my swap. I think memory.limit will not solve my problem. It seems that I need RAM. Unfortunately, I can't buy more RAM. Why R is slow reading big data set? Edwin Start with FAQ 7.28 , http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-is-read_002etable_0028_002 9-so-inefficient_003f However, I think you're going to have much bigger problems if you have a 3.1G data set and a total of 3.2G of RAM: what do you expect to be able to do with this data set once you've read it in? Have you considered storing it in a database and accessing just the bits you need at any one time? 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Large Dataset
For the mean, min, max and standard deviance (deviation I suppose) you don't need to store all data in the memory, you can calculate them incrementally. Read the file line by line (if it is a text file). G. On Tue, Jan 6, 2009 at 6:10 PM, Edwin Sendjaja edw...@web.de wrote: Hi Ben, Using colClasses doensnt improve the performace much. With the data, I will calculate the mean, min, max, and standard deviance. I have also failed to import the data in a Mysql Database. I dont have much knowledge in Mysql. Edwin Edwin Sendjaja edwin7 at web.de writes: Hi Simon, My RAM is only 3.2 GB (actually it should be 4 GB, but my Motherboard doesnt support it. R use almost of all my RAM and half of my swap. I think memory.limit will not solve my problem. It seems that I need RAM. Unfortunately, I can't buy more RAM. Why R is slow reading big data set? Edwin Start with FAQ 7.28 , http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-is-read_002etable_0028_002 9-so-inefficient_003f However, I think you're going to have much bigger problems if you have a 3.1G data set and a total of 3.2G of RAM: what do you expect to be able to do with this data set once you've read it in? Have you considered storing it in a database and accessing just the bits you need at any one time? 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi gabor.csa...@unil.ch 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] Large Dataset
Increase the memory as much as you can, read in the data, (however long it takes) then aggregate the data into smaller chunks, selecting only the bits you want. Remove the big original data set from memory (using rm()) and keep (or save the smaller aggregated data using wite.table()) If this doesnt work you may be out of luck I am afraid. Sorry i cant be of more help but it seems that if you want to deal with collosal data sets, you need to get the right tools for the job (i.e. a better computer or more suitable software) Simon. - Original Message - From: Edwin Sendjaja edw...@web.de To: Simon Pickett simon.pick...@bto.org Cc: r-help@r-project.org Sent: Tuesday, January 06, 2009 5:04 PM Subject: Re: [R] Large Dataset Hi Simons, Is SAS more powerfull than R? Well, I think I cannot afford to buy SAS. actually, my computer isn't really slow. I think 4GB RAM is big enough for personal PC. I am just wondering, why R running so slow with these specs to handling 3 GB data set. What if the data set were 1 TB?mmm.. Edwin Hi, I am not very knowledgeable about this kind of stuff but my guess is that if you have a fairly slow computer and massive data sets there isnt alot you can do except get a better computer, buy more RAM or use something like SAS instead? Hopefully someone else will chip in Edwin, best of luck. Simon. - Original Message - From: Edwin Sendjaja edw...@web.de To: Simon Pickett simon.pick...@bto.org Cc: r-help@r-project.org Sent: Tuesday, January 06, 2009 2:53 PM Subject: Re: [R] Large Dataset Hi Simon, My RAM is only 3.2 GB (actually it should be 4 GB, but my Motherboard doesnt support it. R use almost of all my RAM and half of my swap. I think memory.limit will not solve my problem. It seems that I need RAM. Unfortunately, I can't buy more RAM. Why R is slow reading big data set? Edwin Only a couple of weeks ago I had to deal with this. adjust the memory limit as follows, although you might not want 4000, that is quite high memory.limit(size = 4000) Simon. - Original Message - From: Edwin Sendjaja edw...@web.de To: Simon Pickett simon.pick...@bto.org Cc: r-help@r-project.org Sent: Tuesday, January 06, 2009 12:24 PM Subject: Re: [R] Large Dataset Hi Simon, Thank for your reply. I have read ?Memory but I dont understand how to use. I am not sure if that can solve my problem. Can you tell me more detail? Thanks, Edwin type ?memory into R and that will explain what to do... S - Original Message - From: Edwin Sendjaja edw...@web.de To: r-help@r-project.org Sent: Tuesday, January 06, 2009 11:41 AM Subject: [R] Large Dataset Hi alI, I have a 3.1 GB Dataset ( with 11 coloumns and lots data in int and string). If I use read.table; it takes very long. It seems that my RAM is not big enough (overload) I have 3.2 RAM and 7GB SWAP, 64 Bit Ubuntu. Is there a best sultion to read a large data R? I have seen, that people suggest to use bigmemory package, ff. But it seems very complicated. I dont know how to start with that packages. i have tried to use bigmemory. But I got some kind of errors. Then I gave up. can someone give me an simple example how ot use ff or bigmemory?or maybe re better sollution? Thank you in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Using apply for two datasets
I can run one-sample t-test on an array, for example a matrix myData1, with the following apply(myData1, 2, t.test) Is there a similar fashion using apply() or something else to run 2-sample t-test with datasets from two groups, myData1 and myData2, without looping? TIA, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using apply for two datasets
I think that you can use mapply for this. On Tue, Jan 6, 2009 at 3:24 PM, Gang Chen gangch...@gmail.com wrote: I can run one-sample t-test on an array, for example a matrix myData1, with the following apply(myData1, 2, t.test) Is there a similar fashion using apply() or something else to run 2-sample t-test with datasets from two groups, myData1 and myData2, without looping? TIA, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 [[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] Large Dataset
Bellow, you can see the R data. But this stucks even in first line (read.table..). I dont know how to calculate this and write the result into a new table. Edwin data - read.table(test.data) data - subset(data, (data$Zusatz!=60) (data$Zusatz!=0)) list(EndpointKeepAliveTimeOutIntervalLimit,, PE_ID,, Registrar, Region, RelTime))) split.data - with(data, split(Zusatz, list(EndpointKeepAliveTimeOutIntervalLimit, PE_ID, Run))) #Find the min, max and std dev for each element in the resulting list mins - sapply(split.data, min) maxs - sapply(split.data, max) devs - sapply(split.data, sd) mean - sapply(split.data, mean) name.list - strsplit(names(split.data), \\.) endpointkeepalivetimeoutintervallimit - as.numeric(sapply(name.list, function(x) x[[1]])) pe_id - sapply(name.list, function(x) x[[2]]) run - sapply(name.list, function(x) x[[3]]) #Now construct a new data frame from these values output - data.frame(EndpointKeepAliveTimeOutIntervalLimit=endpointkeepalivetimeoutintervallimit, PE_ID=pe_id, Run=run, Min=mins, Max=maxs, Standardabweichung=devs, Mean=mean) output - subset(output, (output$Min !=Inf)) output_sort-sort(output$EndpointKeepAliveTimeOutIntervalLimit) output-output[order(output$EndpointKeepAliveTimeOutIntervalLimit, partial=order(output$PE_ID)),] rownames(output) - seq(length=nrow(output)) write.table(output,file=Sys.getenv(filepdf), quote = FALSE) For the mean, min, max and standard deviance (deviation I suppose) you don't need to store all data in the memory, you can calculate them incrementally. Read the file line by line (if it is a text file). G. On Tue, Jan 6, 2009 at 6:10 PM, Edwin Sendjaja edw...@web.de wrote: Hi Ben, Using colClasses doensnt improve the performace much. With the data, I will calculate the mean, min, max, and standard deviance. I have also failed to import the data in a Mysql Database. I dont have much knowledge in Mysql. Edwin Edwin Sendjaja edwin7 at web.de writes: Hi Simon, My RAM is only 3.2 GB (actually it should be 4 GB, but my Motherboard doesnt support it. R use almost of all my RAM and half of my swap. I think memory.limit will not solve my problem. It seems that I need RAM. Unfortunately, I can't buy more RAM. Why R is slow reading big data set? Edwin Start with FAQ 7.28 , http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-is-read_002etable_0028_ 002 9-so-inefficient_003f However, I think you're going to have much bigger problems if you have a 3.1G data set and a total of 3.2G of RAM: what do you expect to be able to do with this data set once you've read it in? Have you considered storing it in a database and accessing just the bits you need at any one time? 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Duplicated messages
Folks: I am getting duplicate messages on posts. Please correct my details if I'm wrong, but I believe it's because folks are posting to **both** the addresses, r-help@r-project.org and r-h...@stat.math.eth.ch . I believe the first is just an alias for the second, and that's why the suplicate posts occur. So please choose one or the other, not both. -- Bert Gunter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using apply for two datasets
Hi Gang, Perhaps this post might be useful in this case. Please take a special lookat Gábor Csárdi's reply. http://www.nabble.com/apply,-t-test-and-p-values-to20012292.html#a20012292 HTH, Jorge On Tue, Jan 6, 2009 at 1:10 PM, Gang Chen gangch...@gmail.com wrote: Thanks a lot for the quick help! mapply() seems promising. However, mapply(t.test, myData1, myData2) would not work, so how can I specify the margin in mapply() which function t.test() will be applied over? For example, I specify the 2nd dimension (column) in apply(myData1, 2, t.test) to run one-sample t-test. Is there a way I can achieve the same with mapply()? Thanks again, Gang On Tue, Jan 6, 2009 at 12:34 PM, Henrique Dallazuanna www...@gmail.com wrote: I think that you can use mapply for this. On Tue, Jan 6, 2009 at 3:24 PM, Gang Chen gangch...@gmail.com wrote: I can run one-sample t-test on an array, for example a matrix myData1, with the following apply(myData1, 2, t.test) Is there a similar fashion using apply() or something else to run 2-sample t-test with datasets from two groups, myData1 and myData2, without looping? TIA, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] history: recording
On Tue, 6 Jan 2009, Troels Ring wrote: Thanks a lot - windows(record=TRUE) seems to do the job. If you want to control an already open graphics device you will need the R-devel version, which has a function msgWindow() to change a lot of settings, including 'record'. Sorry not to have found it. Troels jim holtman skrev: ?windows On Tue, Jan 6, 2009 at 10:44 AM, Troels Ring tr...@gvdnet.dk wrote: Hi, I'm using windows xp and R 2.8.0 - I wonder what is the command to put in a script that has the same effect as when in a plot you choose menu History and Recording. Best wishes Troels -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Two Noobie questions
1. I have a list of lm (linear model) objects. Is it possible to select, through subscripts, a particular element (say, the intercept) from all the models? I've tried something like this: List[[1:length(list)]][1] All members of the list are similar. My goal is to have a list of the intercepts and lists of other estimated parameters. Is it better to convert to a matrix? How to do this? 2. Connected to this, how do I convert from a list back to a vector? This problem arose from using split to split a vector by a factor, then selecting a subset of this (ie. length10), leaving me with subset list of my original. Unsplit(newList, factor) doesn't work, presumably due to my removal of some values. Thoughts? Thanks! -Allen -- View this message in context: http://www.nabble.com/Two-Noobie-questions-tp21316554p21316554.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] Two Noobie questions
On Jan 6, 2009, at 1:50 PM, AllenL wrote: 1. I have a list of lm (linear model) objects. Is it possible to select, through subscripts, a particular element (say, the intercept) from all the models? I've tried something like this: ?coef if your list of models is ml, then perhaps something like this partially tested idea: lapply(ml, function(x) coef(x)[1] ) This is what I get using that formulation an available logistic model: coef(lr.TC_HDL_BMI)[1] Intercept -6.132448 List[[1:length(list)]][1] All members of the list are similar. My goal is to have a list of the intercepts and lists of other estimated parameters. Is it better to convert to a matrix? How to do this? 2. Connected to this, how do I convert from a list back to a vector? This problem arose from using split to split a vector by a factor, then selecting a subset of this (ie. length10), leaving me with subset list of my original. Unsplit(newList, factor) doesn't work, presumably due to my removal of some values. Thoughts? ?unlist ll - list(1,2,3,4) ll [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 unlist(ll) [1] 1 2 3 4 str(unlist(ll)) num [1:4] 1 2 3 4 is.vector(unlist(ll)) [1] TRUE -- David Winsemius Thanks! -Allen -- View this message in context: http://www.nabble.com/Two-Noobie-questions-tp21316554p21316554.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] Alternate looping
On Tue, 06-Jan-2009 at 04:27PM +, Luis Ridao Cruz wrote: | R-help, | | I'm using the for control flow to graph plots continuously: | | par(mfrow=c(3,5), mar=c(0.6,.2,1.2,.2),yaxt=n,xaxt=n) | for(j in 1:11) | { | for(i in 1:15) | { | | species - spAldur[spAldur$ar == 1993+i spAldur$aldur == j,] | | plot(spec...@coords[,1], spec...@coords[,2], xlim=c(-10,-3.5), | ylim=c(60.1,63) | , col=3,type=n,xlab=,ylab=) | points(geoFeatures[[dyp100]],pch=.,cex=1.2,col=blue) | . | . | . | }} | | This will plot a map of something in the following way: | | (j=1, i=1), (j=1, i=2),(i=1, i=3),,, | (j=2, i=1), (j=2, i=2),(i=2, i=3),,, | (j=3, i=1), (j=3, i=2),(i=3, i=3),,, | | and so on but I wish to have it like this: | | (j=1, i=1), (j=2,i=2),(i=3,i=3),,, So what do you do for i 11? It might be as simple as a single loop and this: species - spAldur[spAldur$ar == 1993+i spAldur$aldur == i,] HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sqldf with date (class date) variables ?
Hello, I am having trouble with retrieving some data in queries involve with variables with data type date. See the enclosed example: ll-c(21DEC2006,15DEC2006) ss-data.frame(ll) ss-transform(ss,ll=as.date(as.character(ll))) (ss) ll 1 17156 2 17150 tt-sqldf(select ll from ss) (tt) ll 1 NA 2 NA str(ss) 'data.frame': 2 obs. of 1 variable: $ ll:Class 'date' int [1:2] 17156 17150 str(tt) 'data.frame': 2 obs. of 1 variable: $ ll:Class 'date' int [1:2] NA NA So all the elements of ll (of tt) has been converted into NA. Is there anyway that I can query the variables with date data type using sqldf? Many Thanks, Si. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] for loop and if problem
On Tue, 6 Jan 2009, Sake wrote: Hi, I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each gene in my dataset. This looks like a minor variant on the 'first and last observation' thread from a few days ago: http://thread.gmane.org/gmane.comp.lang.r.general/135411 to which several useful solutions were posted. I suggest you read that thread and try to adapt what is there to your situation. If this does not get you all the way there, when you post back it will help to provide commented, minimal, self-contained, reproducible code. What you have given us is not quite there. Here is a start: data - read.csv(http://www.nabble.com/file/p21312449/genlistchrompos.csv,sep=';') and note that colnames(data) [1] Query Gene Chrom Strand Accession [6] Exon Exon_Start.Chr. Exon_Stop.Chr.Exon_Start.Trans. Exon_Stop.Trans. does not include anything like Column 'B', so refer to those column names if you need further help after studying the thread above. HTH, Chuck Attached is the dataset: http://www.nabble.com/file/p21312449/genlistchrompos.csv genlistchrompos.csv Column 'B' is the gene name, 'G' is the starting position and 'H' is the stop position. You can load the dataset by using: data-read.csv(genlistchrompos.csv, sep=;) I hope someone can help me, it's giving me headaches for a week now:-((. Thanks! -- View this message in context: http://www.nabble.com/for-loop-and-if-problem-tp21312449p21312449.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. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two Noobie questions
Thanks for your help! I combined the above two to get the following, which seems to work (if somewhat inelegant): int.List-unlist(lapply(lmList, function(x) {coef(x)[1]}),use.names=FALSE) lmList is my list of lm objects. -Allen David Winsemius wrote: On Jan 6, 2009, at 1:50 PM, AllenL wrote: 1. I have a list of lm (linear model) objects. Is it possible to select, through subscripts, a particular element (say, the intercept) from all the models? I've tried something like this: ?coef if your list of models is ml, then perhaps something like this partially tested idea: lapply(ml, function(x) coef(x)[1] ) This is what I get using that formulation an available logistic model: coef(lr.TC_HDL_BMI)[1] Intercept -6.132448 List[[1:length(list)]][1] All members of the list are similar. My goal is to have a list of the intercepts and lists of other estimated parameters. Is it better to convert to a matrix? How to do this? 2. Connected to this, how do I convert from a list back to a vector? This problem arose from using split to split a vector by a factor, then selecting a subset of this (ie. length10), leaving me with subset list of my original. Unsplit(newList, factor) doesn't work, presumably due to my removal of some values. Thoughts? ?unlist ll - list(1,2,3,4) ll [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 unlist(ll) [1] 1 2 3 4 str(unlist(ll)) num [1:4] 1 2 3 4 is.vector(unlist(ll)) [1] TRUE -- David Winsemius Thanks! -Allen -- View this message in context: http://www.nabble.com/Two-Noobie-questions-tp21316554p21316554.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/Two-Noobie-questions-tp21316554p21317630.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] Using apply for two datasets
Perhaps you can convert your matrices to data frames as in: mapply(t.test,as.data.frame(myData1),as.data.frame(myData2)) to test by column and mapply(t.test,as.data.frame(t(myData1)),as.data.frame(t(myData2))) to test by row? - Original Message From: Gang Chen gangch...@gmail.com To: Henrique Dallazuanna www...@gmail.com Cc: r-h...@stat.math.ethz.ch Sent: Tuesday, January 6, 2009 10:10:44 AM Subject: Re: [R] Using apply for two datasets Thanks a lot for the quick help! mapply() seems promising. However, mapply(t.test, myData1, myData2) would not work, so how can I specify the margin in mapply() which function t.test() will be applied over? For example, I specify the 2nd dimension (column) in apply(myData1, 2, t.test) to run one-sample t-test. Is there a way I can achieve the same with mapply()? Thanks again, Gang On Tue, Jan 6, 2009 at 12:34 PM, Henrique Dallazuanna www...@gmail.com wrote: I think that you can use mapply for this. On Tue, Jan 6, 2009 at 3:24 PM, Gang Chen gangch...@gmail.com wrote: I can run one-sample t-test on an array, for example a matrix myData1, with the following apply(myData1, 2, t.test) Is there a similar fashion using apply() or something else to run 2-sample t-test with datasets from two groups, myData1 and myData2, without looping? TIA, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R SEM package
Does anyone know if the sem package in R can implement a stacked model comparison, for example as in LISREL or AMOS? Thanks, Anthony -- Anthony Steven Dick, Ph.D. Post-Doctoral Fellow Human Neuroscience Laboratory Department of Neurology The University of Chicago 5841 S. Maryland Ave. MC-2030 Chicago, IL 60637 Phone: (773)-834-7770 Email: ad...@uchicago.edu Web: http://home.uchicago.edu/~adick/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Overlaying several qqnorm curves in same frame
Hi all, I want to create a rather standard overlaid qqnorm plot on a single variable, with different subgroups of the same dataset plotted using different colors/symbols/etc. (I don't want side-by-side, rather different-colored curves on the same graph) I managed to do it rather tediously using lapply and split, and wondered whether there is any single-command shortcut. Is there anything on the lattice package perhaps? Thanks in advance, Assaf [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R SEM package
Dear Anthony, I'm not sure what you mean by a stacked model comparison. If you mean a model fit to multiple groups, then the answer is no. If you mean comparison of nested models, then anova() can be used to get a LR test. See ?anova.sem. I hope this helps, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anthony Dick Sent: January-06-09 2:56 PM To: r-help@r-project.org Subject: [R] R SEM package Does anyone know if the sem package in R can implement a stacked model comparison, for example as in LISREL or AMOS? Thanks, Anthony -- Anthony Steven Dick, Ph.D. Post-Doctoral Fellow Human Neuroscience Laboratory Department of Neurology The University of Chicago 5841 S. Maryland Ave. MC-2030 Chicago, IL 60637 Phone: (773)-834-7770 Email: ad...@uchicago.edu Web: http://home.uchicago.edu/~adick/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Overlaying several qqnorm curves in same frame
On 1/6/09, Assaf oron assaf.o...@gmail.com wrote: Hi all, I want to create a rather standard overlaid qqnorm plot on a single variable, with different subgroups of the same dataset plotted using different colors/symbols/etc. (I don't want side-by-side, rather different-colored curves on the same graph) I managed to do it rather tediously using lapply and split, and wondered whether there is any single-command shortcut. Is there anything on the lattice package perhaps? Yes, use qqmath(~x, groups=...), e.g., qqmath(~ height, data = singer, groups = voice.part, auto.key = TRUE) -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using apply for two datasets
Thanks a lot for the suggestions, Jorge and Satoshi Takahama! Both approaches work well... Gang On Tue, Jan 6, 2009 at 2:12 PM, Satoshi Takahama s.takah...@yahoo.com wrote: Perhaps you can convert your matrices to data frames as in: mapply(t.test,as.data.frame(myData1),as.data.frame(myData2)) to test by column and mapply(t.test,as.data.frame(t(myData1)),as.data.frame(t(myData2))) to test by row? - Original Message From: Gang Chen gangch...@gmail.com To: Henrique Dallazuanna www...@gmail.com Cc: r-h...@stat.math.ethz.ch Sent: Tuesday, January 6, 2009 10:10:44 AM Subject: Re: [R] Using apply for two datasets Thanks a lot for the quick help! mapply() seems promising. However, mapply(t.test, myData1, myData2) would not work, so how can I specify the margin in mapply() which function t.test() will be applied over? For example, I specify the 2nd dimension (column) in apply(myData1, 2, t.test) to run one-sample t-test. Is there a way I can achieve the same with mapply()? Thanks again, Gang On Tue, Jan 6, 2009 at 12:34 PM, Henrique Dallazuanna www...@gmail.com wrote: I think that you can use mapply for this. On Tue, Jan 6, 2009 at 3:24 PM, Gang Chen gangch...@gmail.com wrote: I can run one-sample t-test on an array, for example a matrix myData1, with the following apply(myData1, 2, t.test) Is there a similar fashion using apply() or something else to run 2-sample t-test with datasets from two groups, myData1 and myData2, without looping? TIA, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Contributed Documentation
Hi the list, I wrote a tutorial about S4. Is it possible to have a link to it in the page Contributed Documentation or R Documentation on the CRAN web site ? Who shall I contact ? Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R SEM package
Dear Anthony, As I said, the sem package won't do multiple-group analysis. I would like at some point to add multiple-group analysis to the capabilities of the package but I can't say when I might find time to do that. Sorry, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anthony Dick Sent: January-06-09 3:57 PM Cc: r-help@r-project.org Subject: Re: [R] R SEM package Hi John- Thanks for responding so quickly. Love the package by the way. I am using R sem to model fMRI data, and I want to compare models between conditions (i.e., to see if there is a significant difference between specific path coefficients of two models). I believe this amounts to what is commonly referred to as a multi-group analysis, where two models are run simultaneously, allowing some coefficients to vary while others are maintained. The procedure is described briefly in the Appendix of: Pugesek Tomer (1996). Evolutionary Ecology, 10, 387-404. I am not sure if anova() does what I want it to. Anthony John Fox wrote: Dear Anthony, I'm not sure what you mean by a stacked model comparison. If you mean a model fit to multiple groups, then the answer is no. If you mean comparison of nested models, then anova() can be used to get a LR test. See ?anova.sem. I hope this helps, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anthony Dick Sent: January-06-09 2:56 PM To: r-help@r-project.org Subject: [R] R SEM package Does anyone know if the sem package in R can implement a stacked model comparison, for example as in LISREL or AMOS? Thanks, Anthony -- Anthony Steven Dick, Ph.D. Post-Doctoral Fellow Human Neuroscience Laboratory Department of Neurology The University of Chicago 5841 S. Maryland Ave. MC-2030 Chicago, IL 60637 Phone: (773)-834-7770 Email: ad...@uchicago.edu Web: http://home.uchicago.edu/~adick/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Anthony Steven Dick, Ph.D. Post-Doctoral Fellow Human Neuroscience Laboratory Department of Neurology The University of Chicago 5841 S. Maryland Ave. MC-2030 Chicago, IL 60637 Phone: (773)-834-7770 Email: ad...@uchicago.edu Web: http://home.uchicago.edu/~adick/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Social Networks - how to get the same network layout every time when I plot the network?
Hi, I am using the function plot.network from the network library. However, I noticed that every time when I use the function I get a different layout (the network is rotated?). I would like to get the exact same picture every time when I use the function. Is that possible (maybe set a seed or some layout parameters?)? How? Here is an example: n-6 dat - rbinom(n*(n-1)/2,1,.6) net-diag(n) net[lower.tri(net)] - dat net[upper.tri(net)] - t( net )[upper.tri(net)] net #the network library(network) g-network(net,directed=FALSE) plot.network(g) and if I run plot.network(g) again, I get the same network (dah!) but rotated. Any suggestions? Thank you, Despina [[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] Drawing from an empirical distribution
Hi All, Does anybody know if there is a simple way to draw numbers from an empirical distribution? I know that I can plot the empirical cumulative distribution function this easy: plot(ecdf(x)) Now I want to pick a number between 0 and 1 and go back to domain of x. Sounds simple to me. Any suggestion? Thank you, Your culprit (everybody needs a culprit) -- View this message in context: http://www.nabble.com/Drawing-from-an-empirical-distribution-tp21320810p21320810.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] Drawing from an empirical distribution
If the ecdf is 'ecdf(x)', do just: sample(x, size=whatever, replace=TRUE) HTH, Antonio. 2009/1/6 culpritNr1 ig2ar-s...@yahoo.co.uk: Hi All, Does anybody know if there is a simple way to draw numbers from an empirical distribution? I know that I can plot the empirical cumulative distribution function this easy: plot(ecdf(x)) Now I want to pick a number between 0 and 1 and go back to domain of x. Sounds simple to me. Any suggestion? Thank you, Your culprit (everybody needs a culprit) -- View this message in context: http://www.nabble.com/Drawing-from-an-empirical-distribution-tp21320810p21320810.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. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Drawing from an empirical distribution
the empirical distribution gives probability 1/n to each of n observations. rather than sampling the unit interval, just resample the dataset. If x is your dataset, and you want an independent sample of size k, sample(x,size=k,replace=TRUE) albyn On Tue, Jan 06, 2009 at 02:39:17PM -0800, culpritNr1 wrote: Hi All, Does anybody know if there is a simple way to draw numbers from an empirical distribution? I know that I can plot the empirical cumulative distribution function this easy: plot(ecdf(x)) Now I want to pick a number between 0 and 1 and go back to domain of x. Sounds simple to me. Any suggestion? Thank you, Your culprit (everybody needs a culprit) -- View this message in context: http://www.nabble.com/Drawing-from-an-empirical-distribution-tp21320810p21320810.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] Drawing from an empirical distribution
Thank you. That's exactly what I was looking for. Antonio, Fabio Di Narzo wrote: If the ecdf is 'ecdf(x)', do just: sample(x, size=whatever, replace=TRUE) HTH, Antonio. 2009/1/6 culpritNr1 ig2ar-s...@yahoo.co.uk: Hi All, Does anybody know if there is a simple way to draw numbers from an empirical distribution? I know that I can plot the empirical cumulative distribution function this easy: plot(ecdf(x)) Now I want to pick a number between 0 and 1 and go back to domain of x. Sounds simple to me. Any suggestion? Thank you, Your culprit (everybody needs a culprit) -- View this message in context: http://www.nabble.com/Drawing-from-an-empirical-distribution-tp21320810p21320810.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. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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/Drawing-from-an-empirical-distribution-tp21320810p21321149.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] Drawing from an empirical distribution
Sure, but it would be more 'fun' to modify ecdf() slightly to produce an ecqf() function -- essentially reversing the arguments to approxfun()-- and then use ecqf(runif(whatever)) no nit-picking about efficiency, please. url:www.econ.uiuc.edu/~rogerRoger Koenker emailrkoen...@uiuc.eduDepartment of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Jan 6, 2009, at 4:42 PM, Antonio, Fabio Di Narzo wrote: If the ecdf is 'ecdf(x)', do just: sample(x, size=whatever, replace=TRUE) HTH, Antonio. 2009/1/6 culpritNr1 ig2ar-s...@yahoo.co.uk: Hi All, Does anybody know if there is a simple way to draw numbers from an empirical distribution? I know that I can plot the empirical cumulative distribution function this easy: plot(ecdf(x)) Now I want to pick a number between 0 and 1 and go back to domain of x. Sounds simple to me. Any suggestion? Thank you, Your culprit (everybody needs a culprit) -- View this message in context: http://www.nabble.com/Drawing-from-an-empirical-distribution-tp21320810p21320810.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. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Drawing from an empirical distribution
Nit-picking about syntax does seem needed, mea culpa, I intended something more like: Qn - ecqf(x) Qn(runif(whatever)) On Jan 6, 2009, at 5:06 PM, roger koenker wrote: Sure, but it would be more 'fun' to modify ecdf() slightly to produce an ecqf() function -- essentially reversing the arguments to approxfun()-- and then use ecqf(runif(whatever)) no nit-picking about efficiency, please. url:www.econ.uiuc.edu/~rogerRoger Koenker emailrkoen...@uiuc.eduDepartment of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Jan 6, 2009, at 4:42 PM, Antonio, Fabio Di Narzo wrote: If the ecdf is 'ecdf(x)', do just: sample(x, size=whatever, replace=TRUE) HTH, Antonio. 2009/1/6 culpritNr1 ig2ar-s...@yahoo.co.uk: Hi All, Does anybody know if there is a simple way to draw numbers from an empirical distribution? I know that I can plot the empirical cumulative distribution function this easy: plot(ecdf(x)) Now I want to pick a number between 0 and 1 and go back to domain of x. Sounds simple to me. Any suggestion? Thank you, Your culprit (everybody needs a culprit) -- View this message in context: http://www.nabble.com/Drawing-from-an-empirical-distribution-tp21320810p21320810.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. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Memory Efficiency of Symmetric Matrix
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm generating a symmetric correlation matrix using a data matrix as input: mat - cor(data.mat) My question is: Is there a more memory efficient way to store this data? For instance, since: all(mat == t(mat)) every value is duplicated, and I should be able to almost half the memory usage for large matrices. Any thoughts/comments? Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklj9yAACgkQ9gTv6QYzVL6MGQCg1CHsRGAwEMah/8ZuZ9QFI6O5 lcIAnjZ68DE9FABLMd07A3AfdMPRpXIH =5bet -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] Social Networks - how to get the same network layout every time when I plot the network?
If you want the same network each time, then set the random seed to the same value: n-6 dat - rbinom(n*(n-1)/2,1,.6) net-diag(n) net[lower.tri(net)] - dat net[upper.tri(net)] - t( net )[upper.tri(net)] net #the network library(network) g-network(net,directed=FALSE) set.seed(1) plot.network(g) set.seed(1) plot.network(g) On Tue, Jan 6, 2009 at 4:45 PM, Despina Stefan despina.ste...@genmills.com wrote: Hi, I am using the function plot.network from the network library. However, I noticed that every time when I use the function I get a different layout (the network is rotated?). I would like to get the exact same picture every time when I use the function. Is that possible (maybe set a seed or some layout parameters?)? How? Here is an example: n-6 dat - rbinom(n*(n-1)/2,1,.6) net-diag(n) net[lower.tri(net)] - dat net[upper.tri(net)] - t( net )[upper.tri(net)] net #the network library(network) g-network(net,directed=FALSE) plot.network(g) and if I run plot.network(g) again, I get the same network (dah!) but rotated. Any suggestions? Thank you, Despina [[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 that 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] Memory Efficiency of Symmetric Matrix
You can do mat[lower.tri(mat, diag=F)] Søren Fra: r-help-boun...@r-project.org på vegne af Nathan S. Watson-Haigh Sendt: on 07-01-2009 01:28 Til: r-help@r-project.org Emne: [R] Memory Efficiency of Symmetric Matrix -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm generating a symmetric correlation matrix using a data matrix as input: mat - cor(data.mat) My question is: Is there a more memory efficient way to store this data? For instance, since: all(mat == t(mat)) every value is duplicated, and I should be able to almost half the memory usage for large matrices. Any thoughts/comments? Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org http://enigmail.mozdev.org/ iEYEARECAAYFAklj9yAACgkQ9gTv6QYzVL6MGQCg1CHsRGAwEMah/8ZuZ9QFI6O5 lcIAnjZ68DE9FABLMd07A3AfdMPRpXIH =5bet -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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How-To extract data from a matrix of lists subject to a set of given constraints
My goal is to store the DWT coefficients from a number of time series in such a way to be able to extract subsets satisfying giben conditions. I have defined the following 11 matrices whose x-axis represent time intervals and y-axis represent the number of time series: MS - 11 d1.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-1)) d2.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d3.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d4.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-4)) d5.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-5)) d6.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-6)) d7.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-7)) d8.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-8)) d9.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-9)) d10.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-10)) d11.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-11)) Each di.mat (i=1,2,...,11) matrix slot is assigned a DWT coefficient modulus and the signal and cycle number it belongs to: coef - abs (as.numeric (aa.dwt$data[[n]])) #GET DWT COEFFICIENTS .. for (k in 1:length(coef)) { d7.mat [[nCycle ,k]] - list (data=coef [k],variable=paste(insig,:,cyc,sep=)) } As a consequence d7.mat contains the following: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL My goal is to store the DWT coefficients from a number of time series in such a way to be able to extract subsets satisfying giben conditions. I have defined the following 11 matrices whose x-axis represent time intervals and y-axis represent the number of time series: MS - 11 d1.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-1)) d2.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d3.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d4.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-4)) d5.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-5)) d6.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-6)) d7.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-7)) d8.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-8)) d9.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-9)) d10.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-10)) d11.mat - matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-11)) Each di.mat (i=1,2,...,11) matrix slot is assigned a DWT coefficient modulus and the signal and cycle number it belongs to: coef - abs (as.numeric (aa.dwt$data[[n]])) #GET DWT COEFFICIENTS .. for (k in 1:length(coef)) { d7.mat [[nCycle ,k]] - list (data=coef [k],variable=paste(insig,:,cyc,sep=)) } As a consequence d7.mat contains the following: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [2,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [3,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [4,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [5,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [6,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [7,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL [8,] List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL NULL [9,] List,2 List,2 List,2 List,2 NULL NULL NULL NULL NULL NULL d5.mat[[3,4]] $data [1] 0.6290917 $variable [1] 10146:3 d5.mat[[6,4]] $data [1] 1.187133 $variable [1] 10146:6 d5.mat[[8,4]] NULL d5.mat[[10,4]] $data [1] 0.7789786 $variable [1] 10146:10 d5.mat[[50,4]] $data [1] 0.8909976 $variable [1] 10146:50 How can I extract, for instance, all the data from the i_th column of the matrix that satisfy a given conditon? In the case of a matrix A made up of numbers I would write : which (A [,i] 0.1) ...? Thank you in advance for your help. Maura tutti i telefonini TIM! [[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] Contributed Documentation
Christophe Genolini cgenolin at u-paris10.fr writes: Hi the list, I wrote a tutorial about S4. Is it possible to have a link to it in the page Contributed Documentation or R Documentation on the CRAN web site ? Who shall I contact ? Christophe Try c...@r-project.org . Posting to the development list (r-de...@r-project.org) might also be appropriate. I would be curious to see the tutorial myself. 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] Memory Efficiency of Symmetric Matrix
See also the dist() function documentation. If you use indexing as described in ?dist it is straightforward to maintain and use a vector of the distances. Steven McKinney Statistician Molecular Oncology and Breast Cancer Program British Columbia Cancer Research Centre email: smckinney +at+ bccrc +dot+ ca tel: 604-675-8000 x7561 BCCRC Molecular Oncology 675 West 10th Ave, Floor 4 Vancouver B.C. V5Z 1L3 Canada -Original Message- From: r-help-boun...@r-project.org on behalf of Søren Højsgaard Sent: Tue 1/6/2009 4:36 PM To: Nathan S. Watson-Haigh; r-help@r-project.org Subject: Re: [R] Memory Efficiency of Symmetric Matrix You can do mat[lower.tri(mat, diag=F)] Søren Fra: r-help-boun...@r-project.org på vegne af Nathan S. Watson-Haigh Sendt: on 07-01-2009 01:28 Til: r-help@r-project.org Emne: [R] Memory Efficiency of Symmetric Matrix -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm generating a symmetric correlation matrix using a data matrix as input: mat - cor(data.mat) My question is: Is there a more memory efficient way to store this data? For instance, since: all(mat == t(mat)) every value is duplicated, and I should be able to almost half the memory usage for large matrices. Any thoughts/comments? Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org http://enigmail.mozdev.org/ iEYEARECAAYFAklj9yAACgkQ9gTv6QYzVL6MGQCg1CHsRGAwEMah/8ZuZ9QFI6O5 lcIAnjZ68DE9FABLMd07A3AfdMPRpXIH =5bet -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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Generating GUI for r-scripts
Daren Tan daren76 at hotmail.com writes: I have developed some scripts that basically ask for input tab-limited format files, do some processing, and output several pictures or csv. Now I need to have some gui to wrap on top of the scripts, so that end-users can select their input files, adjust some parameters for processing, and select output folder or filenames. Please advice me if there is any tools or project suitable for my tasks. Daren, I'm no expert by any means, but you might take a look at the packages fgui and gWidgets, as well as R Gui Generator (http://rgg.r-forge.r-project.org/). There is also a specific mailing list for gui discussions: http://dir.gmane.org/gmane.comp.lang.r.gui. Hope this helps, Michael Bibo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Memory Efficiency of Symmetric Matrix
the SparseM package might be what you are looking for http://www.econ.uiuc.edu/~roger/research/sparse/SparseM.pdf On Jan 7, 11:36 am, Søren Højsgaard soren.hojsga...@agrsci.dk wrote: You can do mat[lower.tri(mat, diag=F)] Søren Fra: r-help-boun...@r-project.org på vegne af Nathan S. Watson-Haigh Sendt: on 07-01-2009 01:28 Til: r-h...@r-project.org Emne: [R] Memory Efficiency of Symmetric Matrix -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm generating a symmetric correlation matrix using a data matrix as input: mat - cor(data.mat) My question is: Is there a more memory efficient way to store this data? For instance, since: all(mat == t(mat)) every value is duplicated, and I should be able to almost half the memory usage for large matrices. Any thoughts/comments? Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web:http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.orghttp://enigmail.mozdev.org/ iEYEARECAAYFAklj9yAACgkQ9gTv6QYzVL6MGQCg1CHsRGAwEMah/8ZuZ9QFI6O5 lcIAnjZ68DE9FABLMd07A3AfdMPRpXIH =5bet -END PGP SIGNATURE- __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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] RODBC connection die - using more than 1 Rgui/Rcmdr
First of all, I apologize for misleading you by mentioning irrelevant error message. Forget about the error message I stated in the first place. I should have clearly stated in the first place. No error message was shown at the moment of the problem. Without any warnings and error message shown, my entire network connection was killed. Under the circumstance that my computer was thoroughly disconnected from the network, I tried to re-connect through RODBC and I was left with the error message as a result. Thus, as you mentioned in the first reply, yes I admit that error message is a matter of Oracle. not RODBC, since it explains that no connection is available to the database. Second, I suspect that it only matters with RODBC and Oracle. I've not checked with other databases. Thus only users with oracle access might be able to handle this problem. Sorry that I am not able to test in various environments. The following may be the example to reproduce the same error. Only person with Oracle is applicable. Let's assume I have a Oracle database DB1. Within DB1, I have three tables with identical structure.(to make the example simple). (TB1,TB2,TB3) TB1 has data as follows. Col1 1,2,3,4,5,6,7,8,9,.. Col2 A,B,C,D,E,F,G,H,... Col3 a,b,c,d,e,f,g,h,... The table contain hugh amounts of rows. So it will take a while to copy entire table to TB2 or either TB3. (at least 20 secs) What I try to demonstrate next is to reproduce the disconnection error when conducting sqlSave command with more than 1 Rgui with RODBC. library(RODBC) initdb = function() { odbcCloseAll() Con - odbcConnect(dsn=DB1,uid=AA,pwd=ABC,case=oracle) assign('Con', Con, env =.GlobalEnv) } 1. Open Rgui (1) initdb() qry - select * from TB1 tb1 - sqlQuery(Con, qry) 2. Open another Rgui(2) initdb() qry - select * from TB1 tb1 - sqlQuery(Con, qry) 3. When both commands above is done completely, type the following command in each Rgui appropriately. Rgui(1): sqlSave(Con,tb1, TB2, append=TRUE, rownames= FALSE) Rgui(2): sqlSave(Con,tb1, TB3, append=TRUE, rownames= FALSE) The operating moments for both command should be overlapped more than 20 seconds, and you will face the same problem as I did. (That's why I doubt the stability of RODBC with Oracle database). * if you didn't see the problem, try to enlarge the data amount or open more Rgui's and apply for the same instruction as above. I was just wondering whether someone out there might encounter the same problem, and how they deal with the problem. If there's anyone who could enlighten me, your help will be greatly appreciated. Thank you in advance. Duncan Murdoch-2 wrote: On 05/01/2009 9:26 PM, jaey.ahn wrote: Yes, I am aware of that. RODBC connection is automatically shutting down without any warnings or error message. (That's why I jotted down Oracle error message when trying to reconnect). I don't think it's a matter of Oracle since I've tested many query works simultaneously with multiple windows. I suspect RODBC's stability with multiple windows. That would be a bug, so you should put together a simple example to reproduce it. Avoid Rcmdr, try to just use Rgui and RODBC. The big problem will be the database: if your example requires Oracle, only someone with Oracle will be able to debug it, so try to put together a generic example that works with any database with an ODBC driver. I still suspect Oracle here (it did say internal error after all), so please do demonstrate it on some other database before you conclude it's an RODBC problem. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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/RODBC-connection-die---using-more-than-1-Rgui-Rcmdr-tp21301543p21322836.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] breaking a loop in R
Hi All, I was wondering if there is anything that breaks a loop in R. For example, For (k in 1:100) For ( i in 1:10){ If ( condition ){ Break the inner loop } } } In the above case, if the program runs the if statement, then I want the inner loop for (i in 1:10) to stop looping and skip the rest of the program. Thanks for your help -- View this message in context: http://www.nabble.com/breaking-a-loop-in-R-tp21322868p21322868.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] breaking a loop in R
something like this should do it: breakFlag - FALSE For (k in 1:100) For ( i in 1:10){ If ( condition ){ breakFlag - TRUE break } } if (breakFlag) break } On Tue, Jan 6, 2009 at 7:58 PM, kayj kjaj...@yahoo.com wrote: Hi All, I was wondering if there is anything that breaks a loop in R. For example, For (k in 1:100) For ( i in 1:10){ If ( condition ){ Break the inner loop } } } In the above case, if the program runs the if statement, then I want the inner loop for (i in 1:10) to stop looping and skip the rest of the program. Thanks for your help -- View this message in context: http://www.nabble.com/breaking-a-loop-in-R-tp21322868p21322868.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 that 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] Memory Efficiency of Symmetric Matrix
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 andrew wrote: the SparseM package might be what you are looking for http://www.econ.uiuc.edu/~roger/research/sparse/SparseM.pdf On Jan 7, 11:36 am, Søren Højsgaard soren.hojsga...@agrsci.dk wrote: You can do mat[lower.tri(mat, diag=F)] Søren Thanks, although my matrices are dense and not sparse. I have however, found the Matrix package: http://cran.r-project.org/web/packages/Matrix/index.html The dspMatrix class, seems like what I might want: dspMatrix - Symmetric real matrices in packed storage (one triangle only) I'm just trying to test it out with my usual 24k x 24k size matrices. Fra: r-help-boun...@r-project.org på vegne af Nathan S. Watson-Haigh Sendt: on 07-01-2009 01:28 Til: r-h...@r-project.org Emne: [R] Memory Efficiency of Symmetric Matrix I'm generating a symmetric correlation matrix using a data matrix as input: mat - cor(data.mat) My question is: Is there a more memory efficient way to store this data? For instance, since: all(mat == t(mat)) every value is duplicated, and I should be able to almost half the memory usage for large matrices. Any thoughts/comments? Cheers, Nathan __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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. - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklkF14ACgkQ9gTv6QYzVL7ppACbB7se5hh/q34nGz2k/IFj0Y8c 2F4AoMnv+BTGT333lpMFl56pZyczMCyf =PMQ5 -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] Converting data frame to symmetric matrix
try this: L3 - LETTERS[1:3] x=c(1,1,2,2,3,3,4,4,5,5) y=1:10 d - data.frame(cbind(x,y), fac=I(sample(L3, 10, replace=TRUE))) m.out - matrix(ncol=10, nrow=10) m.out[cbind(d$x, d$y)] - d$fac On Tue, Jan 6, 2009 at 3:29 AM, poas...@umich.edu wrote: Dear Sir or Madam, I have the following data frame (which is just a toy example of my larger dataset) L3 - LETTERS[1:3] x=c(1,1,2,2,3,3,4,4,5,5) y=1:10 d - data.frame(cbind(x,y), fac=sample(L3, 10, replace=TRUE)) This data frame produces the following output x y fac 1 1 1 C 2 1 2 C 3 2 3 B 4 2 4 B 5 3 5 C 6 3 6 B 7 4 7 B 8 4 8 C 9 5 9 B 10 5 10 A Is there a command I can use to convert data frame d into a 10 X 10 symmetric matrix where the columns are labeled 1 through 10, the rows are labeled 1 through 10, and the entries in each cell are the corresponding values of fac? For example, the first two columns and rows should have the following entries: 1 2 1 C C 2 C NA Any suggestions will be greatly appreciated. Many thanks, Paul Poast __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 that 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] breaking a loop in R
? `break` On Tue, Jan 6, 2009 at 7:58 PM, kayj kjaj...@yahoo.com wrote: I was wondering if there is anything that breaks a loop in R [[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] Understanding dsyrk_ in C code
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm trying to understand some C code in an R package I'm using. I'm address this question here as it's matrix algebra...and I'm no pro at that! the C command reads: double alpha = 1.0, beta = 0.0; dsyrk_(L, N, nGenes, nGenes, alpha, mat1, nGenes, beta, mat2, nGenes); - From google, I've found out that dsyrk is for performing one of the symmetric rank k operations - whatever that means!? From here: http://linux.die.net/man/l/dsyrk I've found that the calculation being performed is: alpha*A*A' + beta*C However, since alpha is 1 and beta is 0, this reduces to: = 1*A*A' + 0*C = A*A' Which is simply the cross productam I correct? Cheers, Nath - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklkGVYACgkQ9gTv6QYzVL73HgCgvx4OCxcuczv8nd0n6gOEPFYa w3UAnAnDIkvPDen9p7ahz+BdG47V/D/S =gSGC -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] Contributed Documentation
I would too. On Tue, Jan 6, 2009 at 8:17 PM, Ben Bolker bol...@ufl.edu wrote: Christophe Genolini cgenolin at u-paris10.fr writes: Hi the list, I wrote a tutorial about S4. Is it possible to have a link to it in the page Contributed Documentation or R Documentation on the CRAN web site ? Who shall I contact ? Christophe Try c...@r-project.org . Posting to the development list (r-de...@r-project.org) might also be appropriate. I would be curious to see the tutorial myself. 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. -- Stephen Sefick 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bar Plot with Connected Points on 1 Y-Axis
Hi Everyone, Have created a bar plot of the data below using the following code: barplot(TACC,space=0,names.arg=Year). I now want to add a series of connected points to represent the catch. I tried to do this using line(Catch) or points(Catch), however both of these commands result in each data point being aligned with the right edge of each bar. I need them to be solid points in the centre of each bar, and for each point to be connected to its neighbour by a line. Another issue I have is when the points exceed the values for the bar graph (e.g. in 2004 and 2005 catchTACC) R seems to cut them off, I need the axis to be expanded so they can be seen. I'm sure these are relatively simple problems but I am really stuck. Thanks very much for all your help, it is much appreciated. James DATA: Year Species Stock TACC Catch 1 2001ORHOR1 5000 4687 2 2002ORHOR1 6000 3215 3 2003ORHOR1 7000 6782 4 2004ORHOR1 9000 1 5 2005ORHOR1 9000 12000 -- View this message in context: http://www.nabble.com/Bar-Plot-with-Connected-Points-on-1-Y-Axis-tp21324029p21324029.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] Destroying Attributes of a Matrix
Dear all, I have the following structure of a matrix str(mdat) num [1:32268, 1:10] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : NULL How can I destroy the attributes such that it simply gives: str(mdat) num [1:32268, 1:10] 0 0 0 0 0 0 0 0 0 0 ... - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bar Plot with Connected Points on 1 Y-Axis
on 01/06/2009 09:07 PM jimdare wrote: Hi Everyone, Have created a bar plot of the data below using the following code: barplot(TACC,space=0,names.arg=Year). I now want to add a series of connected points to represent the catch. I tried to do this using line(Catch) or points(Catch), however both of these commands result in each data point being aligned with the right edge of each bar. I need them to be solid points in the centre of each bar, and for each point to be connected to its neighbour by a line. Another issue I have is when the points exceed the values for the bar graph (e.g. in 2004 and 2005 catchTACC) R seems to cut them off, I need the axis to be expanded so they can be seen. I'm sure these are relatively simple problems but I am really stuck. Thanks very much for all your help, it is much appreciated. James DATA: Year Species Stock TACC Catch 1 2001ORHOR1 5000 4687 2 2002ORHOR1 6000 3215 3 2003ORHOR1 7000 6782 4 2004ORHOR1 9000 1 5 2005ORHOR1 9000 12000 One key point to note is that barplot() returns the bar midpoints. This is noted in the help for barplot(). The bars are not centered on integer axis values, so you need the returned values to place additional annotation in the proper location relative to the bars. The other thing is to set the range of the y axis using the maximum value in Catch, plus some fudge, so that the plot covers both sets of data and has enough room for the additional points. Thus, presuming that your data is in a data frame called 'DF': mp - barplot(DF$TACC, space = 0, names.arg = DF$Year, ylim = c(0, 13000)) # Now use lines() to add Catch lines(mp, DF$Catch, type = b, pch = 19) See ?barplot, ?lines and ?points for more information. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Destroying Attributes of a Matrix
In this case, how about? dimnames(mdat) - NULL Gundala Viswanath wrote: Dear all, I have the following structure of a matrix str(mdat) num [1:32268, 1:10] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : NULL How can I destroy the attributes such that it simply gives: str(mdat) num [1:32268, 1:10] 0 0 0 0 0 0 0 0 0 0 ... - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heatmap.2 and three colours for specific r anges
Hi, I hope to show a heatmap with thre colours, no gradation. How to specify heatmap.2 to map green for values less than -1, gray for values between -1 and 1, and red for values greater than 1 ? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] directory of files in a zip file?
Hi, All: How can I get the list of files contained in a zip file? zip.file.extract will extract a specific 'file' from 'zipname', but how can I get the names of the files in 'zipname'? Thanks, Spencer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R Threatens SAS According to The NYT
On Wed, Jan 7, 2009 at 11:05 AM, ajay ohri ajayo...@yahoo.com wrote: FYI..not a R -Help Topic, buy I dont know which list to post discussions like this. Regards, Ajay -- Forwarded message -- From: ajay ohri ajayo...@yahoo.com Date: Wed, Jan 7, 2009 at 10:46 AM Subject: Re: R Threatens SAS, According to The New York Times To: sa...@listserv.uga.edu For people who have also wanted to try R , there is new version of R GUI , called Rattle downloadable from www.togaware.com Also check out Interview of Roger Hadaad , Founder of KXEN on his views on analytics at www.decisionstats.com as well as how SPSS is responding to R at http://www.decisionstats.com/2008/11/review-r-for-sas-and-spss-users/ Ajay --- On Wed, 1/7/09, Virtual SUG sfbay0...@aol.com wrote: From: Virtual SUG sfbay0...@aol.com Subject: R Threatens SAS, According to The New York Times To: sa...@listserv.uga.edu Date: Wednesday, January 7, 2009, 10:11 AM Hello everyone... Thought you might be interested in reading this article, which appears in the 1/6/9 online edition of The New York Times: http://www.nytimes.com/2009/01/07/technology/business-computing/07program.html The headline is Data Analysts Captivated by R's Power, and towards the end of the story is the following paragraph: While it is difficult to calculate exactly how many people use R, those most familiar with the software estimate that close to 250,000 people work with it regularly. The popularity of R at universities could threaten SAS Institute, the privately held business software company that specializes in data analysis software. SAS, with more than $2 billion in annual revenue, has been the preferred tool of scholars and corporate managers. Andrew Karp Sierra Information Services www.SierraInfomation.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.