Re: [R] Readjusting the OUTPUT csv file
Amelia wrote a few hundreds of lines This is too much reading. Please try to reduce you problem to 30 lines, and make the example self-contained (your data are not available). In 80% of the cases, the problem is self-resolved after it has been made self-contained. Dieter -- View this message in context: http://n4.nabble.com/Readjusting-the-OUTPUT-csv-file-tp1475448p1475478.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] write.zip?
spencerg wrote: I want to create a file with a name like dat.zip, being a zip file containing dat.csv. I can create dat.csv, then call system('zip -r9 dat.zip dat.csv'). Is there a better way? I can use gzfile to write a gz file, but I don't know how to give that a structure that would support unzipping to a *.csv file. Would a function in package RCompression do this? Dieter -- View this message in context: http://n4.nabble.com/write-zip-tp1475348p1475482.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] write.zip?
On Tue, 9 Feb 2010, spencerg wrote: Can one write a zip file from R? I want to create a file with a name like dat.zip, being a zip file containing dat.csv. I can create dat.csv, then call system('zip -r9 dat.zip dat.csv'). Is there a better way? Not really. One could use compiled code like that in unzip() to do this, but as nothing inside R is involved the only gain would be to not need to have the zip executable present. Omegahat package Rcompression does have means to manipulate .zip files from compiled code with an R interface, but not AFAICS a simpler way to do what you want. I can use gzfile to write a gz file, but I don't know how to give that a structure that would support unzipping to a *.csv file. A zip file is not a gzipped file, even though gzip compression is used for parts of the contents. The header and trailer are quite different. Thanks, Spencer -- Spencer Graves, PE, PhD President and Chief Operating Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Readjusting the OUTPUT csv file
Dear Sir, I really appreciate your suggestion. I was having the probelm of expressing my problem precisely. In fact in my earlier mail, I have tried to write my probelm in my initial few paras only. The rest content is my actual R code which I have written and its working fine except for the final output which I want to have in a particular form. I had produced the said R code as I thought it may be handy for someone who may be interested. For me another option was to attach the related R code but I understand we are not supposed to send the attachments. It was a difficult for me to express my problem effectively in few lines. Please trust me that I had drafted it 2-3 times. I once again try to resend it without the related R code. I thought it may be useful to have this R code handy. But truely I sincerely apologize for the same and do appreciate the time contraints all the R helpers have. Please Forgive me. Here is my probelm restated. ### PROBLEM I have some variables say ABC, DEF, PQR, LMN and XYZ. I am choosing any three varaibles at random at a time for my analysis and name these files as input1.csv, input2.csv and input3.csv. So if I choose variables say ABC, DEF and PQR, I am passing the specifications of these variables to input1.csv, input2.csv and input3.csv respectively. This means in another case even if I choose say LMN, DEF and XYZ in this order, then my input1.csv will have details of LMN, input2.csv will have detaisl of DEF and input3.csv will have details of XYZ. Thus, I am keeping the (input) file names constant but the contents of each of these input files may change from one case to another case. As an example, my input files are as given below. input1.csv name1 value1 DEF 10 input2.csv name2 value2 LMN 8 input3.csv name3 value3 PQR 7 ## __ ## The Problem name1 = read.csv('input1.csv')$name1 value1 = read.csv('input1.csv')$value1 name2 = read.csv('input2.csv')$name2 value2 = read.csv('input2.csv')$value2 name3 = read.csv('input3.csv')$name3 value3 = read.csv('input3.csv')$value3 # (Thus if 1st variable chosen is DEF, then name1 = DEF, value1 = 10. Had I chosen some otehr variable, then name1 and value1 will have different values). Then I carry out my analysis and get the output as given below. Scenario_and_range names values Sc_1 (DEF LMN PQR) name1 10.04 Sc_1 (DEF LMN PQR) name2 8.21 Sc_1 (DEF LMN PQR) name3 7.23 Sc_2 (DEF LMN PQR) name1 9.96 Sc_2 (DEF LMN PQR) name2 8.47 Sc_2 (DEF LMN PQR) name3 7.40 . . The values appearing in the third column are the random nos. generated using the base rate 10, 8 and 7 respectively. My probelm is I know name1 pertains to DEF, name2 pertains to LMN and name3 pertains to PQR. But in the output I am not able to replace name1 with DEF, name2 with LMN and so on i.e. I cannot hardcode the varaible names in data.frame as name1 = DEF, name2 = LMN etc as these names are going to change frome case to case. My objective is to get the names (in column 2 of above table) same as respective names (appearing in 1st column) in its order i.e. instead of name1, I should get DEF, in place of name2, I should get LMN and in place of name3, I should get PQR. Hence, my output should be like - Scenario_and_range names values Sc_1 (DEF LMN PQR) DEF 10.04 Sc_1 (DEF LMN PQR) LMN 8.21 Sc_1 (DEF LMN PQR) PQR 7.23 Sc_2 (DEF LMN PQR) DEF 9.96 Sc_2 (DEF LMN PQR) LMN 8.47 Sc_2 (DEF LMN PQR) PQR 7.40 . . Regards Amelia ##_ --- On Wed, 2/10/10, Dieter Menne dieter.me...@menne-biomed.de wrote: From: Dieter Menne dieter.me...@menne-biomed.de Subject: Re: [R] Readjusting the OUTPUT csv file To: r-help@r-project.org Date: Wednesday, February 10, 2010, 8:02 AM Amelia wrote a few hundreds of lines This is too much reading. Please try to reduce you problem to 30 lines, and make the example self-contained (your data are not available). In 80% of the cases, the problem is self-resolved after it has been made self-contained. Dieter -- View this message in context: http://n4.nabble.com/Readjusting-the-OUTPUT-csv-file-tp1475448p1475478.html Sent from the R help mailing list archive at Nabble.com.
[R] R2HTML
I am having difficulties with R2HTML. If I try to generate a HTML file with the below code, the titles, horizontal line, and scatter plot are there, but the data summary [summary(iris)] is not. --- library(R2HTML) HTMLStart(file=myreport, extension=html, echo=FALSE, HTMLframe=TRUE) HTML.title(Data Description, HR=3) summary(iris) HTMLhr() HTML.title(Scatter Plot, HR=3) plot(iris$Sepal.Length~iris$Sepal.Width) HTMLplot() HTMLStop() --- How do I add summary data to a HTML file? Thanks for any help you can provide Regina Schinner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help Please!
On Wed, Feb 10, 2010 at 2:47 AM, Nick Manginelli theman...@yahoo.com wrote: So I have to use this table of min, max, and mean temps for certain years http://www.stat.berkeley.edu/classes/s133/data/january.tab. I am supposed to figure out which year had the hottest January and which had the coldest. But I dont know how to! Nick Manginelli For starters I'd suggest pruning the data with grep, then you can pretty much eyeball the result. [m...@localhost lab1]$ grep 1$ january.txt 45.550.67 62.120051 50.755.02 59.520061 43.953.23 65.720071 42.252.16 64.720081 46.651.93 59.920091 53 57.75 63.420101 Although you have to decide if you want to use the min, max, or mean temp to rank the years. If you use min for coldest its 2008, using mean it would be 2009. Also, if you are going to play with this data with R you probably want to change the headings because it will be confusing, (to you if not to R) to have column names that match R builtin commands. Maybe use minT meanTmaxT yearday I'm sure someone else here can help you with using R. I'm just learning R myself and also just about to go to sleep. Mike __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Installation require proxy settings (2)
Hi Thanks again to Greg, and Prof Ripley. Greg, I was trying to send you an email, but has been unsuccessful. Speaking to someone from our IT deparment, I am trying to follow your advice to implement the settings to my computer (using Windows), by using Control Panel. I have selected System in Control Panel and chose System, Advanced tab, Environmental Variables, and created the user variables: http_proxy, with value 152.106.241.34:3128 http_proxy_user, with value user:pass (replacing these with my own username and password to connect to the internet via Internet Explorer. I have deleted R, rebooted the computer, and installed R again (NOT choosing Internet2). Then after opening Rgui.exe, I go to the Packages menu in the R console, and select Set CRAN mirror. I choose one, but the R comes back with the following: R chooseCRANmirror() Error in m[, 1L] : incorrect number of dimensions Could you possibly think of a fix for this problem? (Maybe I should try setting System variables?) Thanks Jacob Jacob L van Wyk Department of Statistics University of Johannesburg (APK) PO Box 524, Auckland Park, 2006 Office ph: 011 559 3080 Fax: 011 559 2499 This email and all contents are subject to the following disclaimer: http://www.uj.ac.za/UJ_email_legal_disclaimer.htm [[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] Resampling a grid to coarsen its resolution
That sounds like a sensible way of dealing with the - values... ...but doesn't solve the more important question of how to perform the resampling. Are there are functions in R which have been designed to achieve this? Or is there a standard way of going about this? Many thanks for any advice, Steve _ Send us your Hotmail stories and be featured in our newsletter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help Please!
Please don't reply to this request. This is a student in one of my classes. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 9 Feb 2010, Nick Manginelli wrote: So I have to use this table of min, max, and mean temps for certain years?http://www.stat.berkeley.edu/classes/s133/data/january.tab. I am supposed to figure out which year had the hottest January and which had the coldest. But I dont know how to! Nick Manginelli [[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] Readjusting the OUTPUT csv file
On 02/10/2010 06:02 PM, Amelia Livington wrote: Dear R helpers I have some variables say ABC, DEF, PQR, LMN and XYZ. I am choosing any three varaibles at random at a time for my analysis and name these files as input1.csv, input2.csv and input3.csv. So if I choose variables say ABC, DEF and PQR, I am passing the specifications of these variables to input1.csv, input2.csv and input3.csv respectively. This means in another case even if I choose say LMN, DEF and XYZ in this order, then my input1.csv will have details of LMN, input2.csv will have detaisl of DEF and input3.csv will have details of XYZ. Thus, I am keeping the (input) file names constant but the contents of each of these input files may change from one case to another case. As an example, my input files are as given below. Hi Amelia, I think you have just won the Posting Guide Medal of Honor for a message containing such a detailed description of the problem. I also think that what you need is: names(name1)[1] where you want the name of the variable in the file input1.csv that is read into the object named name1. If this sounds confusing, read in the file as in your excellent example and then execute the above command. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re-execute previous command
Anita and Greg, Thank you for the useful information. -- View this message in context: http://n4.nabble.com/Re-execute-previous-command-tp1474629p1475397.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] Converting pdb to pqr
There are websites using python to convert a pdb to a pqr. I was wondering if there is a simpler way to do it. We have a protein in pdb format, and want to convert that to a pqr file so that the program apbs can open it. We want to accomplish this conversion in R. Thank you for your help. -- View this message in context: http://n4.nabble.com/Converting-pdb-to-pqr-tp1475426p1475426.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] Using R to format a file using a server (PDB to PQR file)
I am trying to write a program that uses R and takes a pdb file, and converts it to a pqr file. This task is simple generally, using the website, http://pdb2pqr-1.wustl.edu/pdb2pqr/. How do you use R to input a pdb file (that is on hand) into the upload pdb file input, and run the website and give the return file to be a pqr file. Thanks for your help. -- View this message in context: http://n4.nabble.com/Using-R-to-format-a-file-using-a-server-PDB-to-PQR-file-tp1475434p1475434.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] RODBC Update image file into a MS-SQL database table
Hi, I am creating some graphs which I want to update into a database table. The procedure I am following is: 1. create the graphs as a png/jpeg file. 2. Read that file as a binary vector 3. sqlUpdate My code: pngfile - file(filename, rb) N - 1e6 repeat{ pngfilecontents - readBin(pngfile, what=raw, n=N) if(length(pngfilecontents) == N) N - 5 * N else break } close(pngfile) #There is a table df_DemandPatternMaster in the database with primary key DemandPatternID, with appropriate record in place with NULL value in pngFile field. update.query - update df_DemandPatternMaster set update.query - paste( update.query, pngFile = ', serialize(pngfilecontents, NULL) , ' where DemandPatternID = , , sep=) d - sqlQuery(connection, update.query) I end up inserting only a byte of data. The reason it seems is that paste sees the serialized vector and creates a vector with the prefix suffix text. I have also tried passing the pngfile handle directly pngfile - file(filename, rb) update.query - paste( update.query, pngFile = ', pngfile, ' where DemandPatternID = , , sep=) This also fails. Please advise. Regards Baan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R2HTML
Hi, Perhaps you could do HTML(summary(iris)) ? Bart -- View this message in context: http://n4.nabble.com/R2HTML-tp1475505p1475547.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] How to repeat the names?
Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1 city_name2 New York City Buffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ... ... ... ... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ... If I try rep((city1,city2), 5) Error: unexpected ',' in rep((city1, Please guide Regards MAdhavi Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to repeat the names?
Hi, Take a look at rep(), specifically the each = parameter. cheers, Paul Madhavi Bhave wrote: Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1city_name2 New York CityBuffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ... ... ... ... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ... If I try rep((city1,city2), 5) Error: unexpected ',' in rep((city1, Please guide Regards MAdhavi Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ [[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. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replace a for loop
Hi everybody! I'm still quite new in R and I don't really understand this whole vectorization thing. For now, I use a for loop (and it works fine), but I think it would be useful to replace it. I want to export the result of a test statistic, which is stored as a list, into a csv file. I therefore have to export each element of the list separately. Here is the code: str(test) List of 3 $ output : num [1:15, 1:6] 1 2 3 4 5 6 7 8 9 10 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr [1:6] con.num psihat p.value p.crit ... $ con: num [1:6, 1:15] 1 -1 0 0 0 0 1 0 -1 0 ... $ num.sig: int 0 for (i in 1:3){ write.csv(test[[i]], file=filename.csv, append=T, quote=F, row.names=T) } As I said, I don't completely understand, but I think one of these apply function might do what I need. Thanks in advance Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to repeat the names?
Hi! I'm kind of a newboe here, but I think it is because read.csv transforms the character variables to factors. Maybe try setting the argument as.is in read.csv(). Or try: rep(as.character(c(city1, city2)),5) That should work. HTH Ivan Le 2/10/2010 10:44, Madhavi Bhave a écrit : Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1city_name2 New York CityBuffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ... ... ... ... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ... If I try rep((city1,city2), 5) Error: unexpected ',' in rep((city1, Please guide Regards MAdhavi Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ [[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] How to repeat the names?
Hello, That's not the problem here. The variables are read as factors. You can use the stringAsFactors argument of read.csv to turn this off: read.csv( 'city.csv', stringsAsFactors = FALSE ) and then you can proceed as you did. Romain On 02/10/2010 10:44 AM, Paul Hiemstra wrote: Hi, Take a look at rep(), specifically the each = parameter. cheers, Paul Madhavi Bhave wrote: Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1 city_name2 New York City Buffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ... ... ... ... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ... If I try rep((city1,city2), 5) Error: unexpected ',' in rep((city1, Please guide Regards MAdhavi -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/NrTG : Rcpp 0.7.5 |- http://tr.im/MPYc : RProtoBuf: protocol buffers for R `- http://tr.im/KfKn : Rcpp 0.7.2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replace a for loop
On Wed, Feb 10, 2010 at 9:50 AM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: I'm still quite new in R and I don't really understand this whole vectorization thing. See [1] for an article on vectorisation and loops in R. Liviu [1] http://www.r-project.org/doc/Rnews/Rnews_2008-1.pdf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using R to format a file using a server (PDB to PQR file)
On Wed, Feb 10, 2010 at 6:16 AM, Amitoj S. Chopra amit...@gmail.com wrote: I am trying to write a program that uses R and takes a pdb file, and converts it to a pqr file. This task is simple generally, using the website, http://pdb2pqr-1.wustl.edu/pdb2pqr/. How do you use R to input a pdb file (that is on hand) into the upload pdb file input, and run the website and give the return file to be a pqr file. Thanks for your help. You can use RCurl to upload a file to an HTML form POST URL using postForm (and see also fileUpload). Then you need to poll the returned URL to see when the conversion is finished, so sleep for 30 seconds or so, and use getURL until the returned HTML looks like the completion page. Then find the link to the output file and use getURL to download it. RCurl is on CRAN, and docs are here - lots of examples: http://www.omegahat.org/RCurl/ Warning: this post contains small parts. Some assembly required. Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 looping in R
vikrant wrote: my-function(servername,dbname,dbtable){ ... final_set - NULL for(b_val in unique_b_vals) { temp1 = subset(init_data,init_data[,3] == b_val,) temp1 = temp1[sample(dim(temp1)[1], 200),] if (is.null(final_set)) { final_set - temp1 } else final_set - rbind(final_set,temp1) } } When I am doing this directly from the command line and not through this function the for loop runs well and gives me the sample data. But when I try to put this in a function the loop is failing and does not contain any data.I debugged the code init_data contains data but final_set does not contain any data. Remove all -, these are harmful for your health and should be used by trained neurosurgeons only. Add final_set (think of return(final_set)) as the last line of your function, and use the function return in your calling part. As an aside: Avoid select *, use select (primary key) where ... is not null instead, and do the sampling on the primary keys. Dieter -- View this message in context: http://n4.nabble.com/Problems-with-looping-in-R-tp1475550p1475596.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] OrdFacReg
Andrew, I've never used OrdFacReg, but a glance at the documentation suggests that you may have to pass your data through prepareData() first. Suggestions: 1. run the example in the docs and see if you can understand the bits and pieces; 2. is NB an ordered factor or is it just an integer vector? use str(); 3. must NB reside in a matrix? -Peter Ehlers Andrew Kosydar wrote: Hi Dennis, Thank you for your response. No, NB is not a matrix, and I have no covariates. Here's a very small sample of the data: effectNB -0.0032001 -0.1208003 -0.0032002 -7.691 -1.4421002 -0.0009001 -0.0142003 -5.0150000 -0.0014002 -0.0080003 -2.3370002 -0.0040501 -0.1014001 -0.0021000 -0.0036002 -0.0024003 -1.1230001 -0.0006002 I am purely interested in whether an increase in NB (for ex: from 0 to 1, or 3 to 4) predicts a directional change with effect. Any advise is greatly appreciated. Many thanks, Andrew On Tue, 9 Feb 2010, Dennis Murphy wrote: Is NB a matrix? See the help page; you also have to specify which covariate(s) are ordinal. HTH, Dennis On Tue, Feb 9, 2010 at 5:53 PM, Andrew Kosydar drewd...@u.washington.edu wrote: Hello All, I have a dataset with a continuous response variable and an ordered factor predictor. I am very interested in using the package OrdFacReg to run my analysis, but I am having a difficult time deciphering the code and making it work for my dataset. Given that this is a new package, I was unable to find any posts regarding OrdFacReg or examples to use as a template. Normally, I would run the analysis as an anova with the following code: NB.aov-aov(effect~NB, data=LH.df) To give you some background, effect is a continuous variable and NB is ordered 0, 1, 2, 3, 4. I tried each of following code to no avail: ordFacReg(effect, NB) ordFacReg(effect, NB, ordering=i, type=LS) ordFacReg(effect, NB, fact, ordfact, ordering=i, type=LS, intercept) I truly appreciate any insights or suggestions on how to best structure the code in order to perform an analysis with ordFacReg. Most Respectfully, Andrew Andrew Kosydar University of Washington Department of Biology 24 Kincaid Hall, Box 351800 Seattle, WA 98195 USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Ehlers University of Calgary __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replace a for loop
After reading the R news, I've tried this code and it works: rapply(list(names(test),test), write.csv, file=filename.csv, append=T, row.names=F) However, the output is structured like this: names(test)[[1]] names(test)[[2]] etc... test[[1]] test[[2]] etc... I would like to alternate names(test) and test in the output. The desired output would be structured like this: names(test)[[1]] test[[1]] names(test)[[2]] test[[2]] etc... Can someone guide me for that step? Better solutions for the whole thing are of course welcomed! Thanks a lot Ivan Le 2/10/2010 10:50, Ivan Calandra a écrit : Hi everybody! I'm still quite new in R and I don't really understand this whole vectorization thing. For now, I use a for loop (and it works fine), but I think it would be useful to replace it. I want to export the result of a test statistic, which is stored as a list, into a csv file. I therefore have to export each element of the list separately. Here is the code: str(test) List of 3 $ output : num [1:15, 1:6] 1 2 3 4 5 6 7 8 9 10 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr [1:6] con.num psihat p.value p.crit ... $ con: num [1:6, 1:15] 1 -1 0 0 0 0 1 0 -1 0 ... $ num.sig: int 0 for (i in 1:3){ write.csv(test[[i]], file=filename.csv, append=T, quote=F, row.names=T) } As I said, I don't completely understand, but I think one of these apply function might do what I need. Thanks in advance Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to plot three graphs on one single plot?
Hello alla I have three kinds of information (x,y1),(x,y2),(x,y3) such that x and y1,y2,y3 are the vectors with the same dimention. Now I want to plot these three class af information on one plot. thank you for your help. khazaei __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 needed in fine tuning the sapply output
Hi All, Say I have a data set with the following structure: Lines - ID ref_rankR1 R2 R3 R4 R5 R6 A 6 3 NA NA7 8 2 B 7 4NA NA 9 5 10 C 3 7NA NA 8 10 8 D 4 2NA NA 4 8 1 E 2 5NA NA 4 7 7 F 8 5NA NA 7 10 9 G 5 9NA NA 8 10 2 H 1 6NA NA 7 10 10 my.data - read.table(con-textConnection(Lines), header = TRUE) close(con) I create a function to compute Spearman's rank correlation between a reference column named ref_rank and columns R1--R6, as shown below: my.func - function(x) { rc - rcorr(my.data[,c(ref_rank)], x) data.frame(Spearman = rc$r[2],Pval=rc$P[2]) } I then apply the function on the desired columns as shown below: a-data.frame(t(sapply(my.data[, 3:8], my.func))) I almost get what I intended to do, but I'm unable to export the data frame a to CSV format. For that matter, I'm not able to remove NA's using na.omit(a). Here's the log: class(a) [1] data.frame write.csv(a,file=aranks.csv,na=) Error in write.table(x, file, nrow(x), p, rnames, sep, eol, na, dec, as.integer(quote), : unimplemented type 'list' in 'EncodeElement' I'm not sure, but I'm suspecting the problem might be in the output structure of the my.func. Any helpful hints in resolving this is highly appreciated. cheers, -Girish sessionInfo() R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] splines grid stats graphics grDevices utils datasets methods [9] base other attached packages: [1] polycor_0.7-7 sfsmisc_1.0-10 mvtnorm_0.9-9 Hmisc_3.7-0 survival_2.35-7 [6] RWinEdt_1.8-2 ggplot2_0.8.5 digest_0.4.2reshape_0.8.3 plyr_0.1.9 [11] proto_0.3-8 loaded via a namespace (and not attached): [1] cluster_1.12.1 Formula_0.2-0kinship_1.1.0-23 lattice_0.17-26 MASS_7.3-4 [6] nlme_3.1-96 plm_1.2-1sandwich_2.2-5 tools_2.10.1 -- View this message in context: http://n4.nabble.com/Help-needed-in-fine-tuning-the-sapply-output-tp1475639p1475639.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] How to plot three graphs on one single plot?
?lines plot(...) lines(...) lines(...) On Wed, Feb 10, 2010 at 5:17 AM, khaz...@ceremade.dauphine.fr wrote: Hello alla I have three kinds of information (x,y1),(x,y2),(x,y3) such that x and y1,y2,y3 are the vectors with the same dimention. Now I want to plot these three class af information on one plot. thank you for your help. khazaei __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] manipulate missing dates in a graphics a vector
Thank you !! That's exactly what I need. Nilza Barros On Tue, Feb 9, 2010 at 10:50 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: # Create a sequence of consecutive dates and assign to a data frame dates - data.frame(day = seq(as.Date('2009-12-01'), by = 'days', length = 10)) # Let's call your data frame (not vector) 'df'; to make sure that things are # compatible, names(df) - c('day', 'y') df$day - as.Date(df$day) # Then, merge(dates, df, all.x =TRUE) dayy 1 2009-12-01 26.8 2 2009-12-02 NA 3 2009-12-03 27.9 4 2009-12-04 25.6 5 2009-12-05 20.8 6 2009-12-06 NA 7 2009-12-07 NA 8 2009-12-08 20.8 9 2009-12-09 NA 10 2009-12-10 NA HTH, Dennis On Tue, Feb 9, 2010 at 4:30 PM, Nilza BARROS nilzabar...@gmail.comwrote: Dear all, I am trying to identify the days absent in a vector so as to be able to display missing data in the graphics in .It should be done automatically since the graphics will be generated for different periods of the year. I have been trying to do a function below but it did not work. I really appreciate any help ordados - function(datas,var) { ind - !datas %in% var # find the missing date in var miss - datas[ind] mat - matrix(NA,length(miss),length(miss)) #insert NA in the missing date mat[,1]-miss jundado - rbind (mat,var) jundado - jundado[order(jundado[,1]),] # sort by dates } For instance: If I have the vector below: 2009-12-01 26.8 2009-12-03 27.9 2009-12-04 25.6 2009-12-05 20.8 2009-12-08 20.8 I will need a result like this one 2009-12-01 26.8 2009-12-02 NA 2009-12-03 27.9 2009-12-04 25.6 2009-12-05 20.8 2009-12-06 NA 2009-12-07 NA 2009-12-08 20.8 Bye and Best Regards Nilza Barros [[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. -- Abraço, Nilza Barros [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to repeat the names?
Dear Sirs, Thanks a lot for your guidance. It worked wonderfully. Regards Madhavi --- On Wed, 10/2/10, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: From: Ivan Calandra ivan.calan...@uni-hamburg.de Subject: Re: [R] How to repeat the names? To: r-help@r-project.org Date: Wednesday, 10 February, 2010, 1:54 AM Hi! I'm kind of a newboe here, but I think it is because read.csv transforms the character variables to factors. Maybe try setting the argument as.is in read.csv(). Or try: rep(as.character(c(city1, city2)),5) That should work. HTH Ivan Le 2/10/2010 10:44, Madhavi Bhave a écrit : Dear R helpers I have a city.csv file as given below. 'city.csv' city_name1 city_name2 New York City Buffallo So I define city_name = read.csv('city.csv') city1 = city_name$city_name1 city2 = city_name$city_name2 My problem is how do I repeat the names one after other say 10 times i.e. my output should be like New York City Buffallo New York City Buffallo New York City Buffallo New York City ... ... ... ... I have tried the following commands rep(c(city1,city2), 5) and I got the output something like this [1] 1 1 1 1 1 1 ... If I try rep((city1,city2), 5) Error: unexpected ',' in rep((city1, Please guide Regards MAdhavi Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ [[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]] -Inline Attachment Follows- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[elided Yahoo spam]] [[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] Converting pdb to pqr
On Feb 10, 2010, at 1:02 AM, Amitoj S. Chopra wrote: There are websites using python to convert a pdb to a pqr. I was wondering if there is a simpler way to do it. We have a protein in pdb format, and want to convert that to a pqr file so that the program apbs can open it. We want to accomplish this conversion in R. Thank you for your help. From context and the fact that apbs does not show up in a search, I am guessing that it is a BioC function and that you would be better off posting on the correct mailing list. -- David. -- View this message in context: http://n4.nabble.com/Converting-pdb-to-pqr-tp1475426p1475426.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. 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.
[R] WMF conversion...
Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SF RUG 2010 kickoff next Tue: John Chambers Drinks!
All Bay Area useRs: Next Tuesday, Feb 16, is our 2010 kick-off meeting with keynote speaker John Chambers: http://www.meetup.com/R-Users/calendar/11203608/ Once again we would like to thank Predictive Analytics World for providing the meeting room. Before John's talk at 7:30, REvolution Computing is hosting the 6:30 Reception to which all useRs are invited. Downtown San Francisco at the Palace Hotel. All details at the above link. 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.
Re: [R] WMF conversion...
On 10.02.2010 13:16, Jason Rupert wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Use another converter to PDF? Uwe Ligges Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] WMF conversion...
Or maybe another output image format, such as tiff or png? 2010/2/10 Uwe Ligges lig...@statistik.tu-dortmund.de On 10.02.2010 13:16, Jason Rupert wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Use another converter to PDF? Uwe Ligges Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Model matrix using dummy regressors or deviation regressors
Dear Peng Yu, If this is indeed Peng Yu (as the email address seems to imply), I believe that you have a copy of my R and S-PLUS Companion to Applied Regression, where the answer is on p. 152, which describes the contrasts argument to lm; the contrasts argument to aov is similar. Hints: (1) the argument is named 'contrasts' and not 'contrasts.args' (as it is for model.matrix, the help page for which incidentally has a clear explanation with examples); (2) the argument takes a named list of contrasts for particular factors not a vector of contrasts with two elements. John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: pengyu...@gmail.com [mailto:pengyu...@gmail.com] On Behalf Of bluesky...@gmail.com Sent: February-09-10 11:44 PM To: John Fox Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] Model matrix using dummy regressors or deviation regressors On Tue, Feb 9, 2010 at 6:09 PM, John Fox j...@mcmaster.ca wrote: Dear bluesky315, There are several ways in R to determine regressors associated with factors. One way is to set the global contrasts option. To get deviation regressors, use options(contrasts=c(contr.sum, contr.poly)), and see ?options and ?contrasts for details. Also see Section 11.1.1 of the Introduction to R manual that comes with R. Instead of change the option globally, it is cleaner to pass the contrast choice as an argument to aov(). It seems that 'contrasts.arg' of model.matrix() can be used for this purpose. I tried something like contrasts.args=c('contr.sum', 'contr.poly'). But it is not working. Would you please show me how to specify this argument for the example that I gave in the original email? I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of bluesky...@gmail.com Sent: February-09-10 6:33 PM To: r-h...@stat.math.ethz.ch Subject: [R] Model matrix using dummy regressors or deviation regressors The model matrix for the code at the end the email is shown below. Since the model matrix doesn't have -1, I think that it is made of dummy regressors rather than deviation regressors. I'm wondering how to make a model matrix using deviation regressors. Could somebody let me know? model.matrix(aaov) (Intercept) A2 B2 B3 A2:B2 A2:B3 1 1 0 0 0 0 0 2 1 0 0 0 0 0 3 1 0 0 0 0 0 4 1 0 0 0 0 0 5 1 1 0 0 0 0 6 1 1 0 0 0 0 7 1 1 0 0 0 0 8 1 1 0 0 0 0 9 1 0 1 0 0 0 10 1 0 1 0 0 0 11 1 0 1 0 0 0 12 1 0 1 0 0 0 13 1 1 1 0 1 0 14 1 1 1 0 1 0 15 1 1 1 0 1 0 16 1 1 1 0 1 0 17 1 0 0 1 0 0 18 1 0 0 1 0 0 19 1 0 0 1 0 0 20 1 0 0 1 0 0 21 1 1 0 1 0 1 22 1 1 0 1 0 1 23 1 1 0 1 0 1 24 1 1 0 1 0 1 attr(,assign) [1] 0 1 2 2 3 3 attr(,contrasts) attr(,contrasts)$A [1] contr.treatment attr(,contrasts)$B [1] contr.treatment # a=2 b=3 n=4 A = rep(sapply(1:a,function(x){rep(x,n)}),b) B = as.vector(sapply(sapply(1:b, function(x){rep(x,n)}), function(x){rep(x,a)})) Y = A + B + rnorm(a*b*n) fr = data.frame(Y=Y,A=as.factor(A),B=as.factor(B)) aaov=aov(Y ~ A * B,fr) summary(aaov) model.matrix(aaov) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] WMF conversion...
Check if your conversion utility lets you specify the resolution of the output and increase it. On Wed, Feb 10, 2010 at 7:16 AM, Jason Rupert jasonkrup...@yahoo.com wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Create a function with multiple object as an output
Dear useRs, I want to make a function that return several object (from a loop). I know, I can put them in a list, then the function return the list, but is it possible that it returns several independent object. I used the assign function to create several object, it works when I use it outside the function, but not inside. Any suggestion ? Here is a piece of code that do something similar to my situation. testfunc - function ( listobj, valueX) { for (i in 1:length(listobj)) { objtemp - get (listobj[i]) objtemp - objtemp * valueX assign(paste(listobj[i], _, valueX, sep=), objtemp) } return (??) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 looping in R
Dear R Experts, This is my R function. my-function(servername,dbname,dbtable){ library(RODBC) channel- odbcDriverConnect(paste(driver=SQL Server;server=,servername)) init_data- sqlQuery(channel,paste(select * from,dbname,..,dbtable)) init_data - subset(init_data,!is.null(init_data[,1]),) print(dim(init_data)) unique_b_vals = unique(init_data[,3]) print(unique_b_vals) final_set - NULL for(b_val in unique_b_vals) { temp1 = subset(init_data,init_data[,3] == b_val,) temp1 = temp1[sample(dim(temp1)[1], 200),] if (is.null(final_set)) { final_set - temp1 } else final_set - rbind(final_set,temp1) } } Here What I am doing is connecting to MS sql Server through R and extracting the data and init_data contains all my data matrix. After getting all the data in init_data I want to randomly select data of size say 200. when I am doing this directly from the command line and not through this function the for loop runs well and gives me the sample data. But when I try to put this in a function the loop is failing and does not contain any data.I debugged the code init_data contains data but final_set does not contain any data. The appending is not working when i put this in a function but the same code works fine without a function Any solution for this? Please Help -- View this message in context: http://n4.nabble.com/Problems-with-looping-in-R-tp1475550p1475550.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] Problems with looping in R
Thanks Dieter. It works. -- View this message in context: http://n4.nabble.com/Problems-with-looping-in-R-tp1475550p1475619.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] Fast way to determine number of lines in a file
Hi Hadley, Hope this is what you are looking for. This approach provides number of lines in a large 'bzip' file using chunks. testconn - file(xyzxyz.csv.bz2, open=r) csize - 1 nolines - 0 while((readnlines - length(readLines(testconn,csize))) 0 ) nolines - nolines+readnlines close(testconn) nolines Regards, Indian_R_Analyst. On Feb 8, 7:16 pm, Hadley Wickham had...@rice.edu wrote: Hi all, Is there afastwayto determine the number of lines in a file? I'm looking for something like count.lines analogous to count.fields. Hadley --http://had.co.nz/ __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help
We get an error while using the following function.Please advise. newton.method(FUN = function(b) 10/b+sum(a)-10*sum((x^b)*a)/sum(x^b), init = 5,tol = 0.001) Error in deriv.default(as.expression(body(FUN)), nms, function.arg = TRUE) : Function 'sum' is not in the derivatives table -- Kanchan Jain Professor Deptt. of Statistics Panjab University Chandigarh-160014 (India) +919872641634 +919814301634 RES: House No. 34, Sector 16, Panchkula -134113 (India) Ph: 0172-2572505, 0172-2567781 [[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] Running rscript in windows
Dear R experts, Suppose I have a small r function myfunction - function(x) { return(x*x) } and I save this function in a test.R text file. Suppose when I open a new seesion in R and I want to run this function myfunction(3) .how should i do it?? -- View this message in context: http://n4.nabble.com/Running-rscript-in-windows-tp1475671p1475671.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] Column width in dbf file ... again ...
Hello, First please excuse me for reposting the same question I sent a few weeks ago, but I did not have any answer ! I am trying to manually choose the width (i.e. number of character allowed) of columns containing text when creating dbf. files using write.dbf (library foreign). In particular, I want to define this width when the column have to contain text but is empty. In that case, by default, write.dbf give a warning message then choose the width equal to the number of character in the column title. Example: df-data.frame(INDEX=1:10, TEXT=NA_character_) write.dbf(df, paste(choose.dir(), //test.dbf,sep=)) # Give a warning message but create the dbf file. The width of the column TEXT is 4 as the number of character in the word TEXT ! Thanks for your help, P.S. : complementary info. R version 2.10.1 (2009-12-14) i386-pc-mingw32 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] WMF conversion...
It appears that Powerpoint is just getting in the way. Why not output high quality pdf or postscript graphics and use LaTeX Beamer to produce exceptionally high quality slides directly in pdf? Frank Jason Rupert wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Frank E Harrell Jr Professor and ChairmanSchool of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using R to format a file using a server (PDB to PQR file)
On 02/09/2010 10:16 PM, Amitoj S. Chopra wrote: I am trying to write a program that uses R and takes a pdb file, and converts it to a pqr file. This task is simple generally, using the website, http://pdb2pqr-1.wustl.edu/pdb2pqr/. How do you use R to input a pdb file (that is on hand) into the upload pdb file input, and run the website and give the return file to be a pqr file. Thanks for your help. Maybe bio3d::write.pqr is for you? http://mccammon.ucsd.edu/~bgrant/bio3d/index.html Martin -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to call the R hidden function lgammacor ?
Dear All, Do you happen to know how to call the R's hidden function lgammacor ? I exported this program and lgamma.c into matlab; however, I cannot obtain the same answer from the matlab version lgamma as the one from the R version lgamma. So I would love to know how to call lgammacor directly in R. Thank you so much! Rlearner [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Create a function with multiple object as an output
you can return a single object, so a list is what you want. you can always break it apart after the return. What is the problem you are trying to solve? Sent from my iPhone. On Feb 10, 2010, at 8:31, Arnaud Mosnier a.mosn...@gmail.com wrote: Dear useRs, I want to make a function that return several object (from a loop). I know, I can put them in a list, then the function return the list, but is it possible that it returns several independent object. I used the assign function to create several object, it works when I use it outside the function, but not inside. Any suggestion ? Here is a piece of code that do something similar to my situation. testfunc - function ( listobj, valueX) { for (i in 1:length(listobj)) { objtemp - get (listobj[i]) objtemp - objtemp * valueX assign(paste(listobj[i], _, valueX, sep=), objtemp) } return (??) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heplot3d / rgl : example causes R GUI to crash
[Env: Tested under Win Xp, R 2.9.2 and R 2.10.1; sessionInfo() at end] I've run into a problem with the heplot3d() function in my heplots package which causes the R GUI to crash ('R for Windows GUI encountered a problem and needs to close...'). I think the problem comes from an rgl call, but, I can't get a traceback or other information because my R session crashes. I've never seen this behavior before. The problem occurs *whenever* I try to supply linear hypotheses to be displayed along with the model terms. Here is a small example: library(heplots) # Soils data, from car package soils.mod - lm(cbind(pH,N,Dens,P,Ca,Mg,K,Na,Conduc) ~ Block + Contour*Depth, data=Soils) Anova(soils.mod) heplot(soils.mod, variables=c(Ca, Mg)) ## this works OK heplot3d(soils.mod, variables=c(Mg, Ca, Na)) ## this crashes R, but it draws most of the plot first heplot3d(soils.mod, variables = c(Mg, Ca, Na), hypotheses = ContourSlope) ## linear.hypothesis does work on this: print(linear.hypothesis(soils.mod, ContourSlope), SSP=FALSE) Multivariate Tests: Df test stat approx F num Df den Df Pr(F) Pillai 1 0.5844882 3.907418 9 25 0.003312 ** Wilks 1 0.4155118 3.907418 9 25 0.003312 ** Hotelling-Lawley 1 1.4066706 3.907418 9 25 0.003312 ** Roy 1 1.4066706 3.907418 9 25 0.003312 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 I would be grateful if someone could (a) confirm that this is a general problem, not just my system; (b) suggest how to determine what is going wrong. sessionInfo() R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rgl_0.89 heplots_0.8-11 car_1.2-16 -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R Group on LinkedIn has new book discounts
The R grouphttp://www.linkedin.com/groups?about=gid=77616trk=anet_ug_grpproon Linkedin.com has book discounts from CRC/Press as well as a new publisher to R, Manning. Manning's new book is introductory level and appears well written. Regards, Ajit -- _ Ajit Gemunu de Silva Oakland CA 94619 skype: ajit_de_silva [[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] heplot3d / rgl : example causes R GUI to crash
On 10/02/2010 9:33 AM, Michael Friendly wrote: [Env: Tested under Win Xp, R 2.9.2 and R 2.10.1; sessionInfo() at end] This is probably a bug in rgl, and I can reproduce it. Bugs in contributed packages are best sent to the maintainer of the package, because otherwise they might be lost. In this case I did see it, so no need for you to do anything more. Duncan Murdoch I've run into a problem with the heplot3d() function in my heplots package which causes the R GUI to crash ('R for Windows GUI encountered a problem and needs to close...'). I think the problem comes from an rgl call, but, I can't get a traceback or other information because my R session crashes. I've never seen this behavior before. The problem occurs *whenever* I try to supply linear hypotheses to be displayed along with the model terms. Here is a small example: library(heplots) # Soils data, from car package soils.mod - lm(cbind(pH,N,Dens,P,Ca,Mg,K,Na,Conduc) ~ Block + Contour*Depth, data=Soils) Anova(soils.mod) heplot(soils.mod, variables=c(Ca, Mg)) ## this works OK heplot3d(soils.mod, variables=c(Mg, Ca, Na)) ## this crashes R, but it draws most of the plot first heplot3d(soils.mod, variables = c(Mg, Ca, Na), hypotheses = ContourSlope) ## linear.hypothesis does work on this: print(linear.hypothesis(soils.mod, ContourSlope), SSP=FALSE) Multivariate Tests: Df test stat approx F num Df den Df Pr(F) Pillai 1 0.5844882 3.907418 9 25 0.003312 ** Wilks 1 0.4155118 3.907418 9 25 0.003312 ** Hotelling-Lawley 1 1.4066706 3.907418 9 25 0.003312 ** Roy 1 1.4066706 3.907418 9 25 0.003312 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 I would be grateful if someone could (a) confirm that this is a general problem, not just my system; (b) suggest how to determine what is going wrong. sessionInfo() R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rgl_0.89 heplots_0.8-11 car_1.2-16 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Total least squares linear regression
Dear all, After a thorough research, I still find myself unable to find a function that does linear regression of 2 vectors of data using the total least squares, also called orthogonal regression (see : http://en.wikipedia.org/wiki/Total_least_squares) instead of the ordinary least squares method. Indeed, the lm function has a method argument but the manual says that there is only one option so far. However, since the samples I am studying have the type of relationship that requires orthogonal regression, I am bound to use it. The only thing I've found so far is the tlsce function in the BCE package (see : http://cran.r-project.org/web/packages/BCE/index.html) but I'm not sure it's of general use or designed for the particular application of taxonomy, since its arguments are supposed to be matrices. If any of you knew a function that does this or had a personnal script to do this kind of regression, I'd be very grateful. Thanks a lot in advance Gnewbee __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] estimators based on Truncated likelihood
HYC == helen...@utoronto.ca on Tue, 09 Feb 2010 22:07:27 -0500 HYC Dear Sir/Madam, HYC HYC May I know if there is any function that estimates the ARCH HYC or GARCH HYC models based on truncated likelihood? HYC HYC Thanks, HYC Helen Hi Helen, TLE has been used in different areas and is well-known in the community. I am presenting work that extents the TLE with an application in GARCH modeling in Singapore next week. The working paper should be available just after the conference. Regards, Yohan -- PhD candidate Swiss Federal Institute of Technology Zurich www.ethz.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] WMF conversion...
PNG images have worked well for me we MS Office: it's a bitmap format, so you need to make sure you have enough pixels for the desired resolution at whatever size it ends up. -thomas On Wed, 10 Feb 2010, Jason Rupert wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Jason __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replace a for loop
Hi how many objects do you have in a list? Loop is ineffective if you use several nested loops and/or there is some unnecessary mimic of simple function. e.g. you can use this set.seed(666) x - runif(10) vysled - 0 for(i in 1:length(x)) { if(vysled x[i]) vysled - vysled else vysled - x[i] } vysled but I would prefer max(x) If you do not perceive performance issues there is usually no need to elaborate *apply. Regards Petr r-help-boun...@r-project.org napsal dne 10.02.2010 11:59:21: After reading the R news, I've tried this code and it works: rapply(list(names(test),test), write.csv, file=filename.csv, append=T, row.names=F) However, the output is structured like this: names(test)[[1]] names(test)[[2]] etc... test[[1]] test[[2]] etc... I would like to alternate names(test) and test in the output. The desired output would be structured like this: names(test)[[1]] test[[1]] names(test)[[2]] test[[2]] etc... Can someone guide me for that step? Better solutions for the whole thing are of course welcomed! Thanks a lot Ivan Le 2/10/2010 10:50, Ivan Calandra a écrit : Hi everybody! I'm still quite new in R and I don't really understand this whole vectorization thing. For now, I use a for loop (and it works fine), but I think it would be useful to replace it. I want to export the result of a test statistic, which is stored as a list, into a csv file. I therefore have to export each element of the list separately. Here is the code: str(test) List of 3 $ output : num [1:15, 1:6] 1 2 3 4 5 6 7 8 9 10 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr [1:6] con.num psihat p.value p.crit ... $ con: num [1:6, 1:15] 1 -1 0 0 0 0 1 0 -1 0 ... $ num.sig: int 0 for (i in 1:3){ write.csv(test[[i]], file=filename.csv, append=T, quote=F, row.names=T) } As I said, I don't completely understand, but I think one of these apply function might do what I need. Thanks in advance Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running rscript in windows
On 10.02.2010 13:09, vikrant wrote: Dear R experts, Suppose I have a small r function myfunction- function(x) { return(x*x) } and I save this function in a test.R text file. Suppose when I open a new seesion in R and I want to run this function myfunction(3) .how should i do it?? source(test.R) myfunction(3) Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] write.zip?
Thanks to Dieter Menne and Prof. Ripley for replies. For certain definitions of better (e.g., transportability?), the Rcompression package might be superior to the system call I mentioned. I also just found the tar function in the utils package, which looks like it might be more transportable than my system call. However, as Prof. Ripley noted, there may not be a simpler way than my system call, especially considering the time I would have to invest to learn how to use it. Thanks again very much, Spencer Graves Prof Brian Ripley wrote: On Tue, 9 Feb 2010, spencerg wrote: Can one write a zip file from R? I want to create a file with a name like dat.zip, being a zip file containing dat.csv. I can create dat.csv, then call system('zip -r9 dat.zip dat.csv'). Is there a better way? Not really. One could use compiled code like that in unzip() to do this, but as nothing inside R is involved the only gain would be to not need to have the zip executable present. Omegahat package Rcompression does have means to manipulate .zip files from compiled code with an R interface, but not AFAICS a simpler way to do what you want. I can use gzfile to write a gz file, but I don't know how to give that a structure that would support unzipping to a *.csv file. A zip file is not a gzipped file, even though gzip compression is used for parts of the contents. The header and trailer are quite different. Thanks, Spencer -- Spencer Graves, PE, PhD President and Chief Operating Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heplot3d / rgl : example causes R GUI to crash
On 10/02/2010 11:07 AM, Michael Friendly wrote: Duncan Murdoch wrote: On 10/02/2010 9:33 AM, Michael Friendly wrote: [Env: Tested under Win Xp, R 2.9.2 and R 2.10.1; sessionInfo() at end] This is probably a bug in rgl, and I can reproduce it. Bugs in contributed packages are best sent to the maintainer of the package, because otherwise they might be lost. In this case I did see it, so no need for you to do anything more. Duncan Murdoch Thanks, Duncan FMI, if you (or anyone) has pointers on how to debug such things, I'd like to learn. It's not easy, but the general idea is to do it in gdb, possibly with a nicer front end (I use Insight). I wrote up instructions on doing this in Windows a few years ago. I think they still work; if you try this and notice anything in my instructions that is out of date, please let me know. The instructions are on http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/, in the page Using gdb to debug C or Fortran code http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/gdb.shtml. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heplot3d / rgl : example causes R GUI to crash
Duncan Murdoch wrote: On 10/02/2010 9:33 AM, Michael Friendly wrote: [Env: Tested under Win Xp, R 2.9.2 and R 2.10.1; sessionInfo() at end] This is probably a bug in rgl, and I can reproduce it. Bugs in contributed packages are best sent to the maintainer of the package, because otherwise they might be lost. In this case I did see it, so no need for you to do anything more. Duncan Murdoch Thanks, Duncan FMI, if you (or anyone) has pointers on how to debug such things, I'd like to learn. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] WMF conversion...
On Feb 10, 2010, at 6:16 AM, Jason Rupert wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Jason As far as I know, there is no MS 'branded' PDF conversion utility. If you have something built-in, it is likely Adobe's Acrobat application, which does provide a PPT to PDF file conversion capability: http://office.microsoft.com/en-us/powerpoint/HA100649921033.aspx If that is what you have, be sure to use any options for the highest quality settings. Other available options will likely use some type of compression, which will degrade the image quality. I would look for any Adobe documentation that you may have on this, or check their web site for online information. Also, review this R FAQ and see if any of the anti-aliasing options in Acrobat Reader (presuming that is what you are viewing the PDF in) might help: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-are-there-unwanted-borders Alternatively, test Zamzar, which is an online conversion facility: http://zamzar.com/ HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replace a for loop
Well actually, in that case, I don't think it is really necessary to replace the loop because it is quite fast with the small size I have. But I thought it would help me to understand how would vectorization work and how to use the *apply functions. Thanks anyway for your piece of advice! Ivan Le 2/10/2010 17:03, Petr PIKAL a écrit : Hi how many objects do you have in a list? Loop is ineffective if you use several nested loops and/or there is some unnecessary mimic of simple function. e.g. you can use this set.seed(666) x- runif(10) vysled- 0 for(i in 1:length(x)) { if(vysled x[i]) vysled- vysled else vysled- x[i] } vysled but I would prefer max(x) If you do not perceive performance issues there is usually no need to elaborate *apply. Regards Petr r-help-boun...@r-project.org napsal dne 10.02.2010 11:59:21: After reading the R news, I've tried this code and it works: rapply(list(names(test),test), write.csv, file=filename.csv, append=T, row.names=F) However, the output is structured like this: names(test)[[1]] names(test)[[2]] etc... test[[1]] test[[2]] etc... I would like to alternate names(test) and test in the output. The desired output would be structured like this: names(test)[[1]] test[[1]] names(test)[[2]] test[[2]] etc... Can someone guide me for that step? Better solutions for the whole thing are of course welcomed! Thanks a lot Ivan Le 2/10/2010 10:50, Ivan Calandra a écrit : Hi everybody! I'm still quite new in R and I don't really understand this whole vectorization thing. For now, I use a for loop (and it works fine), but I think it would be useful to replace it. I want to export the result of a test statistic, which is stored as a list, into a csv file. I therefore have to export each element of the list separately. Here is the code: str(test) List of 3 $ output : num [1:15, 1:6] 1 2 3 4 5 6 7 8 9 10 ... ..- attr(*, dimnames)=List of 2 .. ..$ : NULL .. ..$ : chr [1:6] con.num psihat p.value p.crit ... $ con: num [1:6, 1:15] 1 -1 0 0 0 0 1 0 -1 0 ... $ num.sig: int 0 for (i in 1:3){ write.csv(test[[i]], file=filename.csv, append=T, quote=F, row.names=T) } As I said, I don't completely understand, but I think one of these apply function might do what I need. Thanks in advance Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mlogit: Error reported using sample dataset
I've been working on a multinomial logit model, trying to predict vegetation types as a function of total phosphorus. Previous responses to my postings have pointed me to the mlogit package. I'm now trying to work examples and my data using this package. data(Fishing, package = mlogit) Fish - mlogit.data(Fishing, varying = c(4:11), shape = wide, choice = mode) both of those lines work, as expected. However; summary(mlogit(mode ~ pr + ca -1, data = Fish)) Call: Error in deparse(obj...@call) : trying to get slot call from an object (class mlogit) that is not an S4 object Using my data I've done the following: xx - fwc # copies and protects original data.frame xx$VegType - as.factor(xx$VegType) xx.dat - mlogit.data(xx, varying = NULL, choice = VegType, shape = wide) xx.mlogit - mlogit(VegType ~ TP, data = xx.dat,, reflevel = 1) Error in relevel.factor(attr(mf, index)[[alt]], reflevel) : 'ref' must be an existing level Can someone explain why these errors are occuring and what to do about them? Thanks Using R 2.10.1, Windows XP Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Total least squares linear regression
Hi, The wikipedia shows the matrix algebra that calculates Total regression, you could put this into R code to solve your problem. Also take a look at the pcrcomp or svd function for singular value decmoposition implementation. This would probably not be generic, but that is not a problem for you. groet, Paul Gnewbee wrote: Dear all, After a thorough research, I still find myself unable to find a function that does linear regression of 2 vectors of data using the total least squares, also called orthogonal regression (see : http://en.wikipedia.org/wiki/Total_least_squares) instead of the ordinary least squares method. Indeed, the lm function has a method argument but the manual says that there is only one option so far. However, since the samples I am studying have the type of relationship that requires orthogonal regression, I am bound to use it. The only thing I've found so far is the tlsce function in the BCE package (see : http://cran.r-project.org/web/packages/BCE/index.html) but I'm not sure it's of general use or designed for the particular application of taxonomy, since its arguments are supposed to be matrices. If any of you knew a function that does this or had a personnal script to do this kind of regression, I'd be very grateful. Thanks a lot in advance Gnewbee __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] getting input from the console when running R in batch mode
Hello list: I am using R through Geany in Ubuntu. The way i have Geany configured is that upon invoking the exectute command, Geany does a R myscript.R myscript.out, thus getting all input from the myscript.R file and redirecting all output to the myscript.out file. This is a problem when I want to read, say a numeric value, from the keyboard, or when i'd like to output something to the console: num - scan(stdin(),what=numeric(1),lines=1) Iin this case R ignores the stdin() connection (which should be a terminal class). Is there an easy way around this problem, other than reading my data from a file or using the tcltk library? All i'd like to do is just read values from the terminal/console. Thanks in advance, jose romero [[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] Compose in roxygen - order of function application?
Hello, I wonder if anyone has used the Compose() function in the 'roxygen' package. I find its behavior a bit surprising: f - function(x) x + 1 g - function(x) x * 2 f(g(2)) [1] 5 Compose(f,g)(2) [1] 6 g(f(2)) [1] 6 Compose(g,f)(2) [1] 5 I would have expected Compose(f,g)(x) == f(g(x)) but it appears the order of application is reversed. It would be easy for me to modify with rev(): Compose - function (...) { fs - rev(list(...)) function(...) Reduce(function(x, f) f(x), fs, ...) } But does the current implementation follow another convention I am unaware of? Thanks - Stephen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] WMF conversion...
Thank you very much for your reply. I guess I may be using the wrong terminology. I have Office 2007. In PowerPoint 2007, I can navigate to Save As and then choose PDF or XPS. That option is shown in the attached image. When using that I tried both Standard and Minimum size. Both produced the diagonal lines. Also, I do not see Adobe Acrobat installed on my machine however I am investigating possibly getting that product. Thank you again for the reply. Jason - Original Message From: Marc Schwartz marc_schwa...@me.com To: Jason Rupert jasonkrup...@yahoo.com Cc: R-help@r-project.org Sent: Wed, February 10, 2010 10:30:38 AM Subject: Re: [R] WMF conversion... On Feb 10, 2010, at 6:16 AM, Jason Rupert wrote: Hello R-Help, I've got a bit of an issue with WMF's. I am working on WindowsXP and outputting WMF format images. I then take the WMF format images and insert them in PowerPoint. I take the PowerPoint and convert it to PDF. The WMFs are nothing special. Just the typical x-y plot with a gray dotted grid added and a few matlines. The WMFs, when produced look great! They show all the necessary detail. Unfortunately, after placed in the PowerPoint and the PowerPoint is converted to PDF via MS Office's built in conversion utility, the resulting image have diagonal streaks across them from the y-axis down to the x-axis. The rest of the document is perfect, but the WMF images now have streaks across them. It looks like it may be caused, somehow, by the dotted grid. I am locked into the workflow where I must place images in a PowerPoint and then convert it to PDF, so is there a different image format I should use or is there and intermediate step I need to use so that the streaks do not appear? Thanks for any feedback and insight. Jason As far as I know, there is no MS 'branded' PDF conversion utility. If you have something built-in, it is likely Adobe's Acrobat application, which does provide a PPT to PDF file conversion capability: http://office.microsoft.com/en-us/powerpoint/HA100649921033.aspx If that is what you have, be sure to use any options for the highest quality settings. Other available options will likely use some type of compression, which will degrade the image quality. I would look for any Adobe documentation that you may have on this, or check their web site for online information. Also, review this R FAQ and see if any of the anti-aliasing options in Acrobat Reader (presuming that is what you are viewing the PDF in) might help: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-are-there-unwanted-borders Alternatively, test Zamzar, which is an online conversion facility: http://zamzar.com/ HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Integral of function of dnorm
Dear all, How is it possible in R to calculate the following integral: Integral(-Inf, Inf)[log(dnorm(mean = 3, sd = 1))] how can I define that the density dnorm is taken on (-Inf, Inf) Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to solve: Error in * unused argument(s) ?
Hi all, For some reason, I would like to use functions bellow (see example code bellow), but instead I get the following error message: *Error in foo2(...) : unused argument(s) (arg3 = 3)* #- # example code #- foo1 - function(arg1,...) { print(arg1) foo2(...) foo3(...) } foo2 - function(arg2) { print(arg2) } foo3 - function(arg3) { print(arg3) } foo1(arg1 = 1, arg2 = 2, arg3 =3) #- I tried looking through the R Language Definition, but couldn't find something that helped me understand the issue (way it should happen, and what is a smart strategy to avoid it) Any insight will be greatly appreciated. Thanks, Tal [[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] Superimpose ksmooth() onto barplot
One option is to use the updateusr function in the TeachingDemos package, the help page has examples of adding lines to barplots. -- 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 Nathan S. Watson-Haigh Sent: Tuesday, February 09, 2010 4:44 PM To: r-help@r-project.org Subject: [R] Superimpose ksmooth() onto barplot I'd like to superimpose a ksmooth() onto a barplot(). My data is: d 2009-06-20 2009-06-21 2009-06-22 2009-06-23 2009-06-24 2009-06-25 2009-06-26 2009-06-27 2009-06-28 2009-06-29 2009-06-30 2009-07-01 2009-07-02 Same Breed (B) 12.64 21.08 13.52 12.51 13.71 9.91 14.24 7.18 11.81 5.92 12.04 17.96 2.99 Different Breed 3.70 3.43 5.43 4.43 3.69 1.83 2.95 2.93 4.44 3.47 9.90 10.63 2.92 2009-07-04 2009-07-05 2009-07-06 2009-07-07 2009-07-08 2009-07-09 2009-07-10 2009-07-11 2009-07-12 2009-07-13 2009-07-14 2009-07-15 2009-07-16 Same Breed (B) 27.81 26.79 24.93 23.39 27.52 28.24 12.60 2.25 1.20 0.51 0.18 1.31 0.40 Different Breed 12.16 4.53 8.51 11.77 5.65 11.67 5.81 0.53 1.26 0.42 1.10 0.20 0.29 2009-07-17 2009-07-18 2009-07-19 2009-07-21 2009-07-22 2009-07-23 2009-07-24 2009-07-25 2009-07-26 2009-07-27 2009-07-28 2009-07-29 2009-10-29 Same Breed (B)0.24 0.03 0.05 13.34 7.70 9.50 9.12 8.62 10.60 7.46 13.17 15.55 3.17 Different Breed 0.13 0.01 0.05 4.98 2.75 4.38 2.17 3.51 1.97 2.68 1.60 2.47 0.38 2009-10-30 2009-10-31 2009-11-01 2009-11-02 2009-11-03 2009-11-04 2009-11-05 2009-11-06 2009-11-07 2009-11-08 2009-11-09 2009-11-24 2009-11-25 Same Breed (B)1.39 3.57 3.53 1.30 2.26 3.41 3.44 4.04 1.71 2.16 5.01 4.34 3.58 Different Breed 0.51 0.85 1.49 1.99 6.83 1.91 1.54 1.44 0.60 2.08 1.55 2.13 1.44 2009-11-26 2009-11-27 2009-11-28 2009-11-29 2009-11-30 Same Breed (B)2.12 2.34 1.90 4.99 2.11 Different Breed 4.21 1.00 2.28 2.90 1.68 I thought the following might work ok, but the x-axis doesn't quite line up correctly for the lines because of the spacing between the bars. I could set the space to zero, but does anyone have any thoughts on how to maintain the spacing and stretch the lines data? barplot(as.matrix(d), beside=FALSE, las=2, col=as.numeric(as.factor(rownames(d lines(ksmooth(1:ncol(d), colSums(d), kernel=normal, bandwidth=bandwidth), type=l, lwd=2, col=blue) lines(ksmooth(1:ncol(d), d[1,], kernel=normal, bandwidth=bandwidth), type=l, lwd=2, col=as.numeric(as.factor(rownames(d)))[1]) lines(ksmooth(1:ncol(d), d[2,], kernel=normal, bandwidth=bandwidth), type=l, lwd=2, col=as.numeric(as.factor(rownames(d)))[2]) legend(topright, c(rownames(d), Total), fill=c(as.numeric(as.factor(rownames(d))), blue)) Cheers, Nathan -- Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries University Drive Townsville, QLD 4810 Australia Tel: +61 (0)7 4753 8548 Fax: +61 (0)7 4753 8600 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Calculating mean for a number of columns
Dear all, I am attempting to perform what should be a relatively simple calculation on a number of data frame columns. I am hoping to find the average on a per-row basis for each of the 50 columns. If on a particular row a 'NA' value is encountered, then this should be ignored and the mean formed on the basis of the other rows. However, I'm finding that the end result for each row is identical (when it shouldn't be). I suspect I'm making a syntax error, but can't seem to spot it... PDSI_Jan - cbind(pdsi_195101[,1:2], mean(c(pdsi_195101[,3], pdsi_195201[,3], pdsi_195301[,3], pdsi_195401[,3], pdsi_195501[,3], pdsi_195601[,3], pdsi_195701[,3], pdsi_195801[,3], pdsi_195801[,3], pdsi_195901[,3], pdsi_196001[,3], pdsi_196101[,3], pdsi_196201[,3], pdsi_196301[,3], pdsi_196401[,3], pdsi_196501[,3], pdsi_196601[,3], pdsi_196701[,3], pdsi_196801[,3], pdsi_196901[,3], pdsi_197001[,3], pdsi_197101[,3], pdsi_197201[,3], pdsi_197301[,3], pdsi_197401[,3], pdsi_197501[,3], pdsi_197601[,3], pdsi_197701[,3], pdsi_197801[,3], pdsi_197901[,3], pdsi_198001[,3], pdsi_198101[,3], pdsi_198201[,3], pdsi_198301[,3], pdsi_198401[,3], pdsi_198501[,3], pdsi_198601[,3], pdsi_198701[,3], pdsi_198801[,3], pdsi_198901[,3], pdsi_199001[,3], pdsi_199101[,3], pdsi_199201[,3], pdsi_199301[,3], pdsi_199401[,3], pdsi_199501[,3], pdsi_199601[,3], pdsi_199701[,3], pdsi_199801[,3], pdsi_199901[,3], pdsi_21[,3])), na.rm=TRUE) The object structure for each of the data frames being used is as follows: str(pdsi_195101) 'data.frame': 2756 obs. of 3 variables: $ Latitude : chr -48.75 -51.25 -53.75 -48.75 ... $ Longitude: Factor w/ 144 levels -178.75,-176.25,..: 1 1 1 2 3 3 4 6 6 6 ... $ PDSI : num 4.7 -1.94 -1.29 -0.68 -0.66 -0.49 -0.51 2.52 3.68 4.17 ... Many thanks for any help offered, Steve _ Do you have a story that started on Hotmail? Tell us now __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] WMF conversion...
On Feb 10, 2010, at 11:48 AM, Jason Rupert wrote: Thank you very much for your reply. I guess I may be using the wrong terminology. I have Office 2007. In PowerPoint 2007, I can navigate to Save As and then choose PDF or XPS. That option is shown in the attached image. When using that I tried both Standard and Minimum size. Both produced the diagonal lines. Also, I do not see Adobe Acrobat installed on my machine however I am investigating possibly getting that product. Thank you again for the reply. Jason snip Jason, I stand corrected. While it was not listed on the initial MS Powerpoint page that I referenced, which in fact reinforced the need for Acrobat, digging a little further on the XPS related links, I found the following: http://office.microsoft.com/en-us/help/HA101675271033.aspx which led me to: http://www.microsoft.com/downloads/details.aspx?FamilyId=4D951911-3E7E-4AE6-B059-A2E79ED87041displaylang=en So it would appear that MS does have some type of PDF/XPS export facility available as a separate download for Office. I was not aware of it. Based upon what I found on the Adobe web site, the Acrobat based facilities have a wider variety of quality based configuration options vis-a-vis exporting PDFs. I am going to guess that the MS facility defaults to the two options referenced, each of which sacrifices quality to an extent in deference to keeping the resultant file size manageable. Thus, the two options likely utilize differing levels of compression, each of which are impacting your image quality. I would give the Zamzar site a try as well to see what they deliver quality-wise. Turn around time may be the only issue with an online service. Since Acrobat is not a cheap product another alternative would be to consider using OpenOffice.org's suite, which includes Impress as a Powerpoint-like application. OO.org has a PDF export facility built in and my recollection from years ago when I was on Windows is that the PDF quality was quite good with embedded WMF/EMF images from R. More information here: http://www.openoffice.org/ There are also a variety of other Office to PDF conversion utilities available and if all you need is to export an Office document to PDF, they would also provide cheaper alternatives to Acrobat, which has much more extensive functionality. Try: http://lmgtfy.com/?q=office+pdf+converter One other alternative to consider is to use EPS images from R (see ?postscript) and import those into Office. If you have or can install a Postscript printer driver (you don't actually need to have a PS printer), you can print the PP slide set to a Postscript file and then convert that to a PDF file using a utility like ps2pdf, which is included with Ghostscript. More information here: http://pages.cs.wisc.edu/~ghost/doc/GPL/index.htm There is also an online version here: http://www.ps2pdf.com/convert.htm If you really want to get your hands wet, the approach suggested by Frank using Sweave and the Beamer package is a good way to go, if you are open to learning LaTeX. That is what I tend to use when doing presentations involving R output of both formatted tables and plots. HTH, Marc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to create probeAnno object?
Hi, I want to use segChrom() method in tilingArray package. For that I need to create a probeAnno object. I could not find much much info by ?probeAnno. I need help in creating probeAnno object. Snap shot of the file(.txt): chr1 2500014 2500038 + 0.232689943122845 chr1 2500039 2500063 + 2.60502410304227 chr1 2500062 2500086 + 0.0756595313279895 chr1 2500080 2500104 + 0.78574617788405 chr1 2500122 2500146 + 0.57901385309105 chr1 2500143 2500167 + 0.443992729102625 chr1 2500163 2500187 + 0.538200424867007 chr1 2500183 2500207 + 1.50024545788701 chr1 2500205 2500229 + 0.152549915278444 Thanks in advance. Regards, Ambuj A Thacker The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. [[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] Integral of function of dnorm
Trafim Vanishek wrote: Dear all, How is it possible in R to calculate the following integral: Integral(-Inf, Inf)[log(dnorm(mean = 3, sd = 1))] how can I define that the density dnorm is taken on (-Inf, Inf) Thanks a lot! Er, if you mean integral with respect to the x argument in dnorm, then the answer is -Inf because log(dnorm(x,...)) goes quadratically to -Inf in both directions. If you meant otherwise, please tell us what you meant... -- 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] Calculating mean for a number of columns
On Feb 10, 2010, at 1:18 PM, Steve Murray wrote: Dear all, I am attempting to perform what should be a relatively simple calculation on a number of data frame columns. I am hoping to find the average on a per-row basis for each of the 50 columns. If on a particular row a 'NA' value is encountered, then this should be ignored and the mean formed on the basis of the other rows. However, I'm finding that the end result for each row is identical (when it shouldn't be). I suspect I'm making a syntax error, but can't seem to spot it... PDSI_Jan - cbind(pdsi_195101[,1:2], mean(c(pdsi_195101[,3], pdsi_195201[,3], pdsi_195301[,3], pdsi_195401[,3], pdsi_195501[,3], pdsi_195601[,3], pdsi_195701[,3], pdsi_195801[,3], pdsi_195801[,3], pdsi_195901[,3], pdsi_196001[,3], pdsi_196101[,3], pdsi_196201[,3], pdsi_196301[,3], pdsi_196401[,3], pdsi_196501[,3], pdsi_196601[,3], pdsi_196701[,3], pdsi_196801[,3], pdsi_196901[,3], pdsi_197001[,3], pdsi_197101[,3], pdsi_197201[,3], pdsi_197301[,3], pdsi_197401[,3], pdsi_197501[,3], pdsi_197601[,3], pdsi_197701[,3], pdsi_197801[,3], pdsi_197901[,3], pdsi_198001[,3], pdsi_198101[,3], pdsi_198201[,3], pdsi_198301[,3], pdsi_198401[,3], pdsi_198501[,3], pdsi_198601[,3], pdsi_198701[,3], pdsi_198801[,3], pdsi_198901[,3], pdsi_199001[,3], pdsi_199101[,3], pdsi_199201[,3], pdsi_199301[,3], pdsi_199401[,3], pdsi_199501[,3], pdsi_199601[,3], pdsi_199701[,3], pdsi_199801[,3], pdsi_199901[,3], pdsi_21[,3])), na.rm=TRUE) It's not a syntax error (which would have allowed the parser to spot it.) It's a semantic error (which requires an inter-aural parser). You have created the mean of an extremely long vector using c() and that single value is then being replicated to fill in each of the rows. You probably want to use lapply on a list or sapply on a vector with na.rm=TRUE being supplied as subsidiary argument. The object structure for each of the data frames being used is as follows: str(pdsi_195101) 'data.frame':2756 obs. of 3 variables: $ Latitude : chr -48.75 -51.25 -53.75 -48.75 ... $ Longitude: Factor w/ 144 levels -178.75,-176.25,..: 1 1 1 2 3 3 4 6 6 6 ... $ PDSI : num 4.7 -1.94 -1.29 -0.68 -0.66 -0.49 -0.51 2.52 3.68 4.17 ... Many thanks for any help offered, Steve 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] How to solve: Error in * unused argument(s) ?
On 10.02.2010 18:58, Tal Galili wrote: Hi all, For some reason, I would like to use functions bellow (see example code bellow), but instead I get the following error message: *Error in foo2(...) : unused argument(s) (arg3 = 3)* #- # example code #- foo1- function(arg1,...) { print(arg1) foo2(...) foo3(...) } foo2- function(arg2) { print(arg2) } foo3- function(arg3) { print(arg3) } foo1(arg1 = 1, arg2 = 2, arg3 =3) #- I tried looking through the R Language Definition, but couldn't find something that helped me understand the issue (way it should happen, and what is a smart strategy to avoid it) With ... you are passing arg2 and arg3 to foo2() which only expects one argument. If you have rather different arguments to be passed to more than 1 function, you may want to - either list all arguments as arguments in the calling function (here foo2) or - restrict by calculating on args - list(...) before the foo2(...) call that need to be replaced by do.call(foo2, args) or - invent two arguments for foo1 such as: foo1- function(arg1, foo2args = list(), foo3args = list()) { print(arg1) do.call(foo2, foo2args) do.call(foo3, foo3args) } foo2- function(arg2) { print(arg2) } foo3- function(arg3) { print(arg3) } foo1(arg1 = 1, foo2args=list(arg2 = 2), foo3args=list(arg3 =3)) This way it is still possible to collect various arguments to a function without defining all of them explicitly in the formal definition of foo1. Uwe Ligges Any insight will be greatly appreciated. Thanks, Tal [[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] Readjusting the OUTPUT csv file
Amelia, I think your problem (or at least part of it) comes from the fact that in your learning of R syntax you learned about the magical shortcut index tool $ without gaining an adequate appreciation and understanding of what that is a shortcut for (common misunderstanding). The great thing about the magical shortcuts, is that when used as intended, they make life easier (thus being magical shortcuts), the drawback of magical shortcuts is that when used in ways never intended, the result is often the programming equivalent of accidentally turning yourself into a toad. Don't worry though, the solution is simple, don't use the magical shortcut, but go back to the unmagical tool that it is a shortcut for [[. Try: name1 - read.csv('input1.csv')[[name1]] value1 - read.csv('input1.csv')[[value1]] and see if that does what you intend. Also note that in the above you are reading input1.csv twice, it is probably more efficient to read it once and store the data frame, then extract the information that you want and delete the data frame (I/O can be slow compared to in memory processes). 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 Amelia Livington Sent: Wednesday, February 10, 2010 12:03 AM To: r-help@r-project.org Subject: [R] Readjusting the OUTPUT csv file Dear R helpers I have some variables say ABC, DEF, PQR, LMN and XYZ. I am choosing any three varaibles at random at a time for my analysis and name these files as input1.csv, input2.csv and input3.csv. So if I choose variables say ABC, DEF and PQR, I am passing the specifications of these variables to input1.csv, input2.csv and input3.csv respectively. This means in another case even if I choose say LMN, DEF and XYZ in this order, then my input1.csv will have details of LMN, input2.csv will have detaisl of DEF and input3.csv will have details of XYZ. Thus, I am keeping the (input) file names constant but the contents of each of these input files may change from one case to another case. As an example, my input files are as given below. input1.csv name1 value1 DEF 10 input2.csv name2 value2 LMN 8 input3.csv name3 value3 PQR 7 ## __ ## The Problem name1 = read.csv('input1.csv')$name1 value1 = read.csv('input1.csv')$value1 name2 = read.csv('input2.csv')$name2 value2 = read.csv('input2.csv')$value2 name3 = read.csv('input3.csv')$name3 value3 = read.csv('input3.csv')$value3 # (Thus if 1st variable chosen is DEF, then name1 = DEF, value1 = 10. Had I chosen some otehr variable, then name1 and value1 will have different values). Then I carry out my analysis and get the output as given below. Scenario_and_rangenames values Sc_1 (DEF LMN PQR) name1 10.04 Sc_1 (DEF LMN PQR) name2 8.21 Sc_1 (DEF LMN PQR) name3 7.23 Sc_2 (DEF LMN PQR) name1 9.96 Sc_2 (DEF LMN PQR) name2 8.47 Sc_2 (DEF LMN PQR) name3 7.40 ... .. ... .. My probelm is I know name1 pertains to DEF, name2 pertains to LMN and name3 pertains to PQR. But in the output I am not able to replace name1 with DEF, name2 with LMN and so on i.e. I cannot hardcode the varaible names in data.frame as name1 = DEF, name2 = LMN etc as these names are going to change frome case to case. My objective is to get the names (in column 2 of above table) same as respective names (appearing in 1st column) in its order i.e. instead of name1, I should get DEF, in place of name2, I should get LMN and in place of name3, I should get PQR. Hence, my output should be like - Scenario_and_rangenames values Sc_1 (DEF LMN PQR) DEF10.04 Sc_1 (DEF LMN PQR) LMN 8.21 Sc_1 (DEF LMN PQR) PQR 7.23 Sc_2 (DEF LMN PQR) DEF 9.96 Sc_2 (DEF LMN PQR) LMN 8.47 Sc_2 (DEF LMN PQR) PQR 7.40 ... .. ... .. I have tried to expalin the problem but I am not sure how far I have been clear in that. I am giving below the actual R code I have used to arrive at the required output. Actually I have say 8-9 rates and I am choosing say any three out of them. Each of these rates have three possible ranges with respective probabilities. My objective is to generate random numbers
Re: [R] R2HTML
When I copy/paste/run your code below I get a file with the summary output in a nice table. Telling us your version, operating system, and other information requested in the posting guide may help. -- 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 Regina Schinner Sent: Wednesday, February 10, 2010 1:44 AM To: r-help@r-project.org Subject: [R] R2HTML I am having difficulties with R2HTML. If I try to generate a HTML file with the below code, the titles, horizontal line, and scatter plot are there, but the data summary [summary(iris)] is not. --- library(R2HTML) HTMLStart(file=myreport, extension=html, echo=FALSE, HTMLframe=TRUE) HTML.title(Data Description, HR=3) summary(iris) HTMLhr() HTML.title(Scatter Plot, HR=3) plot(iris$Sepal.Length~iris$Sepal.Width) HTMLplot() HTMLStop() --- How do I add summary data to a HTML file? Thanks for any help you can provide Regina Schinner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ggplot2 stacked line plot
Hi: This is closer, but it is still not what you want; it does, however, show what geom_area is doing when it renders the plot, as can be seen by the colors. data.set - data.frame( Time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)), Type = rep(c('a', 'b', 'c', 'd'), 4), Value = c(10, 12, 14, 16, 14, 14, 20, 18, 18, 16, 22, 20, 26, 20, 24, 26) ) ggplot(data.set, aes(x = Time, y = Value, group = Type)) + geom_area(aes(color = Type), fill = 'transparent', position = 'stack') You can see that a polygon is drawn (and normally filled) for each group, but the line colors are not what you want and the polygon edges are not what you want, either. I'd suggest using cumsum() to get cumulative totals and using geom_line() instead; it would probably be less work...as in: library(ggplot2) data2 - ddply(data.set, .(Time), transform, Csum = cumsum(Value)) ggplot(data2, aes(x = Time, y = Csum, color = Type)) + geom_line() HTH, Dennis On Tue, Feb 9, 2010 at 8:43 PM, Liam Blanckenberg liam.blanckenb...@gmail.com wrote: Hi Hadley, Thank you for taking the time to help me with this - I've constructed the following example to illustrate my problem: require(ggplot2) data.set - data.frame( Time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)), Type = rep(c('a', 'b', 'c', 'd'), 4), Value = c(10, 12, 14, 16, 14, 14, 20, 18, 18, 16, 22, 20, 26, 20, 24, 26) ) When I use the following code: ggplot(data.set, aes(x = Time, y = Value, colour = Type)) + geom_area(aes(fill = Type), position = 'stack') I get a very nice stacked area chart - each layer on the chart represents a Type, with the total height of all the layers representing the total Value across all Types for a given Time period - this is what you would get numerically with the code: with(data.set, aggregate(Value, by = list(Time), sum)) I want to achieve exactly the same thing as this, but instead of having a coloured area to represent each layer I just want a coloured line for each layer. When I use the following code to try and achieve this: ggplot(data.set, aes(x = Time, y = Value, colour = Type)) + geom_line(aes(colour = Type), position = 'stack') I get a warning/error message: Missing ymax in position = 'stack'. Maybe you want position = 'identity'?. The plot still renders, but the lines are not stacked - the plot looks exactly as it would if the following code was used instead: ggplot(data.set, aes(x = Time, y = Value, colour = Type)) + geom_line(aes(colour = Type), position = 'identity') I suspect that the position = 'stack' argument is being ignored and 'identity' is being used by default... Hope this helps, Liam On Wed, Feb 10, 2010 at 10:12 AM, hadley wickham h.wick...@gmail.com wrote: Hi Liam, Yes, that's what that code should do. Could you please send a small reproducible example? Hadley On Tue, Feb 9, 2010 at 4:21 PM, Liam Blanckenberg liam.blanckenb...@gmail.com wrote: Hadley, Thanks for the pointing that error out to me. Unfortunately, revising my code to: p - ggplot2(~, aes(x = ~, y = ~, colour = Type)) + geom_line(aes(colour = Type), position = 'stack') still does not generate what I'm after. I'm essentially after a line plot where each 'Type' ('series' in excel lingo) is stacked in an analogous fashion to a stacked area chart (i.e. geom_area(aes(Fill = Type), position = 'stack')) - again using lines rather than areas though. This chart should look just like a stacked area chart, however rather than each 'layer' (representing a given 'Type') being filled with a colour, each layer should have just a coloured line representing its values. Summing each line vertically for a given value on the x-axis across all the layers (i.e. 'Types') should then give the total y value for that x value (just like vertically summing an area chart). Really all I'm after is a stacked area chart where the fill for each 'Type' has been removed, leaving only a line for each (stacked) Type's value... I hope this is somewhat clear! Many thanks, Liam On Wed, Feb 10, 2010 at 1:53 AM, hadley wickham h.wick...@gmail.com wrote: Hi Liam, Your syntax is a little off. You want: p - ggplot2(~, aes(x = ~, y = ~, colour = Type)) + geom_area(aes(fill = Type), position = 'stack') Position isn't an aesthetic. Hadley On Sun, Feb 7, 2010 at 10:40 PM, Liam Blanckenberg liam.blanckenb...@gmail.com wrote: Hi all, I have been hunting around for hours trying to figure out how to generate a stacked line chart using ggplot2. This type of chart can be generated in excel 2007 by selecting: Chart type Line Stacked line. I can generate a stacked area chart using the following code: p - ggplot2(~, aes(x = ~, y = ~, colour = Type)) + geom_area(aes(position = 'stack', fill = Type)) However, when I try and replicate this using the following code for geom_line: p - ggplot(~, aes(x = ~, y =
[R] Multiple tables by splitting column headings
I have a table in a txt document. The table has column headings that look like this: 1.a, 1.b, 1.c, 2.a, 2.b, 2.c I would like to import these data to R as 2 tables (1 and 2), each with columns a, b, and c. I have seen this done before, but I cannot find the commands to make it happen. Thanks, Henry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] color palette heatmap
Hi, I'm kinda new of the R world. I need to use the heatmap or heatmap.2 function to plot correlation values. 2 questions: - how can I specify a color palette? (would like to have a transition from blue(-1) to white(0) to red(1)) - how can I use heatmap.2 imposing a specific order (like hclust.order)? I mean, I don't want heatmap.2 to re-cluster/re-order my data but just to plot them according to a specified (by me) order (I tried Rowv = hc$order where hc is an hclust object, but without success) can you help me? Thanks a lot! J -- View this message in context: http://n4.nabble.com/color-palette-heatmap-tp1476296p1476296.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] Subscripting
Dataframe1 contains a list of specific dates. Dataframe2 contains a large dataset, one element of which is Date. How do I create a subset of Dataframe2 that excludes the dates from Dataframe1? I know how to do it with a left outer join vs null in SQL, but I can't figure out how to do it more directly via the subcripts that already exist? Dateframe1 Date 1/1/2010 1/18/2010 Dataframe2 Date Attribute Count 1/1/2010 Red 5 1/15/2010 Green 2 1/18/2010 Purple 8 1/19/2010 Yellow 3 ResultingDataframe (Dataframe2 minus the rows that have Dates in Dataframe1) Date Attribute Count 1/15/2010 Green 2 1/19/2010 Yellow 3 -- View this message in context: http://n4.nabble.com/Subscripting-tp1476330p1476330.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] eval function with javascript-semantics possible in R?
Dear r-helpers, I am looking for an R-equivalent for the eval-function in javascript which can interpret a string as code on runtime, thereby allowing things like for (i in c(1:2)) { eval(items + i) - read.csv(eval(filename+ i), dec=,); } which would execute (with filename=testfile): items1 - read.csv(testfile1, dec=,); items2 - read.csv(testfile2, dec=,); The way I intend to use it is to define a string list containing names of date.frames, and interate this list to perform some function: createTable - function(latentVariableNames) { for (currentName in names(latentVariableNames)) { doSomethingWith(currentName) } } Would be grateful for any help! Chaehan [[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] boxplot label cleanup
The boxplot below is close to what I would like, but needs some clean up. I've been unable to address the following: 1) How can I use the full extent of the plot space (there is white space on either side of the data)? 2) How can I reduce the # of month labels (e.g. every 3rd month Jan Mar Jun...) but still keep them staggered? 3) The year labels at the top of the plot have been positioned using the following line mtext(year.observed,3,at=seq(3,99,by=12),padj=-1) I would prefer to position the label using the actual value contained in the date column of the data.frame (which is a date variable type). Fixing the position as I have doesn't seem...pure? 4) The grid is meant to partition the data from year to year and was generated using grid(nx=9,ny=0,col=gray60,lty=1) but it is clearly off. Is there a way to draw the grid lines exactly between december and January? I wasn't sure how much code I should include, so here it all is: (images follow) my.dat-read.table(C:/Eric/Programs/UtilityProgram_Summarize_UNSAT_Zone_Results_8Class/Process_UZF_Output/bin/R_Data_fracETSat_US.txt,header=TRUE,sep=\t) attach(my.dat) dates-strptime(as.character(my.dat$date),%m/%e/%Y) my.dat=my.dat[,2:5] my.dat=data.frame(date=dates,my.dat) detach(my.dat) daterange=c(as.POSIXlt(min(my.dat$date)),as.POSIXlt(max(my.dat$date))) rm(dates) attach(my.dat) cropped=subset(my.dat,Classification==5) natveg=subset(my.dat,Classification==7) cropped[c(1,2,3),] #Example data date Cell_ID Classification WT_Depth Frac_ET_Satsfd 94 1999-04-084395 5 1.572998 0.7596927 95 1999-04-084396 5 1.923096 0.7588058 101 1999-04-084403 5 2.290039 0.7911426 month.year - function (x) {12*(as.POSIXlt(x)$year-99)+as.POSIXlt(x)$mon+1} month-month.year(my.dat$date) months-month.name cropped.month-month.year(cropped$date) mean.cropped.frac-tapply(cropped$Frac_ET_Satsfd,cropped.month,mean) month.observed - numeric(length(mean.cropped.frac)) for(i in 1:length(mean.cropped.frac)){month.observed[i]=as.numeric(names(mean.cropped.frac[i]))%%12} month.observed[month.observed==0]-12 #make the decembers 12 instead of 0 month.names-months[as.numeric(month.observed)] month.names-substr(month.names,1,3) year.vector-function (x) {as.POSIXlt(x)$year+1900} cropped.year-year.vector(cropped$date) mean.cropped.frac.yr-tapply(cropped$Frac_ET_Satsfd,cropped.year,mean) year.observed-numeric(length(mean.cropped.frac.yr)) for(i in 1:length(mean.cropped.frac.yr)){year.observed[i]=as.numeric(names(mean.cropped.frac.yr[i]))} boxplot(Frac_ET_Satsfd~month.year(cropped$date),data=cropped,col=lightblue,outline=F, range=0.0001,ylim=c(0,1),xaxt=n) axis(1,at=1:103,labels=F) mtext(month.names,1,at=1:103,line=rep(c(1,2),2)) mtext(year.observed,3,at=seq(3,99,by=12),padj=-1) grid(nx=9,ny=0,col=gray60,lty=1) http://n4.nabble.com/file/n1476343/timeSeriesMessy.jpg Thanks, Eric -- View this message in context: http://n4.nabble.com/boxplot-label-cleanup-tp1476343p1476343.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] eval function with javascript-semantics possible in R?
Try this: fileName - testfile%s lapply(sprintf(fileName, 1:2), read.csv, dec = ,) On Wed, Feb 10, 2010 at 5:28 PM, Chaehan So chaehan...@gmail.com wrote: Dear r-helpers, I am looking for an R-equivalent for the eval-function in javascript which can interpret a string as code on runtime, thereby allowing things like for (i in c(1:2)) { eval(items + i) - read.csv(eval(filename+ i), dec=,); } which would execute (with filename=testfile): items1 - read.csv(testfile1, dec=,); items2 - read.csv(testfile2, dec=,); The way I intend to use it is to define a string list containing names of date.frames, and interate this list to perform some function: createTable - function(latentVariableNames) { for (currentName in names(latentVariableNames)) { doSomethingWith(currentName) } } Would be grateful for any help! Chaehan [[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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subscripting
Something like: df3 - df2[ !(df2$date %in% df1$date), ] Might be what you want. -- 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 GL Sent: Wednesday, February 10, 2010 12:26 PM To: r-help@r-project.org Subject: [R] Subscripting Dataframe1 contains a list of specific dates. Dataframe2 contains a large dataset, one element of which is Date. How do I create a subset of Dataframe2 that excludes the dates from Dataframe1? I know how to do it with a left outer join vs null in SQL, but I can't figure out how to do it more directly via the subcripts that already exist? Dateframe1 Date 1/1/2010 1/18/2010 Dataframe2 Date Attribute Count 1/1/2010 Red 5 1/15/2010 Green 2 1/18/2010 Purple 8 1/19/2010 Yellow 3 ResultingDataframe (Dataframe2 minus the rows that have Dates in Dataframe1) Date Attribute Count 1/15/2010 Green 2 1/19/2010 Yellow 3 -- View this message in context: http://n4.nabble.com/Subscripting- tp1476330p1476330.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to solve: Error in * unused argument(s) ?
Uwe, thank you very much - that was the solution I was looking for! Best, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- 2010/2/10 Uwe Ligges lig...@statistik.tu-dortmund.de On 10.02.2010 18:58, Tal Galili wrote: Hi all, For some reason, I would like to use functions bellow (see example code bellow), but instead I get the following error message: *Error in foo2(...) : unused argument(s) (arg3 = 3)* #- # example code #- foo1- function(arg1,...) { print(arg1) foo2(...) foo3(...) } foo2- function(arg2) { print(arg2) } foo3- function(arg3) { print(arg3) } foo1(arg1 = 1, arg2 = 2, arg3 =3) #- I tried looking through the R Language Definition, but couldn't find something that helped me understand the issue (way it should happen, and what is a smart strategy to avoid it) With ... you are passing arg2 and arg3 to foo2() which only expects one argument. If you have rather different arguments to be passed to more than 1 function, you may want to - either list all arguments as arguments in the calling function (here foo2) or - restrict by calculating on args - list(...) before the foo2(...) call that need to be replaced by do.call(foo2, args) or - invent two arguments for foo1 such as: foo1- function(arg1, foo2args = list(), foo3args = list()) { print(arg1) do.call(foo2, foo2args) do.call(foo3, foo3args) } foo2- function(arg2) { print(arg2) } foo3- function(arg3) { print(arg3) } foo1(arg1 = 1, foo2args=list(arg2 = 2), foo3args=list(arg3 =3)) This way it is still possible to collect various arguments to a function without defining all of them explicitly in the formal definition of foo1. Uwe Ligges Any insight will be greatly appreciated. Thanks, Tal [[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] Subscripting
On Feb 10, 2010, at 2:26 PM, GL wrote: Dataframe1 contains a list of specific dates. Dataframe2 contains a large dataset, one element of which is Date. How do I create a subset of Dataframe2 that excludes the dates from Dataframe1? I know how to do it with a left outer join vs null in SQL, but I can't figure out how to do it more directly via the subcripts that already exist? Dateframe1 Date 1/1/2010 1/18/2010 Dataframe2 Date Attribute Count 1/1/2010 Red 5 1/15/2010 Green 2 1/18/2010 Purple 8 1/19/2010 Yellow 3 Something along the lines of this untested code: Dataframe2[ !(Dataframe2$Date %in% Dataframe1$Date) , ] ?[ ?%in% ResultingDataframe (Dataframe2 minus the rows that have Dates in Dataframe1) Date Attribute Count 1/15/2010 Green 2 1/19/2010 Yellow 3 -- View this message in context: http://n4.nabble.com/Subscripting-tp1476330p1476330.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. 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] write.zip?
Hi Spencer I just put a new source version (0.9-0) of the Rcompression package on the www.omegahat.org/R repository and it has a new function zip() that creates or appends to a zip file, allowing one to provide alternative names. I'll add support for writing content from memory (i.e. AsIs character strings and raw vectors) soon. It doesn't yet handle replacing or removing elements yet. I may use a different approach (e.g. the 7-zip lzma SDK) to that and other things. D. spencerg wrote: Thanks to Dieter Menne and Prof. Ripley for replies. For certain definitions of better (e.g., transportability?), the Rcompression package might be superior to the system call I mentioned. I also just found the tar function in the utils package, which looks like it might be more transportable than my system call. However, as Prof. Ripley noted, there may not be a simpler way than my system call, especially considering the time I would have to invest to learn how to use it. Thanks again very much, Spencer Graves Prof Brian Ripley wrote: On Tue, 9 Feb 2010, spencerg wrote: Can one write a zip file from R? I want to create a file with a name like dat.zip, being a zip file containing dat.csv. I can create dat.csv, then call system('zip -r9 dat.zip dat.csv'). Is there a better way? Not really. One could use compiled code like that in unzip() to do this, but as nothing inside R is involved the only gain would be to not need to have the zip executable present. Omegahat package Rcompression does have means to manipulate .zip files from compiled code with an R interface, but not AFAICS a simpler way to do what you want. I can use gzfile to write a gz file, but I don't know how to give that a structure that would support unzipping to a *.csv file. A zip file is not a gzipped file, even though gzip compression is used for parts of the contents. The header and trailer are quite different. Thanks, Spencer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Make a table using data with frequency
Dear All, What I want is change following data data alc status age freq 1 0 0 0 408 2 1 0 0 64 3 0 1 0 26 4 1 1 0 30 5 0 0 1 258 6 1 0 1 45 7 0 1 1 78 8 1 1 1 66 To this table. age =0 alc 0 1 status 0 408 64 1 26 30 age =1 alc 0 1 status 0 258 45 1 78 66 How can I do that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hypercube in R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Andrej Kastrin Sent: Monday, February 08, 2010 12:37 PM To: r-help@r-project.org Subject: [R] Hypercube in R Dear all, Does anybody have an idea or suggestion how to construct (plot) 4-dimensional hypercube in R. Thanks in advance for any pointers. Try the following, which plots a projection of a `dimension`-cube to a random 2 dimensional subspace. It uses lm() to do the projection since that is how I think of linear models, but you could use more direct matrix manipulations. It has too many calls to t() in it and it should let you specify the subspace. Try it with par(mfrow=c(3,3), mar=rep(0,4)) for(i in 1:9) f(dimension=4) to get a 9 random views. f - function(dimension) { rorthogonal - function(n = 2, dimension) { # generate `n` random orthonormal vectors # in `dimension` dimensional space x - matrix(rnorm(n*dimension), nrow=n, ncol=dimension) t(eigen(crossprod(x))$vectors) } cube - as.matrix(do.call(expand.grid, rep(list(c(-1,1)),dimension))) # the points pairs with distance 2 are connected by edges ij - which(abs(as.matrix(dist(cube))-2)1e-7, arr.ind=TRUE) # only need edge in one direction ij - ij[ij[,1]ij[,2],] basis - rorthogonal(n=2, dim=dimension) # p is projection of vectices to subspace of basis p - t(lm.fit(x=t(basis), y=t(cube))$coef) # plot vertices plot(p[,1],p[,2],asp=1) # plot edges segments(p[,1][ij[,1]], p[,2][ij[,1]], p[,1][ij[,2]], p[,2][ij[,2]]) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Regards, Andrej __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Novel (Maybe?) Visualizations
D. Dashcle d.dasc...@hotmail.com [Wed, Feb 10, 2010 at 01:13:58AM CET]: I'm interested in using R's plotting capabilities to try to generate a graph showing the relationship/pairing frequency of words appearing in a block of unstructured text. I don't have a specific algorithm or approach in mind, just looking to portray text in an interesting fashion. The output I'm hoping for is something like the following called a Phrase Network: http://manyeyes.alphaworks.ibm.com/manyeyes/page/Phrase_Net.html It looks like you need algorithms to position nodes in order to minimise edge lengths and overlap. A well known program which does that is graphviz. I am quite sure that no one has taken the effort to re-implement the algorithm in R, but there are many R packages that interact with graphviz. I would look for graphviz in www.rseek.org and procede from there. -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johan...@huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Make a table using data with frequency
On Feb 10, 2010, at 2:02 PM, Soyeon Kim wrote: Dear All, What I want is change following data data alc status age freq 1 0 0 0 408 2 1 0 0 64 3 0 1 0 26 4 1 1 0 30 5 0 0 1 258 6 1 0 1 45 7 0 1 1 78 8 1 1 1 66 To this table. age =0 alc 0 1 status 0408 64 1 26 30 age =1 alc 0 1 status 0258 45 1 78 66 How can I do that? Thanks, See ?xtabs With your data in a data frame called 'DF': DF alc status age freq 1 0 0 0 408 2 1 0 0 64 3 0 1 0 26 4 1 1 0 30 5 0 0 1 258 6 1 0 1 45 7 0 1 1 78 8 1 1 1 66 xtabs(freq ~ status + alc + age, data = DF) , , age = 0 alc status 0 1 0 408 64 1 26 30 , , age = 1 alc status 0 1 0 258 45 1 78 66 and you can reverse the process by using as.data.frame.table(): as.data.frame.table(xtabs(freq ~ status + alc + age, data = DF)) status alc age Freq 1 0 0 0 408 2 1 0 0 26 3 0 1 0 64 4 1 1 0 30 5 0 0 1 258 6 1 0 1 78 7 0 1 1 45 8 1 1 1 66 HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] expand the inside of command with rep ?
Hi, I would like to be able to repeat a string within a command. I think there is an easy way but I can not figure out how. Here is an example. x-1:15 I would like to turn this into the following matrix: xm-cbind(x,x,x,x,x) But I would like to do so by having a command that repeats x within the cbind command. Does that make sense? I have tried various things mainly involving the commands rep and paste but cannot get it. cbind(rep('x',times=5)) I am guessing that this is not good programming etiquette? Something seems off about it. But still, I would like to know how to do it. I do understand that I can use a for loop to easily accomplish the desired output but am looking for a solution similar to the above syntax. Thank you for any ideas, Xu Wang -- View this message in context: http://n4.nabble.com/expand-the-inside-of-command-with-rep-tp1476420p1476420.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] expand the inside of command with rep ?
Something like this: do.call( cbind, rep(list(1:10), 5) ) [,1] [,2] [,3] [,4] [,5] [1,]11111 [2,]22222 [3,]33333 [4,]44444 [5,]55555 [6,]66666 [7,]77777 [8,]88888 [9,]99999 [10,] 10 10 10 10 10 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 Xu Wang Sent: Wednesday, February 10, 2010 1:28 PM To: r-help@r-project.org Subject: [R] expand the inside of command with rep ? Hi, I would like to be able to repeat a string within a command. I think there is an easy way but I can not figure out how. Here is an example. x-1:15 I would like to turn this into the following matrix: xm-cbind(x,x,x,x,x) But I would like to do so by having a command that repeats x within the cbind command. Does that make sense? I have tried various things mainly involving the commands rep and paste but cannot get it. cbind(rep('x',times=5)) I am guessing that this is not good programming etiquette? Something seems off about it. But still, I would like to know how to do it. I do understand that I can use a for loop to easily accomplish the desired output but am looking for a solution similar to the above syntax. Thank you for any ideas, Xu Wang -- View this message in context: http://n4.nabble.com/expand-the-inside- of-command-with-rep-tp1476420p1476420.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] expand the inside of command with rep ?
try this: x - 1:5 x.list - lapply(1:15, function(a) x) do.call(cbind, x.list) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [1,]111111111 1 1 1 1 1 1 [2,]222222222 2 2 2 2 2 2 [3,]333333333 3 3 3 3 3 3 [4,]444444444 4 4 4 4 4 4 [5,]555555555 5 5 5 5 5 5 On Wed, Feb 10, 2010 at 3:27 PM, Xu Wang xuwang...@gmail.com wrote: Hi, I would like to be able to repeat a string within a command. I think there is an easy way but I can not figure out how. Here is an example. x-1:15 I would like to turn this into the following matrix: xm-cbind(x,x,x,x,x) But I would like to do so by having a command that repeats x within the cbind command. Does that make sense? I have tried various things mainly involving the commands rep and paste but cannot get it. cbind(rep('x',times=5)) I am guessing that this is not good programming etiquette? Something seems off about it. But still, I would like to know how to do it. I do understand that I can use a for loop to easily accomplish the desired output but am looking for a solution similar to the above syntax. Thank you for any ideas, Xu Wang -- View this message in context: http://n4.nabble.com/expand-the-inside-of-command-with-rep-tp1476420p1476420.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] Installing the glmnet package.
Hello, R version 2.8.0 (2008-10-20) on a linux-64-bit machine. I am trying to install the glmnet package and I get the following error: *** install.packages(pkgs = glmnet) trying URL 'http://cran.parentinginformed.com/src/contrib/glmnet_1.1-5.tar.gz' Content type 'application/x-gzip' length 65521 bytes (63 Kb) opened URL == downloaded 63 Kb * Installing *source* package 'glmnet' ... This package has only been tested with gfortran. So some checks are needed. R_HOME is /usr/lib64/R Attempting to determine R_ARCH... R_ARCH is Attempting to detect how R was configured for Fortran 90 Unsupported Fortran 90 compiler or Fortran 90 compilers unavailable! Stop! ERROR: configuration failed for package 'glmnet' ** Removing '/usr/lib64/R/library/glmnet' it says it had only been tested with the gfortran compiler, but this compiler is on the machine I am using, it is in /usr/bin/. If this is the problem is there a way to specify to install.package where to look for the compiler? If this is not the problem does anyone knows what the problem could be? Le message ci-dessus, ainsi que les documents l'accompagnant, sont destinés uniquement aux personnes identifiées et peuvent contenir des informations privilégiées, confidentielles ou ne pouvant être divulguées. Si vous avez reçu ce message par erreur, veuillez le détruire. This communication ( and/or the attachments ) is intended for named recipients only and may contain privileged or confidential information which is not to be disclosed. If you received this communication by mistake please destroy all copies. Faites bonne impression et imprimez seulement au besoin ! Think green before you print ! Le message ci-dessus, ainsi que les documents l'accompagnant, sont destinés uniquement aux personnes identifiées et peuvent contenir des informations privilégiées, confidentielles ou ne pouvant être divulguées. Si vous avez reçu ce message par erreur, veuillez le détruire. This communication (and/or the attachments) is intended for named recipients only and may contain privileged or confidential information which is not to be disclosed. If you received this communication by mistake please destroy all copies. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hypercube in R
Your solution seems wonderful. I'm going to uninstall ggobi :) Thanks again. Cheers, Andrej On Feb 10, 8:59 pm, William Dunlap wdun...@tibco.com wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Andrej Kastrin Sent: Monday, February 08, 2010 12:37 PM To: r-h...@r-project.org Subject: [R] Hypercube in R Dear all, Does anybody have an idea or suggestion how to construct (plot) 4-dimensional hypercube in R. Thanks in advance for any pointers. Try the following, which plots a projection of a `dimension`-cube to a random 2 dimensional subspace. It uses lm() to do the projection since that is how I think of linear models, but you could use more direct matrix manipulations. It has too many calls to t() in it and it should let you specify the subspace. Try it with par(mfrow=c(3,3), mar=rep(0,4)) for(i in 1:9) f(dimension=4) to get a 9 random views. f - function(dimension) { rorthogonal - function(n = 2, dimension) { # generate `n` random orthonormal vectors # in `dimension` dimensional space x - matrix(rnorm(n*dimension), nrow=n, ncol=dimension) t(eigen(crossprod(x))$vectors) } cube - as.matrix(do.call(expand.grid, rep(list(c(-1,1)),dimension))) # the points pairs with distance 2 are connected by edges ij - which(abs(as.matrix(dist(cube))-2)1e-7, arr.ind=TRUE) # only need edge in one direction ij - ij[ij[,1]ij[,2],] basis - rorthogonal(n=2, dim=dimension) # p is projection of vectices to subspace of basis p - t(lm.fit(x=t(basis), y=t(cube))$coef) # plot vertices plot(p[,1],p[,2],asp=1) # plot edges segments(p[,1][ij[,1]], p[,2][ij[,1]], p[,1][ij[,2]], p[,2][ij[,2]]) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com Regards, Andrej __ r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Simplify the code
Hi all, I wrote the following code for the function that is attached. I want to simply the code. Can some one give me some help? The function is attached and the following is the code: ## f1 is the function calculate the value outside the sum f1 - function(t, a, b) {t/beta(a, b)} ## f2 is the function that calculates the summand f2 - function(j, k, t, a, b){choose(j-1,k-1)*(1-t)^(j-1) * beta(a+k, b+j- k)} ## f3 calculates the sum f3 - function(n, t, a, b){ ss - matrix(0, nrow=n, ncol=n) for (j in 1:n){ for (i in 1:j) { ss[i,j]- f2(j,i, t, a, b) } } sum - sum(ss) return(sum) } ## f is the final function f - function(n,t, a, b) {f1(t,a ,b)*f3(n,t,a,b)} ## Many thanks! Hannah question to R-heip.pdf Description: Adobe PDF document __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to sample from Bivariate Uniform Distribution
Hello all!!! 1) I am wondering is there a way to generate random numbers in R for Bivariate Uniform distribution? 2) Does R have built-in function for generating random numbers for any given bivariate distribution. Any help would be greatly appreciated !! Good day! Haneef Anver -- View this message in context: http://n4.nabble.com/How-to-sample-from-Bivariate-Uniform-Distribution-tp1476395p1476395.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] Sampling from Bivariate Uniform Distribution
Hello all!!! 1) I am wondering is there a way to generate random numbers in R for Bivariate Uniform distribution? 2) Does R have built-in function for generating random numbers for any given bivariate distribution. Any help would be greatly appreciated !! Good day! Haneef Anver [[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.