[R] Multiple correspondence analysis and extended Burt table
Hi there, Does anyone know how to create extended Burt table that includes rows and columns totals and further more how to create Burt table of relative frequencies and conditional relative frequencies. Hope to hear from some of you soon! Ana [[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 on efficiency/vectorization
Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 11 0 00 0 10 b 1 1 11 0 10 0 11 c 0 1 10 0 00 0 01 d 1 0 01 1 11 1 00 e 1 0 00 0 11 0 10 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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] Help on efficiency/vectorization
Hi, Steven, try lapply( x, function( v) rownames(x)[ v == 1]) or lapply( x, function( v, rn) rn[ v == 1], rn = rownames( x))) which is faster. Regards -- Gerrit - AOR Dr. Gerrit Eichner Mathematical Institute, Room 305 E gerrit.eich...@math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/~gcb7 - On Thu, 27 Aug 2009, Steven Kang wrote: Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 11 0 00 0 10 b 1 1 11 0 10 0 11 c 0 1 10 0 00 0 01 d 1 0 01 1 11 1 00 e 1 0 00 0 11 0 10 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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] Help on efficiency/vectorization
You can do for (i in 1:ncol(x)) {names - rownames(x)[which(x[,i]==1)];eval(parse(text=paste(V,i,.ind-names,sep=)));} --- On Thu, 27/8/09, Steven Kang stochastick...@gmail.com wrote: From: Steven Kang stochastick...@gmail.com Subject: [R] Help on efficiency/vectorization To: r-help@r-project.org Received: Thursday, 27 August, 2009, 4:13 PM Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 1 1 0 0 0 0 1 0 b 1 1 1 1 0 1 0 0 1 1 c 0 1 1 0 0 0 0 0 0 1 d 1 0 0 1 1 1 1 1 0 0 e 1 0 0 0 0 1 1 0 1 0 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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] Submit a R job to a server
Deb, I generally run my larger R tasks on a server. Here is my workflow. 1) Write an R script using a text editor. (There are many popular ones.) 2) FTP the R script to your server. 3) SSH into the server 4) Run R 5) Run the script that you uploaded from the R process you just started. On 8/26/09 8:48 PM, Debabrata Midya wrote: Cedrick / Moshe, Thank you very much for such a quick response. My objective is to do the faster calculations by submitting a R job from my desktop to this server. Oracle 8i Enterprise Edition is currently running on this server. My objective is not only limited to access various oracle tables from this server but also I like to utilise this server for faster calculations and I like to use R for this. So far, I did not install anything related to R into this server. I have R installed on my desktop (Windows XP). I use RODBC / ODBC products to access data from this server and I use R / S-PLUS (installed on my desktop) to do the analyses. Is there any way to submit R job from my desktop to this server? How can I use this server to do my job faster? Once again, thank you very much for the time you have given. I am looking forward for your reply. Regards, Deb Cedrick W. Johnsoncedr...@cedrickjohnson.com 27/08/2009 12:41 pm Good Morning Deb- It's unclear (to me at least) what you are trying to do.. What is the server running? Is it running RServe for which you have a userid and pwd or is it just a plain server running some OS? *IF* this is the case (RServe): on the windows machine you will need to: install.packages(Rserve) library(Rserve) ?Rserve --and optionally-- ?RSeval I *think* RSeval/Rserve *may* be what you're looking for, but I am going off just an assumption by what you meant regarding server.. Rserve can be used as a client and server on both platforms (I personally have had more success running the server portion under linux, with linux and java clients in which the clients are a mixture of the package's java access *and* R client access to the rserver instance) More info on rserve at: http://www.rforge.net/Rserve HTH, cedrick Debabrata Midya wrote: Dear R users, Thanks in advance. I am Deb, Statistician at NSW Department of Commerce, Sydney. I am using R 2.9.1 on Windows XP. May I request you to provide me information on the following: 1. I have access to a server ( I have userid and pwd) 2. What are the packages I need to submit a job from Windows XP to this server? Should I need to install any package on this server before submitting a job? Once again, thank you very much for the time you have given. I am looking forward for your reply. Regards, Deb ** This email message, including any attached files, is confidential and intended solely for the use of the individual or entity to whom it is addressed. The NSW Department of Commerce prohibits the right to publish, copy, distribute or disclose any information contained in this email, or its attachments, by any party other than the intended recipient. If you have received this email in error please notify the sender and delete it from your system. No employee or agent is authorised to conclude any binding agreement on behalf of the NSW Department of Commerce by email. The views or opinions presented in this email are solely those of the author and do not necessarily represent those of the Department, except where the sender expressly, and with authority, states them to be the views of NSW Department of Commerce. The NSW Department of Commerce accepts no liability for any loss or damage arising from the use of this email and recommends that the recipient check this email and any attached files for the presence of viruses. ** [[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. ** This email message, including any attached files, is confidential and intended solely for the use of the individual or entity to whom it is addressed. The NSW Department of Commerce prohibits the right to publish, copy, distribute or disclose any information contained in this email, or its attachments, by any party other than the intended recipient. If you have received this email in error please notify the sender and delete it from your system. No employee or agent is authorised to conclude any binding agreement on behalf of the NSW Department of Commerce by email. The views or opinions presented in
Re: [R] as.ltraj error: date should be of the same length as xy
Hello Mike, I have radio tracking data involving relocations of raccoons over the course of a night (locations every 20 minutes). I have the date and time of each location. I am trying to convert the data into an type II ltraj so I can do a first passage time analysis. My problem is that when I try to create the ltraj I get the following error message Error in as.ltraj(xy, da, id) : date should be of the same length as xy Does anybody know why I get this message/what it means/how to fix it? Here is the code I that I have used so far data1- read.csv(file.choose()) xy - data1[,c(X,Y)] da - as.character(data1$Time) da - as.POSIXct(strptime(as.character(data1$Time),%m/%d/%y%H:%M:%S)) id - as.character(data1$id) data1 - as.ltraj(xy, da, id) Error in as.ltraj(xy, da, id) : date should be of the same length as xy If anybody could help me get through this I would greatly appreciate it. The message means that the number of rows differ from the length of da, but it is hard to know why without more detail about your data. For example, it may be that you misspelled the names of your variables (data1$Time instead of data1$time, etc.). There are many possibilities, so it would help if you could show us what is in your data at each step, i.e. the result of the following command: head(data1) xy - data1[,c(X,Y)] head(xy) da - as.character(data1$Time) head(da) da - as.POSIXct(strptime(as.character(data1$Time),%m/%d/%y%H:%M:%S)) head(da) id - as.character(data1$id) head(id) data1 - as.ltraj(xy, da, id) Regards, Clément Calenge -- Clément CALENGE Office national de la chasse et de la faune sauvage Saint Benoist - 78610 Auffargis tel. (33) 01.30.46.54.14 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [Fwd: Re: Video demo of using svSocket with data.table]
Forwarded to R-Help, because I think it could interest people following this thread. Clearly, RServe and svSocket have different goals and very little overlap. Best, Philippe Original Message Subject: Re: Video demo of using svSocket with data.table Date: Wed, 26 Aug 2009 20:34:19 +0100 From: Matthew Dowle mdo...@mdowle.plus.com Reply-To: Matthew Dowle mdo...@mdowle.plus.com To: Philippe Grosjean phgrosj...@sciviews.org, Romain Francois romain.franc...@dbmail.com References: h6kcod$5e...@ger.gmane.org 4a8e632d.6060...@sciviews.org4a8e6af1.9060...@dbmail.com 4a8e9e7d.9070...@sciviews.org Hi Philippe Romain, Thanks - interesting discussion on the list - I just caught up with it now. I agree with everything basically and look forward to the 'planned for the future'. The 'feature' of every clients and the CLI are working with the same objects on the same environment is really important to keep btw - got a bit worried by your *feature* in case you thought it was a bad thing. Rserve doesn't do that! Its a great feature and really important. I compared Rserve to svSocket and came up with this list (confirmed with Simon U). You probably already know this but just in case : 1. The main thing is Rserve's clients each have their own workspace. Its not one shared workspace, unlike with svSocket. So one client can't write something and another client then read it because they only see their own workspaces within Rserve. You might as well start lots of R's basically. 2. There is no CLI (command line interface) to Rserve i.e. no prompt to type at. Its just a process that sits there and responds to clients only. 3. Rserve on windows is limited to only one client connection, no more. The docs say that Windows is not recommended (for this reason). 4. You have to start Rserve first before you send commands to it. With svSocket, you can startup any old R, do some analysis and gather data, then decide to become a server and let clients connect. This is a really important workflow feature. With Rserve you have to think in advance and know that you'll need to be a server. You can't do any of those things with Rserve, but you can with svSocket. Rserve does do binary data transfer though. Regards, Matthew - Original Message - From: Philippe Grosjean phgrosj...@sciviews.org Newsgroups: gmane.comp.lang.r.general To: Romain Francois romain.franc...@dbmail.com Cc: Matthew Dowle mdo...@mdowle.plus.com; r-h...@stat.math.ethz.ch Sent: Friday, August 21, 2009 2:17 PM Subject: Re: Video demo of using svSocket with data.table Romain Francois wrote: Hi Philippe, When Matthew brought this up the first time on this list, there were several replies to warn about potential problems related to R not being thread safe, and that this might cause trouble. Well, that is true, R is not thread safe. What happens, basically, is that R clients run in the tcltk event loop. When a client is doing something, R is locked, processing the client's request before returning to the main loop. On the contrary, something running in the main loop can be interrupted pretty much anytime by a client's request. Regarding different clients, it is first in, first served rule: requests are processed in the order they appear. It would be possible to adapt svSocket to delay processing of (asynchronous only) requests from clients, waiting from flags set by, either the main loop, or another client. That would be rather easy to do. Otherwise, every clients and the CLI are working with the same objects on the same environment (.GlobalEnv, as primary one), but that is a *feature*! One constraint for designing svSocket is that the behaviour of R has to be as much as possible identical when a command is run on the main loop through the CLI, or from within a client. Of course, you can imagine all sorts of bad interactions, and it is very, very easy to write a bad-behaving client. The goal is not to write a client-server architecture, but a multitasking way of manipulating R by the same end-user (thus, not likely to feed bad code from one side to destroy what he is doing from another side :-) Best, Philippe Since you were on holidays, we did not get your viewpoint. Could you elaborate on how you deal with this. browser works off the REPL, so this is unlikely that svSocket can take advantage of it, since the socket runs on a different loop. or maybe you can add something that feeds the R main loop, but I'm not sure this is possible unless you embed R ... Romain On 08/21/2009 11:04 AM, Philippe Grosjean wrote: Hello Matthew and all R-UseRs, You video demo is very nice. This suggests various uses of svSocket that I had not think about! The primary goal was to make it: - flexible (I think it is clear from the demo), - running in the background while not blocking the CLI (Rgui, R.app, or the terminal, very clear from your demo too), - stateful (yes, this is not in your demo, but a client can disconnect and
Re: [R] Plotting to stdout
On Wed, Aug 26, 2009 at 07:53:57PM +, Oliver Bandel wrote: is there a way to write the result of a plot to stdout? I mean even a binary thingy like a png-file, written to stdout?! I tried with the file-argument of png() and jpeg(), but did not get working results. I don't think you can do that. But if you could elaborate on your ultimate goal, perhaps someone can provide an alternative solution. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://webclu.bio.wzw.tum.de/~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.
[R] choosing of CPU's to run R
Dear All, I am considering to buy a workstation. For the CPUs, I wonder whether anybody have the experience in choosing one for the R. Intel Xeon W3540 2.93 8MB/1066 QC CPU is much cheaper as compared with the Intel Xeon E5540 2.53 8MB/1066 QC CPU. However, its Hz 2.93 is bigger than 2.53. I wonder which one would run R quicker. Thank you. Huang [[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] math symbol + value of a variable in legend.
KRCT == Kenneth Roy Cabrera Torres krcab...@une.net.co on Tue, 25 Aug 2009 17:26:04 -0500 writes: KRCT Thank you very much for your help. KRCT To the R gurus: It will be better at the future to simplify this KRCT options. KRCT They are too cumbersome!!! The ones David showed, yes, are too cumbersome. There's a variant, which is even a bit more elegant, but really a small (?) change in R's handling of symbols could make it even more elegant. I'll talk about that on the dedicated list, R-devel. Here's the slightly more elegant code (for current versions of R): plot(1:5,1:5,type=n) legend(topleft, legend= c(as.expression( bquote(mu == .(m1)) ), as.expression( bquote(mu == .(m2)) )), lty = 1:2) ## ## or with subscripts : ## legend(top, legend = c(as.expression( bquote(mu[1] == .(m1)) ), as.expression( bquote(mu[2] == .(m2)) )), lty = 1:2) ## ## or, if you really need to have the subscript as a *variable* as well: ## i1 - 11; i2 - 20 legend(topright, legend = c(as.expression( bquote(mu[.(i1)] == .(m1)) ), as.expression( bquote(mu[.(i2)] == .(m2)) )), lty = 1:2) Martin Maechler, ETH Zurich KRCT El mar, 25-08-2009 a las 18:16 -0400, David Winsemius escribió: On Aug 25, 2009, at 5:51 PM, David Winsemius wrote: On Aug 25, 2009, at 4:30 PM, Kenneth Roy Cabrera Torres wrote: Hi R users: I will like to have a legend with math symbols and also with the value of a variable. But I cannot obtain both at the same time (symbol + value of a variable): Here is a reproducible example: m1-5 m2-12 I think I am violating a fortune but this worked: plot(1:5,1:5,type=n) legend (topleft,legend=c(eval(substitute( expression(paste(mu,=,m1)), list(m1=m1) )) , eval(substitute( expression(paste(mu,=,m2)), list(m2=m2) ) )), lty=1:2) And efforts at simplification were at least partly successful: legend(topleft,legend=c(eval(substitute( expression(mu == m1), list(m1=m1) )) , eval(substitute( expression(mu == m2), list(m2=m2) ) )), lty=1:2) And this adds subscripts to the mu's: plot(1:5,1:5,type=n); legend(topleft, legend=c( eval(substitute( expression(mu[i] == m1), list(i=1, m1=m1) )) , eval(substitute( expression(mu[i] == m2), list(i=2, m2=m2) )) ), lty=1:2) plot(1:5,1:5,type=n) legend (topleft ,legend = c(paste(expression(mu),=,m1),expression(paste(mu,=,m2))),lty=1:2) Thank you for your help. Kenneth -- David Winsemius, MD Heritage Laboratories West Hartford, CT KRCT __ KRCT R-help@r-project.org mailing list KRCT https://stat.ethz.ch/mailman/listinfo/r-help KRCT PLEASE do read the posting guide http://www.R-project.org/posting-guide.html KRCT 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] choosing of CPU's to run R
Dear Huang, I do not know how either of these run R in particular. However, the price difference is because the E5540 is a newer line of chip architecture than the W3540. One of the differences is the speed that data can be transferred to and from the chip (Intel now calls it the QPI, it used to be called the front side bus or just FSB). E5540's QPI speed is 5.8 gigatransfers per second W3540's QPI speed is 4.6 gigatransfers per second. You might also be interested in how much power they take. E5540 uses a maximum 80 watts W3540 uses a maximum 130 watts They both handle the same type (DDR3) and speed (1066) of RAM. If you want more details about them google Gainsetown the E5540 architecture codename Bloomfield the W3540 architecture codename I doubt you would see a big performance difference either way, but I cannot say that for certain. I hope that at least gives you a bit more information about them. Sorry I cannot give a straightforward answer. Best, Joshua On Thu, Aug 27, 2009 at 1:00 AM, huang min minhua...@gmail.com wrote: Dear All, I am considering to buy a workstation. For the CPUs, I wonder whether anybody have the experience in choosing one for the R. Intel Xeon W3540 2.93 8MB/1066 QC CPU is much cheaper as compared with the Intel Xeon E5540 2.53 8MB/1066 QC CPU. However, its Hz 2.93 is bigger than 2.53. I wonder which one would run R quicker. Thank you. Huang [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.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] dimnames in class by object
Hi All, d = data.frame(a=1:10,b=1:10) by1 = rep(c(a,b),5) by(d, by1, function(z) z[,,drop=F]) by1: a a b 1 1 1 3 3 3 5 5 5 7 7 7 9 9 9 by1: b a b 2 2 2 4 4 4 6 6 6 8 8 8 10 10 10 by(d, by1, function(z) z[,1,drop=F]) [1] 1 3 5 7 9 [1] 2 4 6 8 10 Can somebody explain why are the dimnames (i.e. by1: a by1: b) not there this time. Many Thanks Utkarsh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] choosing of CPU's to run R
Thanks, Joshua. It's quite helpful. Hope someone can give some idea whether the Hz or the QPI is relatively important in computing. Huang On Thu, Aug 27, 2009 at 4:41 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: Dear Huang, I do not know how either of these run R in particular. However, the price difference is because the E5540 is a newer line of chip architecture than the W3540. One of the differences is the speed that data can be transferred to and from the chip (Intel now calls it the QPI, it used to be called the front side bus or just FSB). E5540's QPI speed is 5.8 gigatransfers per second W3540's QPI speed is 4.6 gigatransfers per second. You might also be interested in how much power they take. E5540 uses a maximum 80 watts W3540 uses a maximum 130 watts They both handle the same type (DDR3) and speed (1066) of RAM. If you want more details about them google Gainsetown the E5540 architecture codename Bloomfield the W3540 architecture codename I doubt you would see a big performance difference either way, but I cannot say that for certain. I hope that at least gives you a bit more information about them. Sorry I cannot give a straightforward answer. Best, Joshua On Thu, Aug 27, 2009 at 1:00 AM, huang min minhua...@gmail.com wrote: Dear All, I am considering to buy a workstation. For the CPUs, I wonder whether anybody have the experience in choosing one for the R. Intel Xeon W3540 2.93 8MB/1066 QC CPU is much cheaper as compared with the Intel Xeon E5540 2.53 8MB/1066 QC CPU. However, its Hz 2.93 is bigger than 2.53. I wonder which one would run R quicker. Thank you. Huang [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.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.
Re: [R] Submit a R job to a server
Noah Silverman wrote: Deb, I generally run my larger R tasks on a server. Here is my workflow. 1) Write an R script using a text editor. (There are many popular ones.) 2) FTP the R script to your server. 3) SSH into the server 4) Run R 5) Run the script that you uploaded from the R process you just started. Dear Debrata, if this is what you mean by submitting a job, so just login in remotely and starting the job manually, you can do what Noah suggested in a more convenient way: - many Scp / Ftp applications allow editing on the server, meaning you don't have to transfer the file after every change manually. I use a combination of winscp and Notepad++ normally for this. - read the man pages of the unix command screen (by typing man screen on the server) to see how to get a permanent session that stays there for you, after you detach from it. Be sure to test your scripts on your local system before with easy (and faster examples). For packages: The same requirements apply to the R on server as for your local system, you simply need the same packages there. Bernd __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Submit a R job to a server
Bernd Bischl wrote: Noah Silverman wrote: Deb, I generally run my larger R tasks on a server. Here is my workflow. 1) Write an R script using a text editor. (There are many popular ones.) 2) FTP the R script to your server. 3) SSH into the server 4) Run R 5) Run the script that you uploaded from the R process you just started. Dear Debrata, if this is what you mean by submitting a job, so just login in remotely and starting the job manually, you can do what Noah suggested in a more convenient way: - many Scp / Ftp applications allow editing on the server, meaning you don't have to transfer the file after every change manually. I use a combination of winscp and Notepad++ normally for this. Notepad++ has an integrated ftp client very useful for this kind of things (and for editing a web site too). Ciao! mario - read the man pages of the unix command screen (by typing man screen on the server) to see how to get a permanent session that stays there for you, after you detach from it. Be sure to test your scripts on your local system before with easy (and faster examples). For packages: The same requirements apply to the R on server as for your local system, you simply need the same packages there. Bernd __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Fwd: Re: Video demo of using svSocket with data.table]
If you are working on windows, Thomas Baier's statconnDCOM and rcom allow you to access R servers via COM. The statconnDCOM package also has a servermanager which allows to configure servers for exclusive or nonexclusive (= common workspace) usage for different clients (possibly living on different machines). Philippe Grosjean wrote: Forwarded to R-Help, because I think it could interest people following this thread. Clearly, RServe and svSocket have different goals and very little overlap. Best, Philippe Original Message Subject: Re: Video demo of using svSocket with data.table Date: Wed, 26 Aug 2009 20:34:19 +0100 From: Matthew Dowle mdo...@mdowle.plus.com Reply-To: Matthew Dowle mdo...@mdowle.plus.com To: Philippe Grosjean phgrosj...@sciviews.org,Romain Francois romain.franc...@dbmail.com References: h6kcod$5e...@ger.gmane.org 4a8e632d.6060...@sciviews.org4a8e6af1.9060...@dbmail.com 4a8e9e7d.9070...@sciviews.org Hi Philippe Romain, Thanks - interesting discussion on the list - I just caught up with it now. I agree with everything basically and look forward to the 'planned for the future'. The 'feature' of every clients and the CLI are working with the same objects on the same environment is really important to keep btw - got a bit worried by your *feature* in case you thought it was a bad thing. Rserve doesn't do that! Its a great feature and really important. I compared Rserve to svSocket and came up with this list (confirmed with Simon U). You probably already know this but just in case : 1. The main thing is Rserve's clients each have their own workspace. Its not one shared workspace, unlike with svSocket. So one client can't write something and another client then read it because they only see their own workspaces within Rserve. You might as well start lots of R's basically. 2. There is no CLI (command line interface) to Rserve i.e. no prompt to type at. Its just a process that sits there and responds to clients only. 3. Rserve on windows is limited to only one client connection, no more. The docs say that Windows is not recommended (for this reason). 4. You have to start Rserve first before you send commands to it. With svSocket, you can startup any old R, do some analysis and gather data, then decide to become a server and let clients connect. This is a really important workflow feature. With Rserve you have to think in advance and know that you'll need to be a server. You can't do any of those things with Rserve, but you can with svSocket. Rserve does do binary data transfer though. Regards, Matthew - Original Message - From: Philippe Grosjean phgrosj...@sciviews.org Newsgroups: gmane.comp.lang.r.general To: Romain Francois romain.franc...@dbmail.com Cc: Matthew Dowle mdo...@mdowle.plus.com; r-h...@stat.math.ethz.ch Sent: Friday, August 21, 2009 2:17 PM Subject: Re: Video demo of using svSocket with data.table Romain Francois wrote: Hi Philippe, When Matthew brought this up the first time on this list, there were several replies to warn about potential problems related to R not being thread safe, and that this might cause trouble. Well, that is true, R is not thread safe. What happens, basically, is that R clients run in the tcltk event loop. When a client is doing something, R is locked, processing the client's request before returning to the main loop. On the contrary, something running in the main loop can be interrupted pretty much anytime by a client's request. Regarding different clients, it is first in, first served rule: requests are processed in the order they appear. It would be possible to adapt svSocket to delay processing of (asynchronous only) requests from clients, waiting from flags set by, either the main loop, or another client. That would be rather easy to do. Otherwise, every clients and the CLI are working with the same objects on the same environment (.GlobalEnv, as primary one), but that is a *feature*! One constraint for designing svSocket is that the behaviour of R has to be as much as possible identical when a command is run on the main loop through the CLI, or from within a client. Of course, you can imagine all sorts of bad interactions, and it is very, very easy to write a bad-behaving client. The goal is not to write a client-server architecture, but a multitasking way of manipulating R by the same end-user (thus, not likely to feed bad code from one side to destroy what he is doing from another side :-) Best, Philippe Since you were on holidays, we did not get your viewpoint. Could you elaborate on how you deal with this. browser works off the REPL, so this is unlikely that svSocket can take advantage of it, since the socket runs on a different loop. or maybe you can add something that feeds the R main loop, but I'm not sure this is possible unless you embed R ... Romain On 08/21/2009 11:04 AM,
[R] Comparing and adding two data series
Dear R helpers I have two series A and B as given below - A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0.2282, 0.1614) I need to calculate the total in dataset B corresponding to the numbers in dataset A i.e. for no 1 in A, I need the total as 4.0140+0.3798 (as 1 is repeated twice) for no 2, I need the total as 0.0728+0.9538 (as 2 is also repeated tqice and so on) Thus for no 31 in A, I should get only 0.1614. I have written the R code but its not working. My code is as follows, # -- D - array() i = 1 for (i in 1:max(A)) { D[i] = 0 i = i + 1 } # _ T - array() k = 1 m = 1 for (k in 1:max(A)) { for (m in 1:max(A)) { if (D[m] == k) T[k] = T[m] + B[m] else T[k] = T[m] + 0 m= m + 1 } k= k + 1 } # - Please correct me. I think I have messed up with the loops but not able to understand where. Please guide me. Thanking in advance Maithili See the Web#39;s breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.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.
Re: [R] choosing of CPU's to run R
My guess is that there is not a simple answer. My newest machines are extremely fast at doing: sum(rnorm(1e6)) relative to my older machines. But they are not so much faster at doing the work that I actually want done. But if there is a simple answer, I'd be keen to hear it. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User) huang min wrote: Thanks, Joshua. It's quite helpful. Hope someone can give some idea whether the Hz or the QPI is relatively important in computing. Huang On Thu, Aug 27, 2009 at 4:41 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: Dear Huang, I do not know how either of these run R in particular. However, the price difference is because the E5540 is a newer line of chip architecture than the W3540. One of the differences is the speed that data can be transferred to and from the chip (Intel now calls it the QPI, it used to be called the front side bus or just FSB). E5540's QPI speed is 5.8 gigatransfers per second W3540's QPI speed is 4.6 gigatransfers per second. You might also be interested in how much power they take. E5540 uses a maximum 80 watts W3540 uses a maximum 130 watts They both handle the same type (DDR3) and speed (1066) of RAM. If you want more details about them google Gainsetown the E5540 architecture codename Bloomfield the W3540 architecture codename I doubt you would see a big performance difference either way, but I cannot say that for certain. I hope that at least gives you a bit more information about them. Sorry I cannot give a straightforward answer. Best, Joshua On Thu, Aug 27, 2009 at 1:00 AM, huang min minhua...@gmail.com wrote: Dear All, I am considering to buy a workstation. For the CPUs, I wonder whether anybody have the experience in choosing one for the R. Intel Xeon W3540 2.93 8MB/1066 QC CPU is much cheaper as compared with the Intel Xeon E5540 2.53 8MB/1066 QC CPU. However, its Hz 2.93 is bigger than 2.53. I wonder which one would run R quicker. Thank you. Huang [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Winsorized mean and variance
Roberto Perdisci wrote: Hello everybody, after searching around for quite some time, I haven't been able to find a package that provides a function to compute the Windorized mean and variance. Also I haven't found a function that computes the trimmed variance. Is there any such package around? Hi Roberto, The Winsorized variance is similar to the trimmed variance, except that the extreme values are substituted rather than dropped. Define the quantiles within which you want to retain the original values and then substitute the values at the quantiles for all values more extreme in the respective sign direction. Like this: testdat-rnorm(20) winsorVar-function(x,probs=c(0.05,0.95)) { xq-quantile(x,probs=probs) x[x xq[1]]-xq[1] x[x xq[2]]-xq[2] return(var(x)) } Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Comparing and adding two data series
Dear Gerrit Eichner Thanks a million. This only proves how powerful R is. I really appreciate your kind help. Sometimes I really wonder from where I can learn such commands. Thanks again. With warmest regards Maithili --- On Thu, 27/8/09, Gerrit Eichner gerrit.eich...@math.uni-giessen.de wrote: From: Gerrit Eichner gerrit.eich...@math.uni-giessen.de Subject: Re: [R] Comparing and adding two data series To: Maithili Shiva maithili_sh...@yahoo.com Date: Thursday, 27 August, 2009, 10:57 AM Try tapply( B, A, sum) On Thu, 27 Aug 2009, Maithili Shiva wrote: Dear R helpers I have two series A and B as given below - A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0.2282, 0.1614) I need to calculate the total in dataset B corresponding to the numbers in dataset A i.e. for no 1 in A, I need the total as 4.0140+0.3798 (as 1 is repeated twice) for no 2, I need the total as 0.0728+0.9538 (as 2 is also repeated tqice and so on) Thus for no 31 in A, I should get only 0.1614. I have written the R code but its not working. My code is as follows, # -- D - array() i = 1 for (i in 1:max(A)) { D[i] = 0 i = i + 1 } # _ T - array() k = 1 m = 1 for (k in 1:max(A)) { for (m in 1:max(A)) { if (D[m] == k) T[k] = T[m] + B[m] else T[k] = T[m] + 0 m= m + 1 } k= k + 1 } # - Please correct me. I think I have messed up with the loops but not able to understand where. Please guide me. Thanking in advance Maithili See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/ [[alternative HTML version deleted]] Best regards -- Gerrit Best regards -- Gerrit Eichner Viele Grüße -- Gerrit Viele Grüße -- Gerrit Eichner Viele Grüße -- GE Grüße -- Gerrit Grüße -- Gerrit Eichner Grüße -- GE Gruß -- G - AOR Dr. Gerrit Eichner Mathematical Institute, Room 305 E gerrit.eich...@math.uni-giessen.de justus-liebig-university Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/~gcb7 - Love Cricket? Check out live scores, photos, video highlights and mor [[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] Header file related to arithmetic functions
Hi, I am a new to R. I am using C language to write the code and I am calling R functions from C ( I am including R.h, Rmath.h etc. in C code). I would like to know which header file contains the general arithmetic functions(mean etc.) so that I can add that in my C code. I searched in internet but I am getting only one example which calls 'rnorm' function from C code. and 'rnorm' is defined in Rmath.h So pls help in identifying the header files which contains the arithmetic functions -- Prateep Kumar Research Modelling Analyst IGSA Labs Pvt.Ltd. http://igsalabs.com/ Hyderabad India +91 9492846550 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Comparing and adding two data series
Also: rowsum(B, A) On Thu, Aug 27, 2009 at 7:03 AM, Maithili Shivamaithili_sh...@yahoo.com wrote: Dear Gerrit Eichner Thanks a million. This only proves how powerful R is. I really appreciate your kind help. Sometimes I really wonder from where I can learn such commands. Thanks again. With warmest regards Maithili --- On Thu, 27/8/09, Gerrit Eichner gerrit.eich...@math.uni-giessen.de wrote: From: Gerrit Eichner gerrit.eich...@math.uni-giessen.de Subject: Re: [R] Comparing and adding two data series To: Maithili Shiva maithili_sh...@yahoo.com Date: Thursday, 27 August, 2009, 10:57 AM Try tapply( B, A, sum) On Thu, 27 Aug 2009, Maithili Shiva wrote: Dear R helpers I have two series A and B as given below - A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0.2282, 0.1614) I need to calculate the total in dataset B corresponding to the numbers in dataset A i.e. for no 1 in A, I need the total as 4.0140+0.3798 (as 1 is repeated twice) for no 2, I need the total as 0.0728+0.9538 (as 2 is also repeated tqice and so on) Thus for no 31 in A, I should get only 0.1614. I have written the R code but its not working. My code is as follows, # -- D - array() i = 1 for (i in 1:max(A)) { D[i] = 0 i = i + 1 } # _ T - array() k = 1 m = 1 for (k in 1:max(A)) { for (m in 1:max(A)) { if (D[m] == k) T[k] = T[m] + B[m] else T[k] = T[m] + 0 m= m + 1 } k= k + 1 } # - Please correct me. I think I have messed up with the loops but not able to understand where. Please guide me. Thanking in advance Maithili See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/ [[alternative HTML version deleted]] Best regards -- Gerrit Best regards -- Gerrit Eichner Viele Grüße -- Gerrit Viele Grüße -- Gerrit Eichner Viele Grüße -- GE Grüße -- Gerrit Grüße -- Gerrit Eichner Grüße -- GE Gruß -- G - AOR Dr. Gerrit Eichner Mathematical Institute, Room 305 E gerrit.eich...@math.uni-giessen.de justus-liebig-university Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/~gcb7 - Love Cricket? Check out live scores, photos, video highlights and mor [[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] choosing of CPU's to run R
Patrick Burns wrote: My newest machines are extremely fast at doing: sum(rnorm(1e6)) relative to my older machines. But they are not so much faster at doing the work that I actually want done. ...like finishing your next book and that sort of stuff? ;-) -- 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] Comparing and adding two data series
Dear Peter Konings Thanks a lot for your kind advice. It worked wonderfully. Thanks again Regards Maithili --- On Thu, 27/8/09, Peter Konings peter.l.e.koni...@gmail.com wrote: From: Peter Konings peter.l.e.koni...@gmail.com Subject: Re: [R] Comparing and adding two data series To: Maithili Shiva maithili_sh...@yahoo.com Date: Thursday, 27 August, 2009, 11:12 AM Hi Maithili, how about tapply(B, A, sum) HTH Peter. On Thu, Aug 27, 2009 at 12:38 PM, Maithili Shiva maithili_sh...@yahoo.com wrote: Dear R helpers I have two series A and B as given below - A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0.2282, 0.1614) I need to calculate the total in dataset B corresponding to the numbers in dataset A i.e. for no 1 in A, I need the total as 4.0140+0.3798 (as 1 is repeated twice) for no 2, I need the total as 0.0728+0.9538 (as 2 is also repeated tqice and so on) Thus for no 31 in A, I should get only 0.1614. I have written the R code but its not working. My code is as follows, # -- D - array() i = 1 for (i in 1:max(A)) { D[i] = 0 i = i + 1 } # _ T - array() k = 1 m = 1 for (k in 1:max(A)) { for (m in 1:max(A)) { if (D[m] == k) T[k] = T[m] + B[m] else T[k] = T[m] + 0 m= m + 1 } k= k + 1 } # - Please correct me. I think I have messed up with the loops but not able to understand where. Please guide me. Thanking in advance Maithili See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.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. See the Web#39;s breaking stories, chosen by people like you. Check [[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] Help on efficiency/vectorization
try this: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 0 1 0 0 1 0 0 0 1 b 1 0 0 0 1 1 1 1 0 0 c 0 1 0 1 0 0 0 0 1 0 d 0 1 0 0 0 1 0 0 1 1 e 0 0 1 1 0 1 1 0 1 1 lapply(names(x), function(z) rownames(x)[x[[z]] == 1]) [[1]] [1] b [[2]] [1] c d [[3]] [1] a e [[4]] [1] c e [[5]] [1] b [[6]] [1] a b d e [[7]] [1] b e [[8]] [1] b [[9]] [1] c d e [[10]] [1] a d e On Thu, Aug 27, 2009 at 2:13 AM, Steven Kangstochastick...@gmail.com wrote: Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 1 1 0 0 0 0 1 0 b 1 1 1 1 0 1 0 0 1 1 c 0 1 1 0 0 0 0 0 0 1 d 1 0 0 1 1 1 1 1 0 0 e 1 0 0 0 0 1 1 0 1 0 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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] Help on efficiency/vectorization
Try this also: lapply(apply(x == 1, 2, which), names) On Thu, Aug 27, 2009 at 3:13 AM, Steven Kang stochastick...@gmail.comwrote: Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 11 0 00 0 10 b 1 1 11 0 10 0 11 c 0 1 10 0 00 0 01 d 1 0 01 1 11 1 00 e 1 0 00 0 11 0 10 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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. -- 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] Problem merging two data frames
FAQ 7.31 is probably the answer. If you want to try it, convert all your numerics that you want to merge on to character and round to the same value so you can see what is actually being matched. Comparing numerics for equality can present some challanges. On Wed, Aug 26, 2009 at 9:22 PM, Mehdi Khanmwk...@ucdavis.edu wrote: Note: even if I say by=c(LON, LAT), it doesn't work, suggesting that number storage isn't the problem On Wed, Aug 26, 2009 at 6:19 PM, Mehdi Khan mwk...@ucdavis.edu wrote: Hello everyone, Merging two dataframes should be easy. However when I try to merge, R doesn't recognize identical values, even if I am doing it by values that have no decimals. willclayong: vs30 LON LAT Net X wills.cat wills.vs30 clahan.cat clahanvs30 PolyID.wills PolyID.clahan tif.cat STA ELEVATION tif.vs30 1 338.539 -3849590 4319319 NA 2 D 301 D 377 1958 1942 1 150 NA 519 2 712.822 -3849590 4319319 NA 3 D 301 D 377 1958 1942 1 479 NA 519 3 477.652 -3836584 4288164 NA 10 C 464 C 489 1194 9353 3 148 NA 547 4 513.703 -3836575 4287739 NA 11 C 464 C 489 1194 9353 3 485 NA 547 5 477.652 -3835886 4289120 NA 12 C 464 C 489 1194 9353 7 147 NA 388 wald: wald_ol_sta[1:10,] X Wald.vs30 STA vs30 LON LAT 1 1 434.417 1502 274.500 -3077929 3759564 2 2 378.049 NEE2 363.000 -3086165 3718184 3 3 196.848 EMS 336.000 -3143337 3500449 4 4 557.625 1498 659.600 -3103738 3871531 5 5 263.878 1497 274.500 -3102944 3878068 6 6 374.898 1499 274.500 -3109753 3858460 7 7 150.000 230 274.500 -3154048 3482703 8 8 248.342 1205 207.469 -3153294 3497116 9 9 422.256 1495 338.600 -3097854 3990339 10 10 322.540 1496 274.500 -3115300 3863905 willsclayongwald-merge(wald_ol_sta, willsclayong, by=c(LON, LAT, STA, vs30)) returns nothing... if I modify the previous script by adding all=TRUE, I get this: lsclayongwald[1:10,] LON LAT STA vs30 X.x Wald.vs30 Net X.y wills.cat wills.vs30 clahan.cat clahanvs30 PolyID.wills PolyID.clahan tif.cat ELEVATION tif.vs30 1 -3854850 4321856 478 513.703 1155 586.685 NA NA NA NA NA NA NA NA NA NA NA 2 -3849590 4319319 150 338.539 NA NA NA 2 D 301 D 377 1958 1942 1 NA 519 3 -3849590 4319319 479 712.822 NA NA NA 3 D 301 D 377 1958 1942 1 NA 519 4 -3849590 4319319 150 338.539 1152 336.794 NA NA NA NA NA NA NA NA NA NA NA rows 2 and 4 should have merged. Why didn't they? thanks! Mehdi Khan [[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.
[R] (no subject)
dear sir, my data larger than this example but is of the following format: y x Age 30 0.0323 O 24 0.0389 Y 158 0.058 Y 120 0.0581 O 100 0.0471 Y 102 0.0615 Y 160 0.0546 O i ma making a scatter plot of y~x and want to specify different coloured and filled shaped for the points according the the third categorical variable A. the code i have managed is : plot(y~x,pch=as.numeric(factor(Age))) and i can chage the col seperatley with plot(y~xt,pch=as.numeric(factor(maleage))) and have added a legend with: legend(locator(1), as.character(levels(factor(maleage))), pch=1:length(levels(factor(maleage However the problem i have is that using this code R selects the shapes or colours for me? could you help as to how i specify a specific shape for each of the levels in the Age variable? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 for reliability engineering?
Hello there, I work as a researcher on the FATIMAT project, housed in 'Catholic University College Sint Lieven', 'Technologiecampus Gent' (in Belgium) , dealing with fatigue testing machines (check http://mechanics.kahosl.be/fatimat/ for more info). I am using R for studying basic statistics and also for studying reliability analysis. I started a small project on sourceforge for Weibull based reliability analysis. There is an function that displays life data on a Weibull plot as a straight line, mimicking the graphs I found in the excellent The New Weibull Handbook, 5th edition by dr. Robert Bob Abernethy. As I am still learning R, statistics in general and reliability analysis, and not being a brilliant programmer, the code probably isn't too reliable yet. Later this year, students from our IT department and foreign students will join the project to write some seriously beautiful code :-). Check out the code at http://sourceforge.net/projects/weibulltoolkit/. Feel free to join and give feedback! Wolfgang Keller-2 wrote: Hello, I was wondering whether anyone's using R for reliability (RAMS/LCC) engineering? Sincerely, Wolfgang Keller __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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/R-for-reliability-engineering--tp19181845p25167495.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] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS
Dear Sirs, At the outset I sincerely apologize for reproducing my query to you. I also thank all of you for the solution you had provided. It has worked on the actual data I am working with. However, there is this peculiar problem which I had realized only after I had obtained my results. e.g. in the example I had attached A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0..2282, 0.1614) tapply( B, A, sum) I get R output as – 1 2 3 7 14 31 4.3938 1.0266 2.6770 2.7875 0.0033 0.1614 However, my requirement is I should get the output as 1 2 3 4 5 6 7 8 9 …. 14 ………..31 4.3938 1.0266 2.6770 0 0 0 2.7875 0 0 ..0.0033 .. 0.161 i.e. my output should include the values 4, 5, 6, etc. which are not part of dataset A and the corresponding totals in B (which are anyways 0’s). I need this for my further analysis. Its possible for me to add these 0’s manually, however when the dataset is large, its not practical. I am attaching herewith an excel file. I will be grateful if you can guide me. Thanks in advance Maithili start: 2009-08-18 end: -00-00 Thinking of ordering food? Find restaurant numbers on Yahoo! India Local Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.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] Merge data frames but with a twist.
Dear all, Question: How to merge two data frames such that new column are added in a particular way? I'm not actually sure how to best articulate my question to be honest, so i hope showing you what I want to achieve will communicate my question better. Lets say I have two data frames: DF1 - data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=1:2, Datetime=c('08/26/2009 9:30 AM', '08/26/2009 9:30 AM'))) DF2 - data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=3:4, Datetime=c('08/26/2009 11:30 AM', '08/26/2009 11:30 AM'))) And then let us merge these: DF3 - merge(DF1, DF2, all=TRUE) Show MeasureDatetime 1 Firefly 1 08/26/2009 9:30 AM 2 Firefly 3 08/26/2009 11:30 AM 3 Red Dwarf 2 08/26/2009 9:30 AM 4 Red Dwarf 4 08/26/2009 11:30 AM What i would like to do is merge the data frames such that i end up with the following: Show 08/26/2009 9:30 AM08/26/2009 11:30 AM Firefly 13 Red Dwarf24 my reason for doing this is so that i can plot a time series somehow. I hope the formating stays when i post this message and that what i'm trying to do is easy to understand. Thank you kindly for any help in advance. Tony __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
Setup a vector with the shapes and the colors you want that are the same length as the number of levels in Age: x - read.table('clipboard', header=TRUE) x y x Age 1 30 0.0323 O 2 24 0.0389 Y 3 158 0.0580 Y 4 120 0.0581 O 5 100 0.0471 Y 6 102 0.0615 Y 7 160 0.0546 O shapes - c(16,17) colors - c('red', 'green') plot(x$x, x$y, pch=shapes[x$Age], col=colors[x$Age]) On Thu, Aug 27, 2009 at 7:48 AM, Mcdonald, Grantgrant.mcdonal...@imperial.ac.uk wrote: dear sir, my data larger than this example but is of the following format: y x Age 30 0.0323 O 24 0.0389 Y 158 0.058 Y 120 0.0581 O 100 0.0471 Y 102 0.0615 Y 160 0.0546 O i ma making a scatter plot of y~x and want to specify different coloured and filled shaped for the points according the the third categorical variable A. the code i have managed is : plot(y~x,pch=as.numeric(factor(Age))) and i can chage the col seperatley with plot(y~xt,pch=as.numeric(factor(maleage))) and have added a legend with: legend(locator(1), as.character(levels(factor(maleage))), pch=1:length(levels(factor(maleage However the problem i have is that using this code R selects the shapes or colours for me? could you help as to how i specify a specific shape for each of the levels in the Age variable? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS
Try this: tapply(B, factor(A, levels = seq(max(A))), sum) On Thu, Aug 27, 2009 at 9:26 AM, Maithili Shiva maithili_sh...@yahoo.comwrote: Dear Sirs, At the outset I sincerely apologize for reproducing my query to you. I also thank all of you for the solution you had provided. It has worked on the actual data I am working with. However, there is this peculiar problem which I had realized only after I had obtained my results. e.g. in the example I had attached A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0..2282, 0.1614) tapply( B, A, sum) I get R output as 1 2 3714 31 4.3938 1.0266 2.67702.78750.00330.1614 However, my requirement is I should get the output as 1 2 3 4 5 6 7 8 9 . 14 ..31 4.3938 1.0266 2.6770 0 0 0 2.7875 0 0 ..0.0033 .. 0.161 i.e. my output should include the values 4, 5, 6, etc. which are not part of dataset A and the corresponding totals in B (which are anyways 0s). I need this for my further analysis. Its possible for me to add these 0s manually, however when the dataset is large, its not practical. I am attaching herewith an excel file. I will be grateful if you can guide me. Thanks in advance Maithili start: 2009-08-18 end: -00-00 Thinking of ordering food? Find restaurant numbers on Yahoo! India Local Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] Help on efficiency/vectorization
MO == Moshe Olshansky m_olshan...@yahoo.com on Wed, 26 Aug 2009 23:36:22 -0700 (PDT) writes: MO You can do MO for (i in 1:ncol(x)) {names - rownames(x)[which(x[,i]==1)];eval(parse(text=paste(V,i,.ind-names,sep=)));} you can, but after install.packages(fortunes) require(fortunes) fortune(parse) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) So please use one of the other answers given in the thread... MO --- On Thu, 27/8/09, Steven Kang stochastick...@gmail.com wrote: From: Steven Kang stochastick...@gmail.com Subject: [R] Help on efficiency/vectorization To: r-help@r-project.org Received: Thursday, 27 August, 2009, 4:13 PM Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 1 1 0 0 0 0 1 0 b 1 1 1 1 0 1 0 0 1 1 c 0 1 1 0 0 0 0 0 0 1 d 1 0 0 1 1 1 1 1 0 0 e 1 0 0 0 0 1 1 0 1 0 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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. MO __ MO R-help@r-project.org mailing list MO https://stat.ethz.ch/mailman/listinfo/r-help MO PLEASE do read the posting guide http://www.R-project.org/posting-guide.html MO 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] Merge data frames but with a twist.
Try this: xtabs(as.numeric(Measure) ~ Show + Datetime, data = DF3) On Thu, Aug 27, 2009 at 8:04 AM, Tony Breyal tony.bre...@googlemail.comwrote: Dear all, Question: How to merge two data frames such that new column are added in a particular way? I'm not actually sure how to best articulate my question to be honest, so i hope showing you what I want to achieve will communicate my question better. Lets say I have two data frames: DF1 - data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=1:2, Datetime=c('08/26/2009 9:30 AM', '08/26/2009 9:30 AM'))) DF2 - data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=3:4, Datetime=c('08/26/2009 11:30 AM', '08/26/2009 11:30 AM'))) And then let us merge these: DF3 - merge(DF1, DF2, all=TRUE) Show MeasureDatetime 1 Firefly 1 08/26/2009 9:30 AM 2 Firefly 3 08/26/2009 11:30 AM 3 Red Dwarf 2 08/26/2009 9:30 AM 4 Red Dwarf 4 08/26/2009 11:30 AM What i would like to do is merge the data frames such that i end up with the following: Show 08/26/2009 9:30 AM08/26/2009 11:30 AM Firefly 13 Red Dwarf24 my reason for doing this is so that i can plot a time series somehow. I hope the formating stays when i post this message and that what i'm trying to do is easy to understand. Thank you kindly for any help in advance. Tony __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Issues with factors with duplicate (empty) levels
Hello again, Just for your information, I think I found a way to work around the problem described below. I don’t know if it’s the most elegant way, but it seems to work. Am Mittwoch, den 26.08.2009, 11:55 +0200 schrieb Frederik Elwert: Hello! I imported a DJI survey[1] from an SPSS file. When looking at some of the variables, I noticed problems with the `table` function and similar. It seems to be caused by duplicate levels which are generated from the value labels. Not all values have labels, so those who don’t get an empty string as the level, which leads to duplicates. I hope the code and output below illustrates the problem. Is it possible to prevent this? I’d still like to use the labels, so using numeric vectors instead of factors is not the best solution. Regards, Frederik library(foreign) Data - read.spss(js2003_16_29_db.sav, to.data.frame=TRUE, reencode=latin1) table(Data$J203_A) überhaupt nicht wichtig 352256 0 0 0 0 sehr wichtig Mehrfachnennung 4660 0 table(as.numeric(Data$J203_A)) 1234567 35 39 84 227 626 1280 4660 is.factor(Data$J203_A) [1] TRUE levels(Data$J203_A) [1] überhaupt nicht wichtig [3] [5] [7] sehr wichtigMehrfachnennung for (i in 1:ncol(Data)){ if (is.factor(Data[,i])){ lvl - levels(JS2003[,i]) if ( %in% lvl){ empty - lvl == lvl[empty] - (1:length(lvl))[empty] levels(Data[,i]) - lvl } } } table(Data$J203_A) überhaupt nicht wichtig 2 3 35 39 84 4 5 6 227 6261280 sehr wichtig Mehrfachnennung 4660 0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tweedie and lmer
kbs wrote: This is the link that gave me the indication: https://stat.ethz.ch/pipermail/r-help/2007-March/127261.html Are there alternative ways to deal with a high count of zeros for count data with lmer? Fair enough. I think the problem is that lme4 has changed quite a lot in two years -- the hard-coding I refer to may not have been true two years ago. However, in looking at your question more carefully, I don't think you need Tweedie distributions anyway. Tweedie distributions are most useful for *continuous* data with a positive mass at zero, not for zero-inflated count data. For zero-inflated count data, I would try the following: (1) Try fitting a Poisson GLMM and see whether low means and random effects together account for the zeros you see (Warton 2005). (2) use negative binomial or zero-inflated distributions. This is not currently possible with glmer, but you can try glmmADMB or MCMCglmm instead. Or R2WinBUGS, but then you'll have to code your own model in the WinBUGS language. @article{warton_many_2005, title = {Many zeros does not mean zero inflation: comparing the goodness-of-fit of parametric models to multivariate abundance data}, volume = {16}, shorttitle = {Many zeros does not mean zero inflation}, url = {http://dx.doi.org/10.1002/env.702}, doi = {10.1002/env.702}, abstract = {An important step in studying the ecology of a species is choosing a statistical model of abundance; however, there has been little general consideration of which statistical model to use. In particular, abundance data have many zeros (often 50-80 per cent of all values), and zero-inflated count distributions are often used to specifically model the high frequency of zeros in abundance data. However, in such cases it is often taken for granted that a zero-inflated model is required, and the goodness-of-fit to count distributions with and without zero inflation is not often compared for abundance {data.In} this article, the goodness-of-fit was compared for several marginal models of abundance in 20 multivariate datasets (a total of 1672 variables across all datasets) from different sources. Multivariate abundance data are quite commonly collected in applied ecology, and the properties of these data may differ from abundances collected in autecological studies. Goodness-of-fit was assessed using {AIC} values, graphs of observed vs expected proportion of zeros in a dataset, and graphs of the sample mean-variance {relationship.The} negative binomial model was the best fitting of the count distributions, without zero-inflation. The high frequency of zeros was well described by the systematic component of the model (i.e. at some places predicted abundance was high, while at others it was zero) and so it was rarely necessary to modify the random component of the model (i.e. fitting a zero-inflated distribution). A Gaussian model based on transformed abundances fitted data surprisingly well, and rescaled per cent cover was usually poorly fitted by a count distribution. In conclusion, results suggest that the high frequency of zeros commonly seen in multivariate abundance data is best considered to come from distributions where mean abundance is often very low (hence there are many zeros), as opposed to claiming that there are an unusually high number of zeros compared to common parametric distributions. Copyright � 2005 John Wiley \ Sons, Ltd.}, number = {3}, journal = {Environmetrics}, author = {David I. Warton}, year = {2005}, pages = {275--289} } -- View this message in context: http://www.nabble.com/tweedie-and-lmer-tp25156793p25167567.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] tweedie and lmer
If you don't have too many groups then you could get mgcv:gam to fit this using the Tweedie family from mgcv. It's a bit fiddly, but there's an example at the end of ?gam.models with exactly your RE structure. On Wednesday 26 August 2009 17:30, Mohammad AlMarzouq wrote: Hello all, I have count data with about 36% of observations being zeros. I found in some of the examples of the r-help mail archives that a tweedie family of distributions could be used to fit a model with random effects. Upon installing the tweedie package and attempting to fit the following model: lmer(SUS ~ 1 + (1| GRP),REML=FALSE,data=mydata,family=tweedie(var.power=1.55,link.power=0)) I get the following error: Error in famType(glmFit$family) : unknown GLM family: ‘Tweedie’ If it helps, im on a mac with R V 2.9.1, lme4 V.0.999375-31, Tweedie V2.0. Thanks, Mohammad AlMarzouq __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK +44 1225 386603 www.maths.bath.ac.uk/~sw283 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS
On Aug 27, 2009, at 8:31 AM, Henrique Dallazuanna wrote: Try this: tapply(B, factor(A, levels = seq(max(A))), sum) Nice! It might have a disadvantage in that it produces NA's instead of the requested 0's, but that would be easily remedied with an: is.na(obj) - 0 It was much neater than my hack: sapply(1:max(A), function(x) ifelse(x %in% A, tapply(B, A, sum) [as.character(x)], 0) ) Which would have neded to be rbind()'ed to 1:max(A) to get the desired construction. -- David. On Thu, Aug 27, 2009 at 9:26 AM, Maithili Shiva maithili_sh...@yahoo.com wrote: Dear Sirs, At the outset I sincerely apologize for reproducing my query to you. I also thank all of you for the solution you had provided. It has worked on the actual data I am working with. However, there is this peculiar problem which I had realized only after I had obtained my results. e.g. in the example I had attached A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0..2282, 0.1614) tapply( B, A, sum) I get R output as 1 2 3714 31 4.3938 1.0266 2.67702.78750.00330.1614 However, my requirement is I should get the output as 1 2 3 4 5 6 7 8 9 . 14 ..31 4.3938 1.0266 2.6770 0 0 0 2.7875 0 0 ..0.0033 .. 0.161 i.e. my output should include the values 4, 5, 6, etc. which are not part of dataset A and the corresponding totals in B (which are anyways 0s). I need this for my further analysis. Its possible for me to add these 0s manually, however when the dataset is large, its not practical. I am attaching herewith an excel file. I will be grateful if you can guide me. Thanks in advance Maithili start: 2009-08-18 end: -00-00 Thinking of ordering food? Find restaurant numbers on Yahoo! India Local Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge data frames but with a twist.
You may want to use the reshape package for this task: library(reshape) recast(DF3,Show ~ Datetime, id.var=names(DF3),value=Measure) Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM 1 Firefly 3 1 2 Red Dwarf 4 2 If you want to plot time series, you can do something like the following mydf - .Last.value ## save the output from above to mydf library(zoo) zobj - zoo(`mode-`(t(mydf),numeric), as.chron(strptime(names(mydf)[-1],%m/%d/%Y %I:%M %p))) plot(zobj) (zobj is a time series object of the zoo class) - Original Message From: Tony Breyal tony.bre...@googlemail.com To: r-help@r-project.org Sent: Thursday, August 27, 2009 4:04:30 AM Subject: [R] Merge data frames but with a twist. Dear all, Question: How to merge two data frames such that new column are added in a particular way? I'm not actually sure how to best articulate my question to be honest, so i hope showing you what I want to achieve will communicate my question better. Lets say I have two data frames: DF1 - data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=1:2, Datetime=c('08/26/2009 9:30 AM', '08/26/2009 9:30 AM'))) DF2 - data.frame(cbind(Show=c('Firefly', 'Red Dwarf'), Measure=3:4, Datetime=c('08/26/2009 11:30 AM', '08/26/2009 11:30 AM'))) And then let us merge these: DF3 - merge(DF1, DF2, all=TRUE) Show MeasureDatetime 1 Firefly 1 08/26/2009 9:30 AM 2 Firefly 3 08/26/2009 11:30 AM 3 Red Dwarf 2 08/26/2009 9:30 AM 4 Red Dwarf 4 08/26/2009 11:30 AM What i would like to do is merge the data frames such that i end up with the following: Show 08/26/2009 9:30 AM08/26/2009 11:30 AM Firefly 13 Red Dwarf24 my reason for doing this is so that i can plot a time series somehow. I hope the formating stays when i post this message and that what i'm trying to do is easy to understand. Thank you kindly for any help in advance. Tony __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS
Dear Sirs,  Thanks again for the solution. That was VERY KIND of you to readress my query again and again. Please accept my sincere aplogies for referring the problem again and thanks again for the solution. You were very patience and I really appreciate that. Have a great day ahead.  With warm regards  Maithili --- On Thu, 27/8/09, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS To: Henrique Dallazuanna www...@gmail.com Cc: Maithili Shiva maithili_sh...@yahoo.com, r-help@r-project.org Date: Thursday, 27 August, 2009, 1:45 PM On Aug 27, 2009, at 8:31 AM, Henrique Dallazuanna wrote: Try this: tapply(B, factor(A, levels = seq(max(A))), sum) Nice! It might have a disadvantage in that it produces NA's instead of the requested 0's, but that would be easily remedied with an: is.na(obj) - 0 It was much neater than my hack: sapply(1:max(A), function(x) ifelse(x %in% A, tapply(B, A, sum)[as.character(x)], 0) ) Which would have neded to be rbind()'ed to 1:max(A) to get the desired construction. --David. On Thu, Aug 27, 2009 at 9:26 AM, Maithili Shiva maithili_sh...@yahoo.comwrote: Dear Sirs, At the outset I sincerely apologize for reproducing my query to you. I also thank all of you for the solution you had provided. It has worked on the actual data I am working with. However, there is this peculiar problem which I had realized only after I had obtained my results. e.g. in the example I had attached A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0..2282, 0.1614) tapply( B, A, sum) I get R output as â 1     2     3      7      14     31 4.3938   1.0266   2.6770  2.7875  0.0033  0.1614 However, my requirement is I should get the output as 1     2     3      4 5 6 7      8 9 . 14 ..31 4.3938 1.0266 2.6770   0 0 0 2.7875 0 0 ..0.0033 .. 0.161 i.e. my output should include the values 4, 5, 6, etc. which are not part of dataset A and the corresponding totals in B (which are anyways 0âs). I need this for my further analysis. Its possible for me to add these 0âs manually, however when the dataset is large, its not practical. I am attaching herewith an excel file. I will be grateful if you can guide me. Thanks in advance Maithili start: 2009-08-18 end: -00-00 Thinking of ordering food? Find restaurant numbers on Yahoo! India Local     Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. --Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O    [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.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.
Re: [R] Fw: PROBLEM - - COMPARING AND COMBINING two DATASETS
Try this: xtabs(B ~ factor(A, seq(max(A On Thu, Aug 27, 2009 at 8:26 AM, Maithili Shivamaithili_sh...@yahoo.com wrote: Dear Sirs, At the outset I sincerely apologize for reproducing my query to you. I also thank all of you for the solution you had provided. It has worked on the actual data I am working with. However, there is this peculiar problem which I had realized only after I had obtained my results. e.g. in the example I had attached A - c(2, 2, 1, 3, 7, 3, 3, 1, 14, 7, 31) B - c(0.0728,0.9538,4.0140,0.0020,2.5593,0.1620,2.513,0.3798, .0033,0..2282, 0.1614) tapply( B, A, sum) I get R output as – 1 2 3 7 14 31 4.3938 1.0266 2.6770 2.7875 0.0033 0.1614 However, my requirement is I should get the output as 1 2 3 4 5 6 7 8 9 …. 14 ………..31 4.3938 1.0266 2.6770 0 0 0 2.7875 0 0 ..0.0033 .. 0.161 i.e. my output should include the values 4, 5, 6, etc. which are not part of dataset A and the corresponding totals in B (which are anyways 0’s). I need this for my further analysis. Its possible for me to add these 0’s manually, however when the dataset is large, its not practical. I am attaching herewith an excel file. I will be grateful if you can guide me. Thanks in advance Maithili start: 2009-08-18 end: -00-00 Thinking of ordering food? Find restaurant numbers on Yahoo! India Local Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] fitting a linear model line through srip plot
I am creating a strip plot from the lattice library, and would like the display to also have the linear model line through it. How would I do that? stripplot(jitter(vs30)~tif.vs30, data=rastermodel, xlim=c(150,600), ylim=c(0,1000)) yonglm-lm(vs30~tif.vs30, data=rastermodel) 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] distinct elements of a vector
Hello, I have the vector (a,b,a,c) and I trying to obtain it's distinct elements in another vector. Is there a function that can do this? Thanks, Bogdan -- View this message in context: http://www.nabble.com/distinct-elements-of-a-vector-tp25168032p25168032.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] Winsorized mean and variance
This is of great help, thanks! Roberto On Thu, Aug 27, 2009 at 7:20 AM, Jim Lemonj...@bitwrit.com.au wrote: Roberto Perdisci wrote: Hello everybody, after searching around for quite some time, I haven't been able to find a package that provides a function to compute the Windorized mean and variance. Also I haven't found a function that computes the trimmed variance. Is there any such package around? Hi Roberto, The Winsorized variance is similar to the trimmed variance, except that the extreme values are substituted rather than dropped. Define the quantiles within which you want to retain the original values and then substitute the values at the quantiles for all values more extreme in the respective sign direction. Like this: testdat-rnorm(20) winsorVar-function(x,probs=c(0.05,0.95)) { xq-quantile(x,probs=probs) x[x xq[1]]-xq[1] x[x xq[2]]-xq[2] return(var(x)) } Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Submit a R job to a server
Have a look at Karim Chine's R/Biocep project: http://biocep-distrib.r-forge.r-project.org/ /henrik On Wed, Aug 26, 2009 at 9:12 PM, Moshe Olshanskym_olshan...@yahoo.com wrote: Hi Deb, Based on your last note (and after briefly looking at Rserve) I believe that you should install R with all the packages you need on the server and then use it like you are using any workstation, i.e. log in to it and do whatever you need. Regards, Moshe. --- On Thu, 27/8/09, Debabrata Midya debabrata.mi...@commerce.nsw.gov.au wrote: From: Debabrata Midya debabrata.mi...@commerce.nsw.gov.au Subject: Re: [R] Submit a R job to a server To: Cedrick W. Johnson cedr...@cedrickjohnson.com, m_olshan...@yahoo.com Cc: r-help@r-project.org Received: Thursday, 27 August, 2009, 1:48 PM Cedrick / Moshe, Thank you very much for such a quick response. My objective is to do the faster calculations by submitting a R job from my desktop to this server. Oracle 8i Enterprise Edition is currently running on this server. My objective is not only limited to access various oracle tables from this server but also I like to utilise this server for faster calculations and I like to use R for this. So far, I did not install anything related to R into this server. I have R installed on my desktop (Windows XP). I use RODBC / ODBC products to access data from this server and I use R / S-PLUS (installed on my desktop) to do the analyses. Is there any way to submit R job from my desktop to this server? How can I use this server to do my job faster? Once again, thank you very much for the time you have given. I am looking forward for your reply. Regards, Deb Cedrick W. Johnson cedr...@cedrickjohnson.com 27/08/2009 12:41 pm Good Morning Deb- It's unclear (to me at least) what you are trying to do.. What is the server running? Is it running RServe for which you have a userid and pwd or is it just a plain server running some OS? *IF* this is the case (RServe): on the windows machine you will need to: install.packages(Rserve) library(Rserve) ?Rserve --and optionally-- ?RSeval I *think* RSeval/Rserve *may* be what you're looking for, but I am going off just an assumption by what you meant regarding server.. Rserve can be used as a client and server on both platforms (I personally have had more success running the server portion under linux, with linux and java clients in which the clients are a mixture of the package's java access *and* R client access to the rserver instance) More info on rserve at: http://www.rforge.net/Rserve HTH, cedrick Debabrata Midya wrote: Dear R users, Thanks in advance. I am Deb, Statistician at NSW Department of Commerce, Sydney. I am using R 2.9.1 on Windows XP. May I request you to provide me information on the following: 1. I have access to a server ( I have userid and pwd) 2. What are the packages I need to submit a job from Windows XP to this server? Should I need to install any package on this server before submitting a job? Once again, thank you very much for the time you have given. I am looking forward for your reply. Regards, Deb ** This email message, including any attached files, is confidential and intended solely for the use of the individual or entity to whom it is addressed. The NSW Department of Commerce prohibits the right to publish, copy, distribute or disclose any information contained in this email, or its attachments, by any party other than the intended recipient. If you have received this email in error please notify the sender and delete it from your system. No employee or agent is authorised to conclude any binding agreement on behalf of the NSW Department of Commerce by email. The views or opinions presented in this email are solely those of the author and do not necessarily represent those of the Department, except where the sender expressly, and with authority, states them to be the views of NSW Department of Commerce. The NSW Department of Commerce accepts no liability for any loss or damage arising from the use of this email and recommends that the recipient check this email and any attached files for the presence of viruses. ** [[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. ** This email message, including any attached files, is confidential and intended solely for
Re: [R] Merge data frames but with a twist.
On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tuckerbrown_...@yahoo.com wrote: You may want to use the reshape package for this task: library(reshape) recast(DF3,Show ~ Datetime, id.var=names(DF3),value=Measure) Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM 1 Firefly 3 1 2 Red Dwarf 4 2 If you want to plot time series, you can do something like the following mydf - .Last.value ## save the output from above to mydf library(zoo) zobj - zoo(`mode-`(t(mydf),numeric), as.chron(strptime(names(mydf)[-1],%m/%d/%Y %I:%M %p))) plot(zobj) (zobj is a time series object of the zoo class) Note that as.chron can take % codes directly so the as.chron portion can be shortened to: as.chron(names(mydf)[-1],%m/%d/%Y %I:%M %p) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] distinct elements of a vector
Try : unique(c(a,b,a,c)) On Thu, Aug 27, 2009 at 10:48 AM, mirauta bmira...@yahoo.com wrote: Hello, I have the vector (a,b,a,c) and I trying to obtain it's distinct elements in another vector. Is there a function that can do this? Thanks, Bogdan -- View this message in context: http://www.nabble.com/distinct-elements-of-a-vector-tp25168032p25168032.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] generating multiple sequences in subsets of data
I'm running into a problem I can't seem to find a solution for. I'm attempting to add sequences into an existing data set based on subsets of the data. I've done this using a for loop with a small subset of data, but attempting the same process using real data (200k rows) is taking way too long. Here is some sample data and my ultimate goal row1-c(0,1,2,3,4,5,1,2,3,4) row2-c(1,1,1,1,1,1,2,2,2,2) stuff-data.frame(row1=row1,row2=row2) stuff row1 row2 1 01 2 11 3 21 4 31 5 41 6 51 7 12 8 22 9 32 1042 I need to derive 2 columns. I need a sequence for each unique row2, and then I need a sequence that restarts based on a cutoff value for row1 and unique row2. The following table is what is -should- look like using a cutoff of 3 for row4 row1 row2 row3 row4 1 0111 2 1122 3 2133 4 3141 5 4152 6 5163 7 1211 8 2222 9 3231 104242 I need something like row3-sequence(nrow(unique(stuff$row2))) that actually works :-) Here is the for loop that functions properly for row3: stuff$row3-c(1) for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) { stuff$row3[i] = stuff$row3[i-1]+1}} Thanks! Jason Baucom Ateb, Inc. 919.882.4992 O 919.872.1645 F www.ateb.com http://www.ateb.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.
Re: [R] generating multiple sequences in subsets of data
Try this; stuff$row3 - with(stuff, ave(row1, row2, FUN = seq)) I don't understand the fourth column On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom jason.bau...@ateb.comwrote: I'm running into a problem I can't seem to find a solution for. I'm attempting to add sequences into an existing data set based on subsets of the data. I've done this using a for loop with a small subset of data, but attempting the same process using real data (200k rows) is taking way too long. Here is some sample data and my ultimate goal row1-c(0,1,2,3,4,5,1,2,3,4) row2-c(1,1,1,1,1,1,2,2,2,2) stuff-data.frame(row1=row1,row2=row2) stuff row1 row2 1 01 2 11 3 21 4 31 5 41 6 51 7 12 8 22 9 32 1042 I need to derive 2 columns. I need a sequence for each unique row2, and then I need a sequence that restarts based on a cutoff value for row1 and unique row2. The following table is what is -should- look like using a cutoff of 3 for row4 row1 row2 row3 row4 1 0111 2 1122 3 2133 4 3141 5 4152 6 5163 7 1211 8 2222 9 3231 104242 I need something like row3-sequence(nrow(unique(stuff$row2))) that actually works :-) Here is the for loop that functions properly for row3: stuff$row3-c(1) for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) { stuff$row3[i] = stuff$row3[i-1]+1}} Thanks! Jason Baucom Ateb, Inc. 919.882.4992 O 919.872.1645 F www.ateb.com http://www.ateb.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. -- 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] generating multiple sequences in subsets of data
Henrique, That works great! Thanks. The row3 is a sequence that restarts each time a new row2 is reached. Row4 is a sequence that restarts each time a new row2 is reached OR row1 reaches some threshold. By setting a threshold of 3, we expect a restart of the sequence once row1 reaches 3. This way we can have two unique sequences for each row2, assuming of course the threshold is reached. Jason From: Henrique Dallazuanna [mailto:www...@gmail.com] Sent: Thursday, August 27, 2009 11:02 AM To: Jason Baucom Cc: r-help@r-project.org; Steven Few Subject: Re: [R] generating multiple sequences in subsets of data Try this; stuff$row3 - with(stuff, ave(row1, row2, FUN = seq)) I don't understand the fourth column On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom jason.bau...@ateb.com wrote: I'm running into a problem I can't seem to find a solution for. I'm attempting to add sequences into an existing data set based on subsets of the data. I've done this using a for loop with a small subset of data, but attempting the same process using real data (200k rows) is taking way too long. Here is some sample data and my ultimate goal row1-c(0,1,2,3,4,5,1,2,3,4) row2-c(1,1,1,1,1,1,2,2,2,2) stuff-data.frame(row1=row1,row2=row2) stuff row1 row2 1 01 2 11 3 21 4 31 5 41 6 51 7 12 8 22 9 32 1042 I need to derive 2 columns. I need a sequence for each unique row2, and then I need a sequence that restarts based on a cutoff value for row1 and unique row2. The following table is what is -should- look like using a cutoff of 3 for row4 row1 row2 row3 row4 1 0111 2 1122 3 2133 4 3141 5 4152 6 5163 7 1211 8 2222 9 3231 104242 I need something like row3-sequence(nrow(unique(stuff$row2))) that actually works :-) Here is the for loop that functions properly for row3: stuff$row3-c(1) for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) { stuff$row3[i] = stuff$row3[i-1]+1}} Thanks! Jason Baucom Ateb, Inc. 919.882.4992 O 919.872.1645 F www.ateb.com http://www.ateb.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. -- 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] generating multiple sequences in subsets of data
I got this to work. Thanks for the insight! row7 is what I need. checkLimit -function(x) x3 stuff$row6-checkLimit(stuff$row1) stuff$row7 - with(stuff, ave(row1,row2, row6, FUN = sequence)) stuff row1 row2 row3 row4 row5 row6 row7 1 01111 TRUE1 2 11222 TRUE2 3 21333 TRUE3 4 31414 FALSE1 5 41515 FALSE2 6 51616 FALSE3 7 12111 TRUE1 8 22222 TRUE2 9 32313 FALSE1 1042414 FALSE2 Jason From: Henrique Dallazuanna [mailto:www...@gmail.com] Sent: Thursday, August 27, 2009 11:02 AM To: Jason Baucom Cc: r-help@r-project.org; Steven Few Subject: Re: [R] generating multiple sequences in subsets of data Try this; stuff$row3 - with(stuff, ave(row1, row2, FUN = seq)) I don't understand the fourth column On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom jason.bau...@ateb.com wrote: I'm running into a problem I can't seem to find a solution for. I'm attempting to add sequences into an existing data set based on subsets of the data. I've done this using a for loop with a small subset of data, but attempting the same process using real data (200k rows) is taking way too long. Here is some sample data and my ultimate goal row1-c(0,1,2,3,4,5,1,2,3,4) row2-c(1,1,1,1,1,1,2,2,2,2) stuff-data.frame(row1=row1,row2=row2) stuff row1 row2 1 01 2 11 3 21 4 31 5 41 6 51 7 12 8 22 9 32 1042 I need to derive 2 columns. I need a sequence for each unique row2, and then I need a sequence that restarts based on a cutoff value for row1 and unique row2. The following table is what is -should- look like using a cutoff of 3 for row4 row1 row2 row3 row4 1 0111 2 1122 3 2133 4 3141 5 4152 6 5163 7 1211 8 2222 9 3231 104242 I need something like row3-sequence(nrow(unique(stuff$row2))) that actually works :-) Here is the for loop that functions properly for row3: stuff$row3-c(1) for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) { stuff$row3[i] = stuff$row3[i-1]+1}} Thanks! Jason Baucom Ateb, Inc. 919.882.4992 O 919.872.1645 F www.ateb.com http://www.ateb.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. -- 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.
[R] subset of a matrix
Hello everyone, I would appreciate any help with the following. My dataset is a list containing matrices. So if you type e.g. data[[1]] you get something like: [,1][,2] 361a AT 456b AG 72145aTG As you can see my rows have names which are character strings containing numbers and letters. I want something similar to a histogram, per column. i.e. I want to know how many times I have a single repeat character in a column and how many times I have a twice repeated character and so on. Maybe there is an easy way to do this, but I wrote my own code which works perfectly, so don't bother to correct it unless extremely necessary. I write down the code so you know exactly what I'm trying to do: table - vector() for (i in (1:length(data))){ for (j in (1:length(data[[i]][1,]))){ t - table(data[[i]][,j]) table - c(table, t) }} ncount - table[names(table) != -] #this line is necessary to eliminate - characters which should not be included in the analysis sfs - table (ncount) And with this code I get something like: 1 2 3 4 5 6 7 8 9 10 542 125 98 49 47 41 26 31 22 18 which is what I'm looking for. Now comes THE problem: As I said before my rows have names. Each name is unique. I want to apply my analysis to a subset of rows en each matrix, namely all rows whose names start with 3, all that start with 4, all that start with 721. In most cases only the first character is important, but since I have names of different length, in some cases I need the first three characters to differentiate the groups. I want to integrate this into the loop so that I get a vector (such as the one called table in my code) for each subset analyzed. I tried using the subset function, but I couldn't figure out how to use it, because it's intended to use row values to define the subset, not row names. I hope someone can help me out, but please bear in mind I am really new at R and most commands and parameters are really unfamiliar to me. Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subset of a matrix
Hi Carlos, how about this step first: rownames(mydata)-gsub(361a,00361a,rownames(mydata)) rownames(mydata)-gsub(456a,00456a,rownames(mydata)) good luck milton On Thu, Aug 27, 2009 at 12:27 PM, Carlos Gonzalo Merino Mendez carlosgmer...@yahoo.com wrote: Hello everyone, I would appreciate any help with the following. My dataset is a list containing matrices. So if you type e.g. data[[1]] you get something like: [,1][,2] 361a AT 456b AG 72145aTG As you can see my rows have names which are character strings containing numbers and letters. I want something similar to a histogram, per column. i.e. I want to know how many times I have a single repeat character in a column and how many times I have a twice repeated character and so on. Maybe there is an easy way to do this, but I wrote my own code which works perfectly, so don't bother to correct it unless extremely necessary. I write down the code so you know exactly what I'm trying to do: table - vector() for (i in (1:length(data))){ for (j in (1:length(data[[i]][1,]))){ t - table(data[[i]][,j]) table - c(table, t) }} ncount - table[names(table) != -] #this line is necessary to eliminate - characters which should not be included in the analysis sfs - table (ncount) And with this code I get something like: 1 2 3 4 5 6 7 8 9 10 542 125 98 49 47 41 26 31 22 18 which is what I'm looking for. Now comes THE problem: As I said before my rows have names. Each name is unique. I want to apply my analysis to a subset of rows en each matrix, namely all rows whose names start with 3, all that start with 4, all that start with 721. In most cases only the first character is important, but since I have names of different length, in some cases I need the first three characters to differentiate the groups. I want to integrate this into the loop so that I get a vector (such as the one called table in my code) for each subset analyzed. I tried using the subset function, but I couldn't figure out how to use it, because it's intended to use row values to define the subset, not row names. I hope someone can help me out, but please bear in mind I am really new at R and most commands and parameters are really unfamiliar to me. 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generating multiple sequences in subsets of data
On Aug 27, 2009, at 11:58 AM, Jason Baucom wrote: I got this to work. Thanks for the insight! row7 is what I need. checkLimit -function(x) x3 stuff$row6-checkLimit(stuff$row1) You don't actually need those intermediate steps: stuff$row7 - with(stuff, ave(row1, row2, row1 3, FUN = seq)) stuff row1 row2 row7 1 011 2 112 3 213 4 311 5 412 6 513 7 121 8 222 9 321 10422 The expression row1 3 gets turned into a logical vector that ave() is perfectly happy with. -- David Winsemius stuff$row7 - with(stuff, ave(row1,row2, row6, FUN = sequence)) stuff row1 row2 row3 row4 row5 row6 row7 1 01111 TRUE1 2 11222 TRUE2 3 21333 TRUE3 4 31414 FALSE1 5 41515 FALSE2 6 51616 FALSE3 7 12111 TRUE1 8 22222 TRUE2 9 32313 FALSE1 1042414 FALSE2 Jason From: Henrique Dallazuanna [mailto:www...@gmail.com] Sent: Thursday, August 27, 2009 11:02 AM To: Jason Baucom Cc: r-help@r-project.org; Steven Few Subject: Re: [R] generating multiple sequences in subsets of data Try this; stuff$row3 - with(stuff, ave(row1, row2, FUN = seq)) I don't understand the fourth column On Thu, Aug 27, 2009 at 11:55 AM, Jason Baucom jason.bau...@ateb.com wrote: I'm running into a problem I can't seem to find a solution for. I'm attempting to add sequences into an existing data set based on subsets of the data. I've done this using a for loop with a small subset of data, but attempting the same process using real data (200k rows) is taking way too long. Here is some sample data and my ultimate goal row1-c(0,1,2,3,4,5,1,2,3,4) row2-c(1,1,1,1,1,1,2,2,2,2) stuff-data.frame(row1=row1,row2=row2) stuff row1 row2 1 01 2 11 3 21 4 31 5 41 6 51 7 12 8 22 9 32 1042 I need to derive 2 columns. I need a sequence for each unique row2, and then I need a sequence that restarts based on a cutoff value for row1 and unique row2. The following table is what is -should- look like using a cutoff of 3 for row4 row1 row2 row3 row4 1 0111 2 1122 3 2133 4 3141 5 4152 6 5163 7 1211 8 2222 9 3231 104242 I need something like row3-sequence(nrow(unique(stuff$row2))) that actually works :-) Here is the for loop that functions properly for row3: stuff$row3-c(1) for (i in 2:nrow(stuff)) { if ( stuff$row2[i] == stuff$row2[i-1]) { stuff$row3[i] = stuff$row3[i-1]+1}} Thanks! Jason Baucom Ateb, Inc. 919.882.4992 O 919.872.1645 F www.ateb.com http://www.ateb.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. -- 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a simple line graph
Hello On 8/27/09, Josh Roll j_r...@hotmail.com wrote: I am having trouble getting both graphs on the same page. Its separating them, especially when i write them to a pdf. I need visual comparison capabilities. Do i need to include the two data sets in the same plot to make this happen. Thanks http://www.statmethods.net/advgraphs/layout.html http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-base:overlapping_plots Perhaps this: Sz= c(h1,h2,h3,h4) Pred=c(34790.0 ,47559.8, 21197.8, 28198.6) Obs=c(34740 ,48615 ,20420, 26840) plot(Pred, t=l, ylim=c(2,5)) text(Pred, Sz, cex=0.6, pos=4, col=red) par(new=TRUE) plot(Obs, t=l, ylim=c(2,5)) text(Obs, Sz, cex=0.6, pos=4, col=blue) Alternatively you can use lines(), but always pay attention that both graphs be constructed with teh same x and y limits. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 on ar(1)
Hi Assume i have three time series Y, X and Z and the model is Y(t) = b1 + b2*X(t) + b3*Z(t) + u(t) How can I introduce an autoregressive term ar(1) to solve for serial autocorrelation? i've been trying with ar(arg1,arg2,arg3) but it only works for individual series thanks a lot -- Gaspar [[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] subset of a matrix
Hi Carlos, I think I made a wrong suggestion. Sorry about that. I was thinking that if you have the same rowname length it helps you on the data handling. Is it true?! Case yes I can try suggest another automatic way of you get it. bests milton On Thu, Aug 27, 2009 at 12:39 PM, milton ruser milton.ru...@gmail.comwrote: Hi Carlos, how about this step first: rownames(mydata)-gsub(361a,00361a,rownames(mydata)) rownames(mydata)-gsub(456a,00456a,rownames(mydata)) good luck milton On Thu, Aug 27, 2009 at 12:27 PM, Carlos Gonzalo Merino Mendez carlosgmer...@yahoo.com wrote: Hello everyone, I would appreciate any help with the following. My dataset is a list containing matrices. So if you type e.g. data[[1]] you get something like: [,1][,2] 361a AT 456b AG 72145aTG As you can see my rows have names which are character strings containing numbers and letters. I want something similar to a histogram, per column. i.e. I want to know how many times I have a single repeat character in a column and how many times I have a twice repeated character and so on. Maybe there is an easy way to do this, but I wrote my own code which works perfectly, so don't bother to correct it unless extremely necessary. I write down the code so you know exactly what I'm trying to do: table - vector() for (i in (1:length(data))){ for (j in (1:length(data[[i]][1,]))){ t - table(data[[i]][,j]) table - c(table, t) }} ncount - table[names(table) != -] #this line is necessary to eliminate - characters which should not be included in the analysis sfs - table (ncount) And with this code I get something like: 1 2 3 4 5 6 7 8 9 10 542 125 98 49 47 41 26 31 22 18 which is what I'm looking for. Now comes THE problem: As I said before my rows have names. Each name is unique. I want to apply my analysis to a subset of rows en each matrix, namely all rows whose names start with 3, all that start with 4, all that start with 721. In most cases only the first character is important, but since I have names of different length, in some cases I need the first three characters to differentiate the groups. I want to integrate this into the loop so that I get a vector (such as the one called table in my code) for each subset analyzed. I tried using the subset function, but I couldn't figure out how to use it, because it's intended to use row values to define the subset, not row names. I hope someone can help me out, but please bear in mind I am really new at R and most commands and parameters are really unfamiliar to me. 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Winsorized mean and variance
Roberto, Try winsor in the psych package. Bill At 10:21 AM -0400 8/27/09, Roberto Perdisci wrote: This is of great help, thanks! Roberto On Thu, Aug 27, 2009 at 7:20 AM, Jim Lemonj...@bitwrit.com.au wrote: Roberto Perdisci wrote: Hello everybody, after searching around for quite some time, I haven't been able to find a package that provides a function to compute the Windorized mean and variance. Also I haven't found a function that computes the trimmed variance. Is there any such package around? Hi Roberto, The Winsorized variance is similar to the trimmed variance, except that the extreme values are substituted rather than dropped. Define the quantiles within which you want to retain the original values and then substitute the values at the quantiles for all values more extreme in the respective sign direction. Like this: testdat-rnorm(20) winsorVar-function(x,probs=c(0.05,0.95)) { xq-quantile(x,probs=probs) x[x xq[1]]-xq[1] x[x xq[2]]-xq[2] return(var(x)) } Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnight http://www.thebulletin.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subset of a matrix
Try this: lapply(data, function(r) lapply(split(r, substr(sprintf(%05d, as.numeric(gsub([a-z], , row.names(r, 1, 3)), table)) On Thu, Aug 27, 2009 at 1:27 PM, Carlos Gonzalo Merino Mendez carlosgmer...@yahoo.com wrote: Hello everyone, I would appreciate any help with the following. My dataset is a list containing matrices. So if you type e.g. data[[1]] you get something like: [,1][,2] 361a AT 456b AG 72145aTG As you can see my rows have names which are character strings containing numbers and letters. I want something similar to a histogram, per column. i.e. I want to know how many times I have a single repeat character in a column and how many times I have a twice repeated character and so on. Maybe there is an easy way to do this, but I wrote my own code which works perfectly, so don't bother to correct it unless extremely necessary. I write down the code so you know exactly what I'm trying to do: table - vector() for (i in (1:length(data))){ for (j in (1:length(data[[i]][1,]))){ t - table(data[[i]][,j]) table - c(table, t) }} ncount - table[names(table) != -] #this line is necessary to eliminate - characters which should not be included in the analysis sfs - table (ncount) And with this code I get something like: 1 2 3 4 5 6 7 8 9 10 542 125 98 49 47 41 26 31 22 18 which is what I'm looking for. Now comes THE problem: As I said before my rows have names. Each name is unique. I want to apply my analysis to a subset of rows en each matrix, namely all rows whose names start with 3, all that start with 4, all that start with 721. In most cases only the first character is important, but since I have names of different length, in some cases I need the first three characters to differentiate the groups. I want to integrate this into the loop so that I get a vector (such as the one called table in my code) for each subset analyzed. I tried using the subset function, but I couldn't figure out how to use it, because it's intended to use row values to define the subset, not row names. I hope someone can help me out, but please bear in mind I am really new at R and most commands and parameters are really unfamiliar to me. 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. -- 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] subset of a matrix
Hi Milton, Thanks for trying to help anyway. From: milton ruser milton.ru...@gmail.com Cc: r-help@r-project.org Sent: Thursday, August 27, 2009 6:48:41 PM Subject: Re: [R] subset of a matrix Hi Carlos, I think I made a wrong suggestion. Sorry about that. I was thinking that if you have the same rowname length it helps you on the data handling. Is it true?! Case yes I can try suggest another automatic way of you get it. bests milton On Thu, Aug 27, 2009 at 12:39 PM, milton ruser milton.ru...@gmail.com wrote: Hi Carlos, how about this step first: rownames(mydata)-gsub(361a,00361a,rownames(mydata)) rownames(mydata)-gsub(456a,00456a,rownames(mydata)) good luck milton Hello everyone, I would appreciate any help with the following. My dataset is a list containing matrices. So if you type e.g. data[[1]] you get something like: [,1][,2] 361a AT 456b AG 72145aTG As you can see my rows have names which are character strings containing numbers and letters. I want something similar to a histogram, per column. i.e. I want to know how many times I have a single repeat character in a column and how many times I have a twice repeated character and so on. Maybe there is an easy way to do this, but I wrote my own code which works perfectly, so don't bother to correct it unless extremely necessary. I write down the code so you know exactly what I'm trying to do: table - vector() for (i in (1:length(data))){ for (j in (1:length(data[[i]][1,]))){ t - table(data[[i]][,j]) table - c(table, t) }} ncount - table[names(table) != -] #this line is necessary to eliminate - characters which should not be included in the analysis sfs - table (ncount) And with this code I get something like: 1 2 3 4 5 6 7 8 9 10 542 125 98 49 47 41 26 31 22 18 which is what I'm looking for. Now comes THE problem: As I said before my rows have names. Each name is unique. I want to apply my analysis to a subset of rows en each matrix, namely all rows whose names start with 3, all that start with 4, all that start with 721. In most cases only the first character is important, but since I have names of different length, in some cases I need the first three characters to differentiate the groups. I want to integrate this into the loop so that I get a vector (such as the one called table in my code) for each subset analyzed. I tried using the subset function, but I couldn't figure out how to use it, because it's intended to use row values to define the subset, not row names. I hope someone can help me out, but please bear in mind I am really new at R and most commands and parameters are really unfamiliar to me. 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. [[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] subset of a matrix
Hi Henrique, I tried your code. I simply copied and pasted it 'cause I have no idea how it works. What I get is the total number of A's and T's and all other characters, which was not my intention. Maybe I need to make some modifications to your script before being able to apply within my script? Can you explain what for are you using those commands? Thanks for the help anyway. Cheers, Carlos From: Henrique Dallazuanna www...@gmail.com Cc: r-help@r-project.org Sent: Thursday, August 27, 2009 7:00:45 PM Subject: Re: [R] subset of a matrix Try this: lapply(data, function(r) lapply(split(r, substr(sprintf(%05d, as.numeric(gsub([a-z], , row.names(r, 1, 3)), table)) On Thu, Aug 27, 2009 at 1:27 PM, Carlos Gonzalo Merino Mendez carlosgmerin Hello everyone, I would appreciate any help with the following. My dataset is a list containing matrices. So if you type e.g. data[[1]] you get something like: [,1][,2] 361a AT 456b AG 72145aTG As you can see my rows have names which are character strings containing numbers and letters. I want something similar to a histogram, per column. i.e. I want to know how many times I have a single repeat character in a column and how many times I have a twice repeated character and so on. Maybe there is an easy way to do this, but I wrote my own code which works perfectly, so don't bother to correct it unless extremely necessary. I write down the code so you know exactly what I'm trying to do: table - vector() for (i in (1:length(data))){ for (j in (1:length(data[[i]][1,]))){ t - table(data[[i]][,j]) table - c(table, t) }} ncount - table[names(table) != -] #this line is necessary to eliminate - characters which should not be included in the analysis sfs - table (ncount) And with this code I get something like: 1 2 3 4 5 6 7 8 9 10 542 125 98 49 47 41 26 31 22 18 which is what I'm looking for. Now comes THE problem: As I said before my rows have names. Each name is unique. I want to apply my analysis to a subset of rows en each matrix, namely all rows whose names start with 3, all that start with 4, all that start with 721. In most cases only the first character is important, but since I have names of different length, in some cases I need the first three characters to differentiate the groups. I want to integrate this into the loop so that I get a vector (such as the one called table in my code) for each subset analyzed. I tried using the subset function, but I couldn't figure out how to use it, because it's intended to use row values to define the subset, not row names. I hope someone can help me out, but please bear in mind I am really new at R and most commands and parameters are really unfamiliar to me. 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. -- 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] fitting a linear model line through srip plot
Nevermind, I figured another way through the plot command. thanks :) On Thu, Aug 27, 2009 at 7:16 AM, Mehdi Khan mwk...@ucdavis.edu wrote: I am creating a strip plot from the lattice library, and would like the display to also have the linear model line through it. How would I do that? stripplot(jitter(vs30)~tif.vs30, data=rastermodel, xlim=c(150,600), ylim=c(0,1000)) yonglm-lm(vs30~tif.vs30, data=rastermodel) Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mann whitney u
How current is the literature? Is the more recent literature using Mann-Whitney because of inertia rather than best practice? The Mann-Whitney/Wicoxon test is a special case of a permutation test that has a shortcut computation. Fast computers were not available when these tests were developed and so having the shortcut was very valuable. These days with fast computers, that is much less important. Before using the Mann-Whitney/Wilcoxon test, you should ask a few questions (actually these questions are probably appropriate for many different tests): 1. Do I understand what the test statistic is measuring? 2. Do I understand what null and alternative hypotheses are really testing? (note: if the word median came to mind while answering either of the above, then the answer is no). 3. Is this test meaningful for my project? 4. Is this test interesting for my project? 5. Can I explain what this test statistic/hypothesis really is to a lay person? 6. Do I want to explain this to a lay person? If the answers to all the questions are yes, then use the Mann-Whitney/Wilcoxon test, otherwise I would suggest doing a permutation test on a more meaningful statistic. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Mcdonald, Grant Sent: Wednesday, August 26, 2009 5:19 AM To: r-help@R-project.org Subject: [R] mann whitney u Dear Sir, I am comparing two samples using wilcox.test in R. Literature appears to describe mann whitney u test as the most appropriate test to use on my data. is the wilcox.test function equivalent to mann-whitney u? Is there a way to gain the U-value as apposed to the W-value in R? Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] math symbol + value of a variable in legend.
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler Sent: Thursday, August 27, 2009 1:30 AM To: Kenneth Roy Cabrera Torres Cc: RHelp Subject: Re: [R] math symbol + value of a variable in legend. KRCT == Kenneth Roy Cabrera Torres krcab...@une.net.co on Tue, 25 Aug 2009 17:26:04 -0500 writes: KRCT Thank you very much for your help. KRCT To the R gurus: It will be better at the future to simplify this KRCT options. KRCT They are too cumbersome!!! The ones David showed, yes, are too cumbersome. There's a variant, which is even a bit more elegant, but really a small (?) change in R's handling of symbols could make it even more elegant. I'll talk about that on the dedicated list, R-devel. Here's the slightly more elegant code (for current versions of R): plot(1:5,1:5,type=n) legend(topleft, legend= c(as.expression( bquote(mu == .(m1)) ), as.expression( bquote(mu == .(m2)) )), lty = 1:2) Another version that is more easily extendable to longer legends is legend(topright, lty=1:2, legend= as.expression(lapply(c(m1,m2), function(m)bquote(mu==.(m) Another example is: m - c(1,exp(1),pi) plot(m, pch=seq_along(m), xlab=expression(iota), ylab=quote(e^c(0,1,log(pi legend(bottom, pch=seq_along(m), legend=as.expression(lapply(seq_along(m),function(i)bquote(m[.(i)]==.(m[i]) Note that xlab and ylab can be either expressions or calls (or, in general, language objects) but legend must be an expression for this to work. If legend is a list of calls, as in the more direct legend(bottomright, pch=seq_along(m), legend=lapply(seq_along(m),function(i)bquote(m[.(i)]==.(m[i] then it looks like its elements are coerced to character strings (via deparse). If legend's legend= argument would interpret lists differently than it does, treating elements which are expressions or calls as plotmath requests and other types as things to convert to strings, then I think the syntax would be simpler. E.g., your example could be legend(bottomleft, legend=list(bquote(mu==.(m1)), bquote(mu=.(m2))), lty=1:2) You would not have to throw in the extraneous as.expression calls nor have to redefine the c function. Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com ## ## or with subscripts : ## legend(top, legend = c(as.expression( bquote(mu[1] == .(m1)) ), as.expression( bquote(mu[2] == .(m2)) )), lty = 1:2) ## ## or, if you really need to have the subscript as a *variable* as well: ## i1 - 11; i2 - 20 legend(topright, legend = c(as.expression( bquote(mu[.(i1)] == .(m1)) ), as.expression( bquote(mu[.(i2)] == .(m2)) )), lty = 1:2) Martin Maechler, ETH Zurich KRCT El mar, 25-08-2009 a las 18:16 -0400, David Winsemius escribió: On Aug 25, 2009, at 5:51 PM, David Winsemius wrote: On Aug 25, 2009, at 4:30 PM, Kenneth Roy Cabrera Torres wrote: Hi R users: I will like to have a legend with math symbols and also with the value of a variable. But I cannot obtain both at the same time (symbol + value of a variable): Here is a reproducible example: m1-5 m2-12 I think I am violating a fortune but this worked: plot(1:5,1:5,type=n) legend (topleft,legend=c(eval(substitute( expression(paste(mu,=,m1)), list(m1=m1) )) , eval(substitute( expression(paste(mu,=,m2)), list(m2=m2) ) )), lty=1:2) And efforts at simplification were at least partly successful: legend(topleft,legend=c(eval(substitute( expression(mu == m1), list(m1=m1) )) , eval(substitute( expression(mu == m2), list(m2=m2) ) )), lty=1:2) And this adds subscripts to the mu's: plot(1:5,1:5,type=n); legend(topleft, legend=c( eval(substitute( expression(mu[i] == m1), list(i=1, m1=m1) )) , eval(substitute( expression(mu[i] == m2), list(i=2, m2=m2) )) ), lty=1:2) plot(1:5,1:5,type=n) legend (topleft ,legend = c(paste(expression(mu),=,m1),expression(paste(mu,=,m2))),lty=1:2) Thank you for your help. Kenneth -- David Winsemius, MD Heritage Laboratories West Hartford, CT KRCT __ KRCT R-help@r-project.org mailing list KRCT https://stat.ethz.ch/mailman/listinfo/r-help KRCT PLEASE do read the posting guide http://www.R-project.org/posting-guide.html KRCT and provide commented, minimal, self-contained, reproducible code. __
Re: [R] teaching R
I'd suggest looking at Rcmdr by John Fox (http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/). I use it to introduce anthropology students to R for statistical analyses. It is a graphical user interface that lets students quickly begin using R to run statistical analyses. It includes a command window so you can access functions that are not included in the menu structure. Think of it as training wheels (and more) for beginners. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 [[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] Merge data frames but with a twist.
Ah, thanks always - I originally thought as.chron() was required to have all fields (m/d/y hh:mm:ss) as for chron() but I see that the former passes its 'format' argument to as.POSIXct() Good deal! Stephen - Original Message From: Gabor Grothendieck ggrothendi...@gmail.com To: Stephen Tucker brown_...@yahoo.com Cc: Tony Breyal tony.bre...@googlemail.com; r-help@r-project.org Sent: Thursday, August 27, 2009 7:27:26 AM Subject: Re: [R] Merge data frames but with a twist. On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tuckerbrown_...@yahoo.com wrote: You may want to use the reshape package for this task: library(reshape) recast(DF3,Show ~ Datetime, id.var=names(DF3),value=Measure) Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM 1 Firefly 3 1 2 Red Dwarf 4 2 If you want to plot time series, you can do something like the following mydf - .Last.value ## save the output from above to mydf library(zoo) zobj - zoo(`mode-`(t(mydf),numeric), as.chron(strptime(names(mydf)[-1],%m/%d/%Y %I:%M %p))) plot(zobj) (zobj is a time series object of the zoo class) Note that as.chron can take % codes directly so the as.chron portion can be shortened to: as.chron(names(mydf)[-1],%m/%d/%Y %I:%M %p) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge data frames but with a twist.
The inconsistency arose in order to satisfy backward compatibility while giving chron a direct way to use % codes. chron used its own format specification so it would have been difficult to add % codes there; however, as.chron, at the time, did not support a format specification at all so it was still possible to add a format specifier using % codes without disrupting existing code. On Thu, Aug 27, 2009 at 2:21 PM, Stephen Tuckerbrown_...@yahoo.com wrote: Ah, thanks always - I originally thought as.chron() was required to have all fields (m/d/y hh:mm:ss) as for chron() but I see that the former passes its 'format' argument to as.POSIXct() Good deal! Stephen - Original Message From: Gabor Grothendieck ggrothendi...@gmail.com To: Stephen Tucker brown_...@yahoo.com Cc: Tony Breyal tony.bre...@googlemail.com; r-help@r-project.org Sent: Thursday, August 27, 2009 7:27:26 AM Subject: Re: [R] Merge data frames but with a twist. On Thu, Aug 27, 2009 at 9:55 AM, Stephen Tuckerbrown_...@yahoo.com wrote: You may want to use the reshape package for this task: library(reshape) recast(DF3,Show ~ Datetime, id.var=names(DF3),value=Measure) Show 08/26/2009 11:30 AM 08/26/2009 9:30 AM 1 Firefly 3 1 2 Red Dwarf 4 2 If you want to plot time series, you can do something like the following mydf - .Last.value ## save the output from above to mydf library(zoo) zobj - zoo(`mode-`(t(mydf),numeric), as.chron(strptime(names(mydf)[-1],%m/%d/%Y %I:%M %p))) plot(zobj) (zobj is a time series object of the zoo class) Note that as.chron can take % codes directly so the as.chron portion can be shortened to: as.chron(names(mydf)[-1],%m/%d/%Y %I:%M %p) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] math symbol + value of a variable in legend.
Try this: legend(topleft, c(as.expression(bquote(mu == .(m1))), as.expression(bquote(mu == .(m2) On Tue, Aug 25, 2009 at 5:30 PM, Kenneth Roy Cabrera Torres krcab...@une.net.co wrote: Hi R users: I will like to have a legend with math symbols and also with the value of a variable. But I cannot obtain both at the same time (symbol + value of a variable): Here is a reproducible example: m1-5 m2-12 plot(1:5,1:5,type=n) legend(topleft,legend=c(paste(expression(mu),=,m1),expression(paste(mu,=,m2))),lty=1:2) Thank you for your help. Kenneth PD: Using R 2.9.2 on Linux ubuntu 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linuxu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] math symbol + value of a variable in legend.
Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Thursday, August 27, 2009 11:18 AM To: Martin Maechler; Kenneth Roy Cabrera Torres Cc: RHelp Subject: Re: [R] math symbol + value of a variable in legend. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler Sent: Thursday, August 27, 2009 1:30 AM To: Kenneth Roy Cabrera Torres Cc: RHelp Subject: Re: [R] math symbol + value of a variable in legend. KRCT == Kenneth Roy Cabrera Torres krcab...@une.net.co on Tue, 25 Aug 2009 17:26:04 -0500 writes: KRCT Thank you very much for your help. KRCT To the R gurus: It will be better at the future to simplify this KRCT options. KRCT They are too cumbersome!!! The ones David showed, yes, are too cumbersome. There's a variant, which is even a bit more elegant, but really a small (?) change in R's handling of symbols could make it even more elegant. I'll talk about that on the dedicated list, R-devel. Here's the slightly more elegant code (for current versions of R): plot(1:5,1:5,type=n) legend(topleft, legend= c(as.expression( bquote(mu == .(m1)) ), as.expression( bquote(mu == .(m2)) )), lty = 1:2) Another version that is more easily extendable to longer legends is legend(topright, lty=1:2, legend= as.expression(lapply(c(m1,m2), function(m)bquote(mu==.(m) Another example is: m - c(1,exp(1),pi) plot(m, pch=seq_along(m), xlab=expression(iota), ylab=quote(e^c(0,1,log(pi legend(bottom, pch=seq_along(m), legend=as.expression(lapply(seq_along(m),function(i)bquote(m[. (i)]==.(m[i]) Note that xlab and ylab can be either expressions or calls (or, in general, language objects) but legend must be an expression for this to work. If legend is a list of calls, as in the more direct legend(bottomright, pch=seq_along(m), legend=lapply(seq_along(m),function(i)bquote(m[.(i)]==.(m[i] then it looks like its elements are coerced to character strings (via deparse). If legend's legend= argument would interpret lists differently than it does, treating elements which are expressions or calls as plotmath requests and other types as things to convert to strings, then I think the syntax would be simpler. E.g., your example could be legend(bottomleft, legend=list(bquote(mu==.(m1)), bquote(mu=.(m2))), lty=1:2) You would not have to throw in the extraneous as.expression calls nor have to redefine the c function. To try this out, redefine as.graphicsAnnot to process lists specially, before the existing check for is.language(x)||!is.object(x): as.graphicsAnnot - function (x) if (is.list(x)) { as.expression(lapply(x, function(xi) { if(is.expression(xi)) xi[[1]] else if (is.language(xi)) xi else as.character(xi) })) } else if (is.language(x) || !is.object(x)) { x } else { as.character(x) } Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com ## ## or with subscripts : ## legend(top, legend = c(as.expression( bquote(mu[1] == .(m1)) ), as.expression( bquote(mu[2] == .(m2)) )), lty = 1:2) ## ## or, if you really need to have the subscript as a *variable* as well: ## i1 - 11; i2 - 20 legend(topright, legend = c(as.expression( bquote(mu[.(i1)] == .(m1)) ), as.expression( bquote(mu[.(i2)] == .(m2)) )), lty = 1:2) Martin Maechler, ETH Zurich KRCT El mar, 25-08-2009 a las 18:16 -0400, David Winsemius escribió: On Aug 25, 2009, at 5:51 PM, David Winsemius wrote: On Aug 25, 2009, at 4:30 PM, Kenneth Roy Cabrera Torres wrote: Hi R users: I will like to have a legend with math symbols and also with the value of a variable. But I cannot obtain both at the same time (symbol + value of a variable): Here is a reproducible example: m1-5 m2-12 I think I am violating a fortune but this worked: plot(1:5,1:5,type=n) legend (topleft,legend=c(eval(substitute( expression(paste(mu,=,m1)), list(m1=m1) )) , eval(substitute( expression(paste(mu,=,m2)), list(m2=m2) ) )), lty=1:2) And efforts at simplification were at least partly successful: legend(topleft,legend=c(eval(substitute( expression(mu == m1), list(m1=m1) )) , eval(substitute( expression(mu == m2), list(m2=m2) ) )), lty=1:2) And this adds subscripts to the mu's: plot(1:5,1:5,type=n);
[R] standard error associated with correlation coefficient
I want the standard error associated with a correlation. I can calculate using cor var, but am wondering if there are libraries that already provide this function. [[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] Best R text editors?
Quick informal poll: what is everyone's favorite text editor for working with R? I'd like to hear from people who are using editors that have some level of direct R interface (e.g. Tinn-R, Komodo+SciViews). Thanks! --j -- Jonathan A. Greenberg, PhD Postdoctoral Scholar Center for Spatial Technologies and Remote Sensing (CSTARS) University of California, Davis One Shields Avenue The Barn, Room 250N Davis, CA 95616 Cell: 415-794-5043 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] teaching R
And if your students are used to work with Excel (on Windows) and will have data in Excel, consider RExcel (more info at rcom.univie.ac.at) which among other things gives you the R Commander menu as an Excel menu. Disclaimer: I am the author of RExcel. David L Carlson wrote: I'd suggest looking at Rcmdr by John Fox (http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/). I use it to introduce anthropology students to R for statistical analyses. It is a graphical user interface that lets students quickly begin using R to run statistical analyses. It includes a command window so you can access functions that are not included in the menu structure. Think of it as training wheels (and more) for beginners. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 [[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. -- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ignore an error and go back to ....
Dear R users, is there way to ignore an error and go back to 1st line? I mean, #--- while (or repeat) { 1 2 . . . 6 } #- For example, if I have an error in the 6th line, then I'd like to go back to the 1st line. I've already tried try, but it didn't work. Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context: http://www.nabble.com/ignore-an-error-and-go-back-to--tp25179265p25179265.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] select one function from two of them
Hi all, I have two functions called test1() and test2(). Now how do I select one of them in test3()?? Say test3-function(func=test1){ if (func==test1){ now.func-test1() } else now.func-test2() } I know this function I wrote does not right. Do anyone can tell me how to do that for real? Thanks a million S.H. -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University [[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] select one function from two of them in another function
Hi all, I have two functions called test1() and test2(). Now how do I select one of them in test3()?? Say test3-function(func=test1){ if (func==test1){ now.func-test1() } else now.func-test2() } I know this function I wrote does not right. Do anyone can tell me how to do that for real? Thanks a million S.H. -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University [[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] teaching R
Along this same note, are there any editors that have good code completion (intellisense) capabilities for R? I'll be teaching R to undergraduates this semester and I imagine having code completion would be helpful. Andreas Stefik, Ph.D. Department of Computer Science Southern Illinois University Edwardsville On Thu, Aug 27, 2009 at 2:51 PM, Erich Neuwirth erich.neuwi...@univie.ac.at wrote: And if your students are used to work with Excel (on Windows) and will have data in Excel, consider RExcel (more info at rcom.univie.ac.at) which among other things gives you the R Commander menu as an Excel menu. Disclaimer: I am the author of RExcel. David L Carlson wrote: I'd suggest looking at Rcmdr by John Fox (http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/). I use it to introduce anthropology students to R for statistical analyses. It is a graphical user interface that lets students quickly begin using R to run statistical analyses. It includes a command window so you can access functions that are not included in the menu structure. Think of it as training wheels (and more) for beginners. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 [[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. -- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] select one function from two of them
Try this: test1 - function()cat(Call: Test 1, \n) test2 - function()cat(Call: Test 2, \n) test3 - function(FUN) match.fun(FUN) test3(test1) On Thu, Aug 27, 2009 at 5:39 PM, SH.Chou cls3...@gmail.com wrote: Hi all, I have two functions called test1() and test2(). Now how do I select one of them in test3()?? Say test3-function(func=test1){ if (func==test1){ now.func-test1() } else now.func-test2() } I know this function I wrote does not right. Do anyone can tell me how to do that for real? Thanks a million S.H. -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University [[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. -- 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] teaching R
On 8/27/09, Andreas Stefik stef...@gmail.com wrote: Along this same note, are there any editors that have good code completion (intellisense) capabilities for R? I'll be teaching R to undergraduates this semester and I imagine having code completion would be helpful. Personally I find JGR a comfortable console/editor combination, and it also offers code suggestions pop-ups. When it is released and matures, orchestra [1] will be offering advanced code completion. Liviu [1] http://r-forge.r-project.org/projects/orchestra/ (see the useR slides) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] setting par(srt) according to plot aspect ratio
How can I look up the aspect ratio of a plot, so I can use that to correctly adjust the angle of text which is supposed to be parallel to a line in the plot? The following example code works for a 1:1 aspect ratio, but puts the text at the wrong angle if the plot region is short and wide or tall and narrow. I can't find a par() component containing the plot aspect ratio. It will be for png() or postscript() output, if that matters. f - function(x) x g - function(x) 2*x (f_angle - atan(1)*180/pi) (g_angle - atan(2)*180/pi) xpos - 0.2 plot(f) plot(g,add=TRUE) par(srt=f_angle) text(xpos,f(xpos),label=y=x,pos=3) par(srt=g_angle) text(xpos,g(xpos),label=y=2x,pos=3) -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[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] teaching R
Am Donnerstag, den 27.08.2009, 15:40 -0500 schrieb Andreas Stefik: Along this same note, are there any editors that have good code completion (intellisense) capabilities for R? I'll be teaching R to undergraduates this semester and I imagine having code completion would be helpful. JGR[1] is quite good at code completion and shows function signatures as a tooltip. (At least in the Console, I’m not sure this still works in the editor component.) But I’m also quite pleased with R’s readline support, so a plain terminal window gives you quite good code completion. :-) Cheers, Frederik [1] http://jgr.markushelbig.org/JGR.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] select one function from two of them in another function
Is this what you want -- this returns a function that you can then call: test1 - function() 1 test2 - function() 2 test3 - function(func='test1'){ # return the function to call + if (func == 'test1') return(test1) + return(test2) + } # test it test3()() # default -- notice the second set of parens [1] 1 test3('test1')() [1] 1 test3('test2')() [1] 2 On Thu, Aug 27, 2009 at 4:41 PM, SH.Choucls3...@gmail.com wrote: Hi all, I have two functions called test1() and test2(). Now how do I select one of them in test3()?? Say test3-function(func=test1){ if (func==test1){ now.func-test1() } else now.func-test2() } I know this function I wrote does not right. Do anyone can tell me how to do that for real? Thanks a million S.H. -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University [[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] ignore an error and go back to ....
Give us the example where 'try' did not work. Something like this should work while(){ 1 2 try.err - try(...code that might error) if (try.err, 'try-error') next 3 } On Thu, Aug 27, 2009 at 4:21 PM, kathiekathryn.lord2...@gmail.com wrote: Dear R users, is there way to ignore an error and go back to 1st line? I mean, #--- while (or repeat) { 1 2 . . . 6 } #- For example, if I have an error in the 6th line, then I'd like to go back to the 1st line. I've already tried try, but it didn't work. Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context: http://www.nabble.com/ignore-an-error-and-go-back-to--tp25179265p25179265.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.
[R] Data set variables meaning
Hi all, Does anybody know the meaning of the values 0 - 1, for each variable from data sex2 avaible from the package logistf? Thanks in advance. Best, Caio [[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] select one function from two of them in another function
While correct, the solution below is unnecessarily complicated. Functions can be passed around and used as arguments just like any other objects. Hence (using Jim's example): test3 - function(func)func test3(test1)() [1] 1 test3(test2)() [1] 2 Of course. arguments can be entered in the parentheses as usual: test3(function(x)x^2) (5) [1] 25 Bert Gunter Genentech Nonclinical Biostatisics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jim holtman Sent: Thursday, August 27, 2009 1:58 PM To: SH.Chou Cc: r-help@r-project.org Subject: Re: [R] select one function from two of them in another function Is this what you want -- this returns a function that you can then call: test1 - function() 1 test2 - function() 2 test3 - function(func='test1'){ # return the function to call + if (func == 'test1') return(test1) + return(test2) + } # test it test3()() # default -- notice the second set of parens [1] 1 test3('test1')() [1] 1 test3('test2')() [1] 2 On Thu, Aug 27, 2009 at 4:41 PM, SH.Choucls3...@gmail.com wrote: Hi all, I have two functions called test1() and test2(). Now how do I select one of them in test3()?? Say test3-function(func=test1){ if (func==test1){ now.func-test1() } else now.func-test2() } I know this function I wrote does not right. Do anyone can tell me how to do that for real? Thanks a million S.H. -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University -- = Shih-Hsiung, Chou Department of Industrial Manufacturing and Systems Engineering Kansas State University [[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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] setting par(srt) according to plot aspect ratio
I frequently use R's help facilities and I know about the asp argument to plot, but this doesn't answer my question. I would like to allow the aspect to be determined automatically but *query* the aspect ratio for future use. I suppose one work-around would be to use the data ranges and plot region dimensions to estimate an appropriate value for asp, but this more complicated than I was hoping for. Thanks, Levi On Thu, Aug 27, 2009 at 6:19 PM, Bert Gunter gunter.ber...@gene.com wrote: Use R's help facilities, please. help.search(aspect ratio) gets you to ?plot.window which then gets you to ?plot (actually plot.default() ) Bert Gunter Genentech Nonclinical Biostatisics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Levi Waldron Sent: Thursday, August 27, 2009 1:54 PM To: r-help@r-project.org Subject: [R] setting par(srt) according to plot aspect ratio How can I look up the aspect ratio of a plot, so I can use that to correctly adjust the angle of text which is supposed to be parallel to a line in the plot? The following example code works for a 1:1 aspect ratio, but puts the text at the wrong angle if the plot region is short and wide or tall and narrow. I can't find a par() component containing the plot aspect ratio. It will be for png() or postscript() output, if that matters. f - function(x) x g - function(x) 2*x (f_angle - atan(1)*180/pi) (g_angle - atan(2)*180/pi) xpos - 0.2 plot(f) plot(g,add=TRUE) par(srt=f_angle) text(xpos,f(xpos),label=y=x,pos=3) par(srt=g_angle) text(xpos,g(xpos),label=y=2x,pos=3) -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[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. -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[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] Help on efficiency/vectorization
Many thanks to all for resolving my issue! On Thu, Aug 27, 2009 at 10:33 PM, Martin Maechler maech...@stat.math.ethz.ch wrote: MO == Moshe Olshansky m_olshan...@yahoo.com on Wed, 26 Aug 2009 23:36:22 -0700 (PDT) writes: MO You can do MO for (i in 1:ncol(x)) {names - rownames(x)[which(x[,i]==1)];eval(parse(text=paste(V,i,.ind-names,sep=)));} you can, but after install.packages(fortunes) require(fortunes) fortune(parse) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) So please use one of the other answers given in the thread... MO --- On Thu, 27/8/09, Steven Kang stochastick...@gmail.com wrote: From: Steven Kang stochastick...@gmail.com Subject: [R] Help on efficiency/vectorization To: r-help@r-project.org Received: Thursday, 27 August, 2009, 4:13 PM Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can get quite messy if there are hundreds of columns. Arbitrary data set and codes are shown below for your reference: x - as.data.frame(matrix(round(runif(50),0),nrow=5)) rownames(x) - letters[1:dim(x)[1]] x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 1 1 1 0 0 0 0 10 b 1 1 1 1 0 1 0 0 11 c 0 1 1 0 0 0 0 0 01 d 1 0 0 1 1 1 1 1 00 e 1 0 0 0 0 1 1 0 10 V1.ind - rownames(x)[x[,V1]==1] V2.ind - rownames(x)[x[,V2]==1] V3.ind - rownames(x)[x[,V3]==1] V4.ind - rownames(x)[x[,V4]==1] : : V10.ind - rownames(x)[x[,V10]==1] V1.ind [1] b d e V2.ind [1] a b c V3.ind [1] a b c : : V10.ind [1] b c Your expertise in resolving this issue would be highly appreciated. Steve [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. MO __ MO R-help@r-project.org mailing list MO https://stat.ethz.ch/mailman/listinfo/r-help MO PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html MO and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Transform data for repeated measures
I have a dataset that I'm trying to rearrange for a repeated measures analysis: It looks like: patient basefev1 fev11h fev12h fev13h fev14h fev15h fev16h fev17h fev18h drug 201 2.46 2.68 2.76 2.50 2.30 2.14 2.40 2.33 2.20a 202 3.50 3.95 3.65 2.93 2.53 3.04 3.37 3.14 2.62a 203 1.96 2.28 2.34 2.29 2.43 2.06 2.18 2.28 2.29a 204 3.44 4.08 3.87 3.79 3.30 3.80 3.24 2.98 2.91a And I want to make it look like: Patient FEV time drug 201 2.460 a 201 2.681 a 201 2.762 a 201 2.503 a And so on . . . . . There would be 9 time and drug is a factor variable. I know there is a way to do this in R but I cannot remember the function. I've looked at the transpose function in (base) but that doesn't seem to be what I want. Can something like this be done easily from within package functions or would it require writing something custom? Another program would use something like the transpose procedure, but I'm trying to stay away from that program. Thanks, Patrick R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] grDevices datasets tcltk splines graphics stats utils methods base other attached packages: [1] svSocket_0.9-43 svMisc_0.9.48 TinnR_1.0.3 R2HTML_1.59-1 Hmisc_3.6-1 survival_2.35-4 loaded via a namespace (and not attached): [1] cluster_1.12.0 grid_2.9.2 lattice_0.17-25 tools_2.9.2 This email message, including any attachments, is for th...{{dropped:6}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Transform data for repeated measures
?reshape On 28/08/2009, at 11:37 AM, Richardson, Patrick wrote: I have a dataset that I'm trying to rearrange for a repeated measures analysis: It looks like: patient basefev1 fev11h fev12h fev13h fev14h fev15h fev16h fev17h fev18h drug 201 2.46 2.68 2.76 2.50 2.30 2.14 2.40 2.33 2.20a 202 3.50 3.95 3.65 2.93 2.53 3.04 3.37 3.14 2.62a 203 1.96 2.28 2.34 2.29 2.43 2.06 2.18 2.28 2.29a 204 3.44 4.08 3.87 3.79 3.30 3.80 3.24 2.98 2.91a And I want to make it look like: Patient FEV time drug 201 2.460 a 201 2.681 a 201 2.762 a 201 2.503 a And so on . . . . . There would be 9 time and drug is a factor variable. I know there is a way to do this in R but I cannot remember the function. I've looked at the transpose function in (base) but that doesn't seem to be what I want. Can something like this be done easily from within package functions or would it require writing something custom? Another program would use something like the transpose procedure, but I'm trying to stay away from that program. Thanks, Patrick ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Transform data for repeated measures
I suspect reshape() is the function you're looking for; there is also a reshape package that you might prefer. It's also quite easy to do this in base R using unlist() and some indexing with rep, but that may be more than you care to deal with. Bert Gunter Genentech Nonclinical Biostatisics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Richardson, Patrick Sent: Thursday, August 27, 2009 4:37 PM To: r help Subject: [R] Transform data for repeated measures I have a dataset that I'm trying to rearrange for a repeated measures analysis: It looks like: patient basefev1 fev11h fev12h fev13h fev14h fev15h fev16h fev17h fev18h drug 201 2.46 2.68 2.76 2.50 2.30 2.14 2.40 2.33 2.20a 202 3.50 3.95 3.65 2.93 2.53 3.04 3.37 3.14 2.62a 203 1.96 2.28 2.34 2.29 2.43 2.06 2.18 2.28 2.29a 204 3.44 4.08 3.87 3.79 3.30 3.80 3.24 2.98 2.91a And I want to make it look like: Patient FEV time drug 201 2.460 a 201 2.681 a 201 2.762 a 201 2.503 a And so on . . . . . There would be 9 time and drug is a factor variable. I know there is a way to do this in R but I cannot remember the function. I've looked at the transpose function in (base) but that doesn't seem to be what I want. Can something like this be done easily from within package functions or would it require writing something custom? Another program would use something like the transpose procedure, but I'm trying to stay away from that program. Thanks, Patrick R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] grDevices datasets tcltk splines graphics stats utils methods base other attached packages: [1] svSocket_0.9-43 svMisc_0.9.48 TinnR_1.0.3 R2HTML_1.59-1 Hmisc_3.6-1 survival_2.35-4 loaded via a namespace (and not attached): [1] cluster_1.12.0 grid_2.9.2 lattice_0.17-25 tools_2.9.2 This email message, including any attachments, is for th...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problems with strsplit using a split of ' \\\ ' : a regex problem
I have a vector of gene symbols, some of which have multiple aliases. In the case of an alias, they are separated by ' \\\ '. Here is a real world example, which would represent one element of my vector: Eif4g2 /// Eif4g2-ps1 /// LOC678831 What I would like to do is input the vector into a function and output a vector with just the first alias of each element (or, if there are no aliases, just the one symbol). So I wrote a simple little function to do this: get.first.id.func - function(vec, splitter){ vec.lst - strsplit(vec, splitter) first.func - function(vec1){vec1[1]} vec.out - sapply(vec.lst, first.func) vec.out } For a trivial example, this works: a - c(a_b, c_d) get.first.id.func(a, _) [1] a c I am running into problems, however, with the real world split of ' \\\ ' I'm not even able to construct a sample vector of my own! Here is what I get: a - c('a \\\ b', 'a \\\ b') a [1] a \\ b a \\ b a - c('a b', 'a b') a [1] a b a b I KNOW this is related to R's peculiarities with \ escapes, but I don't have the expertise to know how to get around it. I would be very interested to learn: 1. how to construct a vector such that a == c('a \\\ b', 'a \\\ b') 2. how to properly input my split into my function so that I get the split desired. Thanks regex experts! Mark Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** [[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] problems with strsplit using a split of ' \\\ ' : a regex problem
You need a escape before each backslash: a - c('a \\ b', 'a \\ b') cat(a, \n) You can write in this form: strsplit(a, .*\\.* ) On Thu, Aug 27, 2009 at 10:03 PM, Mark Kimpel mwkim...@gmail.com wrote: I have a vector of gene symbols, some of which have multiple aliases. In the case of an alias, they are separated by ' \\\ '. Here is a real world example, which would represent one element of my vector: Eif4g2 /// Eif4g2-ps1 /// LOC678831 What I would like to do is input the vector into a function and output a vector with just the first alias of each element (or, if there are no aliases, just the one symbol). So I wrote a simple little function to do this: get.first.id.func - function(vec, splitter){ vec.lst - strsplit(vec, splitter) first.func - function(vec1){vec1[1]} vec.out - sapply(vec.lst, first.func) vec.out } For a trivial example, this works: a - c(a_b, c_d) get.first.id.func(a, _) [1] a c I am running into problems, however, with the real world split of ' \\\ ' I'm not even able to construct a sample vector of my own! Here is what I get: a - c('a \\\ b', 'a \\\ b') a [1] a \\ b a \\ b a - c('a b', 'a b') a [1] a b a b I KNOW this is related to R's peculiarities with \ escapes, but I don't have the expertise to know how to get around it. I would be very interested to learn: 1. how to construct a vector such that a == c('a \\\ b', 'a \\\ b') 2. how to properly input my split into my function so that I get the split desired. Thanks regex experts! Mark Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** [[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. -- 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] setting par(srt) according to plot aspect ratio
For posterity's sake, here is the solution I figured out. Putting the following lines after the plot(f) command seems to set the angle correctly: myasp - (par(fin)[2]-par(mai)[1]-par(mai)[3])/(par(fin)[1]-par(mai)[2]-par(mai)[4]) (f_angle - atan(myasp)*180/pi) (g_angle - atan(2*myasp)*180/pi) -- Levi Waldron post-doctoral fellow Jurisica Lab, Ontario Cancer Institute Division of Signaling Biology TMDT 9-304D 101 College Street Toronto, Ontario M5G 1L7 (416)581-7453 [[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] problems with strsplit using a split of ' \\\ ' : a regex problem
Thanks Henrique. I had actually tried using 6 back-slashes but didn't know to use 'cat' to see the non-escaped representation (see below to see my original confusion). Your strsplit, of course, works great. Thanks again! a [1] a \\ b a \\ b cat(a) a \\\ b a \\\ b Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** On Thu, Aug 27, 2009 at 9:15 PM, Henrique Dallazuanna www...@gmail.comwrote: You need a escape before each backslash: a - c('a \\ b', 'a \\ b') cat(a, \n) You can write in this form: strsplit(a, .*\\.* ) On Thu, Aug 27, 2009 at 10:03 PM, Mark Kimpel mwkim...@gmail.com wrote: I have a vector of gene symbols, some of which have multiple aliases. In the case of an alias, they are separated by ' \\\ '. Here is a real world example, which would represent one element of my vector: Eif4g2 /// Eif4g2-ps1 /// LOC678831 What I would like to do is input the vector into a function and output a vector with just the first alias of each element (or, if there are no aliases, just the one symbol). So I wrote a simple little function to do this: get.first.id.func - function(vec, splitter){ vec.lst - strsplit(vec, splitter) first.func - function(vec1){vec1[1]} vec.out - sapply(vec.lst, first.func) vec.out } For a trivial example, this works: a - c(a_b, c_d) get.first.id.func(a, _) [1] a c I am running into problems, however, with the real world split of ' \\\ ' I'm not even able to construct a sample vector of my own! Here is what I get: a - c('a \\\ b', 'a \\\ b') a [1] a \\ b a \\ b a - c('a b', 'a b') a [1] a b a b I KNOW this is related to R's peculiarities with \ escapes, but I don't have the expertise to know how to get around it. I would be very interested to learn: 1. how to construct a vector such that a == c('a \\\ b', 'a \\\ b') 2. how to properly input my split into my function so that I get the split desired. Thanks regex experts! Mark Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail The real problem is not whether machines think but whether men do. -- B. F. Skinner ** [[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. -- 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.
[R] Spatio-Temporal Models in the ramps package
The ramps package looks very appealing. I have run the examples in the package .pdf and gone through the .pdf article at the Journal of Statistical Software, and am very impressed. Is it possible to see a spatio-temporal example in R script as well? Thanks. -- View this message in context: http://www.nabble.com/Spatio-Temporal-Models-in-the-ramps-package-tp25181149p25181149.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] Which one is the right test?
Hi, I have a population. Then I have picked one relatively small sub-sample of it using a particular criterion. The means of the whole population and that of the sample seems to differ significantly. The distributions are not normal. What is the right test? Atte Tenkanen University of Turku, Finland Department of Musicology +35823335278 http://users.utu.fi/attenka/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 column width
Hi, I generated a 3-column heatmap, however, I want to have a smaller column width and big font size of label on the right side. Thanks! sessionInfo() R version 2.9.1 (2009-06-26) i486-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base [[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] SFBA R Users Group - Fall kickoff w/ Hadley Wickham, more news, call for presenters
The San Francisco Bay Area useR Group is very excited to host Hadley Wickham on Sep 17 for our Fall kickoff meeting. Details at http://www.meetup.com/R-Users/calendar/10446894/ This year we are moving our regular meeting monthly meeting to the 2nd Tuesday of each month. Also, we hope to rotate the venue around the Bay Area. Hadley's presentation will be on the Cal Berkeley campus. Exceptions to the 2nd Tuesday rule will be made to accommodate out of town speakers, like Hadley, and special events. One such event is our 2010 kickoff meeting co-sponsored by Predictive Analytics World on Feb 16th where we expect to repeat last February's highly successful meeting. Mark your calendars! Be sure to join our meetup http://www.meetup.com/R-Users/ to keep up with the latest news. Last, but certainly not least, we are setting our 2009/2010 schedule now. If you would like to present to an enthusiast bunch of gRoupies, please contact Mike Driscoll or myself. Best, Jim Porzak Ancestry.com San Francisco, CA www.linkedin.com/in/jimporzak use R! Group SF: www.meetup.com/R-Users/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem plotting with ggplot2
Dear R-Help subsribers, upon running into a wonderful ggplot2 package by accident, I abruptly encountered another problem. Almost every command run with ggplot2 results in some sort of error. The one below is far the most common one. Kind people from ggplot2 mailing list couldn't manage to solve the problem, so I'm re-posting it here to try my luck. I will recommend myself for any tips on how to solve this, as I would really benefit from using this package. head(cebelice) time c2 1 00:00 0 2 00:15 0 3 00:30 0 4 00:45 0 5 01:00 0 6 01:15 0 dim(cebelice) [1] 96 2 ggplot(cebelice, aes(x=time, y=c2)) + geom_histogram() Error in all.vars(as.formula(.$facets)) : could not find function as.formula This is straight from ggplot2 sample page for barplots: c - ggplot(mtcars, aes(factor(cyl))) c + geom_bar() Error in get(transform, env = ., inherits = TRUE)(., ...) : attempt to apply non-function Sincerely yours, Roman [[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.