[R] How to convert a graph into an image in R
In R, I want to convert the plotted graph into an image and save it, so that i can make use of it later. - Thank you, with regards, Punitha -- View this message in context: http://r.789695.n4.nabble.com/How-to-convert-a-graph-into-an-image-in-R-tp4643584.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 convert a graph into an image in R
On Sep 18, 2012, at 10:57 PM, punitha wrote: In R, I want to convert the plotted graph into an image and save it, so that i can make use of it later. Generally the GUI's handle this with 'save as...' functions. but if you are in a console session then consult: ?Devices ?pdf ?png ?jpeg -- David Winsemius, MD Alameda, CA, 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.
Re: [R] scraping with session cookies
Hi ? The key is that you want to use the same curl handle for both the postForm() and for getting the data document. site = u = http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18; library(RCurl) curl = getCurlHandle(cookiefile = , verbose = TRUE) postForm(site, disclaimer_action=I Agree) Now we have the cookie in the curl handle so we can use that same curl handle to request the data document: txt = getURLContent(u, curl = curl) Now we can use readHTMLTable() on the local document content: library(XML) tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors = FALSE) Rather than knowing how to post the form, I like to read the form programmatically and generate an R function to do the submission for me. The RHTMLForms package can do this. library(RHTMLForms) forms = getHTMLFormDescription(u, FALSE) fun = createFunction(forms[[1]]) Then we can use fun(.curl = curl) instead of postForm(site, disclaimer_action=I Agree) This helps to abstract the details of the form. D. On 9/18/12 5:57 PM, CPV wrote: Hi, I am starting coding in r and one of the things that i want to do is to scrape some data from the web. The problem that I am having is that I cannot get passed the disclaimer page (which produces a session cookie). I have been able to collect some ideas and combine them in the code below but I dont get passed the disclaimer page. I am trying to agree the disclaimer with the postForm and write the cookie to a file, but I cannot do it succesfully The webpage cookies are written to the file but the value is FALSE... So any ideas of what I should do or what I am doing wrong with? Thank you for your help, library(RCurl) library(XML) site - http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18; postForm(site, disclaimer_action=I Agree) cf - cookies.txt no_cookie - function() { curlHandle - getCurlHandle(cookiefile=cf, cookiejar=cf) getURL(site, curl=curlHandle) rm(curlHandle) gc() } if ( file.exists(cf) == TRUE ) { file.create(cf) no_cookie() } allTables - readHTMLTable(site) allTables [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] invalid labels; length 2 should be 1 or 0
Dear list, I am trying to impute the two level data, I have a question about a warning. Could you give me some suggestions please? Thank you very much. Here is my code and output of mice package: ini - mice(try, maxit=0) pred=ini$pred pred FAC1_1 FAC2_1 FAC3_1 FAC4_1 FAC5_1 FAC6_1 FAC7_1 FAC8_1 FAC9_1 FAC10_1 ClassSize_1 ClassSize_2 ClassSize_3 intercept TeacherID_1 bulg_1 bulg_2 FAC1_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC2_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC3_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC4_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC5_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC6_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC7_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC8_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC9_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FAC10_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ClassSize_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ClassSize_2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ClassSize_3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 intercept0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 TeacherID_1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 bulg_1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bulg_2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bulg_3 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 bulg_3 FAC1_1 0 FAC2_1 0 FAC3_1 0 FAC4_1 0 FAC5_1 0 FAC6_1 0 FAC7_1 0 FAC8_1 0 FAC9_1 0 FAC10_1 0 ClassSize_1 0 ClassSize_2 0 ClassSize_3 0 intercept0 TeacherID_1 1 bulg_1 0 bulg_2 0 bulg_3 0 pred[bulg_1,]=c(2,2,2,2,2,2,2,2,2,2,1,0,0,2,-2,0,0,0) imp=mice(try,meth=c(,,,2l.norm,2l.norm,2l.norm),pred=pred,maxit=3) iter imp variable 1 1 bulg_3Error in factor(x[, type == (-2)], labels = 1:n.class) : invalid labels; length 2 should be 1 or 0 class(formi$bulg_1) [1] numeric class(formi$bulg_2) [1] numeric class(formi$bulg_3) [1] numeric The TeacherID_1 is the second level ID. bulg_1, bulg_2, and bulg_3 are continuous variables that need to be imputed. Why the factor() was used for continuous variables? Thank you very much. Best regards, ya [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with calculation from dataframe with multiple entries per sample
On Wednesday, September 19, 2012, Jul_biologyGrad wrote: Thanks everyone for the help! I pulled together a bunch of your suggestions to get the result that I needed. I'm posting my final code below. Probably not the most efficient way of doing things but gets the job done in a way that a newbie can understand! ##Here again is the example dataset Sample-c(1,1,1,2,2,2,3,3,3) Mass-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5) Time-c(1,2,3,1,2,3,1,2,3) mydata-as.data.frame(cbind(Sample,Time,Mass)) One (strongly advised) bit of advice. Don't use the as.data.frame(cbind()) construction -- it's really quite odious. cbind() forces its arguments all to the same mode, while the entire point of a df is to allow different types. As.df could theoretically see values of different types, but it has no idea what went into cbind() so it doesn't bother to change it. Rather you should use the data.frame constructor directly: data.frame(Sample, Time, Mass) It might not matter here but it will save you headaches down the road. Cheers, RMW [[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] Discrepancies in weighted nonlinear least squares
Dear all, I encounter some discrepancies when comparing the deviance of a weighted and unweigthed model with the AIC values. A general example (from 'nls'): DNase1 - subset(DNase, Run == 1) fm1DNase1 - nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1) This is the unweighted fit, in the code of 'nls' one can see that 'nls' generates a vector wts - rep(1, n). Now for a weighted fit: fm2DNase1 - nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1, weights = rep(1:8, each = 2)) in which I assign dcreasing weights for each of the 8 concentrations with 2 replicates. Now with 'deviance' I get: deviance(fm1DNase1) [1] 0.004789569 deviance(fm2DNase1) [1] 0.0164259 Telling me that the weighted fit has a significantly higher deviance (is a worse fit). Now with AIC (or BIC) I get AIC(fm1DNase1) [1] -76.41642 AIC(fm2DNase1) [1] -372.5437 Which tells me that the second fit is by orders of magnitude the better one. Why so? If I define AIC based on residual sum-of-squares as found in the textbooks RSS - function (object) { w - object$weights r - residuals(object) if (is.null(w)) w - rep(1, length(r)) sum(w * residuals(object)^2) } AICrss - function(object) { n - nobs(object) k - length(coef(object)) rss - RSS(object) n * log((2 * pi)/n) + n + 2 + n * log(rss) + 2 * k } I get AICrss(fm1DNase1) [1] -76.41642 Which is the same value as the above AIC (stats:::AIC.logLik) based on log-likelihood but AICrss(fm2DNase1) [1] -56.69772 which is higher and fits perfectly to the also higher deviance of the second model. Could anyone enlighten me? Is the standard AIC implementation for 'nls' models not appliccable in case of weighted fitting? Cheers, Andrej ___ Dr. rer. nat. Andrej-Nikolai Spiess Department of Andrology University Hospital Hamburg-Eppendorf Martinistr. 52 20246 Hamburg phone: +49-40-7410-51585 fax: +49-40-7410-51554 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] factor expansion
Hi I did not see any answer yet but can you explain what you mean by factor expansion? Something like expand.grid? Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Jose Bustos Melo Sent: Wednesday, September 12, 2012 4:16 PM To: r-help@r-project.org Subject: [R] factor expansion I'm trying to use a data base from SPSS and get all data representing the true data. I would like to use a variable as expansion data. In our data base we have the variable with the factor expansion, but we have not idea how to set it in R. Any idea? Thanks in advance! José [[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] Why x[1] is not getting substituted?
Hi because you need to evaluate it. print(paste(Trial and ,eval(x[1]), sheet)) Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Sri krishna Devarayalu Balanagu Sent: Tuesday, September 18, 2012 11:41 AM To: r-help@r-project.org Subject: [R] Why x[1] is not getting substituted? Suppose I want the output as Trial and a sheet without quotes x=c(a, b, c) print(Trial and x[1] sheet) Getting Trial and x[1] sheet Can anyone help? Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-6692tel:+91-40-6692 and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). [[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] [newbie] aggregating table() results and simplifying code with loop
-Original Message- From: ridav...@gmail.com Sent: Wed, 19 Sep 2012 00:42:50 +0200 To: ruipbarra...@sapo.pt Subject: Re: [R] [newbie] aggregating table() results and simplifying code with loop Hi dear R-helpers, I really appreciate your coding the answers to (my) questions. I am now in the situation to get results in a very shorter time and with a proper code. + the study (summary) + In (short) response to the question by John, the global target of the analysis is to identify the dynamics of crop sequences in a given region. The spatial grain is the elementary watershed (as defined by the local water agency). The temporal grain is a 5 year period (it allows, according to previous analyses, to grasp the major crop sequences for the study area). The input data is a grid of points where the land cover has been monitored since the 80's up to now (with a couple of interruptions). The first part of the analysis was aimed at characterizing crop sequences and their occurrences in the different watersheds. The step of the analysis for what I'm asking your help is aimed at calculating the return time of the most relevant crops (from an agronomic point of view), on which operate then a clustering. Raw attempts I've tried so far with other methods appeared to give promising results, so I've decided to improve the approach using R. Here is where you come in. +++ ++ (unsolved) questions +++ The proposal by John is clear to me, probably because his way of coding is closer to my capability to understand. That's because I'm much closer to you in knowledge about R. The solution by Rui looks interesting, complete and effective (few elementary functions and reduced time to have the results to be used in the other steps of the analysis). Nevertheless I'm still in trouble because I'm not used with function (that's one of the reasons I'm here). The following questions will sound naive to you, but I'm not able to decrypt Rui's code without asking again your help. Basic manuals (like R Language Definition ch. 4, or The R Inferno ch. 5) were not sufficient for me to understand how w, DF, Mat, WS and currcols are defined. In other words, I see that the five embedded functions Rui has proposed call for the above mentioned arguments, but I'm not able to understand at which moment these arguments are defined. +++ Rui's approach is very, very nice but does seem a bit opaque to us newbies. I think the first thing is : Do you undrestand the 'result' list structure? It sounds like you do but basically he is processing each set of conditions that you supplied and storing them indiviually as data frames in each element of the list. Secondly, to work through the functions you should be able to step through each function without running the function. For example for F5 the working parts are sp - split(w, w$V8) res - do.call( rbind, lapply(sp, f4) ) res - data.frame(res) res = We see from the main program that result - lapply(want, f5) so for the above code want is the w value. Just stick it into the code and see what happens. That is print out values as you go. Each call seems to go to another function but bit by bit you should be able to see what is happening. I suspect it will be messy but it should help a bit. Another trick might be to make up a very tiny data set that meets all conditions and run the program in, I think , debug mode and stick in print statements all along the way so that you can get a feel for what is happening at each step. In any case you should be able to extact each condition from result by something like crop - result[[1]] (note [[1]] rather than [1] and run ddply() or aggregate() on the resulting data frame to see if the output looks reasonable. Thanks for the quick summary. Once I realised that WS = Watershed I thought that was what it was likely to be about but it`s handy to know and sometimes even a slight bit of knowledge about the subject area can help alert one to something strange in the output that may indicate a programing or logic problem. Good luck. R is amazingly powerful and can often produce results much more quickly than other stats language but it requires a different mindset. I used to get very funny mind aches when I first started using it after years of SAS or SYSTAT or even SPSS. Everything flows without warnings, so I have the bad feeling to find myself less smart than R... That not a big problem, but having not understood the arguments, I do not understand the functions (so, the results). Thanks in advance for meeting this call for some extra-help... Take care, Dd
Re: [R] Why x[1] is not getting substituted?
Sri krishna Devarayalu Balanagu wrote: Suppose I want the output as Trial and a sheet without quotes x=c(a, b, c) print(Trial and x[1] sheet) Getting Trial and x[1] sheet Can anyone help? And for your sins in not reading the documentation: cat(paste(rev(c(sheet,x[1],and,Trial))),\n) R helps those who help themselves Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem in displaying image in browser using Rook
hi, I wanted to convert a graph into image and display it in browser, i got the image in the given folder and everything is coming out well but the image is not being displayed, even the error or warning is not being given so i dont know what exactly i have made mistake in the code, please can anyone help me out in this please. sample = function(env) { req = Rook::Request$new(env) res = Rook::Response$new() res$write('Name:\n') res$write('form method=POST\n') res$write('input type=text name=name1 \nbr') res$write('Age:\n') res$write('form method=POST\n') res$write('input type=text name=age \nbr') res$write('Profession:\n') res$write('form method=POST\n') res$write('input type=text name=profession value=8\nbr') res$write('input type=submit name=Go!\n/form\nbr') if (!is.null(req$POST())) { x-req$POST()[[name1]] y-req$POST()[[age]] n-req$POST()[[profession]] res$write(x) res$write('br') res$write(y) res$write('br') res$write(n) res$write('br') png(file=P_Chart_All_Dims.png, bg=transparent,width=900,height=480) data(cars) plot(cars,col=green) dev.off() res$write(' P_Chart_All_Dims.png ') } res$finish() } s = Rhttpd$new() s$add(app = sample, name = visbin) s$start() s$browse(visbin) thanks in advance :) - Thank you, with regards, Punitha -- View this message in context: http://r.789695.n4.nabble.com/problem-in-displaying-image-in-browser-using-Rook-tp4643596.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] Importing a CSV file
Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file A.csv has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Setting library path (again)
Hi, Sorry for posting a question that has been asked before but I couldn't quite find the right answer in previous help topics. I am trying to set my library path to a user-specified library (C:/Users/K/Documents/Work/RLib). I have used .libPaths(C:/Users/K/Documents/Work/RLib) but when I check the .libPaths(), both the user-specified and default libraries appear. It appears that R is still using the default pathway as well (I tried removing certain packages from the user library to see if they still work and they do). I have seen solutions involving setting R_LIB in the .REnviron to the user library but I am unsure as to how to do this; is this done in the R program itself or through other means? I am running 32-bit Windows 7, R version 2.15.1 Again, sorry for the repeat question but setting directories is not my strong point. Kyran. -- Kyran Graham (PhD Candidate) School of Medicine Pharmacology, University of Western Australia (M510) 35 Stirling Highway Crawley, WA 6009 Centre for Clinical Research in Neuropsychiatry, Graylands Hospital Private Bag No 1 Claremont, WA 6910 Phone: 9347 6430 Email: graha...@student.uwa.edu.au [[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] Importing a CSV file
Hi, load() is for R's binary data files. You need to use read.csv(), as you tried, but probably with the complete path. A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) Sarah On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou anthi.oi...@gmail.com wrote: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file ‘A.csv’ has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing a CSV file
Hello, Try ?read.csv. dat - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Note that unlike what happens with load() you'll need an explicit assignment. Hope this helps, Rui Barradas Em 19-09-2012 09:54, Anthi Oikonomou escreveu: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'A.csv' has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Importing a CSV file
Hi, Should'nt it be A - read.csv(C:Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) (c:\\ becomes c:\ In general I think it is better to use / and //) Frans -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Sarah Goslee Verzonden: woensdag 19 september 2012 15:44 Aan: Anthi Oikonomou CC: r-h...@stat.math.ethz.ch Onderwerp: Re: [R] Importing a CSV file Hi, load() is for R's binary data files. You need to use read.csv(), as you tried, but probably with the complete path. A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) Sarah On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou anthi.oi...@gmail.com wrote: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'A.csv' has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Setting library path (again)
On 19/09/2012 6:30 AM, Kyran Graham wrote: Hi, Sorry for posting a question that has been asked before but I couldn't quite find the right answer in previous help topics. I am trying to set my library path to a user-specified library (C:/Users/K/Documents/Work/RLib). I have used .libPaths(C:/Users/K/Documents/Work/RLib) but when I check the .libPaths(), both the user-specified and default libraries appear. It appears that R is still using the default pathway as well (I tried removing certain packages from the user library to see if they still work and they do). I have seen solutions involving setting R_LIB in the .REnviron to the user library but I am unsure as to how to do this; is this done in the R program itself or through other means? I am running 32-bit Windows 7, R version 2.15.1 Again, sorry for the repeat question but setting directories is not my strong point. Depending on the security settings on your computer, you might not be able to do this, or might have to log in as administrator to do it. But here are two ways to set R_LIBS: 1. Outside of R, go into Control Panel | System | Advanced system settings | Environment variables. 2. Under User variables for you, click on New. Set Variable name to R_LIBS. Set variable value to C:/Users/K/Documents/Work/RLib/. (Leave off the quotes. They probably won't hurt, but I haven't tested that...) 3. Click OK enough time to save the changes. The second way is to find where R is installed and edit Renviron.site: 1. Run R.home() within R, to find where R is installed. 2. Outside of R, go to the etc subdirectory of the home directory. Create the Renviron.site file there using Notepad (or edit the existing one). To get it to save the file without a .txt instruction, you'll need to put the name in quotes when you do Save As. 3. In that file, put the line R_LIBS=C:/Users/K/Documents/Work/RLib/ This should work the next time you start R. 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] Importing a CSV file
On Wed, Sep 19, 2012 at 9:53 AM, Frans Marcelissen frans.marcelis...@digipsy.nl wrote: Hi, Should'nt it be A - read.csv(C:Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) (c:\\ becomes c:\ In general I think it is better to use / and //) Frans No idea; I was copying the original poster's version. In this case, it would definitely be better to take advice on path construction from someone who uses Windows! Sarah -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Sarah Goslee Verzonden: woensdag 19 september 2012 15:44 Aan: Anthi Oikonomou CC: r-h...@stat.math.ethz.ch Onderwerp: Re: [R] Importing a CSV file Hi, load() is for R's binary data files. You need to use read.csv(), as you tried, but probably with the complete path. A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) Sarah On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou anthi.oi...@gmail.com wrote: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'A.csv' has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing a CSV file
Em 19-09-2012 15:01, Sarah Goslee escreveu: On Wed, Sep 19, 2012 at 9:53 AM, Frans Marcelissen frans.marcelis...@digipsy.nl wrote: Hi, Should'nt it be A - read.csv(C:Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) (c:\\ becomes c:\ In general I think it is better to use / and //) Frans No idea; I was copying the original poster's version. In this case, it would definitely be better to take advice on path construction from someone who uses Windows! I use Windows and the answer is no, the four backslashes don't make sense, because like Frans said, c:\\ becomes c:\ (There is no such thing as c: --- c:\\). Rui Barradas Sarah -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Sarah Goslee Verzonden: woensdag 19 september 2012 15:44 Aan: Anthi Oikonomou CC: r-h...@stat.math.ethz.ch Onderwerp: Re: [R] Importing a CSV file Hi, load() is for R's binary data files. You need to use read.csv(), as you tried, but probably with the complete path. A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) Sarah On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou anthi.oi...@gmail.com wrote: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'A.csv' has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing a CSV file
On Sep 19, 2012, at 9:26 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Em 19-09-2012 15:01, Sarah Goslee escreveu: On Wed, Sep 19, 2012 at 9:53 AM, Frans Marcelissen frans.marcelis...@digipsy.nl wrote: Hi, Should'nt it be A - read.csv(C:Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) (c:\\ becomes c:\ In general I think it is better to use / and //) Frans No idea; I was copying the original poster's version. In this case, it would definitely be better to take advice on path construction from someone who uses Windows! I use Windows and the answer is no, the four backslashes don't make sense, because like Frans said, c:\\ becomes c:\ (There is no such thing as c: --- c:\\). Rui Barradas Ahoy Mateys, Not to mention, creating file paths on Windows is an A FAQ: http://cran.r-project.org/bin/windows/base/rw-FAQ.html#R-can_0027t-find-my-file Savvy? Marc Schwartz P.S. It's International Talk Like a Pirate Day, which of course fits with a certain language we all hold dear. Somebody had to do it... ;-) Sarah -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Sarah Goslee Verzonden: woensdag 19 september 2012 15:44 Aan: Anthi Oikonomou CC: r-h...@stat.math.ethz.ch Onderwerp: Re: [R] Importing a CSV file Hi, load() is for R's binary data files. You need to use read.csv(), as you tried, but probably with the complete path. A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) Sarah On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou anthi.oi...@gmail.com wrote: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'A.csv' has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why x[1] is not getting substituted?
On Sep 19, 2012, at 6:26 AM, PIKAL Petr wrote: Hi because you need to evaluate it. print(paste(Trial and ,eval(x[1]), sheet)) The eval is superfluous, since paste() already evaluates its unquoted arguments. print(paste(Trial and, x[1], sheet)) [1] Trial and a sheet -- David. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Sri krishna Devarayalu Balanagu Sent: Tuesday, September 18, 2012 11:41 AM To: r-help@r-project.org Subject: [R] Why x[1] is not getting substituted? Suppose I want the output as Trial and a sheet without quotes x=c(a, b, c) print(Trial and x[1] sheet) Getting Trial and x[1] sheet Can anyone help? Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-6692tel:+91-40-6692 and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). [[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. David Winsemius, MD Alameda, CA, 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] effective way to return only the first argument of which()
Hi, I was looking for a function like which() but only returns the first argument. Compare: x - c(1,2,3,4,5,6) y - 4 which(xy) returns: 5,6 which(xy)[1] returns: 5 which(xy)[1] is exactly what i need. I did use this but the dataset is too big (~18 mio. Points). That's why i need a more effective way to get the first element of a vector which is bigger/smaller than a specific number. I found match() but this function only works for equal numbers. Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scraping with session cookies
Thank you for your help Duncan, I have been trying what you suggested however I am getting an error when trying to create the function fun- createFunction(forms[[1]]) it says Error in isHidden I hasDefault : operations are possible only for numeric, logical or complex types On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: Hi ? The key is that you want to use the same curl handle for both the postForm() and for getting the data document. site = u = http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 library(RCurl) curl = getCurlHandle(cookiefile = , verbose = TRUE) postForm(site, disclaimer_action=I Agree) Now we have the cookie in the curl handle so we can use that same curl handle to request the data document: txt = getURLContent(u, curl = curl) Now we can use readHTMLTable() on the local document content: library(XML) tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors = FALSE) Rather than knowing how to post the form, I like to read the form programmatically and generate an R function to do the submission for me. The RHTMLForms package can do this. library(RHTMLForms) forms = getHTMLFormDescription(u, FALSE) fun = createFunction(forms[[1]]) Then we can use fun(.curl = curl) instead of postForm(site, disclaimer_action=I Agree) This helps to abstract the details of the form. D. On 9/18/12 5:57 PM, CPV wrote: Hi, I am starting coding in r and one of the things that i want to do is to scrape some data from the web. The problem that I am having is that I cannot get passed the disclaimer page (which produces a session cookie). I have been able to collect some ideas and combine them in the code below but I dont get passed the disclaimer page. I am trying to agree the disclaimer with the postForm and write the cookie to a file, but I cannot do it succesfully The webpage cookies are written to the file but the value is FALSE... So any ideas of what I should do or what I am doing wrong with? Thank you for your help, library(RCurl) library(XML) site - http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 postForm(site, disclaimer_action=I Agree) cf - cookies.txt no_cookie - function() { curlHandle - getCurlHandle(cookiefile=cf, cookiejar=cf) getURL(site, curl=curlHandle) rm(curlHandle) gc() } if ( file.exists(cf) == TRUE ) { file.create(cf) no_cookie() } allTables - readHTMLTable(site) allTables [[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. [[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] effective way to return only the first argument of which()
On Wed, Sep 19, 2012 at 3:20 PM, Mike Spam ichmags...@googlemail.com wrote: Hi, I was looking for a function like which() but only returns the first argument. Compare: x - c(1,2,3,4,5,6) y - 4 which(xy) returns: 5,6 which(xy)[1] returns: 5 which(xy)[1] is exactly what i need. I did use this but the dataset is too big (~18 mio. Points). That's why i need a more effective way to get the first element of a vector which is bigger/smaller than a specific number. I found match() but this function only works for equal numbers. It's long felt a little hack-ish but you can actually use which.min() or which.max() on logical vectors for just this purpose. x - sample(20) which.max(x 5) # first x satisfying the condition. Cheers, Michael Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] effective way to return only the first argument of which()
?which.max --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Mike Spam ichmags...@googlemail.com wrote: Hi, I was looking for a function like which() but only returns the first argument. Compare: x - c(1,2,3,4,5,6) y - 4 which(xy) returns: 5,6 which(xy)[1] returns: 5 which(xy)[1] is exactly what i need. I did use this but the dataset is too big (~18 mio. Points). That's why i need a more effective way to get the first element of a vector which is bigger/smaller than a specific number. I found match() but this function only works for equal numbers. Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] effective way to return only the first argument of which()
Hi, Thanks Michael, but i think this is even slower. x -sample(2000) which(x 5)[1] which.max(x 5) system.time(for(i in 1:100) which.max(x 5)) User System verstrichen 60.84 13.70 86.33 system.time(for(i in 1:100) which(x 5)[1]) User System verstrichen 40.458.25 48.95 Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] effective way to return only the first argument of which()
The original method is faster than which.max for longish numeric vectors (in R-2.15.1), but you should check time and memory usage on your own machine: x - runif(18e6) system.time(for(i in 1:100)which(x0.99)[1]) user system elapsed 11.641.05 12.70 system.time(for(i in 1:100)which.max(x0.99)) user system elapsed 16.382.94 19.35 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Wednesday, September 19, 2012 8:06 AM To: Mike Spam; r-help@r-project.org Subject: Re: [R] effective way to return only the first argument of which() ?which.max --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Mike Spam ichmags...@googlemail.com wrote: Hi, I was looking for a function like which() but only returns the first argument. Compare: x - c(1,2,3,4,5,6) y - 4 which(xy) returns: 5,6 which(xy)[1] returns: 5 which(xy)[1] is exactly what i need. I did use this but the dataset is too big (~18 mio. Points). That's why i need a more effective way to get the first element of a vector which is bigger/smaller than a specific number. I found match() but this function only works for equal numbers. Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R package for dashboard
What package can be used to produce dashboard in R? Thanks and Regards, Xin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] drop zero slots from table?
I find myself doing --8---cut here---start-8--- tab - table(...) tab - tab[tab 0] tab - sort(tab,decreasing=TRUE) --8---cut here---end---8--- all the time. I am wondering if the drop 0 (and maybe even sort?) can be effected by some magic argument to table() which I fail to discover in the docs? Obviously, I could use droplevels() to avoid 0 counts in the first place, but I do not want to drop the levels in the data. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://ffii.org http://truepeace.org http://www.memritv.org http://honestreporting.com http://dhimmi.com MS Windows: error: the operation completed successfully. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scraping with session cookies
You don't need to use the getHTMLFormDescription() and createFunction(). Instead, you can use the postForm() call. However, getHTMLFormDescription(), etc. is more general. But you need the very latest version of the package to deal with degenerate forms that have no inputs (other than button clicks). You can get the latest version of the RHTMLForms package from github git clone g...@github.com:omegahat/RHTMLForms.git and that has the fixes for handling the degenerate forms with no arguments. D. On 9/19/12 7:51 AM, CPV wrote: Thank you for your help Duncan, I have been trying what you suggested however I am getting an error when trying to create the function fun- createFunction(forms[[1]]) it says Error in isHidden I hasDefault : operations are possible only for numeric, logical or complex types On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: Hi ? The key is that you want to use the same curl handle for both the postForm() and for getting the data document. site = u = http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 library(RCurl) curl = getCurlHandle(cookiefile = , verbose = TRUE) postForm(site, disclaimer_action=I Agree) Now we have the cookie in the curl handle so we can use that same curl handle to request the data document: txt = getURLContent(u, curl = curl) Now we can use readHTMLTable() on the local document content: library(XML) tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors = FALSE) Rather than knowing how to post the form, I like to read the form programmatically and generate an R function to do the submission for me. The RHTMLForms package can do this. library(RHTMLForms) forms = getHTMLFormDescription(u, FALSE) fun = createFunction(forms[[1]]) Then we can use fun(.curl = curl) instead of postForm(site, disclaimer_action=I Agree) This helps to abstract the details of the form. D. On 9/18/12 5:57 PM, CPV wrote: Hi, I am starting coding in r and one of the things that i want to do is to scrape some data from the web. The problem that I am having is that I cannot get passed the disclaimer page (which produces a session cookie). I have been able to collect some ideas and combine them in the code below but I dont get passed the disclaimer page. I am trying to agree the disclaimer with the postForm and write the cookie to a file, but I cannot do it succesfully The webpage cookies are written to the file but the value is FALSE... So any ideas of what I should do or what I am doing wrong with? Thank you for your help, library(RCurl) library(XML) site - http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 postForm(site, disclaimer_action=I Agree) cf - cookies.txt no_cookie - function() { curlHandle - getCurlHandle(cookiefile=cf, cookiejar=cf) getURL(site, curl=curlHandle) rm(curlHandle) gc() } if ( file.exists(cf) == TRUE ) { file.create(cf) no_cookie() } allTables - readHTMLTable(site) allTables [[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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help reproducing a contour plot
Hi All, I am trying to reproduce this using R instead. [image: Full-size image (38 K)] I tried using the following code *SChla - read.csv(SM_Chla_data.csv)* *Atlantis - SChla[16:66,]* *head(Atlantis)* * * Seamount Station Depth Pico Nano Micro Total_Chdbar Latitude Longitud 16 Atlantis1217 Surface 0.0639 0.1560 0.0398 0.2597 2.082 -32.71450 57.29733 17 Atlantis1217 Shallow 0.0305 0.1250 0.0740 0.2295 24.524 -32.71450 57.29733 18 Atlantis1217Deep 0.1660 0.3560 0.0734 0.5954 49.573 -32.71450 57.29733 19 Atlantis1217Fmax 0.1740 0.5200 0.1830 0.8770 79.595 -32.71450 57.29733 20 Atlantis1217 Below 0.0235 0.0486 0.0242 0.0963 199.067 -32.71450 57.29733 21 Atlantis1225 Surface 0.0764 0.1490 0.0333 0.2587 0.409 -32.71133 57.27150 *# Obtaining longitude and depth data* *Long - SMfrac[,6]* *dbar - -SMfrac[,5] #reverse depth* * * *#converting data to percentage of total chl a* * * *picoFrac - Atlantis$Pico/Atlantis$Total_Ch*100* *nanoFrac - Atlantis$Nano/Atlantis$Total_Ch*100* *microFrac - Atlantis$Micro/Atlantis$Total_Ch*100* * * * * *library(akima)* * * *par(mfrow = c(3,1)) * * * *contour(interp(Long, dbar, picoFrac),nlevels = 6,* * xlab =Longitude, main= Pico, * * ylab =Depth, ylim = c(-200,0), method = simple,* * col = light green)* * * *contour(interp(Long, dbar, nanoFrac), nlevels = 6,* * xlab =Longitude, main= Nano,* * ylab =Depth,ylim = c(-200,0), method = simple,* * col = green)* * * *contour(interp(Long, dbar, microFrac),nlevels = 6,* * xlab =Longitude, main= Micro,* * ylab =Depth,ylim = c(-200,0), * * lylab =Depth, method = simple,* * col = dark green)* I can get the contours plotted. Not sure if this is 100 % correct but it looks as expected. Can you guys please help me to add/display my data points. I would also like to fill the contours in grayscale/colour (e.g. levels 0, 20, 40, 60, 80. 100 %) and add a legend to the graph. As of yet I haven't tried to figure out how to add the stations as a secondary axis to the plot. Thanks for the help and advice. Tinus -- M.J. Sonnekus PhD Candidate (The Phytoplankton of the southern Agulhas Current Large Marine Ecosystem (ACLME)) Department of Botany South Campus Nelson Mandela Metropolitan University PO Box 77000 Port Elizabeth South Africa 6031 Cell: 082 080 9638 E-mail: tsonne...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] effective way to return only the first argument of which()
Le mercredi 19 septembre 2012 à 15:23 +, William Dunlap a écrit : The original method is faster than which.max for longish numeric vectors (in R-2.15.1), but you should check time and memory usage on your own machine: x - runif(18e6) system.time(for(i in 1:100)which(x0.99)[1]) user system elapsed 11.641.05 12.70 system.time(for(i in 1:100)which.max(x0.99)) user system elapsed 16.382.94 19.35 If you the probability that such an element appears at the beginning of the vector, a custom hack might well be more efficient. The problem with , which() and which.max() is that they will go over all the elements of the vector even if it's not needed at all. So you can start with a small subset of the vector, and increase its size in a few steps until you find the value you're looking for. Proof of concept (the values of n obviously need to be adapted): x -runif(1e7) find - function(x, lim) { len - length(x) for(n in 2^(14:0)) { val - which(x[seq.int(1L, len/n)] lim) if(length(val) 0) return(val[1]) } return(NULL) } system.time(for(i in 1:100)which(x0.999)[1]) utilisateur système écoulé 9.740 5.795 15.890 system.time(for(i in 1:100)which.max(x0.999)) utilisateur système écoulé 14.288 9.510 24.562 system.time(for(i in 1:100)find(x, .999)) utilisateur système écoulé 0.017 0.002 0.019 find(x, .999) [1] 1376 (Looks almost like cheating... ;-) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Wednesday, September 19, 2012 8:06 AM To: Mike Spam; r-help@r-project.org Subject: Re: [R] effective way to return only the first argument of which() ?which.max --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Mike Spam ichmags...@googlemail.com wrote: Hi, I was looking for a function like which() but only returns the first argument. Compare: x - c(1,2,3,4,5,6) y - 4 which(xy) returns: 5,6 which(xy)[1] returns: 5 which(xy)[1] is exactly what i need. I did use this but the dataset is too big (~18 mio. Points). That's why i need a more effective way to get the first element of a vector which is bigger/smaller than a specific number. I found match() but this function only works for equal numbers. Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R package for dashboard
Depends on your requirement . Who is going to use it. Do you want something like running in browser or something like excel or somewhat different like Tcl tk. Best Regards, Bhupendrasinh Thakre Sent from my iPhone On Sep 19, 2012, at 10:48 AM, XINLI LI lihaw...@gmail.com wrote: What package can be used to produce dashboard in R? Thanks and Regards, Xin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] drop zero slots from table?
Function --8---cut here---start-8--- sorted.table - function (vec) { tab - table(vec) tab - tab[tab 0] sort(tab, decreasing=TRUE) } --8---cut here---end---8--- does what I want but it prints vec instead of the name of its argument: --8---cut here---start-8--- sorted.table(foo$bar) vec A B 10 3 --8---cut here---end---8--- how do I pass all arguments of sorted.table() on to table() as is? thanks! * Sam Steingold f...@tah.bet [2012-09-19 11:51:08 -0400]: I find myself doing tab - table(...) tab - tab[tab 0] tab - sort(tab,decreasing=TRUE) all the time. I am wondering if the drop 0 (and maybe even sort?) can be effected by some magic argument to table() which I fail to discover in the docs? Obviously, I could use droplevels() to avoid 0 counts in the first place, but I do not want to drop the levels in the data. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://memri.org http://thereligionofpeace.com http://www.PetitionOnline.com/tap12009/ http://dhimmi.com Beauty is only a light switch away. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drop zero slots from table?
Here is one way: sorted.table - function(x, name = if (is.list(x))names(x) else deparse(substitute(x))[1]) { +tab - table(x) +names(dimnames(tab)) - name +tab - tab[tab 0] +sort(tab, decreasing=TRUE) + } digits - factor(trunc(100*log2(1:20)%%.1), levels=0:9) sorted.table(digits) digits 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(data.frame(DigitsColumn=digits)) DigitsColumn 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(digits, name=My Digits) My Digits 0 8 2 6 4 5 9 4 3 2 1 1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Steingold Sent: Wednesday, September 19, 2012 9:13 AM To: r-help@r-project.org Subject: Re: [R] drop zero slots from table? Function --8---cut here---start-8--- sorted.table - function (vec) { tab - table(vec) tab - tab[tab 0] sort(tab, decreasing=TRUE) } --8---cut here---end---8--- does what I want but it prints vec instead of the name of its argument: --8---cut here---start-8--- sorted.table(foo$bar) vec A B 10 3 --8---cut here---end---8--- how do I pass all arguments of sorted.table() on to table() as is? thanks! * Sam Steingold f...@tah.bet [2012-09-19 11:51:08 -0400]: I find myself doing tab - table(...) tab - tab[tab 0] tab - sort(tab,decreasing=TRUE) all the time. I am wondering if the drop 0 (and maybe even sort?) can be effected by some magic argument to table() which I fail to discover in the docs? Obviously, I could use droplevels() to avoid 0 counts in the first place, but I do not want to drop the levels in the data. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://memri.org http://thereligionofpeace.com http://www.PetitionOnline.com/tap12009/ http://dhimmi.com Beauty is only a light switch away. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why x[1] is not getting substituted?
I nominate Jim's answer below for the fortunes package. On Wed, Sep 19, 2012 at 3:50 AM, Jim Lemon j...@bitwrit.com.au wrote: Sri krishna Devarayalu Balanagu wrote: Suppose I want the output as Trial and a sheet without quotes x=c(a, b, c) print(Trial and x[1] sheet) Getting Trial and x[1] sheet Can anyone help? And for your sins in not reading the documentation: cat(paste(rev(c(sheet,x[1],and,Trial))),\n) R helps those who help themselves 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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] export date field using sqlSave
Hello- I'm receiving an error when I try to export a dataframe into Access 2010 containing a date field using sqlSave. The error I'm receiving is: [RODBC] Failed exec in Update 22018 39 [Microsoft][ODBC Microsoft Access Driver]Invalid character value for cast specification I can export all other columns, except the date column. If I convert the date column to julian (numeric) it works fine, but if I keep it as POSIXct, POSIXt, or date, it will return the same error. I'm using RODBC version 1.3-6. Thank you -al __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] write.table: strange output has been produced
Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Intracellular trafficking, secretion, and 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p CytoskeletonCELLULAR PROCESSES AND SIGNALING 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p Intracellular trafficking, secretion, and vesicular transport CELLU and metabolism METABOLISM 8 And this is a piece of code that produced this: 8 n = nrow(statdata) extra = data.frame(kogdefline=rep(NA,n), kogClass = rep(NA,n), kogGroup = rep(NA,n)) subset = intersect(statdata$id, annot$id) MR = match(subset, annot$id) ML = match(subset, statdata$id) extra[ML,1] = as.character(annot[MR,2]) extra[ML,2] = as.character(annot[MR,3]) extra[ML,3] = as.character(annot[MR,4]) # strangely, if I do # extra[ML,] = as.character(annot[MR,2:4]) # it produces digits (???) instead of a string value mergedData = data.frame(statdata, extra) write.table(mergedData, 'filename.csv', sep=',') 8 Any ideas why this is happening? Many thanks -Igor __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Warning Message: In if (deparse(params[[nm]][[3]]) != 1)
I am using the gnls procedure in nlme package to fit a nonlinear model as: nl.fit-gnls(Y ~ b0*exp(b1/X), data = data1, params=list( b0~p1+I(p1^2)+p2+I(p2^2)+p3+I(p3^2)+p5+p6 b1~p8+p2+I(p2^2)+p3+p9+p10+p11), start = c(25,0,0,0,0,0,0,0,0,-8.6,0,0,0,0,0,0,0), weights=varPower(form =~ X) ) When I run this code, the model getts fitted but there are 2 warning messages as Warning messages: 1: In if (deparse(params[[nm]][[3]]) != 1) { : the condition has length 1 and only the first element will be used 2: In if (deparse(params[[nm]][[3]]) != 1) { : the condition has length 1 and only the first element will be used I have no idea what there messages imply. Any idea from somebody? Charles -- View this message in context: http://r.789695.n4.nabble.com/Warning-Message-In-if-deparse-params-nm-3-1-tp4643638.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] R package for dashboard
One of the package which I know of is rgooglevis. However there should be some more in the same line. Copying it to the list so someone else also chime in for answer. Best Regards, Bhupendrasinh Thakre Sent from my iPhone On Sep 19, 2012, at 11:52 AM, XINLI LI lihaw...@gmail.com wrote: Thank you very much for reply, my intention is to load them directly into browser. Could you let me know what is the best way to do it? Regards, xin On 9/19/12, Bhupendrasinh Thakre vickytha...@gmail.com wrote: Depends on your requirement . Who is going to use it. Do you want something like running in browser or something like excel or somewhat different like Tcl tk. Best Regards, Bhupendrasinh Thakre Sent from my iPhone On Sep 19, 2012, at 10:48 AM, XINLI LI lihaw...@gmail.com wrote: What package can be used to produce dashboard in R? Thanks and Regards, Xin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] scraping with session cookies
Thanks again, I run the script with the postForm(site, disclaimer_action=I Agree) and it does not seem to do anything, the webpage is still the disclaimer page thus I am getting the error below Error in function (classes, fdef, mtable) : unable to find an inherited method for function readHTMLTable, for signature NULL I also downloaded the latest version of RHTMLForms (omegahat-RHTMLForms-251743f.zip) and it does not seem to install correctly.. I used the code install.packages(C:/Users/cess/Downloads/omegahat-RHTMLForms-251743f.zip, type=win.binary, repos=NULL) Any suggestion of what could be causing these problems? On Wed, Sep 19, 2012 at 9:49 AM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: You don't need to use the getHTMLFormDescription() and createFunction(). Instead, you can use the postForm() call. However, getHTMLFormDescription(), etc. is more general. But you need the very latest version of the package to deal with degenerate forms that have no inputs (other than button clicks). You can get the latest version of the RHTMLForms package from github git clone g...@github.com:omegahat/RHTMLForms.git and that has the fixes for handling the degenerate forms with no arguments. D. On 9/19/12 7:51 AM, CPV wrote: Thank you for your help Duncan, I have been trying what you suggested however I am getting an error when trying to create the function fun- createFunction(forms[[1]]) it says Error in isHidden I hasDefault : operations are possible only for numeric, logical or complex types On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: Hi ? The key is that you want to use the same curl handle for both the postForm() and for getting the data document. site = u = http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 library(RCurl) curl = getCurlHandle(cookiefile = , verbose = TRUE) postForm(site, disclaimer_action=I Agree) Now we have the cookie in the curl handle so we can use that same curl handle to request the data document: txt = getURLContent(u, curl = curl) Now we can use readHTMLTable() on the local document content: library(XML) tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors = FALSE) Rather than knowing how to post the form, I like to read the form programmatically and generate an R function to do the submission for me. The RHTMLForms package can do this. library(RHTMLForms) forms = getHTMLFormDescription(u, FALSE) fun = createFunction(forms[[1]]) Then we can use fun(.curl = curl) instead of postForm(site, disclaimer_action=I Agree) This helps to abstract the details of the form. D. On 9/18/12 5:57 PM, CPV wrote: Hi, I am starting coding in r and one of the things that i want to do is to scrape some data from the web. The problem that I am having is that I cannot get passed the disclaimer page (which produces a session cookie). I have been able to collect some ideas and combine them in the code below but I dont get passed the disclaimer page. I am trying to agree the disclaimer with the postForm and write the cookie to a file, but I cannot do it succesfully The webpage cookies are written to the file but the value is FALSE... So any ideas of what I should do or what I am doing wrong with? Thank you for your help, library(RCurl) library(XML) site - http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 postForm(site, disclaimer_action=I Agree) cf - cookies.txt no_cookie - function() { curlHandle - getCurlHandle(cookiefile=cf, cookiejar=cf) getURL(site, curl=curlHandle) rm(curlHandle) gc() } if ( file.exists(cf) == TRUE ) { file.create(cf) no_cookie() } allTables - readHTMLTable(site) allTables [[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. [[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,
Re: [R] Warning Message: In if (deparse(params[[nm]][[3]]) != 1)
Usually the source of such errors is the data you provide to the function. Since you have not followed the posting guide and provided a reproducible example, we are under a significant handicap in troubleshooting your problem. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. obuyacharles csaba...@vt.edu wrote: I am using the gnls procedure in nlme package to fit a nonlinear model as: nl.fit-gnls(Y ~ b0*exp(b1/X), data = data1, params=list( b0~p1+I(p1^2)+p2+I(p2^2)+p3+I(p3^2)+p5+p6 b1~p8+p2+I(p2^2)+p3+p9+p10+p11), start = c(25,0,0,0,0,0,0,0,0,-8.6,0,0,0,0,0,0,0), weights=varPower(form =~ X) ) When I run this code, the model getts fitted but there are 2 warning messages as Warning messages: 1: In if (deparse(params[[nm]][[3]]) != 1) { : the condition has length 1 and only the first element will be used 2: In if (deparse(params[[nm]][[3]]) != 1) { : the condition has length 1 and only the first element will be used I have no idea what there messages imply. Any idea from somebody? Charles -- View this message in context: http://r.789695.n4.nabble.com/Warning-Message-In-if-deparse-params-nm-3-1-tp4643638.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] write.table: strange output has been produced
On Sep 19, 2012, at 9:12 AM, Igor wrote: Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Intracellular trafficking, secretion, and 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p CytoskeletonCELLULAR PROCESSES AND SIGNALING 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p Intracellular trafficking, secretion, and vesicular transport CELLU and metabolism METABOLISM This looks like the sort of thing that occurs when there is a mismatched or missing double or single quote or perhaps comment character ( # that terminated a line read) somewhare. The logical place to look is in the line of data just above the pathological stretch of data. You have clearly only offered a truncated version of the data, since there are many instances of lines ending without matching quotes, even one in the first line. -- David. 8 And this is a piece of code that produced this: 8 n = nrow(statdata) extra = data.frame(kogdefline=rep(NA,n), kogClass = rep(NA,n), kogGroup = rep(NA,n)) subset = intersect(statdata$id, annot$id) MR = match(subset, annot$id) ML = match(subset, statdata$id) extra[ML,1] = as.character(annot[MR,2]) extra[ML,2] = as.character(annot[MR,3]) extra[ML,3] = as.character(annot[MR,4]) # strangely, if I do # extra[ML,] = as.character(annot[MR,2:4]) # it produces digits (???) instead of a string value mergedData = data.frame(statdata, extra) write.table(mergedData, 'filename.csv', sep=',') 8 Any ideas why this is happening? Many thanks -Igor David Winsemius, MD Alameda, CA, 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.
Re: [R] write.table: strange output has been produced
It would also be helpful if you could provide the output of 'str' for all the objects that you are using. e.g., str(statdata)str(extra) Also in creating your data.frame, use stringsAsFactors = FALSE: extra = data.frame(kogdefline=rep(NA,n) , kogClass = rep(NA,n) , kogGroup = rep(NA,n) , stringsAsFactors = FALSE ) On Wed, Sep 19, 2012 at 12:12 PM, Igor ig...@essex.ac.uk wrote: Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Intracellular trafficking, secretion, and 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p CytoskeletonCELLULAR PROCESSES AND SIGNALING 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p Intracellular trafficking, secretion, and vesicular transport CELLU and metabolism METABOLISM 8 And this is a piece of code that produced this: 8 n = nrow(statdata) extra = data.frame(kogdefline=rep(NA,n), kogClass = rep(NA,n), kogGroup = rep(NA,n)) subset = intersect(statdata$id, annot$id) MR = match(subset, annot$id) ML = match(subset, statdata$id) extra[ML,1] = as.character(annot[MR,2]) extra[ML,2] = as.character(annot[MR,3]) extra[ML,3] = as.character(annot[MR,4]) # strangely, if I do # extra[ML,] = as.character(annot[MR,2:4]) # it produces digits (???) instead of a string value mergedData = data.frame(statdata, extra) write.table(mergedData, 'filename.csv', sep=',') 8 Any ideas why this is happening? Many thanks -Igor __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the
[R] Multi lines in R plot
Dear R users, I'm plotting 5 loess smooth lines in one paragraph. Since the publisher does not print colorful pictures, I differentiate them by using different line types. I'm wondering if there are other options to make the graph more readable. It is really difficult for readers to tell the differences between those dash lines. Thanks. Gary [[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] drop zero slots from table?
cool, thanks! Still, I wonder if there is a way to pass all args as is from a function downward (like in a lisp macro); something like sorted.table - function (...) { tab - table(...); ... } * William Dunlap jqha...@gvopb.pbz [2012-09-19 16:26:08 +]: Here is one way: sorted.table - function(x, name = if (is.list(x))names(x) else deparse(substitute(x))[1]) { +tab - table(x) +names(dimnames(tab)) - name +tab - tab[tab 0] +sort(tab, decreasing=TRUE) + } digits - factor(trunc(100*log2(1:20)%%.1), levels=0:9) sorted.table(digits) digits 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(data.frame(DigitsColumn=digits)) DigitsColumn 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(digits, name=My Digits) My Digits 0 8 2 6 4 5 9 4 3 2 1 1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Steingold Sent: Wednesday, September 19, 2012 9:13 AM To: r-help@r-project.org Subject: Re: [R] drop zero slots from table? Function --8---cut here---start-8--- sorted.table - function (vec) { tab - table(vec) tab - tab[tab 0] sort(tab, decreasing=TRUE) } --8---cut here---end---8--- does what I want but it prints vec instead of the name of its argument: --8---cut here---start-8--- sorted.table(foo$bar) vec A B 10 3 --8---cut here---end---8--- how do I pass all arguments of sorted.table() on to table() as is? thanks! * Sam Steingold f...@tah.bet [2012-09-19 11:51:08 -0400]: I find myself doing tab - table(...) tab - tab[tab 0] tab - sort(tab,decreasing=TRUE) all the time. I am wondering if the drop 0 (and maybe even sort?) can be effected by some magic argument to table() which I fail to discover in the docs? Obviously, I could use droplevels() to avoid 0 counts in the first place, but I do not want to drop the levels in the data. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://memri.org http://thereligionofpeace.com http://www.PetitionOnline.com/tap12009/ http://dhimmi.com Beauty is only a light switch away. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://thereligionofpeace.com http://mideasttruth.com http://palestinefacts.org http://openvotingconsortium.org http://truepeace.org If you will not bring your husband coffee in bed, his day may start with a beer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] where are these NAs coming from?
I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://ffii.org http://honestreporting.com http://camera.org http://www.memritv.org http://dhimmi.com I don't like cats! -- Come on, you just don't know how to cook them! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are these NAs coming from?
Well, you have no reproducible example, but I suspect either of these will fix it: locals - z[z$country == mycountry !is.na(z$country),] locals - subset(z, country == mycountry) Sarah On Wed, Sep 19, 2012 at 1:50 PM, Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are these NAs coming from?
At least provide a reproducible example by creating the problem with a subset of 'z' and 'mycountry' Could something like this be happening? x - data.frame(country = 1:5, language = 1:5) mycountry - NA z - x[x$country == mycountry,] z country language NANA NA NA.1 NA NA NA.2 NA NA NA.3 NA NA NA.4 NA NA On Wed, Sep 19, 2012 at 1:50 PM, Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://ffii.org http://honestreporting.com http://camera.org http://www.memritv.org http://dhimmi.com I don't like cats! -- Come on, you just don't know how to cook them! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] effective way to return only the first argument of which()
Well, following up on this observation, which can be put under the heading of Sometimes vectorization can be much slower than explicit loops , I offer the following: firsti -function(x,k) { i - 1 while(x[i]=k){i - i+1} i } system.time(for(i in 1:100)which(x.99)[1]) user system elapsed 19.1 2.422.2 system.time(for(i in 1:100)which.max(x.99)) user system elapsed 30.456.75 37.46 system.time(for(i in 1:100)firsti(x,.99)) user system elapsed 0.030.000.03 ## About a 500 - 1000 fold speedup ! firsti(x,.99) [1] 122 It doesn't seem to scale too badly, either (whatever THAT means!): (Of course, the which() versions are essentially identical in timing, and so are omitted) system.time(for(i in 1:100)firsti(x,.)) user system elapsed 2.700.002.72 firsti(x,.) [1] 18200 Of course, at some point, the explicit looping is awful -- with k = .99, the index was about 36, and the timing test took 54 seconds. So I guess the point is -- as always -- that the optimal approach depends on the nature of the data. Prudence and robustness clearly demands the vectorized which() approaches if you have no information. But if you do know something about the data, then you can often write much faster tailored solutions. Which is hardly revelatory, of course. Cheers to all, Bert On Wed, Sep 19, 2012 at 8:55 AM, Milan Bouchet-Valat nalimi...@club.fr wrote: Le mercredi 19 septembre 2012 à 15:23 +, William Dunlap a écrit : The original method is faster than which.max for longish numeric vectors (in R-2.15.1), but you should check time and memory usage on your own machine: x - runif(18e6) system.time(for(i in 1:100)which(x0.99)[1]) user system elapsed 11.641.05 12.70 system.time(for(i in 1:100)which.max(x0.99)) user system elapsed 16.382.94 19.35 If you the probability that such an element appears at the beginning of the vector, a custom hack might well be more efficient. The problem with , which() and which.max() is that they will go over all the elements of the vector even if it's not needed at all. So you can start with a small subset of the vector, and increase its size in a few steps until you find the value you're looking for. Proof of concept (the values of n obviously need to be adapted): x -runif(1e7) find - function(x, lim) { len - length(x) for(n in 2^(14:0)) { val - which(x[seq.int(1L, len/n)] lim) if(length(val) 0) return(val[1]) } return(NULL) } system.time(for(i in 1:100)which(x0.999)[1]) utilisateur système écoulé 9.740 5.795 15.890 system.time(for(i in 1:100)which.max(x0.999)) utilisateur système écoulé 14.288 9.510 24.562 system.time(for(i in 1:100)find(x, .999)) utilisateur système écoulé 0.017 0.002 0.019 find(x, .999) [1] 1376 (Looks almost like cheating... ;-) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Wednesday, September 19, 2012 8:06 AM To: Mike Spam; r-help@r-project.org Subject: Re: [R] effective way to return only the first argument of which() ?which.max --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Mike Spam ichmags...@googlemail.com wrote: Hi, I was looking for a function like which() but only returns the first argument. Compare: x - c(1,2,3,4,5,6) y - 4 which(xy) returns: 5,6 which(xy)[1] returns: 5 which(xy)[1] is exactly what i need. I did use this but the dataset is too big (~18 mio. Points). That's why i need a more effective way to get the first element of a vector which is bigger/smaller than a specific number. I found match() but this function only works for equal numbers. Thanks, Nico __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
Re: [R] where are these NAs coming from?
Thanks, Sarah, your answer is, indeed, revealing: --8---cut here---start-8--- z - data.frame(a=c(1,2,3),b=c(5,6,NA)) z a b 1 1 5 2 2 6 3 3 NA z[z$b==6,] a b 2 2 6 NA NA NA --8---cut here---end---8--- why do I get an extra all NA row? * Sarah Goslee fnenu.tbf...@tznvy.pbz [2012-09-19 13:54:56 -0400]: Well, you have no reproducible example, but I suspect either of these will fix it: locals - z[z$country == mycountry !is.na(z$country),] locals - subset(z, country == mycountry) Sarah On Wed, Sep 19, 2012 at 1:50 PM, Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://americancensorship.org http://honestreporting.com http://truepeace.org http://ffii.org .ACMD setaloiv siht gnidaeR __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are these NAs coming from?
On 19/09/2012 1:50 PM, Sam Steingold wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! Why not look? z may be big, but which(is.na(locals$language)) only contains 229 values, and you could look at the z rows for those (or the first few of them if 229 is too many). 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] where are these NAs coming from?
R doesn't know whether the missing (NA) value is 6 or not, so by default it returns it so the user can make up her own mind. If you're using square brackets for subsetting, you need to explicitly handle NA cases. If using subset(), the default behavior is to remove them. ?[ explains this. Sarah On Wed, Sep 19, 2012 at 2:03 PM, Sam Steingold s...@gnu.org wrote: Thanks, Sarah, your answer is, indeed, revealing: --8---cut here---start-8--- z - data.frame(a=c(1,2,3),b=c(5,6,NA)) z a b 1 1 5 2 2 6 3 3 NA z[z$b==6,] a b 2 2 6 NA NA NA --8---cut here---end---8--- why do I get an extra all NA row? * Sarah Goslee fnenu.tbf...@tznvy.pbz [2012-09-19 13:54:56 -0400]: Well, you have no reproducible example, but I suspect either of these will fix it: locals - z[z$country == mycountry !is.na(z$country),] locals - subset(z, country == mycountry) Sarah On Wed, Sep 19, 2012 at 1:50 PM, Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drop zero slots from table?
Why don't you try that and tell us if it works? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: Sam Steingold [mailto:sam.steing...@gmail.com] On Behalf Of Sam Steingold Sent: Wednesday, September 19, 2012 10:48 AM To: r-help@r-project.org; William Dunlap Subject: Re: drop zero slots from table? cool, thanks! Still, I wonder if there is a way to pass all args as is from a function downward (like in a lisp macro); something like sorted.table - function (...) { tab - table(...); ... } * William Dunlap jqha...@gvopb.pbz [2012-09-19 16:26:08 +]: Here is one way: sorted.table - function(x, name = if (is.list(x))names(x) else deparse(substitute(x))[1]) { +tab - table(x) +names(dimnames(tab)) - name +tab - tab[tab 0] +sort(tab, decreasing=TRUE) + } digits - factor(trunc(100*log2(1:20)%%.1), levels=0:9) sorted.table(digits) digits 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(data.frame(DigitsColumn=digits)) DigitsColumn 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(digits, name=My Digits) My Digits 0 8 2 6 4 5 9 4 3 2 1 1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Steingold Sent: Wednesday, September 19, 2012 9:13 AM To: r-help@r-project.org Subject: Re: [R] drop zero slots from table? Function --8---cut here---start-8--- sorted.table - function (vec) { tab - table(vec) tab - tab[tab 0] sort(tab, decreasing=TRUE) } --8---cut here---end---8--- does what I want but it prints vec instead of the name of its argument: --8---cut here---start-8--- sorted.table(foo$bar) vec A B 10 3 --8---cut here---end---8--- how do I pass all arguments of sorted.table() on to table() as is? thanks! * Sam Steingold f...@tah.bet [2012-09-19 11:51:08 -0400]: I find myself doing tab - table(...) tab - tab[tab 0] tab - sort(tab,decreasing=TRUE) all the time. I am wondering if the drop 0 (and maybe even sort?) can be effected by some magic argument to table() which I fail to discover in the docs? Obviously, I could use droplevels() to avoid 0 counts in the first place, but I do not want to drop the levels in the data. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://memri.org http://thereligionofpeace.com http://www.PetitionOnline.com/tap12009/ http://dhimmi.com Beauty is only a light switch away. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://thereligionofpeace.com http://mideasttruth.com http://palestinefacts.org http://openvotingconsortium.org http://truepeace.org If you will not bring your husband coffee in bed, his day may start with a beer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are these NAs coming from?
I don't. You are getting to be a regular around here, so you should know better by now. Please stop posting non-reproducible sample code. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drop zero slots from table?
* William Dunlap jqha...@gvopb.pbz [2012-09-19 18:20:50 +]: Why don't you try that and tell us if it works? Because in my wildest dreams it did not occur to me that this could be valid code in any programming language. It appears to be valid R, which seems to be out-perling Perl at every turn. However, it does not do what I want: it does not result in the right name for the returned table. Thanks a lot for your insight! -Original Message- From: Sam Steingold [mailto:sam.steing...@gmail.com] On Behalf Of Sam Steingold Sent: Wednesday, September 19, 2012 10:48 AM To: r-help@r-project.org; William Dunlap Subject: Re: drop zero slots from table? cool, thanks! Still, I wonder if there is a way to pass all args as is from a function downward (like in a lisp macro); something like sorted.table - function (...) { tab - table(...); ... } * William Dunlap jqha...@gvopb.pbz [2012-09-19 16:26:08 +]: Here is one way: sorted.table - function(x, name = if (is.list(x))names(x) else deparse(substitute(x))[1]) { +tab - table(x) +names(dimnames(tab)) - name +tab - tab[tab 0] +sort(tab, decreasing=TRUE) + } digits - factor(trunc(100*log2(1:20)%%.1), levels=0:9) sorted.table(digits) digits 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(data.frame(DigitsColumn=digits)) DigitsColumn 0 8 2 6 4 5 9 4 3 2 1 1 sorted.table(digits, name=My Digits) My Digits 0 8 2 6 4 5 9 4 3 2 1 1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Steingold Sent: Wednesday, September 19, 2012 9:13 AM To: r-help@r-project.org Subject: Re: [R] drop zero slots from table? Function --8---cut here---start-8--- sorted.table - function (vec) { tab - table(vec) tab - tab[tab 0] sort(tab, decreasing=TRUE) } --8---cut here---end---8--- does what I want but it prints vec instead of the name of its argument: --8---cut here---start-8--- sorted.table(foo$bar) vec A B 10 3 --8---cut here---end---8--- how do I pass all arguments of sorted.table() on to table() as is? thanks! * Sam Steingold f...@tah.bet [2012-09-19 11:51:08 -0400]: I find myself doing tab - table(...) tab - tab[tab 0] tab - sort(tab,decreasing=TRUE) all the time. I am wondering if the drop 0 (and maybe even sort?) can be effected by some magic argument to table() which I fail to discover in the docs? Obviously, I could use droplevels() to avoid 0 counts in the first place, but I do not want to drop the levels in the data. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://memri.org http://thereligionofpeace.com http://www.PetitionOnline.com/tap12009/ http://dhimmi.com Beauty is only a light switch away. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://thereligionofpeace.com http://mideasttruth.com http://palestinefacts.org http://openvotingconsortium.org http://truepeace.org If you will not bring your husband coffee in bed, his day may start with a beer. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://truepeace.org http://iris.org.il http://thereligionofpeace.com http://palestinefacts.org Feynman: 'Philosophy of science is as useful to scientists as ornithology is to birds' __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are these NAs coming from?
* jim holtman wubyg...@tznvy.pbz [2012-09-19 13:58:08 -0400]: At least provide a reproducible example by creating the problem with a subset of 'z' and 'mycountry' if I knew how to reproduce the problem, I would have known what was going on. Could something like this be happening? precisely, thanks! x - data.frame(country = 1:5, language = 1:5) mycountry - NA z - x[x$country == mycountry,] z country language NANA NA NA.1 NA NA NA.2 NA NA NA.3 NA NA NA.4 NA NA On Wed, Sep 19, 2012 at 1:50 PM, Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://ffii.org http://honestreporting.com http://camera.org http://www.memritv.org http://dhimmi.com I don't like cats! -- Come on, you just don't know how to cook them! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://ffii.org http://camera.org http://jihadwatch.org http://americancensorship.org http://mideasttruth.com Independence: nobody pays for you. Liberty: nobody thinks for you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] effective way to return only the first argument of which()
On 19-09-2012, at 20:02, Bert Gunter wrote: Well, following up on this observation, which can be put under the heading of Sometimes vectorization can be much slower than explicit loops , I offer the following: firsti -function(x,k) { i - 1 while(x[i]=k){i - i+1} i } system.time(for(i in 1:100)which(x.99)[1]) user system elapsed 19.1 2.422.2 system.time(for(i in 1:100)which.max(x.99)) user system elapsed 30.456.75 37.46 system.time(for(i in 1:100)firsti(x,.99)) user system elapsed 0.030.000.03 ## About a 500 - 1000 fold speedup ! firsti(x,.99) [1] 122 It doesn't seem to scale too badly, either (whatever THAT means!): (Of course, the which() versions are essentially identical in timing, and so are omitted) system.time(for(i in 1:100)firsti(x,.)) user system elapsed 2.700.002.72 firsti(x,.) [1] 18200 Of course, at some point, the explicit looping is awful -- with k = .99, the index was about 36, and the timing test took 54 seconds. So I guess the point is -- as always -- that the optimal approach depends on the nature of the data. Prudence and robustness clearly demands the vectorized which() approaches if you have no information. But if you do know something about the data, then you can often write much faster tailored solutions. Which is hardly revelatory, of course. And compiling the firsti function can also be quite lucrative! firsti - function(x,k) { i - 1 while(x[i]=k){i - i+1} i } library(compiler) firsti.c - cmpfun(firsti) firsti(x,.99) [1] 93 firsti.c(x,.99) [1] 93 system.time(for(i in 1:100)firsti(x,.99)) user system elapsed 0.014 0.000 0.013 system.time(for(i in 1:100)firsti.c(x,.99)) user system elapsed 0.002 0.000 0.002 system.time(for(i in 1:100)firsti(x,.)) user system elapsed 2.148 0.013 2.164 system.time(for(i in 1:100)firsti.c(x,.)) user system elapsed 0.393 0.002 0.396 And in a new run (without the above tests) with k=.99 the index was 1089653 and the timing for the uncompiled function was 152 seconds and the timing for the compiled function was 28.8 seconds! Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] effective way to return only the first argument of which()
Excellent point! Thanks. -- Bert On Wed, Sep 19, 2012 at 12:00 PM, Berend Hasselman b...@xs4all.nl wrote: On 19-09-2012, at 20:02, Bert Gunter wrote: Well, following up on this observation, which can be put under the heading of Sometimes vectorization can be much slower than explicit loops , I offer the following: firsti -function(x,k) { i - 1 while(x[i]=k){i - i+1} i } system.time(for(i in 1:100)which(x.99)[1]) user system elapsed 19.1 2.422.2 system.time(for(i in 1:100)which.max(x.99)) user system elapsed 30.456.75 37.46 system.time(for(i in 1:100)firsti(x,.99)) user system elapsed 0.030.000.03 ## About a 500 - 1000 fold speedup ! firsti(x,.99) [1] 122 It doesn't seem to scale too badly, either (whatever THAT means!): (Of course, the which() versions are essentially identical in timing, and so are omitted) system.time(for(i in 1:100)firsti(x,.)) user system elapsed 2.700.002.72 firsti(x,.) [1] 18200 Of course, at some point, the explicit looping is awful -- with k = .99, the index was about 36, and the timing test took 54 seconds. So I guess the point is -- as always -- that the optimal approach depends on the nature of the data. Prudence and robustness clearly demands the vectorized which() approaches if you have no information. But if you do know something about the data, then you can often write much faster tailored solutions. Which is hardly revelatory, of course. And compiling the firsti function can also be quite lucrative! firsti - function(x,k) { i - 1 while(x[i]=k){i - i+1} i } library(compiler) firsti.c - cmpfun(firsti) firsti(x,.99) [1] 93 firsti.c(x,.99) [1] 93 system.time(for(i in 1:100)firsti(x,.99)) user system elapsed 0.014 0.000 0.013 system.time(for(i in 1:100)firsti.c(x,.99)) user system elapsed 0.002 0.000 0.002 system.time(for(i in 1:100)firsti(x,.)) user system elapsed 2.148 0.013 2.164 system.time(for(i in 1:100)firsti.c(x,.)) user system elapsed 0.393 0.002 0.396 And in a new run (without the above tests) with k=.99 the index was 1089653 and the timing for the uncompiled function was 152 seconds and the timing for the compiled function was 28.8 seconds! Berend -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] where are these NAs coming from?
if I knew how to reproduce the problem, I would have known what was going on. This is a worthless excuse. You are the one with the example in front of you. I grant that paring it down to email size can take some time, but every second of that time is worthwhile, and at least half the battle is having data that triggers the problem. So learn to use dput() to put a few records of the offending data into each email when you put your code into the email, and give it a test drive pin a clean R environment and voila, you too can make a reproducible example. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Sam Steingold s...@gnu.org wrote: * jim holtman wubyg...@tznvy.pbz [2012-09-19 13:58:08 -0400]: At least provide a reproducible example by creating the problem with a subset of 'z' and 'mycountry' if I knew how to reproduce the problem, I would have known what was going on. Could something like this be happening? precisely, thanks! x - data.frame(country = 1:5, language = 1:5) mycountry - NA z - x[x$country == mycountry,] z country language NANA NA NA.1 NA NA NA.2 NA NA NA.3 NA NA NA.4 NA NA On Wed, Sep 19, 2012 at 1:50 PM, Sam Steingold s...@gnu.org wrote: I see this: --8---cut here---start-8--- length(which(is.na(z$language))) [1] 0 locals - z[z$country == mycountry,] length(which(is.na(locals$language))) [1] 229 --8---cut here---end---8--- where are those locals without the language coming from?! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://ffii.org http://honestreporting.com http://camera.org http://www.memritv.org http://dhimmi.com I don't like cats! -- Come on, you just don't know how to cook them! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Warning Message: In if (deparse(params[[nm]][[3]]) != 1)
I am not sure if it is possible to provide a data set sufficient to fit this model and reproduce the error. However, I noticed that the warnings no longer show up when the number of predictors for b0 and b1 in b0~ and b1 ~ is small (3 to 5). Could this be an effect too many subcoefficients of b0 and b1? charles -- View this message in context: http://r.789695.n4.nabble.com/Warning-Message-In-if-deparse-params-nm-3-1-tp4643638p4643649.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] R package for dashboard
HI, May be brew package helps you. You can also check this link (http://learnr.wordpress.com/2009/04/09/ggplot2-sales-dashboard/). A.K. - Original Message - From: XINLI LI lihaw...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Wednesday, September 19, 2012 11:48 AM Subject: [R] R package for dashboard What package can be used to produce dashboard in R? Thanks and Regards, Xin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FASTA annot issue
I am trying to pull a subset form a large group of FASTA sequences. I need to pull them based on the annot and write.fasta them. I have my subset annot titles in a .csv. What is the way to go about this? I tried pulling the sequences from a .csv but then MEGA 5 was not happy when i tried to put them back and I need to use MEGA to keep my data uniform. Any help would be greatly appreciated Thank you Mary [[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] Wilcoxon Test and Mean Ratios
Hello All, I am writing to ask your opinion on how to interpret this case. I have two vectors a and b that I am trying to compare. The wilcoxon test is giving me a pvalue of 5.139217e-303 of a over b with the alternative greater. Now if I make a summary on each of them I have the following summary(a) Min. 1st Qu.Median Mean 3rd Qu. Max. 0.000 0.0001411 0.0002381 0.0002671 0.0003623 0.0012910 summary(c) Min. 1st Qu.Median Mean 3rd Qu. Max. 0.000 0.000 0.000 0.0004947 0.0002972 1.000 The mean ratio is then around 0.5399031 which naively goes in opposite direction of the wilcoxon test ( I was expecting to find a ratio 1) Even after removing outlier using the outlier package, I still have the same thing. Can someone help me explain why I do have this result and how to explain it ? Thanks in advance Rad __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] issue accessing help files
Dear R-help community, I am unable to access help files when using the typical ?function.of.interest command. For example, if I type ?anova, Internet Explorer opens, but I am never connected to the usual page describing the nuances of the anova function. This is a new problem (just started occurring a few days ago). I am currently using R 2.14.1 on a Windows XP machine. As suggested by someone else on another list serve I have placed the session info below for a brief session where this occurred. NOTE: I am not trying to access any functions for libraries that are not active (for example, anova is in the default Stats package). Any suggestions on how to resolve this issue or any insights on why this may be occurring are greatly appreciated. Thanks in advance for your help. sessionInfo() R version 2.14.1 (2011-12-22) Platform: i386-pc-mingw32/i386 (32-bit) 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 loaded via a namespace (and not attached): [1] tools_2.14.1 -- Basil Iannone University of Illinois at Chicago Department of Biological Sciences (MC 066) 845 W. Taylor St. Chicago, IL 60607-7060 Email: bian...@uic.edu Phone: 312-355-3231 Fax: 312-413-2435 http://www2.uic.edu/~bianno2 [[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] histogram plot spacing problem
Hi, So I plot a histogram using the built-in hist function: hist(rnorm(100), ...). Now the y-axis starts at its lower end at 0 (very sensible, of course) and that's where the baseline for the rectangles of the histogram is drawn, but the x-axis itself is offset a bit to the lower. I.e. there is some space between x-axis and null-point of y-axis / histogram lower end. What do I need to do to get rid of that space, so that x- and y-axis will intersect at y=0 ? Ideally the solution should be device- and screen-size independent. 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] write.table: strange output has been produced
Hi David - Thank you for your reply. You are probably right. The last 'normal' line doesn't have a double quote closed. There is the complete line below: -8 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP-GMP specific 5-nucleotidaseNucleotide transport and metabolism METABOLISM --8 So it might be that the annotation dataset is actually the culprit. But it gets more complicated when I try to find find this string in the 'annot' object using the id value. The id 159998 is present in the output from 'intersect' function: which(subset == 159998) [1] 539 It also present in statdata: which(statdata$id == 159998) [1] 1502 But I cannot find it in the 'annot' object??? which(annot$id == 159998) integer(0) class(annot$id) [1] integer Could it be that the annot dataset contains some illegal symbols that screw everything? Shall I just edit it first with 'sed' to remove everything except alpha-numeric before importing to R... -Igor On Wed, 2012-09-19 at 10:26 -0700, David Winsemius wrote: On Sep 19, 2012, at 9:12 AM, Igor wrote: Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Intracellular trafficking, secretion, and 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p CytoskeletonCELLULAR PROCESSES AND SIGNALING 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p Intracellular trafficking, secretion, and vesicular transport CELLU and metabolism METABOLISM This looks like the sort of thing that occurs when there is a mismatched or missing double or single quote or perhaps comment character ( # that terminated a line read) somewhare. The logical place to look is in the line of data just above the pathological stretch of data. You have clearly only offered a truncated version of the data, since there are many instances of lines ending without matching quotes, even one in the first line. -- David.
Re: [R] write.table: strange output has been produced
Hi Jim - Thank you for your reply. -8 str(annot) 'data.frame': 6895 obs. of 4 variables: $ id : int 231803 231804 231805 231810 231811 231816 231818 177697 223131 231823 ... $ kogdefline : Factor w/ 1898 levels 17 beta-hydroxysteroid dehydrogenase type 3, HSD17B3,..: 1633 693 704 1627 1042 507 1870 1448 730 185 ... $ kogClass: Factor w/ 26 levels ,Amino acid transport and metabolism ,..: 26 4 24 20 18 24 10 22 25 6 ... $ kogGroup: Factor w/ 5 levels ,CELLULAR PROCESSES AND SIGNALING,..: 3 4 2 2 2 2 2 3 3 2 ... str(statdata) 'data.frame': 3887 obs. of 8 variables: $ id: chr 267533 246792 271961 237478 ... $ baseMean : num 288 519 309 189 341 ... $ baseMeanA : num 574 1025 617 375 661 ... $ baseMeanB : num 1.392 13.592 0.535 2.23 21.621 ... $ foldChange: num 0.002426 0.013258 0.000866 0.00594 0.032733 ... $ log2FoldChange: num -8.69 -6.24 -10.17 -7.4 -4.93 ... $ pval : num 2.82e-104 1.70e-94 4.82e-81 1.63e-79 6.62e-78 ... $ padj : num 7.31e-100 2.20e-90 4.16e-77 1.06e-75 3.43e-74 ... - attr(*, na.action)=Class 'omit' Named int [1:1235] 17 18 20 22 31 33 39 43 44 45 ... .. ..- attr(*, names)= chr [1:1235] NA NA.1 NA.2 NA.3 ... str(extra) 'data.frame': 3887 obs. of 3 variables: $ kogdefline: chr NA NA NA NA ... $ kogClass : chr NA NA NA NA ... $ kogGroup : chr NA NA NA NA ... -8 Also I tried stringsAsFactors = FALSE, it doesn't seem to make any difference. -Igor On Wed, 2012-09-19 at 13:36 -0400, jim holtman wrote: It would also be helpful if you could provide the output of 'str' for all the objects that you are using. e.g., str(statdata)str(extra) Also in creating your data.frame, use stringsAsFactors = FALSE: extra = data.frame(kogdefline=rep(NA,n) , kogClass = rep(NA,n) , kogGroup = rep(NA,n) , stringsAsFactors = FALSE ) On Wed, Sep 19, 2012 at 12:12 PM, Igor ig...@essex.ac.uk wrote: Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Intracellular trafficking, secretion, and 171703 171703 KOG2674 Cysteine protease
Re: [R] Help reproducing a contour plot
Hello, I remember this dataset from not a long time ago. Please use dput() to post your data and do not use formatting to post code. As for the question, though your example is not reproducible (it doesn't run) see http://gallery.r-enthusiasts.com/graph/contour_plot_%3Cbr%3EMaunga_Whau_Volcano,21 Hope this helps, Rui Barradas Em 19-09-2012 16:55, Tinus Sonnekus escreveu: Hi All, I am trying to reproduce this using R instead. [image: Full-size image (38 K)] I tried using the following code *SChla - read.csv(SM_Chla_data.csv)* *Atlantis - SChla[16:66,]* *head(Atlantis)* * * Seamount Station Depth Pico Nano Micro Total_Chdbar Latitude Longitud 16 Atlantis1217 Surface 0.0639 0.1560 0.0398 0.2597 2.082 -32.71450 57.29733 17 Atlantis1217 Shallow 0.0305 0.1250 0.0740 0.2295 24.524 -32.71450 57.29733 18 Atlantis1217Deep 0.1660 0.3560 0.0734 0.5954 49.573 -32.71450 57.29733 19 Atlantis1217Fmax 0.1740 0.5200 0.1830 0.8770 79.595 -32.71450 57.29733 20 Atlantis1217 Below 0.0235 0.0486 0.0242 0.0963 199.067 -32.71450 57.29733 21 Atlantis1225 Surface 0.0764 0.1490 0.0333 0.2587 0.409 -32.71133 57.27150 *# Obtaining longitude and depth data* *Long - SMfrac[,6]* *dbar - -SMfrac[,5] #reverse depth* * * *#converting data to percentage of total chl a* * * *picoFrac - Atlantis$Pico/Atlantis$Total_Ch*100* *nanoFrac - Atlantis$Nano/Atlantis$Total_Ch*100* *microFrac - Atlantis$Micro/Atlantis$Total_Ch*100* * * * * *library(akima)* * * *par(mfrow = c(3,1)) * * * *contour(interp(Long, dbar, picoFrac),nlevels = 6,* * xlab =Longitude, main= Pico, * * ylab =Depth, ylim = c(-200,0), method = simple,* * col = light green)* * * *contour(interp(Long, dbar, nanoFrac), nlevels = 6,* * xlab =Longitude, main= Nano,* * ylab =Depth,ylim = c(-200,0), method = simple,* * col = green)* * * *contour(interp(Long, dbar, microFrac),nlevels = 6,* * xlab =Longitude, main= Micro,* * ylab =Depth,ylim = c(-200,0), * * lylab =Depth, method = simple,* * col = dark green)* I can get the contours plotted. Not sure if this is 100 % correct but it looks as expected. Can you guys please help me to add/display my data points. I would also like to fill the contours in grayscale/colour (e.g. levels 0, 20, 40, 60, 80. 100 %) and add a legend to the graph. As of yet I haven't tried to figure out how to add the stations as a secondary axis to the plot. Thanks for the help and advice. Tinus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] correlating matrices
Hi, thank you for taking the time and reading my question. My question is twofold: 1. I have several matrices with variables and one matrix with water levels. I want to predict the water level with the data in the other matrices. Basically, * mod-lm(matrix1 ~ matrix2+matrix3)* ( What looks like a minus is meant to be the wiggly minus.) Of course I could dissemble the matrices and paste their columns into one long, long vector. But the method above gives reasonable results. Are there any methodological objections against doing this? 2. After having done the regression I now want to make a prediction. Thus given the coefficients of my regression mod and matrix2 and matrix3 I want to predict a new matrix. This is where the matrix approach becomes difficult. I made it work, but it is very unelegant: *pred-rep(coef(mod)[1],2)+coef(mod)[2]*matrix2+coef(mod)[3]*matrix3 PRED-matrix(pred, nrow=length(matrix1[,1]), ncol=length(matrix1[1,]), byrow=F)* Is there a more elegant way of doing this? Because I dont have two but six matrices as independent variables, so it becomes pretty lengthy. I could not make the command predict() work for this. Thank you! -- View this message in context: http://r.789695.n4.nabble.com/correlating-matrices-tp4643660.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] Merging two or more frequency tables
I am new to R and am looking to merge two or more frequency tables into one. I have searched around but have been unable to find exactly what I need. I have two frequency tables obtained from two sample texts t0-table(strsplit(tolower(It was the age of wisdom it was the age of foolishness it was the epoch of belief), \\W)) t1-table(strsplit(tolower(it was the epoch of incredulity it was the season of Light it was the season of Darkness), \\W)) so I get: t0 age belief epoch foolishness it of the was wisdom 2 1 1 1 3 3 3 3 1 t1 darkness epoch incredulity it light of season the was 1 1 1 3 1 3 2 33 I need to merge these two tables into one so that the frequencies for each word are added, e.g. the word it would have 6. So resulting table would be age beliefdarkness epochfoolishness incredulity it light 2 112 1 1 6 1 of seasonthewas wisdom 62 6 6 1 Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Merging-two-or-more-frequency-tables-tp4643663.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] histogram plot spacing problem
Hello, Try the following. x - rnorm(100) hist(x, xaxt = n) axis(1, at = pretty(x), pos = 0) Hope this helps, Rui Barradas Em 19-09-2012 18:51, firespot escreveu: Hi, So I plot a histogram using the built-in hist function: hist(rnorm(100), ...). Now the y-axis starts at its lower end at 0 (very sensible, of course) and that's where the baseline for the rectangles of the histogram is drawn, but the x-axis itself is offset a bit to the lower. I.e. there is some space between x-axis and null-point of y-axis / histogram lower end. What do I need to do to get rid of that space, so that x- and y-axis will intersect at y=0 ? Ideally the solution should be device- and screen-size independent. thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] issue accessing help files
Hello, I had a problem seeing the help pages with R 2.14.(0 or 1? I don't remember) on Windows 7. Then I realized that after a command like print, Rgui would first display an error message saying that the temp directory used by help didn't exist. The solution I've found was to manually create it whenever this happened. And to issue a print statement after a missed ?function one. Apparently the error message was waiting to be displayed somewhere. The problem was corrected with R 2.15.0 so I recommened you update your installation of R. Hope this helps, Rui Barradas Em 19-09-2012 19:19, Basil Iannone escreveu: Dear R-help community, I am unable to access help files when using the typical ?function.of.interest command. For example, if I type ?anova, Internet Explorer opens, but I am never connected to the usual page describing the nuances of the anova function. This is a new problem (just started occurring a few days ago). I am currently using R 2.14.1 on a Windows XP machine. As suggested by someone else on another list serve I have placed the session info below for a brief session where this occurred. NOTE: I am not trying to access any functions for libraries that are not active (for example, anova is in the default Stats package). Any suggestions on how to resolve this issue or any insights on why this may be occurring are greatly appreciated. Thanks in advance for your help. sessionInfo() R version 2.14.1 (2011-12-22) Platform: i386-pc-mingw32/i386 (32-bit) 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 loaded via a namespace (and not attached): [1] tools_2.14.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] New Package 'JMbayes' for the Joint Modeling of Longitudinal and Survival Data under a Bayesian approach
Dear R-users, I would like to announce the release of the new package JMbayes available from CRAN (http://CRAN.R-project.org/package=JMbayes). This package fits shared parameter models for the joint modeling of normal longitudinal responses and event times under a Bayesian approach using JAGS, WinBUGS or OpenBUGS. The package has a single model-fitting function called jointModelBayes(), which accepts as main arguments a linear mixed effects object fit returned by function lme() of package nlme, and a Cox model object fit returned by function coxph() of package survival. * jointModelBayes() allows for joint models with relative risk survival submodels with Weibull or B-spline approximated baseline hazard functions (controlled by argument 'survMod'). * In addition, argument 'param' of jointModelBayes() specifies the association structure between the longitudinal and survival processes; available options are: - td-value which is the classic joint model formulation used in Wulfsohn and Tsiatis (1997); - td-extra which is a user-defined, possibly time-dependent, term based on the specification of the 'extraForm' argument of jointModelBayes(). This could be used to include terms, such as the time-dependent slope (i.e., the derivative of the subject-specific linear predictor of the linear mixed model), and the time-dependent cumulative effect (i.e., the integral of the subject-specific linear predictor of the linear mixed model); - td-both which is the combination of the previous two parameterizations, i.e., the current value and the user-specified terms are included in the linear predictor of the relative risk model; and - shared-RE where only the random effects of the linear mixed model are included in the linear predictor of the survival submodel. The package also provides functionality for computing dynamic predictions for the longitudinal and time-to-event outcomes using functions predict() and survfitJM(), respectively. As always, any kind of feedback (questions, suggestions, bug-reports, etc.) is more than welcome. Best, Dimitris -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Data Frame (Very Simple Problem)
Hi List Members, This is a very stupid problem but I am not able to know what the solution can be. I am trying to run a query like below *Program Flow :* 1. a - data.frame(table( cut( Sys.time() + seq(0,82800,3600), 60 mins) )) # It generates the 60 minute intervals. Thanks David 2. b - data.frame(a$Var1) # To extract only First Column i.e. Var1 3. class(b) # checking class 4. b[1:1,1:1] # Trying to access the first row and the problem starts. 2. b - Sys.time()+ 5*60 # 5 minute interval increase 3. ifelse(b[1:1,1:1] * *Sys.time()+5*60,rnorm(1,0,5),Sys.sleep) Error: unexpected string constant in ifelse(b[2:2,1:1] My only aim is to run ifelse for checking whether the program is running or not.Please help *Data :* a - structure(list(Var1 = structure(1:24, .Label = c(2012-09-19 16:40:00, 2012-09-19 17:40:00, 2012-09-19 18:40:00, 2012-09-19 19:40:00, 2012-09-19 20:40:00, 2012-09-19 21:40:00, 2012-09-19 22:40:00, 2012-09-19 23:40:00, 2012-09-20 00:40:00, 2012-09-20 01:40:00, 2012-09-20 02:40:00, 2012-09-20 03:40:00, 2012-09-20 04:40:00, 2012-09-20 05:40:00, 2012-09-20 06:40:00, 2012-09-20 07:40:00, 2012-09-20 08:40:00, 2012-09-20 09:40:00, 2012-09-20 10:40:00, 2012-09-20 11:40:00, 2012-09-20 12:40:00, 2012-09-20 13:40:00, 2012-09-20 14:40:00, 2012-09-20 15:40:00), class = factor), Freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c(Var1, Freq), row.names = c(NA, -24L), class = data.frame) *Session Info * R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) 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 datasets utils [6] methods base other attached packages: [1] rcom_2.2-5 rscproxy_2.0-5 loaded via a namespace (and not attached): [1] tools_2.15.1 Best Regards, Bhupendrasinh Thakre *Disclaimer :* The information contained in this communication is confi...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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.table: strange output has been produced
On Sep 19, 2012, at 12:20 PM, Igor Chernukhin wrote: Hi David - Thank you for your reply. You are probably right. The last 'normal' line doesn't have a double quote closed. There is the complete line below: -8 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP-GMP specific 5-nucleotidase Nucleotide transport and metabolism METABOLISM --8 So it might be that the annotation dataset is actually the culprit. But it gets more complicated when I try to find find this string in the 'annot' object using the id value. The id 159998 is present in the output from 'intersect' function: which(subset == 159998) [1] 539 It also present in statdata: which(statdata$id == 159998) [1] 1502 But I cannot find it in the 'annot' object??? which(annot$id == 159998) integer(0) class(annot$id) [1] integer Could it be that the annot dataset contains some illegal symbols that screw everything? Shall I just edit it first with 'sed' to remove everything except alpha-numeric before importing to R... I find it very productive to use the count.fields function. It lets you play around with removing the comment character which you do not yet seem to have done. I find this code particularly useful: table(count.fields(file = fil.ext, sep=, quote=', comment.char=)) This would get tripped up with commas inside the double-quotes quoted strings, but I do not see any of those in the fragments your offered. -- David. -Igor On Wed, 2012-09-19 at 10:26 -0700, David Winsemius wrote: On Sep 19, 2012, at 9:12 AM, Igor wrote: Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Intracellular trafficking, secretion, and 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p CytoskeletonCELLULAR PROCESSES AND SIGNALING 171703 171703 KOG2674 Cysteine protease required for autophagy - Apg4p/Aut2p Intracellular trafficking, secretion, and vesicular transport CELLU and metabolism METABOLISM This looks like the sort of thing
Re: [R] Help reproducing a contour plot
On Sep 19, 2012, at 8:55 AM, Tinus Sonnekus wrote: Hi All, I am trying to reproduce this using R instead. [image: Full-size image (38 K)] I tried using the following code *SChla - read.csv(SM_Chla_data.csv)* *Atlantis - SChla[16:66,]* *head(Atlantis)* * * Seamount Station Depth Pico Nano Micro Total_Chdbar Latitude Longitud 16 Atlantis1217 Surface 0.0639 0.1560 0.0398 0.2597 2.082 -32.71450 57.29733 17 Atlantis1217 Shallow 0.0305 0.1250 0.0740 0.2295 24.524 -32.71450 57.29733 18 Atlantis1217Deep 0.1660 0.3560 0.0734 0.5954 49.573 -32.71450 57.29733 19 Atlantis1217Fmax 0.1740 0.5200 0.1830 0.8770 79.595 -32.71450 57.29733 20 Atlantis1217 Below 0.0235 0.0486 0.0242 0.0963 199.067 -32.71450 57.29733 21 Atlantis1225 Surface 0.0764 0.1490 0.0333 0.2587 0.409 -32.71133 57.27150 *# Obtaining longitude and depth data* *Long - SMfrac[,6]* *dbar - -SMfrac[,5] #reverse depth* * * *#converting data to percentage of total chl a* * * *picoFrac - Atlantis$Pico/Atlantis$Total_Ch*100* *nanoFrac - Atlantis$Nano/Atlantis$Total_Ch*100* *microFrac - Atlantis$Micro/Atlantis$Total_Ch*100* * * * * *library(akima)* * * *par(mfrow = c(3,1)) * * * *contour(interp(Long, dbar, picoFrac),nlevels = 6,* * xlab =Longitude, main= Pico, * * ylab =Depth, ylim = c(-200,0), method = simple,* * col = light green)* * * *contour(interp(Long, dbar, nanoFrac), nlevels = 6,* * xlab =Longitude, main= Nano,* * ylab =Depth,ylim = c(-200,0), method = simple,* * col = green)* * * *contour(interp(Long, dbar, microFrac),nlevels = 6,* * xlab =Longitude, main= Micro,* * ylab =Depth,ylim = c(-200,0), * * lylab =Depth, method = simple,* * col = dark green)* I can get the contours plotted. Not sure if this is 100 % correct but it looks as expected. Can you guys please help me to add/display my data points. I would also like to fill the contours in grayscale/colour (e.g. levels 0, 20, 40, 60, 80. 100 %) and add a legend to the graph. As of yet I haven't tried to figure out how to add the stations as a secondary axis to the plot. Why wouldn't you just use the points() function after each contour? -- David. David Winsemius, MD Alameda, CA, 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.
Re: [R] Data Frame (Very Simple Problem)
Hello, Your code is reproducible and completely explains the issue, thanks. First I had the impression of a well organized question. Then I've read point 4. 4. The sequence 1:1 starts and ends at 1. You don't need b[1:1, 1:1], b[1, 1] will do. Then you assign a different value to 'b'. This time it's a vector, not a data.frame. The ifelse corrected is # 'b' is now 1-dim ifelse(b[1] Sys.time()+5*60, rnorm(1,0,5), Sys.sleep) (Why the '*' and the double quotes?) Then I've realized that you had restarted the counting, but starting with point 2. Hope this helps, Rui Barradas Em 19-09-2012 22:54, Bhupendrasinh Thakre escreveu: Hi List Members, This is a very stupid problem but I am not able to know what the solution can be. I am trying to run a query like below *Program Flow :* 1. a - data.frame(table( cut( Sys.time() + seq(0,82800,3600), 60 mins) )) # It generates the 60 minute intervals. Thanks David 2. b - data.frame(a$Var1) # To extract only First Column i.e. Var1 3. class(b) # checking class 4. b[1:1,1:1] # Trying to access the first row and the problem starts. 2. b - Sys.time()+ 5*60 # 5 minute interval increase 3. ifelse(b[1:1,1:1] * *Sys.time()+5*60,rnorm(1,0,5),Sys.sleep) Error: unexpected string constant in ifelse(b[2:2,1:1] My only aim is to run ifelse for checking whether the program is running or not.Please help *Data :* a - structure(list(Var1 = structure(1:24, .Label = c(2012-09-19 16:40:00, 2012-09-19 17:40:00, 2012-09-19 18:40:00, 2012-09-19 19:40:00, 2012-09-19 20:40:00, 2012-09-19 21:40:00, 2012-09-19 22:40:00, 2012-09-19 23:40:00, 2012-09-20 00:40:00, 2012-09-20 01:40:00, 2012-09-20 02:40:00, 2012-09-20 03:40:00, 2012-09-20 04:40:00, 2012-09-20 05:40:00, 2012-09-20 06:40:00, 2012-09-20 07:40:00, 2012-09-20 08:40:00, 2012-09-20 09:40:00, 2012-09-20 10:40:00, 2012-09-20 11:40:00, 2012-09-20 12:40:00, 2012-09-20 13:40:00, 2012-09-20 14:40:00, 2012-09-20 15:40:00), class = factor), Freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c(Var1, Freq), row.names = c(NA, -24L), class = data.frame) *Session Info * R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) 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 datasets utils [6] methods base other attached packages: [1] rcom_2.2-5 rscproxy_2.0-5 loaded via a namespace (and not attached): [1] tools_2.15.1 Best Regards, Bhupendrasinh Thakre *Disclaimer :* The information contained in this communication is confi...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] write.table: strange output has been produced
Thank you David - you put me into right direction. Back to normal, problem sorted. I've missed a single quote in 'annot' data when I imported it from file using read.table function with the default 'quote' argument. quote=\ did the trick. Many thanks -Igor On Wed, 2012-09-19 at 14:55 -0700, David Winsemius wrote: On Sep 19, 2012, at 12:20 PM, Igor Chernukhin wrote: Hi David - Thank you for your reply. You are probably right. The last 'normal' line doesn't have a double quote closed. There is the complete line below: -8 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP-GMP specific 5-nucleotidaseNucleotide transport and metabolism METABOLISM --8 So it might be that the annotation dataset is actually the culprit. But it gets more complicated when I try to find find this string in the 'annot' object using the id value. The id 159998 is present in the output from 'intersect' function: which(subset == 159998) [1] 539 It also present in statdata: which(statdata$id == 159998) [1] 1502 But I cannot find it in the 'annot' object??? which(annot$id == 159998) integer(0) class(annot$id) [1] integer Could it be that the annot dataset contains some illegal symbols that screw everything? Shall I just edit it first with 'sed' to remove everything except alpha-numeric before importing to R... I find it very productive to use the count.fields function. It lets you play around with removing the comment character which you do not yet seem to have done. I find this code particularly useful: table(count.fields(file = fil.ext, sep=, quote=', comment.char=)) This would get tripped up with commas inside the double-quotes quoted strings, but I do not see any of those in the fragments your offered. -- David. -Igor On Wed, 2012-09-19 at 10:26 -0700, David Winsemius wrote: On Sep 19, 2012, at 9:12 AM, Igor wrote: Good afternoon all - While making a steady progress in learning R after Matlab I encountered a problem which seems to require some extra help to move over. Basically I want to merge a data from biological statistical dataset with annotation data extracted from another dataset using an 'id' crossreference and write it to report file. The first part goes absolutely fine, I have merged both data into data.frame but when I try to write it to csv file using 'write.table' it seems like it does write the 'data.frame' object but it also insert some parts from the annotation data which are not suppose to be there... There is a little snapshot of the file output below to illustrate. The upper half is fine, that's how it should be. The lower half, which is actually appears to be space-separated, not coma, obviously grabbed from the annotation dataset and is not supposed to be here. 8 344,166128,126.44286392082,179.904700814932,72.9810270267088,0.40566492535281,-1.3016395254146,2.47449355237252e-07,4.2901159299567e-06,Chitinas 18816,238247,92.5282508325735,135.981255262454,49.0752464026927,0.36089714209487,-1.47034037615176,2.5330054329543e-07,4.38862252337004e-06,Prot 22072,222365,30.8191942806426,52.4262903365628,9.21209822472236,0.17571524068522,-2.50868876576414,2.54433836512085e-07,4.40531098485028e-06,NA,N 25062,226605,30.808007579908,50.3976662241578,11.2183489356581,0.22259659575825,-2.16749656564076,2.54934711860645e-07,4.41103467375713e-06,NA,NA 7539,247009,75.4175439970731,34.4643221134552,116.370765880691,3.37655751642533,1.7313265164,2.60010673210741e-07,4.49585878338091e-06,NA,NA, 407,267139,425.559675915702,279.393013150954,571.72633868045,2.04631580522577,1.03302881149302,2.61074218843609e-07,4.51123710239304e-06,NA,NA,NA 26530,171300,146.80096060985,80.0063286553601,213.595592564339,2.66973370924738,1.4166958484644,2.68061220749976e-07,4.62888115991058e-06,NA,NA,N 3078,159013,34.3260176515511,52.4580790080106,16.1939562950917,0.308702808057816,-1.69570948866688,2.69104298652827e-07,4.64379716436078e-06,40S 4657,159998,133.10761487064,185.450704462326,80.7645252789532,0.435504009074069,-1.19924209513405,2.75544399955331e-07,4.75176501174632e-06,IMP- 171597 171597 KOG1347 Uncharacterized membrane protein, predicted efflux pump General function prediction onlyPOORLY CHARACTERIZED 171658 171658 KOG4290 Predicted membrane protein Function unknown POORLY CHARACTERIZED 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking and secretion Signal transduction mechanisms CELLULAR 171660 171660 KOG0903 Phosphatidylinositol 4-kinase, involved in intracellular trafficking
[R] [R-pkgs] lqmm package 1.02
Dear R users lqmm version 1.02 is now on CRAN. lqmm provides commands for estimation of linear quantile regression models with random effects. Commands for independent and count data are also available. A few bugs have been fixed since lqmm 1.0. Updates of this package are (usually) made available on https://r-forge.r-project.org/R/?group_id=1396 prior to submission to CRAN. -- Marco Geraci PhD CStat Lecturer in Biostatistics Institute of Child Health, University College London London WC1N 1EH, UK Web: http://marcogeraci.wordpress.com [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging two or more frequency tables
HI, Try this: dt0-data.frame(t0) dt1-data.frame(t1) res1-merge(dt0,dt1,by=Var1) res2-aggregate(Freq.x+Freq.y~Var1,data=res1,sum) colnames(res2)[2]-Freq res3-rbind( dt0[!dt0$Var1%in%res2$Var1,],dt1[!dt1$Var1%in%res2$Var1,] ,res2) row.names(res3)-1:nrow(res3) xtabs(Freq~Var1,data=res3) #Var1 # age belief epoch foolishness it of # 2 1 2 1 6 6 # the was wisdom darkness incredulity light # 6 6 1 1 1 1 # season # 2 - Original Message - From: mcelis mce...@lightminersystems.com To: r-help@r-project.org Cc: Sent: Wednesday, September 19, 2012 3:08 PM Subject: [R] Merging two or more frequency tables I am new to R and am looking to merge two or more frequency tables into one. I have searched around but have been unable to find exactly what I need. I have two frequency tables obtained from two sample texts t0-table(strsplit(tolower(It was the age of wisdom it was the age of foolishness it was the epoch of belief), \\W)) t1-table(strsplit(tolower(it was the epoch of incredulity it was the season of Light it was the season of Darkness), \\W)) so I get: t0 age belief epoch foolishness it of the was wisdom 2 1 1 1 3 3 3 3 1 t1 darkness epoch incredulity it light of season the was 1 1 1 3 1 3 2 3 3 I need to merge these two tables into one so that the frequencies for each word are added, e.g. the word it would have 6. So resulting table would be age belief darkness epoch foolishness incredulity it light 2 1 1 2 1 1 6 1 of season the was wisdom 6 2 6 6 1 Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Merging-two-or-more-frequency-tables-tp4643663.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] Merging two or more frequency tables
Hello, Try the following. fun - function(x, ...){ z - Reduce(paste, list(x, ...)) tsum - table(strsplit(tolower(z), \\W)) tsum } x - It was the age of wisdom it was the age of foolishness it was the epoch of belief y - it was the epoch of incredulity it was the season of Light it was the season of Darkness fun(x, y) z - It was the era of R fun(x, y, z) Hope this helps, Rui Barradas Em 19-09-2012 20:08, mcelis escreveu: I am new to R and am looking to merge two or more frequency tables into one. I have searched around but have been unable to find exactly what I need. I have two frequency tables obtained from two sample texts t0-table(strsplit(tolower(It was the age of wisdom it was the age of foolishness it was the epoch of belief), \\W)) t1-table(strsplit(tolower(it was the epoch of incredulity it was the season of Light it was the season of Darkness), \\W)) so I get: t0 age belief epoch foolishness it of the was wisdom 2 1 1 1 3 3 3 3 1 t1 darkness epoch incredulity it light of season the was 1 1 1 3 1 3 2 33 I need to merge these two tables into one so that the frequencies for each word are added, e.g. the word it would have 6. So resulting table would be age beliefdarkness epochfoolishness incredulity it light 2 112 1 1 6 1 of seasonthewas wisdom 62 6 6 1 Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Merging-two-or-more-frequency-tables-tp4643663.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] Data Frame (Very Simple Problem)
Hi, Try this: a - data.frame(table( cut( Sys.time() + seq(0,82800,3600), 60 mins) b - data.frame(a$Var1) str(b) #'data.frame': 24 obs. of 1 variable: # $ a.Var1: Factor w/ 24 levels 2012-09-19 18:03:00,..: 1 2 3 4 5 6 7 8 9 1 b1-within(b,{a.Var1-as.POSIXct(a.Var1,format=%Y-%m-%d %H:%M:%S)}) b1[1,] #[1] 2012-09-19 18:03:00 EDT Sys.time()+5*60 #[1] 2012-09-19 18:25:55 EDT set.seed(1) ifelse(b1[1,] (Sys.time()+5*60),rnorm(1,0,5),Sys.sleep) #[1] -3.132269 A.K. - Original Message - From: Bhupendrasinh Thakre vickytha...@gmail.com To: R help r-help@r-project.org Cc: Sent: Wednesday, September 19, 2012 5:54 PM Subject: [R] Data Frame (Very Simple Problem) Hi List Members, This is a very stupid problem but I am not able to know what the solution can be. I am trying to run a query like below *Program Flow :* 1. a - data.frame(table( cut( Sys.time() + seq(0,82800,3600), 60 mins) )) # It generates the 60 minute intervals. Thanks David 2. b - data.frame(a$Var1) # To extract only First Column i.e. Var1 3. class(b) # checking class 4. b[1:1,1:1] # Trying to access the first row and the problem starts. 2. b - Sys.time()+ 5*60 # 5 minute interval increase 3. ifelse(b[1:1,1:1] * *Sys.time()+5*60,rnorm(1,0,5),Sys.sleep) Error: unexpected string constant in ifelse(b[2:2,1:1] My only aim is to run ifelse for checking whether the program is running or not.Please help *Data :* a - structure(list(Var1 = structure(1:24, .Label = c(2012-09-19 16:40:00, 2012-09-19 17:40:00, 2012-09-19 18:40:00, 2012-09-19 19:40:00, 2012-09-19 20:40:00, 2012-09-19 21:40:00, 2012-09-19 22:40:00, 2012-09-19 23:40:00, 2012-09-20 00:40:00, 2012-09-20 01:40:00, 2012-09-20 02:40:00, 2012-09-20 03:40:00, 2012-09-20 04:40:00, 2012-09-20 05:40:00, 2012-09-20 06:40:00, 2012-09-20 07:40:00, 2012-09-20 08:40:00, 2012-09-20 09:40:00, 2012-09-20 10:40:00, 2012-09-20 11:40:00, 2012-09-20 12:40:00, 2012-09-20 13:40:00, 2012-09-20 14:40:00, 2012-09-20 15:40:00), class = factor), Freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c(Var1, Freq), row.names = c(NA, -24L), class = data.frame) *Session Info * R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) 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 datasets utils [6] methods base other attached packages: [1] rcom_2.2-5 rscproxy_2.0-5 loaded via a namespace (and not attached): [1] tools_2.15.1 Best Regards, Bhupendrasinh Thakre *Disclaimer :* The information contained in this communication is confi...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] correlating matrices
Hello, Inline. Em 19-09-2012 19:56, frauke escreveu: Hi, thank you for taking the time and reading my question. My question is twofold: 1. I have several matrices with variables and one matrix with water levels. I want to predict the water level with the data in the other matrices. Basically, * mod-lm(matrix1 ~ matrix2+matrix3)* ( What looks like a minus is meant to be the wiggly minus.) Of course I could dissemble the matrices and paste their columns into one long, long vector. But the method above gives reasonable results. Are there any methodological objections against doing this? No, not really. I would use cbind(matrix2, matrix3) but the result is the same. It's a matter of choice. 2. After having done the regression I now want to make a prediction. Thus given the coefficients of my regression mod and matrix2 and matrix3 I want to predict a new matrix. This is where the matrix approach becomes difficult. I made it work, but it is very unelegant: *pred-rep(coef(mod)[1],2)+coef(mod)[2]*matrix2+coef(mod)[3]*matrix3 PRED-matrix(pred, nrow=length(matrix1[,1]), ncol=length(matrix1[1,]), byrow=F)* Is there a more elegant way of doing this? Yes! ?predict.lm Without 'newdata' it gives you the fitted values. With new data it gives you predictions. Beware, 'newdata' must be a data.frame. Hope this helps, Rui Barradas Because I dont have two but six matrices as independent variables, so it becomes pretty lengthy. I could not make the command predict() work for this. Thank you! -- View this message in context: http://r.789695.n4.nabble.com/correlating-matrices-tp4643660.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] Lowest AIC after stepAIC can be lowered by manual reduction of variables (Florian Moser)
A few general comments about stepwiseAIC and a suggestion of how to select models a) Apart form the problem, that stepwise selection is not a garanty to get the best model, you need to have a lot of data to avoid overfitting if your model includes 7 parameter plus interactions ( 10 observations per parameter is what you are ideally looking for). b) Have a look at Anderson and Burnham's book of 2002 about multi model inference if you want to understand how to proper use AIC. What I'm doing for my analysis at the moment (count data of two species, host and herbivore): 1) I checked which of my parameters explained the abundance of the species , using GLMs and bootstrapping of an LR-test to check if the model with the parameter is better than one without the parameter ( one way to deal with outliers and extrema) 2) Then I build all combinations of those parameters, that predicted the two species well (p-values 0.05, and 95% sucessfull bootstrapping). 3) I wrote down all the multiple models with decent p-values and calculated AICc ( AICc is for small data sets, and should be used anyway as for very large N AIC almost equals AICc) (the package glmulti does all the combination models and you can set limits on number of parameters or interactions etc) 4) I manually calculated the weigth based on the AICc of each model with proper performance. This gives you a good idea of which one the best model is and how good that model is compared to all the others models considered. Also, you can calculate weights for each parameter which is very usefull if several models are equally good. I my case, the better models had only one or two parameters, but were ecologically meaningfull and not just the result of data dredging. Hope this helps, Cheers Claas Damken PhD candidate School of Environment The University of Auckland | Te Whare Wananga o Tamaki Makaurau New Zealand Von: r-help-boun...@r-project.org [r-help-boun...@r-project.org]quot; im Auftrag von quot;r-help-requ...@r-project.org [r-help-requ...@r-project.org] Gesendet: Mittwoch, 19. September 2012 22:00 Bis: r-help@r-project.org Betreff: R-help Digest, Vol 115, Issue 19 Send R-help mailing list submissions to r-help@r-project.org To subscribe or unsubscribe via the World Wide Web, visit https://stat.ethz.ch/mailman/listinfo/r-help or, via email, send a message with subject or body 'help' to r-help-requ...@r-project.org You can reach the person managing the list at r-help-ow...@r-project.org When replying, please edit your Subject line so it is more specific than Re: Contents of R-help digest... Today's Topics: 12. Lowest AIC after stepAIC can be lowered by manual reduction ofvariables (Florian Moser) -- Message: 12 Date: Tue, 18 Sep 2012 14:27:34 +0100 (BST) From: Florian Moser flose...@yahoo.de To: r-help@r-project.org Subject: [R] Lowest AIC after stepAIC can be lowered by manual reduction ofvariables Message-ID: 1347974854.4978.yahoomailclas...@web28904.mail.ir2.yahoo.com Content-Type: text/plain Hello I am not really a statistic person, so it's possible i did something completely wrong... if this is the case: sorry... I try to get the best GLM model (with the lowest AIC) for my dataset. Therefore I run a stepAIC (in the MASS package) for my GLM allowing only two-variable-interactions. For the output (summary) I got a model with 7 (of 8) variabels and 5 interactions and AIC=40.008 BUT: When I take this model and reduce stepwise further variables manually (starting with the one with the highest p-values and first reducing all interactions of a variable before i reduce the variable itself) until i can't reduce more variables since all (or its interaction) have a p-value 0.1, I get a model with 4 variables and 2 interactions and an AIC of 33.879 So my questions: Why didn't the stepAIC give me the model with AIC=33.879? And which model should I think of as the best? For my calculations I used these formulae: gm1-glm(cpi~time+tank+...,data=d1) gm2-stepAIC(gm1) summary(gm2) #to get the best model - AIC=40.008 #afterwards I reduced manually using the formula: summary(glm(cpi~time+tank+...,data=d1)) giving me a model with AIC=33.879 Hope you understand what I did, and that you can help me. Thanks Florian [[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] Merging two or more frequency tables
Both solutions work great. Thank you for your help. -- View this message in context: http://r.789695.n4.nabble.com/Merging-two-or-more-frequency-tables-tp4643663p4643692.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] Merging two or more frequency tables
HI, Inspired from Rui's function: Slightly modified: fun1-function(x,...){ z-paste(unlist(list(x,...)),collapse= ) tsum-table(strsplit(tolower(z),\\W)) tsum} fun1(x,y) # age belief darkness epoch foolishness incredulity # 2 1 1 2 1 1 # it light of season the was # 6 1 6 2 6 6 # wisdom # 1 A.K. - Original Message - From: Rui Barradas ruipbarra...@sapo.pt To: mcelis mce...@lightminersystems.com Cc: r-help@r-project.org Sent: Wednesday, September 19, 2012 6:18 PM Subject: Re: [R] Merging two or more frequency tables Hello, Try the following. fun - function(x, ...){ z - Reduce(paste, list(x, ...)) tsum - table(strsplit(tolower(z), \\W)) tsum } x - It was the age of wisdom it was the age of foolishness it was the epoch of belief y - it was the epoch of incredulity it was the season of Light it was the season of Darkness fun(x, y) z - It was the era of R fun(x, y, z) Hope this helps, Rui Barradas Em 19-09-2012 20:08, mcelis escreveu: I am new to R and am looking to merge two or more frequency tables into one. I have searched around but have been unable to find exactly what I need. I have two frequency tables obtained from two sample texts t0-table(strsplit(tolower(It was the age of wisdom it was the age of foolishness it was the epoch of belief), \\W)) t1-table(strsplit(tolower(it was the epoch of incredulity it was the season of Light it was the season of Darkness), \\W)) so I get: t0 age belief epoch foolishness it of the was wisdom 2 1 1 1 3 3 3 3 1 t1 darkness epoch incredulity it light of season the was 1 1 1 3 1 3 2 3 3 I need to merge these two tables into one so that the frequencies for each word are added, e.g. the word it would have 6. So resulting table would be age belief darkness epoch foolishness incredulity it light 2 1 1 2 1 1 6 1 of season the was wisdom 6 2 6 6 1 Any suggestions? -- View this message in context: http://r.789695.n4.nabble.com/Merging-two-or-more-frequency-tables-tp4643663.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Wilcoxon Test and Mean Ratios
On Thu, Sep 20, 2012 at 5:46 AM, Mohamed Radhouane Aniba arad...@gmail.com wrote: Hello All, I am writing to ask your opinion on how to interpret this case. I have two vectors a and b that I am trying to compare. The wilcoxon test is giving me a pvalue of 5.139217e-303 of a over b with the alternative greater. Now if I make a summary on each of them I have the following summary(a) Min. 1st Qu.Median Mean 3rd Qu. Max. 0.000 0.0001411 0.0002381 0.0002671 0.0003623 0.0012910 summary(c) Min. 1st Qu.Median Mean 3rd Qu. Max. 0.000 0.000 0.000 0.0004947 0.0002972 1.000 The mean ratio is then around 0.5399031 which naively goes in opposite direction of the wilcoxon test ( I was expecting to find a ratio 1) There's nothing conceptually strange about the Wilcoxon test showing a difference in the opposite direction to the difference in means. It's probably easiest to think about this in terms of the Mann-Whitney version of the same test, which is based on the proportion of pairs of one observation from each group where the `a' observation is higher. Your 'c' vector has a lot more zeros, so a randomly chosen observation from 'c' is likely to be smaller than one from 'a', but the non-zero observations seem to be larger, so the mean of 'c' is higher. The Wilcoxon test probably isn't very useful in a setting like this, since its results really make sense only under 'stochastic ordering', where the shift is in the same direction across the whole distribution. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Wilcoxon Test and Mean Ratios
Thank you Thomas, So you think a t-test is more adequate to use in this case ? Rad On Sep 19, 2012, at 8:43 PM, Thomas Lumley tlum...@uw.edu wrote: On Thu, Sep 20, 2012 at 5:46 AM, Mohamed Radhouane Aniba arad...@gmail.com wrote: Hello All, I am writing to ask your opinion on how to interpret this case. I have two vectors a and b that I am trying to compare. The wilcoxon test is giving me a pvalue of 5.139217e-303 of a over b with the alternative greater. Now if I make a summary on each of them I have the following summary(a) Min. 1st Qu.Median Mean 3rd Qu. Max. 0.000 0.0001411 0.0002381 0.0002671 0.0003623 0.0012910 summary(c) Min. 1st Qu.Median Mean 3rd Qu. Max. 0.000 0.000 0.000 0.0004947 0.0002972 1.000 The mean ratio is then around 0.5399031 which naively goes in opposite direction of the wilcoxon test ( I was expecting to find a ratio 1) There's nothing conceptually strange about the Wilcoxon test showing a difference in the opposite direction to the difference in means. It's probably easiest to think about this in terms of the Mann-Whitney version of the same test, which is based on the proportion of pairs of one observation from each group where the `a' observation is higher. Your 'c' vector has a lot more zeros, so a randomly chosen observation from 'c' is likely to be smaller than one from 'a', but the non-zero observations seem to be larger, so the mean of 'c' is higher. The Wilcoxon test probably isn't very useful in a setting like this, since its results really make sense only under 'stochastic ordering', where the shift is in the same direction across the whole distribution. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland [[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 can I give same name to column and row?
Hi R User, I calculated a correlation matrix and I was trying to give a same name for rows and columns (heading) in the correlation matrix. But, I was not able to do so. Would you mind let me know how I can assign the same name for the heading of row and columns in the matrix? I appreciate for your help. cheers, K [[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 can I give same name to column and row?
Hello, ?colnames Regards, Pascal Le 20/09/2012 11:48, Kristi Glover a écrit : Hi R User, I calculated a correlation matrix and I was trying to give a same name for rows and columns (heading) in the correlation matrix. But, I was not able to do so. Would you mind let me know how I can assign the same name for the heading of row and columns in the matrix? I appreciate for your help. cheers, K [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how can I give same name to column and row?
It does that automatically. Just assign the names you want to the data.frame before you compute the correlation matrix: x - data.frame(matrix(rnorm(100), ncol=5)) colnames(x) - c(A, B, C, D, E) y - cor(x) y A B C D E A 1. -0.08053608 -0.05444754 0.02173336 -0.31879440 B -0.08053608 1. -0.02621494 0.16279797 -0.19011677 C -0.05444754 -0.02621494 1. -0.18518459 0.37355793 D 0.02173336 0.16279797 -0.18518459 1. -0.05316086 E -0.31879440 -0.19011677 0.37355793 -0.05316086 1. rownames(y) [1] A B C D E y - cor(x) colnames(y) [1] A B C D E -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Kristi Glover Sent: Wednesday, September 19, 2012 9:48 PM To: R-help Subject: [R] how can I give same name to column and row? Hi R User, I calculated a correlation matrix and I was trying to give a same name for rows and columns (heading) in the correlation matrix. But, I was not able to do so. Would you mind let me know how I can assign the same name for the heading of row and columns in the matrix? I appreciate for your help. cheers, K [[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] Importing a CSV file
Hi All, I have used windows R. We can also write like this: A - read.csv(C:/Users/Anthi/Desktop/R/A.csv,header=TRUE) On Wed, Sep 19, 2012 at 8:09 PM, Marc Schwartz marc_schwa...@me.com wrote: On Sep 19, 2012, at 9:26 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Em 19-09-2012 15:01, Sarah Goslee escreveu: On Wed, Sep 19, 2012 at 9:53 AM, Frans Marcelissen frans.marcelis...@digipsy.nl wrote: Hi, Should'nt it be A - read.csv(C:Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) (c:\\ becomes c:\ In general I think it is better to use / and //) Frans No idea; I was copying the original poster's version. In this case, it would definitely be better to take advice on path construction from someone who uses Windows! I use Windows and the answer is no, the four backslashes don't make sense, because like Frans said, c:\\ becomes c:\ (There is no such thing as c: --- c:\\). Rui Barradas Ahoy Mateys, Not to mention, creating file paths on Windows is an A FAQ: http://cran.r-project.org/bin/windows/base/rw-FAQ.html#R-can_0027t-find-my-file Savvy? Marc Schwartz P.S. It's International Talk Like a Pirate Day, which of course fits with a certain language we all hold dear. Somebody had to do it... ;-) Sarah -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] Namens Sarah Goslee Verzonden: woensdag 19 september 2012 15:44 Aan: Anthi Oikonomou CC: r-h...@stat.math.ethz.ch Onderwerp: Re: [R] Importing a CSV file Hi, load() is for R's binary data files. You need to use read.csv(), as you tried, but probably with the complete path. A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE) Sarah On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou anthi.oi...@gmail.com wrote: Hi, I am trying to import csv file in R console I have saved my data in a file on the desktop named R and here is my problematic script load(C:\\Users\\Anthi\\Desktop\\R\\A.csv) Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'A.csv' has magic number ';Abra' Use of save versions prior to 2 is deprecated when I don t load and I ask to read here is the answer A -read.csv(A.csv,header=TRUE) Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'A.csv': No such file or directory Do you know what should I do? Thank you in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] scraping with session cookies
Try this, library(RCurl) library(XML) site- http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 URL-getURL(site) Text=htmlParse(URL,asText=T) This will give you all the web dat in an HTML-Text format. You can use getNodeSet function to extract whatever links or texts that you want from that page. I hope this helps. Best, Heramb On Wed, Sep 19, 2012 at 10:26 PM, CPV ceal...@gmail.com wrote: Thanks again, I run the script with the postForm(site, disclaimer_action=I Agree) and it does not seem to do anything, the webpage is still the disclaimer page thus I am getting the error below Error in function (classes, fdef, mtable) : unable to find an inherited method for function readHTMLTable, for signature NULL I also downloaded the latest version of RHTMLForms (omegahat-RHTMLForms-251743f.zip) and it does not seem to install correctly.. I used the code install.packages(C:/Users/cess/Downloads/omegahat-RHTMLForms-251743f.zip, type=win.binary, repos=NULL) Any suggestion of what could be causing these problems? On Wed, Sep 19, 2012 at 9:49 AM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: You don't need to use the getHTMLFormDescription() and createFunction(). Instead, you can use the postForm() call. However, getHTMLFormDescription(), etc. is more general. But you need the very latest version of the package to deal with degenerate forms that have no inputs (other than button clicks). You can get the latest version of the RHTMLForms package from github git clone g...@github.com:omegahat/RHTMLForms.git and that has the fixes for handling the degenerate forms with no arguments. D. On 9/19/12 7:51 AM, CPV wrote: Thank you for your help Duncan, I have been trying what you suggested however I am getting an error when trying to create the function fun- createFunction(forms[[1]]) it says Error in isHidden I hasDefault : operations are possible only for numeric, logical or complex types On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang dtemplel...@ucdavis.edu wrote: Hi ? The key is that you want to use the same curl handle for both the postForm() and for getting the data document. site = u = http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 library(RCurl) curl = getCurlHandle(cookiefile = , verbose = TRUE) postForm(site, disclaimer_action=I Agree) Now we have the cookie in the curl handle so we can use that same curl handle to request the data document: txt = getURLContent(u, curl = curl) Now we can use readHTMLTable() on the local document content: library(XML) tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors = FALSE) Rather than knowing how to post the form, I like to read the form programmatically and generate an R function to do the submission for me. The RHTMLForms package can do this. library(RHTMLForms) forms = getHTMLFormDescription(u, FALSE) fun = createFunction(forms[[1]]) Then we can use fun(.curl = curl) instead of postForm(site, disclaimer_action=I Agree) This helps to abstract the details of the form. D. On 9/18/12 5:57 PM, CPV wrote: Hi, I am starting coding in r and one of the things that i want to do is to scrape some data from the web. The problem that I am having is that I cannot get passed the disclaimer page (which produces a session cookie). I have been able to collect some ideas and combine them in the code below but I dont get passed the disclaimer page. I am trying to agree the disclaimer with the postForm and write the cookie to a file, but I cannot do it succesfully The webpage cookies are written to the file but the value is FALSE... So any ideas of what I should do or what I am doing wrong with? Thank you for your help, library(RCurl) library(XML) site - http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18 postForm(site, disclaimer_action=I Agree) cf - cookies.txt no_cookie - function() { curlHandle - getCurlHandle(cookiefile=cf, cookiejar=cf) getURL(site, curl=curlHandle) rm(curlHandle) gc() } if ( file.exists(cf) == TRUE ) { file.create(cf) no_cookie() } allTables - readHTMLTable(site) allTables [[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,