[R] R Macro Question
Dear all, I am a new R user, and I have a question about R macro. Here is the situation, I want to do item option analysis (options include: A , B, C, D), below is the codes for option A analyses. #option A analyses optiona-mat.or.vec(nrow(responsedata2), ncol(responsedata2)) # create A matrix by recoding for (i in 1:ncol(responsedata2)){ optiona[,i]-recode(responsedata2[,i],'A'=1;NA=NA;else=0) } # compute mean for A matrix pa-rep(0,ncol(optiona)) for (i in 1:ncol(optiona)){ pa[i]-round(mean(optiona[,i],na.rm=TRUE),2) } pa1-as.data.frame(pa) I can repeat the codes for other options such as B, C and D, but I am wondering if I can do it in a macro way--subsituting A a in the codes with B b, etc. In SAS it can be done easily, but I could not get it to work in R. Waiting for your reply. And thank you so much in advance. Meng [[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] Extracting Element from S4 objects
Are there internal methods available for R2.6 (I'm using the mac os x gui) for extracting (or subsetting) S4 objects? Using the independence_test() function implemented in the COIN package, I can't seem to select out p-values upon completion of each iteration of a loop. Sorry if my search was incomplete beforehand. -- View this message in context: http://www.nabble.com/Extracting-Element-from-S4-objects-tp23302265p23302265.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to replace values?
Hello all, I have a list of genes as follows (A) Number GeneName 0 YAR003W 1 YAR007C 2 YAR008W 3 YBL035C 4 YBL111C 5 YBL112C And I have a list of gene interactions as follows (B) 0 - 1 1 - 5 3 - 4 2 - 3 I want to replace the values in (B) with the corresponding values in (A) ie, I want to achieve the following 0 - 1 replaced with YAR003W -YAR007C 1 - 5 replaced with YAR007C - YBL112C 3 - 4 replaced with YBL035C - YBL111C 2 - 3 replaced with YAR008W - YBL035C The example is simple with (A) and (B) only having a few lines. But in reality, (A) may contain more than 1000 genes and (B) may contain thousands of interactions. Any suggestions on how to achieve the above task are welcomed! -- Suhaila Zainudin PhD Candidate Universiti Teknologi Malaysia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Understanding padding in lattice
Hi In the development version of R, there is a new showViewport() function that might help with debugging this sort of thing. Try ... showViewport() ... or possibly ... showViewport(newpage=TRUE) ... just after drawing your plot. Paul Deepayan Sarkar wrote: On Tue, Apr 28, 2009 at 11:51 AM, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Dear R-users, I am trying to understand what the different padding arguments in trellis.par.set are exactly controlling the space around lattice plots. I have used the following code as a basis for testing but it did not really help me to visualize how the value of each argument changes the margins and the plotting area. I guess a better way to visualize the effects of these padding items would be to create colored polygons for each related area of interest... but I would need to know what are these areas beforehand! You can retrieve the undelying grid layout and show it using library(grid) grid.show.layout(lattice:::lattice.getStatus(layout.details)$page.layout) which is close to what you are describing. Otherwise, there's no easy way to insert polygons in these areas that I know of. You could try setting negative padding values to see what they do. -Deepayan Any advise on how to improve this code would be greatly appreciated. Sebastien ### library(lattice) foo - data.frame(x=rep(seq(10),9),y=rep(seq(10),9),z=rep(0,90),id=rep(seq(9),each=10)) plot1 - xyplot(y+z~x|id, data=foo, type=c(p,l), distribute.type = TRUE, main=This is a test, sub=Subtitle, auto.key=T) trellis.device(pdf, file = trellis_par_test.pdf, paper=letter, #family=Courier, theme = list(fontsize = list(text = 10, points = 10))) trellis.par.set(layout.widths =list(left.padding=0, right.padding=0), layout.heights=list(top.padding =1, main.key.padding =1, axis.xlab.padding=1, key.sub.padding =1, bottom.padding =1), axis.components=list(top=list(tck=1, pad1=1, pad2=1),right=list(tck=1, pad1=1, pad2=1))) print(plot1) dev.off() ### -- *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie R question PART2
Hi, The example given: library(hwriter) htmlFile = tempfile() hwrite(Hello World, htmlFile) browseURL(htmlFile) worked. Including the line: example(hwrite) which is very nice. But I am a bit confused. Am I using elements of Rpad package? Or is this strictly to do with hwriter package? Please clue me in. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: Wed 4/29/2009 10:32 AM To: Tena Sakai Cc: ted.hard...@manchester.ac.uk; r-help@r-project.org Subject: Re: [R] Newbie R question PART2 Tena Sakai wrote: Hi, Many thanks to Wacek Kusnierczyk and Ted Harding. I learned 3 new tricks. (Not bad for a newbie?) $ R --silent --no-save barebone.R $ R --quiet --no-save barebone.R $ R --slave barebone.R With slight differences, they all do what I wanted. Moving right along my tiny agenda... Given the same one-liner, cat ('Hello World!\n') would someone please show me how to turn this one liner into a web page with Rpad? For the basic 'put text in an html page' library(hwriter) htmlFile = tempfile() hwrite(Hello World, htmlFile) browseURL(htmlFile) for more advanced static pages example(hwrite) Martin Obviously, What I want to build is a web page, where it say click here and when it is clicked the screen blanks out and give a line: Hello World! I have looked at an example or two of Rpad, but it was overly complicated for simpleminded newbie. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: ted.hard...@manchester.ac.uk [mailto:ted.hard...@manchester.ac.uk] Sent: Tue 4/28/2009 2:11 PM To: r-help@r-project.org Cc: Tena Sakai Subject: RE: [R] Newbie R question On 28-Apr-09 20:42:45, Tena Sakai wrote: Hi, I am a newbie with R. My environment is linux and I have a file. I call it barebone.R, which has one line: cat ('Hello World!\n') I execute this file as: R --no-save barebone.R And it does what I expect. What I get is 20+/- lines of text, one of which is 'Hello World!'. How would I go about getting rid of all but the line I am after, 'Hello World!'? Regards, Tena Sakai tsa...@gallo.ucsf.edu An unusual request! I had to browse 'man R' a bit before getting a hint. R --silent --nosave barebone.R should do it! Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 28-Apr-09 Time: 22:11:23 -- XFMail -- [[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.
[R] problem about finding power in test about variances
Hello All I am new to this list. I have a problem where for a single sample drawn from normal population, null hypothesis is that variance = k (say). Alternative hypothesis is variance k. Now if we know the true variance, then I would like to calculate the sample size required to produce certain power (for some significance). How do I do this ? I thought of using pwr.chisq.test, and I contacted the author stephane champely, but he said his package can't do this. Does anybody have an idea ? Thanks Ati __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] if condition doesn't evaluate to True/False
OK test - list( NULL, NULL, NULL) gives you list with three null values. But you can not subscript it like test[[1,1] what original poster did and you can not produce data frame with multiple NULL values test - data.frame(NULL, NULL, NULL) test data frame with 0 columns and 0 rows str(test) 'data.frame': 0 obs. of 0 variables and test it with is.null is.null(test) [1] FALSE regards Petr Bert Gunter gunter.ber...@gene.com napsal dne 29.04.2009 18:34:00: test - list(NULL) Bert Gunter Nonclinical Biostatistics 467-7374 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Petr PIKAL Sent: Wednesday, April 29, 2009 8:21 AM To: ml-r-h...@epigenomics.com Cc: r-h...@stat.math.ethz.ch; Moumita Das Subject: Re: [R] if condition doesn't evaluate to True/False Hi r-help-boun...@r-project.org napsal dne 29.04.2009 17:05:01: see ?is.null e.g. if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) ) { your code } It probably will not work as sub_grp_whr_cls_data[sbgrp_no,1]==NULL implicates that there is character value NULL. I am not sure if you can get NULL as a part of some object. I tried and failed. See what you get x- c(1,2,3, NULL) Regards Petr Moumita Das wrote: Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]==NULL || sub_grp_whr_cls_data[sbgrp_no,1]==*) should evaluate to TRUE ,but it evaluated to NA So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]==NULL || sub_grp_whr_cls_data[sbgrp_no,1]==*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == NULL || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there 's no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||sub_grp_whr_cls_data[sbgrp_no,1]==) should automatically evaluate to * TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||sub_grp_whr_cls_data[sbgrp_no,1]==) evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||sub_grp_whr_cls_data[sbgrp_no,1]==) is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where condition is available why doesn't it evaluate to TRUE when a where condition available is NULL or no where condition is available.* Here I have taken the example of two databases where I tried to get the where clause for subgroup 1.In case of Database1 it was not available in case of Databse2 it was available.But the problem may appear for the same database also, when where clause is available for say one subgroup and not for the other. -- -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Matthias Burger Project Manager/ Biostatistician Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany phone:+49-30-24345-0fax:+49-30-24345-555 http://www.epigenomics.com matthias.bur...@epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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,
Re: [R] Corrupt data frame construction - bug?
On 29/04/2009 9:21 PM, Steven McKinney wrote: Thanks Duncan, Comments and a proposed bug fix in-line below: Thanks; sorry for the misinformation about the $ method. I'm not going to have time today to look at the patch, but will check it out tomorrow, unless someone else gets there first. Duncan Murdoch -Original Message- From: Duncan Murdoch [mailto:murd...@stats.uwo.ca] Sent: Wednesday, April 29, 2009 5:10 PM To: Steven McKinney Cc: R-help@r-project.org Subject: Re: [R] Corrupt data frame construction - bug? On 29/04/2009 6:41 PM, Steven McKinney wrote: Hi useRs, A recent coding infelicity along these lines yielded a corrupt data frame. foo - matrix(1:12, nrow = 3) bar - data.frame(foo) bar$NewCol - foo[foo[, 1] == 4, 4] bar lapply(bar, length) foo - matrix(1:12, nrow = 3) bar - data.frame(foo) bar$NewCol - foo[foo[, 1] == 4, 4] bar X1 X2 X3 X4 NewCol 1 1 4 7 10 NA 2 2 5 8 11 NA 3 3 6 9 12 NA Warning message: In format.data.frame(x, digits = digits, na.encode = FALSE) : corrupt data frame: columns will be truncated or padded with NAs lapply(bar, length) $X1 [1] 3 $X2 [1] 3 $X3 [1] 3 $X4 [1] 3 $NewCol [1] 0 Is this a bug in the data.frame machinery? If an attempt is made to add a new column to a data frame, and the new object does not have length = number of rows of data frame, or cannot be made to have such length via recycling, shouldn't an error be thrown? Instead in this example I end up with a corrupt data frame having one zero-length column. Should this be reported as a bug, or did I misinterpret the documentation? I don't think $ uses any data.frame machinery. You are working at a lower level. If you had added the new column using bar - data.frame(bar, NewCol=foo[foo[, 1] == 4, 4]) you would have seen the error: Error in data.frame(bar, NewCol = foo[foo[, 1] == 4, 4]) : arguments imply differing number of rows: 3, 0 But since you treated it as a list, it let you go ahead and create something that was labelled as a data.frame but wasn't. This is one of the reasons some people prefer S4 methods: it's easier to protect against people who mislabel things. I did some more digging on '$' - there is a data.frame method for it: getAnywhere($-.data.frame ) A single object matching '$-.data.frame' was found It was found in the following places package:base registered S3 method for $- from namespace base namespace:base with value function (x, i, value) { cl - oldClass(x) class(x) - NULL nrows - .row_names_info(x, 2L) if (!is.null(value)) { N - NROW(value) if (N nrows) stop(gettextf(replacement has %d rows, data has %d, N, nrows), domain = NA) if (N nrows N 0L) if (nrows%%N == 0L length(dim(value)) = 1L) value - rep(value, length.out = nrows) else stop(gettextf(replacement has %d rows, data has %d, N, nrows), domain = NA) if (is.atomic(value)) names(value) - NULL } x[[i]] - value class(x) - cl return(x) }environment: namespace:base I placed a browser() command before return(x) and did some poking around. It seems to me there's a bug in this function. It should be able to detect the problem I threw at it, and throw an error as you point out is thrown by the other data.frame assign method. I modified the rows if (N nrows N 0L) if (nrows%%N == 0L length(dim(value)) = 1L) to read if (N nrows) if (N 0L nrows%%N == 0L length(dim(value)) = 1L) as in $-.data.frame - function (x, i, value) { cl - oldClass(x) class(x) - NULL nrows - .row_names_info(x, 2L) if (!is.null(value)) { N - NROW(value) if (N nrows) stop(gettextf(replacement has %d rows, data has %d, N, nrows), domain = NA) if (N nrows) if (N 0L nrows%%N == 0L length(dim(value)) = 1L) value - rep(value, length.out = nrows) else stop(gettextf(replacement has %d rows, data has %d, N, nrows), domain = NA) if (is.atomic(value)) names(value) - NULL } x[[i]] - value class(x) - cl return(x) } Now it detects the problem I created, in the fashion you demonstrated above for the replacement using data.frame(). foo - matrix(1:12, nrow = 3) bar - data.frame(foo) bar$NewCol - foo[foo[, 1] == 4, 4] Error in `$-.data.frame`(`*tmp*`, NewCol, value = integer(0)) : replacement has 0 rows, data has 3 It doesn't appear to stumble on weird data frames (these from the ?data.frame help page) L3 - LETTERS[1:3] (d - data.frame(cbind(x=1, y=1:10), fac=sample(L3, 10, replace=TRUE))) (d0 - d[, FALSE]) # NULL data frame with 10 rows (d.0 - d[FALSE, ]) # 0 rows data frame (3 cols) (d00 - d0[FALSE,]) # NULL data frame with 0 rows d0$NewCol - foo[foo[, 1] == 4, 4] Error
Re: [R] Corrupt data frame construction - bug?
Duncan Murdoch wrote: On 29/04/2009 6:41 PM, Steven McKinney wrote: foo - matrix(1:12, nrow = 3) bar - data.frame(foo) bar$NewCol - foo[foo[, 1] == 4, 4] bar X1 X2 X3 X4 NewCol 1 1 4 7 10 NA 2 2 5 8 11 NA 3 3 6 9 12 NA Warning message: In format.data.frame(x, digits = digits, na.encode = FALSE) : corrupt data frame: columns will be truncated or padded with NAs Is this a bug in the data.frame machinery? If an attempt is made to add a new column to a data frame, and the new object does not have length = number of rows of data frame, or cannot be made to have such length via recycling, shouldn't an error be thrown? Instead in this example I end up with a corrupt data frame having one zero-length column. Should this be reported as a bug, or did I misinterpret the documentation? I don't think $ uses any data.frame machinery. You are working at a lower level. well, there is the function `$-.data.frame`. why does bar$NewCol - ... *not* dispatch to $-.data.frame? $- is used on bar, and bar is a data frame: is(bar) # data.frame ... trace('$-.data.frame') bar$foo - 1 # no output trace('$-') bar$foo - 1 # trace: `$-`(`*tmp*`, foo, value = 1) (still with the ugly *tmp*-hack) and, actually, ?'$-.data.frame' says: ## S3 replacement method for class 'data.frame': x$i - value If you had added the new column using bar - data.frame(bar, NewCol=foo[foo[, 1] == 4, 4]) you would have seen the error: Error in data.frame(bar, NewCol = foo[foo[, 1] == 4, 4]) : arguments imply differing number of rows: 3, 0 But since you treated it as a list, he has *not*: he has used the S3 replacement method for class 'data.frame'. the fact that it didn't work as expected seems to be a consequence of a bug in the dispatch mechanism. it let you go ahead and create something that was labelled as a data.frame but wasn't. wasn't? what wasn't what? after bar$NewCol - integer(0), bar is labelled as a data frame, and it seems to actually *be* a data frame; data frame operations seem to work on bar, and the warning from print bar talks about a corrupt data frame, not a non-data frame. or do you mean that bar is not a data frame internally? that would be a semantic weirdo where a user successfully performs an operation on a data frame and gets a zombie. in any case, looks like a bug. This is one of the reasons some people prefer S4 methods: it's easier to protect against people who mislabel things. it's *R* that mislabels things here. i can't see the user doing any explicit labelling; the only stuff used was data.frame() and '$-.', which should dispatch to '$-.data.frame'. the resulting zombie object is clearly R's, not the user's, fault. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem in as.date
I never understood that why is the value returned by as.date function in the library(survival) never matches with the description given in the help file: Following is the extract from ?as.date Description: Converts any of the following character forms to a Julian date: 8/31/56, 8-31-1956, 31 8 56, 083156, 31Aug56, or August 31 1956. Usage: as.date(x, order = mdy, ...) Value: For each date, the number of days between it and January 1, 1960. The date will be missing if the string is not interpretable. But here is what happens when you actually use it: as.date(c(1jan1960)) [1] 1Jan60 Can somebody explain this? Also please suggest me the best function in R to convert from as.Date(2009-08-13) to Julian and vice versa. Regards Utkarsh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Curved arrows
I'm trying to draw an arrow with a curved shaft on the graph as a straight one looks messy on a detailed graph. I've looked in arrows but it doesn't seem to give an option. larrows doesn't look much more promising. I had a look in the archive and couldn't find anything. Any thoughts? Thanks Paul -- View this message in context: http://www.nabble.com/Curved-arrows-tp23312316p23312316.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] Hoe to get RESIDUAL VARIANCE in logistic regression using lmer
Hello everybody, using the lmer function, I have fitted the following logistic mixed regression model on an experimental data set containing one fixed factor (Cond) and three random variables (Sito, Area, Trans): model-lmer(Caul~Cond+(1|Sito)+(1|Area)+(1|Trans), data=dataset, family=binomial) this is the output: summary(model) Generalized linear mixed model fit by the Laplace approximation Formula: Caul ~ Cond + (1 | Sito) + (1 | Area) + (1 | Trans) Data: dataset AIC BIC logLik deviance 548.7 573.7 -268.3536.7 Random effects: Groups NameVariance Std.Dev. Trans (Intercept) 3.2313398 1.797593 Area (Intercept) 0.000 0.00 Sito (Intercept) 0.0047151 0.068667 Number of obs: 480, groups: Trans, 48; Area, 12; Sito, 2 As you can see the residual variance is missing. Can anybody tell me why? Does anybody know how can I get it? Thank you for your attention, I wish somebody can help me. Have a nice day, best regards, Tommaso Alestra -- View this message in context: http://www.nabble.com/Hoe-to-get-RESIDUAL-VARIANCE-in-logistic-regression-using-lmer-tp23313330p23313330.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] meta regression in R using lme function
Hello Jan, As far as know, fixing sigma to 1 is not possible in R with lme. That is why I started to write my own functions to allow me to fit mixed-effects models in R. Quite some time ago, I put one of those functions on my website, which can be downloaded here: http://www.wvbauer.com/downloads.html. Since some people have indicated to me that they have found the function useful, I have been expanding the function into a full package, which I will be relasing shortly. It includes a much-improved version of the function that is currently on my website and methods for printing, ploting, residual extraction, influence diagnostics, and so on. The Mantel-Haenszel and Peto's method are also implemented. In a second stage, I will be adding functions to fit the bivariate mixed-effects model and then a multivariate model function, which is useful for more complex syntheses (such as when doing a meta-analysis of mixed-treatment comparisons). So maybe the upcoming package will be useful to you. Best, -- Wolfgang Viechtbauer Department of Methodology and Statistics University of Maastricht, The Netherlands http://www.wvbauer.com/ Original Message From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jan van de Kassteele Sent: Wednesday, April 29, 2009 15:02 To: r-help@r-project.org Subject: [R] meta regression in R using lme function Dear all, We are trying to do a meta regression in R using the lme function. The reason for doing this with lme function is that we have covariates and studies within references. In S-Plus this is possible by using the following command: lme(outcome ~ covars, random = ~1 | reference/study, weights = varFixed(~var.outcome), data = mydata, control = lmeControl(sigma = 1)) This means that the residual variance is equal to var.outcome times sigma, where sigma is fixed to 1. In R we do not know how to fix sigma = 1 in the lmeControl. Has anyone experience with this? If so, how can we solve this problem? We can't stand that we can do it in S-Plus, but not in R! Jan van de Kassteele Maarten Schipper __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rjava - JDK not found
Hi, I would like to test the new package RGG (R Gui Generator). This package requires the installation of several other package. One of them is rJava. I installed sun-java6-jdk and run the R CMD javareconf but the installation still fails ! Do you have any ideas ? * Installing *source* package rJava ... checking for gcc... gcc -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -std=gnu99 accepts -g... yes checking for gcc -std=gnu99 option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -std=gnu99 -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/wait.h that is POSIX.1 compatible... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for string.h... (cached) yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking whether time.h and sys/time.h may both be included... yes configure: checking whether gcc -std=gnu99 supports static inline... yes checking Java support in R... present: interpreter : '/usr/lib/jvm/java-6-sun/jre/bin/java' archiver: '/usr/lib/jvm/java-6-sun/bin/jar' compiler: '/usr/lib/jvm/java-6-sun/bin/javac' header prep.: '/usr/lib/jvm/java-6-sun/bin/javah' cpp flags : '-I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux' java libs : '-L/usr/lib/jvm/java-6-sun-1.6.0.07/jre/lib/amd64/server -L/usr/lib/jvm/java-6-sun-1.6.0.07/jre/lib/amd64 -L/usr/lib/jvm/java-6-sun-1.6.0.07/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/lib -L/usr/lib -ljvm:-L/usr/lib32:-L/usr/lib64' checking whether JNI programs can be compiled... configure: error: Cannot compile a simple JNI program. See config.log for details. Make sure you have Java Development Kit installed and correctly registered in R. If in doubt, re-run R CMD javareconf as root. ERROR: configuration failed for package rJava _ Découvrez toutes les possibilités de communication avec vos proches [[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] useR! 2009 program available
Dear members of the R user community, I am pleased to inform you that the program of the useR! 2009 conference (Rennes, France, July 8 to 10, 2009) is available online: http://www.agrocampus-ouest.fr/math/useR-2009/program.html You can register from the link below: http://www.agrocampus-ouest.fr/math/useR-2009/formulaires/registration.php The conference web page: http://www.agrocampus-ouest.fr/math/useR-2009/accomodation.html gives a list of hotels and some student rooms (200) are also available on the campus (Rennes will be very busy at the conference time because the cultural event `Festival Les tombées de la nuit' will take place at the same time, so we recommend to book as soon as possible). We hope to meet you in Rennes! F. Husson -- Francois Husson Applied Mathematics Department Agrocampus 65 rue de Saint-Brieuc - CS 84215 - 35042 RENNES Tel : 33 (0) 2 23 48 58 86 Fax : 33 (0) 2 23 48 58 71 mél : hus...@agrocampus-ouest.fr http://www.agrocampus-ouest.fr/math/husson useR!2009 : http://www.agrocampus-ouest.fr/math/useR-2009 ___ r-annou...@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-announce __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Select the same rows
thanks Seangduan sangduan J. wrote: Hi all, I have a problem selecting some rows from a random data. I'd like to select the same rows (before 0) . For example: A [1] 0 [2] 1 [3] 2 [4] 0 [5] 1 [6] 0 [7] 1 [8] 2 [9] 3 [10] 4 I'd like to select the row where a = 2 1 4 I searched on the search of the R site but I did'nt find anything of simple. Can someone help me? Thank you very much Seangduan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Select-the-same-rows-tp23289646p23311532.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] finite mixture model (2-component Weibull): plotting Weibull components?
Dear Knowledgeable R Community Members, Please excuse my ignorance, I apologize in advance if this is an easy question, but I am a bit stumped and could use a little guidance. I have a finite mixture modeling problem -- for example, a 2-component Weibull mixture -- where the components have a large overlap, and I am trying to adapt the mclust package which concern to normal mixture to solve this problem. I need to decompose that mixture into its 2 components which will need to be plotted. What I don't know how to do is: (1) restrict the number of components to 2 . (2) obtain and plot a component Weibull density (Note: my real dataset will not have peaks this well separated, but I needed to find a small example.) Any information you might be able to shed on this would be very much appreciated With appreciation for your help. Thank you in advance Cordially; Abdoul Aziz Junior NDOYE GREQAM Marseille. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace values?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, If the coding would start at 1 rather than 0 then +1's in the penultimate line could be eliminated. Sigbert - --- gene - c(YAR003W, YAR007C, YAR008W, YBL035C, YBL111C, YBL112C) print(gene) to - c(0,1,3,2) # to - c(1,2,4,3) from - c(1,5,4,3) # from - c(2,6,5,4) gene[to+1] - gene[from+1] # gene[to] - gene[from] print(gene) -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD4DBQFJ+YKUWvYUYQkj1zkRAjlVAJ9NrHySXnFCUmyBS7XbBwgAeOu1XQCVHvCa omPs62LERNyQJ/+I9uL52g== =seex -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mode(x) - double
SOLVED: I imported again the data like this: data - scan (data.txt) Thanks Phil Spector! Alessandra aledanda wrote: Hi, I need your help!! I imported a big coloumn vector from a txt file but it results as mode :list I want to change it in numeric otherwise I can't do my analysis. This is what i get: mode (data) - double Error in eval(expr, envir, enclos) : (list) object cannot be coerced to type 'double' Thanks a lot!!! Alessandra -- View this message in context: http://www.nabble.com/mode%28x%29-%3C--%22double%22-tp23296727p23313192.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] problem about finding power in test about variances
ati sundar wrote: Hello All I am new to this list. I have a problem where for a single sample drawn from normal population, null hypothesis is that variance = k (say). Perhaps you want to tell us more precisely what you are going to do rather than asking the same inprecise question again and again (including messages to single persons on the list). Is k fixed or the variance? What are your data? Specify a valid Null / Alternative combination. If you Null is variance = k (say) then you alternative is variance != k or if the alternative is variance k, then your null is probably variance = k Uwe Ligges Alternative hypothesis is variance k. Now if we know the true variance, then I would like to calculate the sample size required to produce certain power (for some significance). How do I do this ? I thought of using pwr.chisq.test, and I contacted the author stephane champely, but he said his package can't do this. Does anybody have an idea ? Thanks Ati __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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] URGENTE
Sto imparando ora ad utilizzare R. Ho un problema: devo caricare i dati da un file xls creato da me, utilizzando la funzione read.xls produce il seguente errore: Errore in xls2csv(xls, sheet, verbose = verbose, ..., perl = perl) : Unable to read xls file 'indagineUSA.xls'. Errore in file.exists(tfn) : argomento 'file' non valido Cosa c'è che non va? La directory di lavoro è quella giusta. Grazie [[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] Legend best position
Christian Bustamante wrote: Hi all, I'm doing a lot of plots and all of them should have a legend. The problem is that this legend not always have to be in the same place, because some plots can override the legend box. I'm wondering if there exist a command that optimally allocate the legend position, I'm refer to a MATLAB's command'slegend and it's option Best. Exist? It's not perfect, but the emptyspace function in the plotrix package does a reasonable job if the plot isn't really full. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] finite mixture model (2-component Weibull): plotting Weibull components?
mclust doesn't do Weibull mixtures, only Gaussian ones (though you may approximate a Weibull by several Gaussians). You may look up the flexmix package, which either does it already or a method function can be provided to do it. There is also an example fitting a mixture distribution in Venables and Ripley's MASS book with normals (including plotting the density), which you could adapt for Weibull distributions by plugging in the corresponding functions for the Weibull. (1) restrict the number of components to 2 . Specify G=2 in mclust (if want to fit 2 Gaussians). (2) obtain and plot a component Weibull density Generally, adding a Weibull mixture density to a plot works by x - seq(0,100,by=0.1) # or whatever reasonable choice of x-values lines(x,p*dweibull(x,s11,s12)+(1-p)*dweibull(x,s21,s22)) where p, s11, s12, s21, s22 are the mixture parameters. Regards, Christian *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] library which convert dates
Grześ wrote: I'm looking for library which let mi convert dates for example like this: 00-06-05 00:00 00-08-06 00:00 00-08-16 00:00 00-05-23 00:00 00-01-14 00:00 00-10-28 00:00 and as a result I want to get a 3 levels Hi Gregorio, I might be wildly wrong, but I think you want to read in dates like this: mydatestrings-c(00-06-05 00:00,...) mydates-strftime(mydatestrings,format=%y-%m-%d %H:%M) myresult-cut(mydates,breaks=3) to get the year 2000 divided into thirds. Feel free to ignore this if I am wildly wrong. 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] Using predict with glmmPQL
I am wondering if anyone knows how to use predict with a glmmPQL model, where you want to predict the response for one factor in the model? Originally I used predict on a GLM (gamma, log link) in the following way: p.1-predict(model1,data.frame(year=as.factor(xv),nafdiv=as.factor(rep( 3N,length(xv))), duration=1000, cfv=as.factor(rep(106166,length(xv))), hooks=rep(1,length(xv))),type=response,se.fit=T) where model1 standardises catch rate and includes nafo area, year, duration of fishing sets, and vessel (cfv) as explanatory variables with an offset of hooks. To predict the years we had data for, we substituted a vector xv of years into predict and specified the values to be used for the other explanatory variables. This seemed to work well. When I switched to a glmmPQL model, with vessel as a random effect, I adapted predict to: predict(model1, catch, type=response) where catch is the dataframe used for the original model. This works but gives a predicted value for every trip (each row) in my table. I have tried specifying values in a dataframe like the GLM example above and including year as a vector but I get the following error message Error in `contrasts-`(`*tmp*`, value = contr.treatment) : contrasts can be applied only to factors with 2 or more levels Any advice is appreciated! Sophie [[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] Hoe to get RESIDUAL VARIANCE in logistic regression using lmer
Dear Tommaso, The residuals variance is fixed at 1 with the binomial family. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens tomal Verzonden: donderdag 30 april 2009 12:10 Aan: r-help@r-project.org Onderwerp: [R] Hoe to get RESIDUAL VARIANCE in logistic regression using lmer Hello everybody, using the lmer function, I have fitted the following logistic mixed regression model on an experimental data set containing one fixed factor (Cond) and three random variables (Sito, Area, Trans): model-lmer(Caul~Cond+(1|Sito)+(1|Area)+(1|Trans), data=dataset, family=binomial) this is the output: summary(model) Generalized linear mixed model fit by the Laplace approximation Formula: Caul ~ Cond + (1 | Sito) + (1 | Area) + (1 | Trans) Data: dataset AIC BIC logLik deviance 548.7 573.7 -268.3536.7 Random effects: Groups NameVariance Std.Dev. Trans (Intercept) 3.2313398 1.797593 Area (Intercept) 0.000 0.00 Sito (Intercept) 0.0047151 0.068667 Number of obs: 480, groups: Trans, 48; Area, 12; Sito, 2 As you can see the residual variance is missing. Can anybody tell me why? Does anybody know how can I get it? Thank you for your attention, I wish somebody can help me. Have a nice day, best regards, Tommaso Alestra -- View this message in context: http://www.nabble.com/Hoe-to-get-RESIDUAL-VARIANCE-in-logistic-regressio n-using-lmer-tp23313330p23313330.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. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Curved arrows
Paul, there might be other solutions as well, but there is an internal function in the igraph package that can draw curved arrows, it is called igraph:::igraph.Arrows(). As it is an internal function, it is not documented, but I think it is pretty straightforward to use. For the 'curved' argument you can give a number, try values between 0 and 1, or (if I remember well) -1 and 0 if you want it to curve towards the opposite side. Best, Gabor On Thu, Apr 30, 2009 at 10:57 AM, Paul Chatfield p.s.chatfi...@rdg.ac.uk wrote: I'm trying to draw an arrow with a curved shaft on the graph as a straight one looks messy on a detailed graph. I've looked in arrows but it doesn't seem to give an option. larrows doesn't look much more promising. I had a look in the archive and couldn't find anything. Any thoughts? Thanks Paul -- View this message in context: http://www.nabble.com/Curved-arrows-tp23312316p23312316.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. -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Corrupt data frame construction - bug?
Duncan Murdoch wrote: On 29/04/2009 9:21 PM, Steven McKinney wrote: Thanks Duncan, Comments and a proposed bug fix in-line below: Thanks; sorry for the misinformation about the $ method. maybe it's a good idea to change your strategy and avoid blaming users for faults that lie on the software's side. r is buggy, and you might well be more open to admitting there is a bug in a particular function instead of suggesting that people mislabel things and the like. best, vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem in as.date
What you see is the result of 'printing' something of the class 'date'. x - as.date(c(1jan1960)) x [1] 1Jan60 str(x) Class 'date' int 0 unclass(x) [1] 0 getAnywhere('print.date') A single object matching print.date was found It was found in the following places registered S3 method for print from namespace survival namespace:survival with value function (x, quote, prefix, ...) { fun - options()$print.date if (is.null(fun)) x - date.ddmmmyy(x) else x - get(fun)(x) if (missing(quote)) quote - FALSE invisible(print(x, quote = quote)) } environment: namespace:survival Notice that if you 'unclass' x you get the value 0 which is the number of days from 1/1/1960 of your input. On Thu, Apr 30, 2009 at 2:16 AM, utkarshsinghal utkarsh.sing...@global-analytics.com wrote: I never understood that why is the value returned by as.date function in the library(survival) never matches with the description given in the help file: Following is the extract from ?as.date Description: Converts any of the following character forms to a Julian date: 8/31/56, 8-31-1956, 31 8 56, 083156, 31Aug56, or August 31 1956. Usage: as.date(x, order = mdy, ...) Value: For each date, the number of days between it and January 1, 1960. The date will be missing if the string is not interpretable. But here is what happens when you actually use it: as.date(c(1jan1960)) [1] 1Jan60 Can somebody explain this? Also please suggest me the best function in R to convert from as.Date(2009-08-13) to Julian and vice versa. Regards Utkarsh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] URGENTE
Hi Barbara, How about you copy-and-past the data into the notepad.exe editor and df-read.table (..., head=T, sep=\t) ? ciao miltinho brazil-toronto 2009/4/30 barbara.r...@uniroma1.it Sto imparando ora ad utilizzare R. Ho un problema: devo caricare i dati da un file xls creato da me, utilizzando la funzione read.xls produce il seguente errore: Errore in xls2csv(xls, sheet, verbose = verbose, ..., perl = perl) : Unable to read xls file 'indagineUSA.xls'. Errore in file.exists(tfn) : argomento 'file' non valido Cosa c'è che non va? La directory di lavoro è quella giusta. Grazie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I sample cases within a matrix?
Hi Silvia, excuse me if I'm missing something but sampling the row numbers should make it : let M be your matrix, and spM a sample with n rows : spM - M[sample(seq(1,dim(M)[1],by=1), n),] Regards, Olivier Silvia Lomascolo wrote: Hi R community, I am trying to obtain a sample from a matrix but sample(my.matrix) doesn't do what I need. I have a matrix of 1287 interactions between the species in columns and the species in rows and I want to obtain a smaller matrix with say, 800 interactions, that may or may not have the same number of columns and/or rows (i.e., some interactions may not be retrieved in a smaller sample). For example, my original mock matrix M is [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 The command sample(my.matrix) samples whole cells from my matrix, such that if the interaction between species 1 and 1 is included in the sample, they always show 140 interactions. But what I want is to sample cases within each cell. My sample matrix S could have =140 interactions between species 1 and 1, =100 between species 1 and 2, etc. Again, if some combination is absent from the sample matrix, that's OK. Here's my code, in case it helps: pla- c(10, 9, 6, 5, 3) #abundance of pla species pol- c(14, 10, 9, 4, 2) #abundance of pol species m-pla%*%t(pol) #matrix of interactions according to pla and pol abundance m [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 sample(m) #doesn't give me what I want... I have searched the forum for an answer but all questions regarding sampling from matrices refer to sampling whole rows or columns, not cases within a matrix. Thanks in advance for any help! Silvia. -- View this message in context: http://www.nabble.com/How-do-I-sample-%22cases%22-within-a-matrix--tp23296664p23314865.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] factor issue
Hi, I have a column which I have to convert from factors to numeric. I am using the command as.numeric(variable) to do this. But when I convert the numeric value becomes different from factor . for example. class(B) [1] factor B [1] 180 NA 183 175 163 155 NA 188 191 160 170 165 152 170 165 [16] 163 160 163 165 NA as.numeric(B) [1] 46 NA 47 42 30 26 NA 49 50 29 37 32 24 37 32 30 29 30 32 NA Is there a different way to convert factor to respective number ? also when i try to unclass it i get following output unclass(B) [1] 46 NA 47 42 30 26 NA 49 50 29 37 32 24 37 32 30 29 30 32 NA attr(,levels) [1] 102 104 107 109 110 112 114 117 119 122 124 125 [13] 127 129 130 132 135 137 140 142 145 147 150 152 [25] 153 155 157 159 160 163 164 165 166 167 168 169 [37] 170 171 172 173 174 175 177 178 179 180 183 185 [49] 188 191 193 196 198 201 203 211 46 48 51 56 [61] 58 60 61 63 64 65 66 69 71 74 76 79 [73] 81 84 86 89 91 94 97 99 U Any help will be appreciated. Thanks a lot. Regards, Nataraju GM -- No relationship is Static .. You either Step up or Step down [[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] factor issue
check the following: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f Best, Dimitris Nattu wrote: Hi, I have a column which I have to convert from factors to numeric. I am using the command as.numeric(variable) to do this. But when I convert the numeric value becomes different from factor . for example. class(B) [1] factor B [1] 180 NA 183 175 163 155 NA 188 191 160 170 165 152 170 165 [16] 163 160 163 165 NA as.numeric(B) [1] 46 NA 47 42 30 26 NA 49 50 29 37 32 24 37 32 30 29 30 32 NA Is there a different way to convert factor to respective number ? also when i try to unclass it i get following output unclass(B) [1] 46 NA 47 42 30 26 NA 49 50 29 37 32 24 37 32 30 29 30 32 NA attr(,levels) [1] 102 104 107 109 110 112 114 117 119 122 124 125 [13] 127 129 130 132 135 137 140 142 145 147 150 152 [25] 153 155 157 159 160 163 164 165 166 167 168 169 [37] 170 171 172 173 174 175 177 178 179 180 183 185 [49] 188 191 193 196 198 201 203 211 46 48 51 56 [61] 58 60 61 63 64 65 66 69 71 74 76 79 [73] 81 84 86 89 91 94 97 99 U Any help will be appreciated. Thanks a lot. Regards, Nataraju GM -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] stepAICc
Dear R users, Would it be difficult to change the code of stepAIC (from the MASS library) to use AICc instead of AIC? It would be great to know of someone has tried this already. Best wishes Christoph. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 do I sample cases within a matrix?
Well Silvia, I understand that I didn't read your post carefully. Forget about my previous (unrelevant) post. regards. olivier Olivier ETERRADOSSI wrote: Hi Silvia, excuse me if I'm missing something but sampling the row numbers should make it : let M be your matrix, and spM a sample with n rows : spM - M[sample(seq(1,dim(M)[1],by=1), n),] Regards, Olivier Silvia Lomascolo wrote: Hi R community, I am trying to obtain a sample from a matrix but sample(my.matrix) doesn't do what I need. I have a matrix of 1287 interactions between the species in columns and the species in rows and I want to obtain a smaller matrix with say, 800 interactions, that may or may not have the same number of columns and/or rows (i.e., some interactions may not be retrieved in a smaller sample). For example, my original mock matrix M is [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 The command sample(my.matrix) samples whole cells from my matrix, such that if the interaction between species 1 and 1 is included in the sample, they always show 140 interactions. But what I want is to sample cases within each cell. My sample matrix S could have =140 interactions between species 1 and 1, =100 between species 1 and 2, etc. Again, if some combination is absent from the sample matrix, that's OK. Here's my code, in case it helps: pla- c(10, 9, 6, 5, 3) #abundance of pla species pol- c(14, 10, 9, 4, 2) #abundance of pol species m-pla%*%t(pol) #matrix of interactions according to pla and pol abundance m [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 sample(m) #doesn't give me what I want... I have searched the forum for an answer but all questions regarding sampling from matrices refer to sampling whole rows or columns, not cases within a matrix. Thanks in advance for any help! Silvia. -- View this message in context: http://www.nabble.com/How-do-I-sample-%22cases%22-within-a-matrix--tp23296664p23315275.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 do I sample cases within a matrix?
Hi again Silvia (last time... ?), now : do I understand : you want 1) to randomly select some intersections between rows and columns 2) randomly select a number of cases for each intersection (being = the number of initial cases ? if yes, here is my solution, using your example : # select intersections, put them in new matrix mm mm-m[sample(seq(1,5,by=1),2),sample(seq(1,5,by=1),3)] # make a function that samples a number of cases foo-function(x) sample(seq(1,x,by=1),1) # use mapply mmm-matrix(mapply(mm,FUN=foo),dim(mm)[1],dim(mm)[2]) On my computer it seems to work... hope this really help, this time ! Regards. Olivier Silvia Lomascolo wrote: Hi R community, I am trying to obtain a sample from a matrix but sample(my.matrix) doesn't do what I need. I have a matrix of 1287 interactions between the species in columns and the species in rows and I want to obtain a smaller matrix with say, 800 interactions, that may or may not have the same number of columns and/or rows (i.e., some interactions may not be retrieved in a smaller sample). For example, my original mock matrix M is [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 The command sample(my.matrix) samples whole cells from my matrix, such that if the interaction between species 1 and 1 is included in the sample, they always show 140 interactions. But what I want is to sample cases within each cell. My sample matrix S could have =140 interactions between species 1 and 1, =100 between species 1 and 2, etc. Again, if some combination is absent from the sample matrix, that's OK. Here's my code, in case it helps: pla- c(10, 9, 6, 5, 3) #abundance of pla species pol- c(14, 10, 9, 4, 2) #abundance of pol species m-pla%*%t(pol) #matrix of interactions according to pla and pol abundance m [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 sample(m) #doesn't give me what I want... I have searched the forum for an answer but all questions regarding sampling from matrices refer to sampling whole rows or columns, not cases within a matrix. Thanks in advance for any help! Silvia. -- View this message in context: http://www.nabble.com/How-do-I-sample-%22cases%22-within-a-matrix--tp23296664p23315500.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] Curved arrows
On Thu, Apr 30, 2009 at 2:37 PM, p.s.chatfi...@rdg.ac.uk wrote: Hey - I tried this without success. The igraph doesn't work with R 2.9.0, That is strange, why not? so I'm using it with the 2.8.0 version which is the previous one I had. Can you write a simple code that would put an arrow with a curved shaft on, e.g plot(3,5) igraph.Arrows(3,4,4,5) Exactly like this, but the function is not exported, and you need the 'curved' argument: plot(3,5) igraph:::igraph.Arrows(3,4,4,5) igraph:::igraph.Arrows(3,4,4,5, curved=TRUE) igraph:::igraph.Arrows(3,4,4,5, curved=-0.5) igraph:::igraph.Arrows(3,4,4,5, curved=-1) igraph:::igraph.Arrows(3,4,4,5, curved=1) You need igraph version 0.5.2 for this I think. Type head(igraph:::igraph.Arrows) to see the other arguments to play with. Gabor Thanks for your quick reply before that was much appreciated, Paul Gábor Csárdi-2 wrote: Paul, there might be other solutions as well, but there is an internal function in the igraph package that can draw curved arrows, it is called igraph:::igraph.Arrows(). As it is an internal function, it is not documented, but I think it is pretty straightforward to use. For the 'curved' argument you can give a number, try values between 0 and 1, or (if I remember well) -1 and 0 if you want it to curve towards the opposite side. Best, Gabor On Thu, Apr 30, 2009 at 10:57 AM, Paul Chatfield p.s.chatfi...@rdg.ac.uk wrote: I'm trying to draw an arrow with a curved shaft on the graph as a straight one looks messy on a detailed graph. I've looked in arrows but it doesn't seem to give an option. larrows doesn't look much more promising. I had a look in the archive and couldn't find anything. Any thoughts? Thanks Paul -- View this message in context: http://www.nabble.com/Curved-arrows-tp23312316p23312316.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. -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Quoted from: http://www.nabble.com/Curved-arrows-tp23312316p23312605.html -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stepAICc
Dear Christoph, I done that and more. You'll find the functions below my signature. It is mainly based on stepAIC from MASS. But it does more. AICc = c(TRUE, FALSE) determines whether to use AICc or AIC Furthermore it does not only refines the 'best' model but all good models. A good model is defined as a model which has a AIC(c) values that differs less that delta from the best model. Delta is by default 2, but you can set it yourself. Delta = 0 would do the same thing a stepAIC from MASS. Bandwidth controles the minimum number of models to refine. Bandwidth = 10 will refine the 10 best models, regardless of AIC. Marginal is a named list to indicate marginality. marginal = list(A = c(B, C), B = C) means that A can only enter the model if B and C are present and B can only enter the model if C is present. Likewise B can only leave the model is A is not present and C if A nor B are present. joint allows to specify variables that must enter or leave the model simultaneous. joint = list(c(X, Y), c(SinX, CosX)) HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey stepAIC - function (object, scope, scale = 0, direction = c(both, backward, forward), trace = 1, steps = 1000, use.start = FALSE, k = 2, bandwidth = 10, marginal = NULL, AICc = TRUE, delta = 2, joint = NULL, positive.definite = FALSE, ...){ mydeviance - function(x, ...) { dev - deviance(x) if (!is.null(dev)){ dev } else { extractAIC(x, k = 0)[2] } } cut.string - function(string) { if (length(string) 1){ string[-1] - paste(\n, string[-1], sep = ) } string } Terms - terms(object) object$formula - Terms if (inherits(object, lme)){ object$call$fixed - Terms } else { if (inherits(object, gls)){ object$call$model - Terms } else { object$call$formula - Terms } } if (use.start){ warning('use.start' cannot be used with R's version of glm) } md - missing(direction) direction - match.arg(direction) backward - direction == both | direction == backward forward - direction == both | direction == forward if (missing(scope)) { fdrop - numeric(0) fadd - attr(Terms, factors) if (md){ forward - FALSE } } else { if (is.list(scope)) { if(!is.null(fdrop - scope$lower)){ fdrop - attr(terms(update.formula(object, fdrop)), factors) colnames(fdrop) - sapply(strsplit(colnames(fdrop), :, fixed = TRUE), function(x) paste(sort(x), collapse = :)) fdrop - fdrop[, order(colnames(fdrop))] } else { fdrop - numeric(0) } if (!is.null(fadd - scope$upper)){ fadd - attr(terms(update.formula(object, fadd)), factors) colnames(fadd) - sapply(strsplit(colnames(fadd), :, fixed = TRUE), function(x) paste(sort(x), collapse = :)) fadd - fadd[, order(colnames(fadd))] } } else { if (!is.null(fadd - scope)){ fadd - attr(terms(update.formula(object, scope)), factors) colnames(fadd) - sapply(strsplit(colnames(fadd), :, fixed = TRUE), function(x) paste(sort(x), collapse = :)) fadd - fadd[, order(colnames(fadd))] } fdrop - numeric(0) } } models - vector(list, steps) if (is.list(object) (nmm - match(nobs, names(object), 0)) 0) { n - object[[nmm]] } else { n - length(residuals(object)) } fit - object bAIC - extractAIC(fit, scale, k = k, ...) # bAIC - extractAIC(fit, scale, k = k) edf - bAIC[1] if(AICc){ bAIC - bAIC[2] + (2 * edf + (edf * 1)) / (n - edf - 1) } else { bAIC - bAIC[2] } if (is.na(bAIC)){ stop(AIC is not defined for this model, so stepAIC cannot proceed) } Terms - terms(fit) # reorder the covariates in alphabetical order response - as.list(attr(Terms, variables))[[attr(Terms, response) + 1]] if(length(attr(Terms, factors)) 0){ fixed -
Re: [R] 2 way ANOVA with possible pseudoreplication
Well, it's clearly not pseudoreplication if it's not replication! But the observations within animal could well be associated. You seem to have a straightforward experiment with multiple treatment combinations on multiple subjects. You could do several things. The most obvious is probably to consider 'animal' (or 'subject') as a random effect. You can do that with lme or lmer: lme(y~trt1*trt2, random=1|animal, data=...) or lmer(y~trt1*trt2+(1|animal), data=...) If you have a balanced design (all treatment combinations on all animals) and the treatments can reasonably be considered as fixed effects, you have a blocked design that can be analysed with a model of the form y~trt1*trt2+block (it is, under those circumstances, valid to compare treatment effects directly with the residual term; the 'block' effect just drops out as long as it's additive) or, using aov, with summary(aov(y~trt1*trt2+Error(block), data=.. )) That would make me nervous if different animals were given different sets of treatment combinations unless you'd been really clever and used a balanced incomplete block design (you'd certainly know if you had planned it that way!) The other obvious questions are whether treatments were applied in a consistent order, as a cross-over design or in randomised order, and whether there is carry-over. Carry-over and the related cross-over designs are distinctly outside my experience, though; chemists can normally ignore carry-over. I assume there's a biostatistician in the house... ... and of course I'm naively assuming that the treatments are factors and that you aren't studying dose-response curves or other things that need gradient terms. If you are, I suppose you'll want to look at Pinheiro and Bates rather carefully... Steve e nat_h fbs...@leeds.ac.uk 29/04/2009 13:43 Hi, I have an experiment with 2 independant factors which I have been trying to analyse in R. The problem is that there are several data points recorded on the same animal. However, no combination of treatments is repeated on the same animal. All possible combinations of treatments are done in a random order with as many points as possible being done on 1 animal before moving onto the next. The suggested way to remove pseudoreplication is to average the points from the same animal. However, as my measures on the same animal are of different treatment combinations so this makes no sense. It is also suggested that as I have random and fixed effects I should use a mixed effects model. However, given that my independant variables are factorial I am not sure how to incorporate this. I would be very grateful for any advice on methods of getting round this problem or whether I have sufficiently accounted from my none independant measures experimentally. Many thanks, Natalie -- View this message in context: http://www.nabble.com/2-way-ANOVA-with-possible-pseudoreplication-tp23295845p23295845.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. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mode(x) - double
Hi, I need your help!! I imported a big coloumn vector from a txt file but it results as mode :list I want to change it in numeric otherwise I can't do my analysis. How did you import the data? What function did you use? This is what i get: mode (data) - double Error in eval(expr, envir, enclos) : (list) object cannot be coerced to type 'double' Maybe unlist(data), but to get a more precise answer you have to tell us how you read the data in R Best, Giovanni Thanks a lot!!! Alessandra -- View this message in context: http://www.nabble.com/mode%28x%29-%3C--%22double%22-tp23296727p23296727.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. -- Giovanni Petris gpet...@uark.edu Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rjava - JDK not found
I completely removed the java-sun version and install the openjdk instead. I re-launched the R CMD reconf. The installation still failed ! install.packages(rJava) Warning in install.packages(rJava) : argument 'lib' is missing: using '/home/martial/R/x86_64-unknown-linux-gnu-library/2.9' trying URL 'http://cran.fr.r-project.org/src/contrib/rJava_0.6-2.tar.gz' Content type 'application/x-tar' length 237115 bytes (231 Kb) opened URL == downloaded 231 Kb * Installing *source* package rJava ... checking Java support in R... present: interpreter : '/usr/bin/java' archiver: '' compiler: '' header prep.: '' cpp flags : '-I/usr/lib/jvm/java-6-openjdk/jre/../include' java libs : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm' configure: error: Java Development Kit (JDK) is missing or not registered in R Make sure R is configured with full Java support (including JDK). Run R CMD javareconf as root to add Java support to R. It's interesting to notice that the result of the javareconf is totally different: ~$ R CMD javareconf -e /bin/bash Java interpreter : /usr/lib/jvm/java-6-openjdk//jre/bin/java Java version : 1.6.0_0 Java home path : /usr/lib/jvm/java-6-openjdk/ Java compiler: /usr/lib/jvm/java-6-openjdk//bin/javac Java headers gen.: /usr/lib/jvm/java-6-openjdk//bin/javah Java archive tool: /usr/lib/jvm/java-6-openjdk//bin/jar Java library path: $(JAVA_HOME)jre/lib/amd64/server:$(JAVA_HOME)jre/lib/amd64:$(JAVA_HOME)jre/../lib/amd64::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)jre/lib/amd64/server -L$(JAVA_HOME)jre/lib/amd64 -L$(JAVA_HOME)jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm JNI cpp flags: -I$(JAVA_HOME)/include The following Java variables have been exported: JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH Runnig: /bin/bash However, ~$ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_0 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: not present Java headers gen.: Java archive tool: Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm JNI cpp flags: -I$(JAVA_HOME)/../include Updating Java configuration in /usr/local/lib64/R Done. In fact the javareconf is called in sudo mode during the installation of the package rjava. How can I fix the java support in sudo mode ? Any ideas ?? From: martial100...@hotmail.com To: r-help@r-project.org Date: Thu, 30 Apr 2009 10:43:38 + Subject: [R] rjava - JDK not found Hi, I would like to test the new package RGG (R Gui Generator). This package requires the installation of several other package. One of them is rJava. I installed sun-java6-jdk and run the R CMD javareconf but the installation still fails ! Do you have any ideas ? * Installing *source* package rJava ... checking for gcc... gcc -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -std=gnu99 accepts -g... yes checking for gcc -std=gnu99 option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -std=gnu99 -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/wait.h that is POSIX.1 compatible... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for string.h... (cached) yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking whether time.h and sys/time.h may both be included... yes configure: checking whether gcc -std=gnu99 supports static inline... yes checking Java support in R... present: interpreter : '/usr/lib/jvm/java-6-sun/jre/bin/java' archiver: '/usr/lib/jvm/java-6-sun/bin/jar' compiler:
[R] What is the R version of the S function fac.design?
Hi R Community: What is the R version of the S function fac.design()? Please reply to: p...@cdc.gov Thanks! Phil Smith CDC Atlanta, GA [[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] Optim and hessian
The technical issue of this query has been answered by Ravi Varadhan (essentially use numDeriv on the final parameter set to get the hessian). This msg is about getting feedback to those of us trying to improve optimization capabilities. Ravi and I, among others, are working on a substitute package for optim() and related issues. This will still allow access to existing codes -- some of which I wrote in the mid 1970s for strange antique computers with 4K words of storage for program AND data. Some of these codes need updating, but even more, our knowledge base for advising people what to use needs better evidence of how well things perform in modern R settings, including new platforms as they come along. Tools to build such a base of information are part of an ancillary project. For those interested, please get in touch off-list. We have a wiki where we are sharing ideas. It's currently users only, as it is a work in progress that we would not want quoted, but I'll be happy to provide access on request. John Nash Original Msg. Hi, my name is Marcel R. Lopes. My problem is, I made a code to calculate the estimates of a Cox model with random effects. Used to optimize the R command for this. The estimates were calculated correctly, but the Hessian matrix does not have good values. The same thing was done in SAS and gave good results for the Hessian Matrix. Where is the problem in R? As the Hessian is calculated?. How could I solve this problem?. I would be grateful if you could help me __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] odbcConnectAccess in Access sub
HI: Is it possible to use the RODBC package within MS Access. I have been using from R but was just wondering if it could be used along with R(D)COM. Something like this: Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim myApp As StatConnector Set myApp = New StatConnector myApp.GetErrorText myApp.Init R myApp.EvaluateNoReturn library(RODBC) myApp.EvaluateNoReturn myDB - odbcConnectAccess(CurrentDb) 'query the database and save it as R object 'a' myApp.EvaluateNoReturn a - sqlQuery(CurrentDb, Paste(select * From Sample)) myApp.EvaluateNoReturn plot(a) Thanks in advance Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, 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] How do I sample cases within a matrix?
Both Oliver's and Chuck's code seem to work. Thank you very much!! I will keep working on this and might get back to the forum for more help if I get stuck. Thanks, really. PS: Does any of you know why your replies don't show up in the main forum? I get the message that the message hasn't been posted but all of you did get it. I'm subscribed to the list. I followed all the instructions to do it, but it still says that I cannot post on the forum... I'm confused Olivier ETERRADOSSI wrote: Hi again Silvia (last time... ?), now : do I understand : you want 1) to randomly select some intersections between rows and columns 2) randomly select a number of cases for each intersection (being = the number of initial cases ? if yes, here is my solution, using your example : # select intersections, put them in new matrix mm mm-m[sample(seq(1,5,by=1),2),sample(seq(1,5,by=1),3)] # make a function that samples a number of cases foo-function(x) sample(seq(1,x,by=1),1) # use mapply mmm-matrix(mapply(mm,FUN=foo),dim(mm)[1],dim(mm)[2]) On my computer it seems to work... hope this really help, this time ! Regards. Olivier Silvia Lomascolo wrote: Hi R community, I am trying to obtain a sample from a matrix but sample(my.matrix) doesn't do what I need. I have a matrix of 1287 interactions between the species in columns and the species in rows and I want to obtain a smaller matrix with say, 800 interactions, that may or may not have the same number of columns and/or rows (i.e., some interactions may not be retrieved in a smaller sample). For example, my original mock matrix M is [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 The command sample(my.matrix) samples whole cells from my matrix, such that if the interaction between species 1 and 1 is included in the sample, they always show 140 interactions. But what I want is to sample cases within each cell. My sample matrix S could have =140 interactions between species 1 and 1, =100 between species 1 and 2, etc. Again, if some combination is absent from the sample matrix, that's OK. Here's my code, in case it helps: pla- c(10, 9, 6, 5, 3) #abundance of pla species pol- c(14, 10, 9, 4, 2) #abundance of pol species m-pla%*%t(pol) #matrix of interactions according to pla and pol abundance m [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 sample(m) #doesn't give me what I want... I have searched the forum for an answer but all questions regarding sampling from matrices refer to sampling whole rows or columns, not cases within a matrix. Thanks in advance for any help! Silvia. -- View this message in context: http://www.nabble.com/How-do-I-sample-%22cases%22-within-a-matrix--tp23296664p23317153.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 do I sample cases within a matrix?
Thank you! This seems to work!!! Silvia. Charles C. Berry wrote: See below On Wed, 29 Apr 2009, Silvia Lomascolo wrote: Hi R community, I am trying to obtain a sample from a matrix but sample(my.matrix) doesn't do what I need. I have a matrix of 1287 interactions between the species in columns and the species in rows and I want to obtain a smaller matrix with say, 800 interactions, that may or may not have the same number of columns and/or rows (i.e., some interactions may not be retrieved in a smaller sample). For example, my original mock matrix M is [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 The command sample(my.matrix) samples whole cells from my matrix, such that if the interaction between species 1 and 1 is included in the sample, they always show 140 interactions. But what I want is to sample cases within each cell. My sample matrix S could have =140 interactions between species 1 and 1, =100 between species 1 and 2, etc. Again, if some combination is absent from the sample matrix, that's OK. Here's my code, in case it helps: pla- c(10, 9, 6, 5, 3) #abundance of pla species pol- c(14, 10, 9, 4, 2) #abundance of pol species m-pla%*%t(pol) #matrix of interactions according to pla and pol abundance m [,1] [,2] [,3] [,4] [,5] [1,] 140 100 90 40 20 [2,] 126 90 81 36 18 [3,] 84 60 54 24 12 [4,] 70 50 45 20 10 [5,] 42 30 27 126 sample(m) #doesn't give me what I want... If I understand you, m.index - 1:length(m) # sample all 1287: new.m - matrix(table( factor( sample(rep(m.index,m),1287), m.index )),nr=5) all.equal(m, new.m) # verify that original was reproduced [1] TRUE # now sample just 800 new.m - matrix(table( factor( sample(rep(m.index,m),800), m.index )),nr=5) m-new.m # look at the difference Chuck I have searched the forum for an answer but all questions regarding sampling from matrices refer to sampling whole rows or columns, not cases within a matrix. Thanks in advance for any help! Silvia. -- View this message in context: http://www.nabble.com/How-do-I-sample-%22cases%22-within-a-matrix--tp23296664p23296664.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/How-do-I-sample-%22cases%22-within-a-matrix--tp23296664p23317180.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to know what device I am using
Some years ago I wrote a plotting routine that was run on both Linux Windows computers. There were some differences in the way the plot looked from the windows device and the X11 device. To ensure consistency I used getOption(device)) and made some changes to the plotting if the windows device was being used. Using this routine again, years later, I now notice that getOption(device) returns a function listing, but no longer a string with the name of the device. What is the best way to query which device is the default? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] odbcConnectAccess function
HI: Is it possible to use the RODBC package within MS Access. I have been using from R but was just wondering if it could be used along with R(D)COM. Something like this: Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim myApp As StatConnector Set myApp = New StatConnector myApp.GetErrorText myApp.Init R myApp.EvaluateNoReturn library(RODBC) myApp.EvaluateNoReturn myDB - odbcConnectAccess(CurrentDb) 'query the database and save it as R object 'a' myApp.EvaluateNoReturn a - sqlQuery(CurrentDb, Paste(select * From Sample)) myApp.EvaluateNoReturn plot(a) Thanks in advance Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, 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] odbcConnectAccess function
Feilipe, You should look at the RODBC package It works great ! Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Felipe Carrillo mazatlanmex...@y ahoo.com To Sent by: r-h...@stat.math.ethz.ch r-help-boun...@r- cc project.org Subject [R] odbcConnectAccess function 04/30/2009 07:17 AM MST Please respond to mazatlanmex...@ya hoo.com HI: Is it possible to use the RODBC package within MS Access. I have been using from R but was just wondering if it could be used along with R(D)COM. Something like this: Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim myApp As StatConnector Set myApp = New StatConnector myApp.GetErrorText myApp.Init R myApp.EvaluateNoReturn library(RODBC) myApp.EvaluateNoReturn myDB - odbcConnectAccess(CurrentDb) 'query the database and save it as R object 'a' myApp.EvaluateNoReturn a - sqlQuery(CurrentDb, Paste(select * From Sample)) myApp.EvaluateNoReturn plot(a) Thanks in advance Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] setting key boxes in xyplot
I thought I mimicked the coded correctly, but find an error/omission somewhere in the xyplot function shown below. eggs # alligator egg fate dput(round(eggs, 2), file = ) structure(list(Year = c(1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000), NumEggs = c(323, 1729, 1127, 104, 267, 291, 352, 478, 532, 569, 263, 490, 244, 428, 527, 670), Failed = c(183, 199, 257, 503, 99, 139, 273, NA, 0, 55, 237, 581, 271, 144, 117, 43), Mean = c(0.29, 0.49, 0.55, 0.45, 0.26, 0.34, 0, 0.49, 0.77, 0.57, 0.77, NA, 0.69, 0.64, 0.51, 0.66), Eggs.p = c(0.19, 1, 0.65, 0.06, 0.15, 0.17, 0.2, 0.28, 0.31, 0.33, 0.15, 0.28, 0.14, 0.25, 0.3, 0.39), Fail.p = c(0.31, 0.34, 0.44, 0.87, 0.17, 0.24, 0.47, NA, 0, 0.09, 0.41, 1, 0.47, 0.25, 0.2, 0.07)), .Names = c(Year, NumEggs, Failed, Mean, Eggs.p, Fail.p), row.names = c(1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000), class = data.frame) xyplot(Eggs.p + Fail.p + Mean ~ Year , data = eggs, cex = 0.8, pch = c(2, 5), panel = panel.superpose.2, main = Alligator Nest Fate, ylab = Prop. of Total Number of Hatched Eggs \n Prop. of Total Flooded Eggs, legend = list(right = list(fun = grid::textGrob(Mean HSI, rot=90))), col=(1:3), type = c(b, b, h), key = list(text = list(c(Proportion Hatched R^2 = 0.13, Proportion Flooded R^2 = -0.23, Mean HSI)), col = c(black,red, green)), columns = 3) Thanks for the assistance. Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Binaries no longer compiled for RH EL4, i386?
I see that R 2.9.0 *.rpms have been compiled for RH EL5, i386 and x86_64, and also for EL4 x86_64, but not for EL4 i386. Is this an oversight or will that version no longer be compiled? Scott Waichler Pacific Northwest National Laboratory scott.waich...@pnl.gov __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 Macro Question
On Wed, 29 Apr 2009, Jenn wrote: Dear all, I?am?a?new?R?user,?and?I?have?a?question?about?R?macro. Here?is?the?situation,?I?want?to?do?item?option?analysis?(options?include:?A ,?B,?C,?D),?below?is?the?codes?for?option?A?analyses. #option?A?analyses optiona-mat.or.vec(nrow(responsedata2),?ncol(responsedata2)) #?create?A?matrix?by?recoding for?(i?in?1:ncol(responsedata2)){ ??? optiona[,i]-recode(responsedata2[,i],'A'=1;NA=NA;else=0) } #?compute?mean?for?A?matrix pa-rep(0,ncol(optiona)) for?(i?in?1:ncol(optiona)){ ??? pa[i]-round(mean(optiona[,i],na.rm=TRUE),2) } pa1-as.data.frame(pa) ? I?can?repeat?the?codes?for?other?options such as B, C and D,?but?I?am?wondering?if?I?can?do?it? in?a?macro?way--subsituting?A?a?in?the?codes?with?B?b,?etc. In?SAS?it?can?be?done?easily,?but?I?could?not?get?it?to?work?in?R. I suspect that 'it' can also be done easily in R. But you have not really told the list what 'it' is. You should provide some R code that actually works- as the R Posting Guide recommends. The 'code' above is not syntactically valid R, so you haven't really run it and neither can we. The function 'recode' is not in base R, so you have to provide it or refer to the contributed package frmo which it is obtained. I can only guess what you are trying to do, but I'd say mapply() or one of its relatives (lapply, tapply, ... ) is probably equal to the type of task you wish to perform. HTH, Chuck Waiting?for?your?reply. And?thank?you?so?much?in?advance. Meng [[alternative HTML version deleted]] Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Binaries no longer compiled for RH EL4, i386?
The maintainer of the RHEL RPMs no longer has an i386 machine running EL4, and cross-building on an x86_64 machine did not work, so I did not distribute them. As noted in a previous thread, there is a project to port the Fedora R RPMs to Enterprise Linux: On Thursday 23 April 2009 15:08:26 Marc Schwartz wrote: More info here: http://fedoraproject.org/wiki/EPEL and the specific link for R for RHEL 4/x84_64 is: http://download.fedora.redhat.com/pub/epel/4/x86_64/repoview/R.html RPMs for R 2.9.0 have been built but not pushed yet. In the future I will put the EPEL RPMs on CRAN so that they are compatible with the Fedora RPMs. Martyn On Thu, 2009-04-30 at 07:48 -0700, Waichler, Scott R wrote: I see that R 2.9.0 *.rpms have been compiled for RH EL5, i386 and x86_64, and also for EL4 x86_64, but not for EL4 i386. Is this an oversight or will that version no longer be compiled? Scott Waichler Pacific Northwest National Laboratory scott.waich...@pnl.gov --- This message and its attachments are strictly confidenti...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to know what device I am using
See ?dev.cur and ?options esp. the para on 'device' under 'Options set in package grDevices' CCB On Thu, 30 Apr 2009, Halld?r Bj?rnsson wrote: Some years ago I wrote a plotting routine that was run on both Linux Windows computers. There were some differences in the way the plot looked from the windows device and the X11 device. To ensure consistency I used getOption(device)) and made some changes to the plotting if the windows device was being used. Using this routine again, years later, I now notice that getOption(device) returns a function listing, but no longer a string with the name of the device. What is the best way to query which device is the default? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie R question PART2
Tena Sakai wrote: Hi, The example given: library(hwriter) htmlFile = tempfile() hwrite(Hello World, htmlFile) browseURL(htmlFile) worked. Including the line: example(hwrite) which is very nice. But I am a bit confused. Am I using elements of Rpad package? Or is this strictly to do with hwriter package? sorry, it is me that needs to be clued in. I misread your email; the example above has nothing to do with Rpad. And for windows users, satisfying R and firefox (for instance) seems to require htmlFile = file.path(tempdir(), tmp.html) and browseURL(paste(file://, htmlFile, sep=)) Martin Please clue me in. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: Wed 4/29/2009 10:32 AM To: Tena Sakai Cc: ted.hard...@manchester.ac.uk; r-help@r-project.org Subject: Re: [R] Newbie R question PART2 Tena Sakai wrote: Hi, Many thanks to Wacek Kusnierczyk and Ted Harding. I learned 3 new tricks. (Not bad for a newbie?) $ R --silent --no-save barebone.R $ R --quiet --no-save barebone.R $ R --slave barebone.R With slight differences, they all do what I wanted. Moving right along my tiny agenda... Given the same one-liner, cat ('Hello World!\n') would someone please show me how to turn this one liner into a web page with Rpad? For the basic 'put text in an html page' library(hwriter) htmlFile = tempfile() hwrite(Hello World, htmlFile) browseURL(htmlFile) for more advanced static pages example(hwrite) Martin Obviously, What I want to build is a web page, where it say click here and when it is clicked the screen blanks out and give a line: Hello World! I have looked at an example or two of Rpad, but it was overly complicated for simpleminded newbie. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: ted.hard...@manchester.ac.uk [mailto:ted.hard...@manchester.ac.uk] Sent: Tue 4/28/2009 2:11 PM To: r-help@r-project.org Cc: Tena Sakai Subject: RE: [R] Newbie R question On 28-Apr-09 20:42:45, Tena Sakai wrote: Hi, I am a newbie with R. My environment is linux and I have a file. I call it barebone.R, which has one line: cat ('Hello World!\n') I execute this file as: R --no-save barebone.R And it does what I expect. What I get is 20+/- lines of text, one of which is 'Hello World!'. How would I go about getting rid of all but the line I am after, 'Hello World!'? Regards, Tena Sakai tsa...@gallo.ucsf.edu An unusual request! I had to browse 'man R' a bit before getting a hint. R --silent --nosave barebone.R should do it! Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 28-Apr-09 Time: 22:11:23 -- XFMail -- [[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] Using 'aggregate' when dependent on row value increments
Dear all, I have a data frame of three columns, which I have sorted by Latitude as follows: test2[60:80,] Latitude Longitude Sim_1986 6194885.25-29.25 2.175345 6195785.25-28.75 8.750486 6196785.25-28.25 33.569305 6197785.25-27.75 23.702572 6198885.25-27.25 26.488602 6200085.25-26.75 23.915724 6201285.25-26.25 25.055082 6202785.25-25.75 26.609823 6204785.25-25.25 28.813068 6206684.25-24.75 25.069952 5234184.75-82.25 34.940380 5243484.75-81.75 56.192116 5253184.75-81.25 41.409431 5261683.75-80.75 56.717590 5270183.75-80.25 68.887123 5278183.75-79.75 74.133286 5286583.75-79.25 41.309422 5295182.25-78.75 69.863419 5305282.25-78.25 21.480116 5316482.25-77.75 58.799141 5597982.25-68.75 70.028358 What I am hoping to do is to use the aggregate command to calculate the mean of Sim_1986' per 1-degree increment of Latitude. So, using the above subset of the data frame as an example, a mean would be produced based on the Sim_1986 values between where Latitude 85, 84, 83, 82. The maximum latitude in the dataset as a whole is 83.75 and the minimum is -55.75. Is it possible to also output corresponding latitude values for each 'grouped mean', so that I can easily associate each mean value with its latitudinal band? Many thanks for any help offered, Steve _ [[elided Hotmail spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rjava - JDK not found
Done ! install.packages(rJava) Warning in install.packages(rJava) : argument 'lib' is missing: using '/home/martial/R/x86_64-unknown-linux-gnu-library/2.9' trying URL 'http://cran.fr.r-project.org/src/contrib/rJava_0.6-2.tar.gz' Content type 'application/x-tar' length 237115 bytes (231 Kb) opened URL == downloaded 231 Kb * Installing *source* package rJava ... checking Java support in R... present: interpreter : '/usr/bin/java' archiver: '' compiler: '' header prep.: '' cpp flags : '-I/usr/lib/jvm/java-6-openjdk/jre/../include' java libs : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm' configure: error: Java Development Kit (JDK) is missing or not registered in R Make sure R is configured with full Java support (including JDK). Run R CMD javareconf as root to add Java support to R. The fact is that some the path for the archiver, the compiler and the header are missing. Thus, when doing the javareconf, just add the path for the missing variables. ~$ sudo R CMD javareconf JAVAC=/usr/lib/jvm/java-6-openjdk/jre/../bin/javac JAR=/usr/bin/jar JAVAH=/usr/bin/javah Java interpreter : /usr/bin/java Java version : 1.6.0_0 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: /usr/lib/jvm/java-6-openjdk/jre/../bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm JNI cpp flags: -I$(JAVA_HOME)/../include Updating Java configuration in /usr/local/lib64/R Done. Then launch the R and install the package: ~$ sudo R install.packages(rJava) (...) checking Java support in R... present: interpreter : '/usr/bin/java' archiver: '/usr/bin/jar' compiler: '/usr/lib/jvm/java-6-openjdk/jre/../bin/javac' header prep.: '/usr/bin/javah' cpp flags : '-I/usr/lib/jvm/java-6-openjdk/jre/../include' java libs : '-L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm' checking whether JNI programs can be compiled... yes checking JNI data types... ok checking whether JRI should be compiled (autodetect)... no checking whether debugging output should be enabled... no checking whether memory profiling is desired... no checking whether threads support is requested... no checking whether callbacks support is requested... no checking whether JNI cache support is requested... no checking whether JRI is requested... no (...) ** building package indices ... * DONE (rJava) That's all ! ^^ _ r ! Téléchargez-le maintenant ! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem about finding power in test about variances
Ok sorry Uwe. Let me put a specific problem. I have some data for which sample size n=15 and sample standard deviation s=0.008 mm. Now there are two parts of the question. Here the random variable is diameter of rivet hole. a) Is there a strong evidence to indicate that the standard deviation of hole diameter exceeds 0.01 mm. Use aplha=0.05 . Now here Ho: variance = (0.01)^2 = 0.0001 mm H1: variance 0.0001 mm we can use test statistic chisq = (n-1)*s^2 / 0.0001 Chisq has degree of freedom n-1=14. So using this test statistic we can check the null hypothesis. I can do this part. Now lets look at the next part. b)If true variance (sigma) is as large as 0.0125 mm, what sample size will be required to detect this with power of at least 0.8 Now this is the part where I am stuck and I want to use R to solve this I know that R has power tests for other test statistics, but how do I solve this ? Ati --- On Thu, 4/30/09, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: From: Uwe Ligges lig...@statistik.tu-dortmund.de Subject: Re: [R] problem about finding power in test about variances To: atisun...@yahoo.com Cc: r-help@r-project.org Date: Thursday, April 30, 2009, 4:37 PM ati sundar wrote: Hello All I am new to this list. I have a problem where for a single sample drawn from normal population, null hypothesis is that variance = k (say). Perhaps you want to tell us more precisely what you are going to do rather than asking the same inprecise question again and again (including messages to single persons on the list). Is k fixed or the variance? What are your data? Specify a valid Null / Alternative combination. If you Null is variance = k (say) then you alternative is variance != k or if the alternative is variance k, then your null is probably variance = k Uwe Ligges Alternative hypothesis is variance k. Now if we know the true variance, then I would like to calculate the sample size required to produce certain power (for some significance). How do I do this ? I thought of using pwr.chisq.test, and I contacted the author stephane champely, but he said his package can't do this. Does anybody have an idea ? Thanks Ati __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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] Using 'aggregate' when dependent on row value increments
Is this what you want: aggregate(x$Sim_1986, list(trunc(x$Latitude)), mean) Group.1x 1 82 55.04276 2 83 60.26186 3 84 39.40297 4 85 22.12000 On Thu, Apr 30, 2009 at 11:50 AM, Steve Murray smurray...@hotmail.comwrote: Dear all, I have a data frame of three columns, which I have sorted by Latitude as follows: test2[60:80,] Latitude Longitude Sim_1986 6194885.25-29.25 2.175345 6195785.25-28.75 8.750486 6196785.25-28.25 33.569305 6197785.25-27.75 23.702572 6198885.25-27.25 26.488602 6200085.25-26.75 23.915724 6201285.25-26.25 25.055082 6202785.25-25.75 26.609823 6204785.25-25.25 28.813068 6206684.25-24.75 25.069952 5234184.75-82.25 34.940380 5243484.75-81.75 56.192116 5253184.75-81.25 41.409431 5261683.75-80.75 56.717590 5270183.75-80.25 68.887123 5278183.75-79.75 74.133286 5286583.75-79.25 41.309422 5295182.25-78.75 69.863419 5305282.25-78.25 21.480116 5316482.25-77.75 58.799141 5597982.25-68.75 70.028358 What I am hoping to do is to use the aggregate command to calculate the mean of Sim_1986' per 1-degree increment of Latitude. So, using the above subset of the data frame as an example, a mean would be produced based on the Sim_1986 values between where Latitude 85, 84, 83, 82. The maximum latitude in the dataset as a whole is 83.75 and the minimum is -55.75. Is it possible to also output corresponding latitude values for each 'grouped mean', so that I can easily associate each mean value with its latitudinal band? Many thanks for any help offered, Steve _ [[elided Hotmail spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] Using 'aggregate' when dependent on row value increments
Many thanks for the very useful responses in such a short time. I'm not a former SAS user - more a naive R user who didn't realise that a sort wasn't necessary! Jim, your solution worked really well - thanks. Thanks again for the great solutions. Steve __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 R question PART2
Thank you, Martin, for clarification. What you pointed out to me is so nice, so much so that I want to frame it and entitle it as serendipity. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: Thu 4/30/2009 8:39 AM To: Tena Sakai Cc: ted.hard...@manchester.ac.uk; r-help@r-project.org Subject: Re: [R] Newbie R question PART2 Tena Sakai wrote: Hi, The example given: library(hwriter) htmlFile = tempfile() hwrite(Hello World, htmlFile) browseURL(htmlFile) worked. Including the line: example(hwrite) which is very nice. But I am a bit confused. Am I using elements of Rpad package? Or is this strictly to do with hwriter package? sorry, it is me that needs to be clued in. I misread your email; the example above has nothing to do with Rpad. And for windows users, satisfying R and firefox (for instance) seems to require htmlFile = file.path(tempdir(), tmp.html) and browseURL(paste(file://, htmlFile, sep=)) Martin Please clue me in. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: Wed 4/29/2009 10:32 AM To: Tena Sakai Cc: ted.hard...@manchester.ac.uk; r-help@r-project.org Subject: Re: [R] Newbie R question PART2 Tena Sakai wrote: Hi, Many thanks to Wacek Kusnierczyk and Ted Harding. I learned 3 new tricks. (Not bad for a newbie?) $ R --silent --no-save barebone.R $ R --quiet --no-save barebone.R $ R --slave barebone.R With slight differences, they all do what I wanted. Moving right along my tiny agenda... Given the same one-liner, cat ('Hello World!\n') would someone please show me how to turn this one liner into a web page with Rpad? For the basic 'put text in an html page' library(hwriter) htmlFile = tempfile() hwrite(Hello World, htmlFile) browseURL(htmlFile) for more advanced static pages example(hwrite) Martin Obviously, What I want to build is a web page, where it say click here and when it is clicked the screen blanks out and give a line: Hello World! I have looked at an example or two of Rpad, but it was overly complicated for simpleminded newbie. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: ted.hard...@manchester.ac.uk [mailto:ted.hard...@manchester.ac.uk] Sent: Tue 4/28/2009 2:11 PM To: r-help@r-project.org Cc: Tena Sakai Subject: RE: [R] Newbie R question On 28-Apr-09 20:42:45, Tena Sakai wrote: Hi, I am a newbie with R. My environment is linux and I have a file. I call it barebone.R, which has one line: cat ('Hello World!\n') I execute this file as: R --no-save barebone.R And it does what I expect. What I get is 20+/- lines of text, one of which is 'Hello World!'. How would I go about getting rid of all but the line I am after, 'Hello World!'? Regards, Tena Sakai tsa...@gallo.ucsf.edu An unusual request! I had to browse 'man R' a bit before getting a hint. R --silent --nosave barebone.R should do it! Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 28-Apr-09 Time: 22:11:23 -- XFMail -- [[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] use of input in system()
On Fri, 24 Apr 2009, Duncan Murdoch wrote: On 4/24/2009 10:29 AM, Mike Miller wrote: First, it looks like there is bug in the documentation... According to the documentation for system(): http://stat.ethz.ch/R-manual/R-patched/library/base/html/system.html input if a character vector is supplied, this is copied one string per line to a temporary file, and the standard input of command is redirected to the file This seems to mean that the standard input of command is redirected *from* the file. From the file, to the command. Example: The redirection is done *to* the file handle. The fact that input is read from that handle is a different issue. Thanks very much for the reply. After seeing your response, I'm sure the document isn't wrong (not a bug) but it is a very terse explanation that I think many people will find hard to follow, as I did. First, a temporary file is created. Where is it? What is it called? If the name/location don't matter, does it even matter that a temporary file is created? Is this just info about the internal workings of R that the user doesn't need to know? Then the standard input of command is redirected to the file. I think I get this now. I think it means that this is being done behind the scenes: command file Would it help users to tell them that, if that is correct? It would have helped me. I think this is basically what it is doing: # For input to the system command we'll need a command and a vector: command - any command string v - c(some, vector) # make a temp file: filename - tempfile( tmpdir=tempdir() ) write.table(v, file=filename, sep=\n, row.names=FALSE, col.names=FALSE, quote=FALSE) # Then I think these two system commands do the same thing: system( paste(command, , filename, sep= ) ) system( command, input=v ) It would be nice if there were more documentation so that I could understand this better. I wasn't understanding why system() hangs sometimes as in the simple examples below, but I think I get it now: The stdout goes only to the last command in a string of semi-colon-separated commands. If that's right, it makes sense. Mike This works: system( cat -, input=foo ) foo This hangs until I hit ctrl-c: system( cat - ; echo bar, input=foo ) This works: system( echo bar; cat -, input=foo ) bar foo This hangs until I hit ctrl-c: system( cat - ; cat -, input=foo ) Best, Mike __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] overlaying several subsets of data frame in pairs plot
Hello I have a multivariate data frame giving various responses for several treatments. I would like to plot the relationship in the responses in a pairs plot with different symbols for the different treatments. In a regular plot I would have used 'matplot' or just added the new treatments with the 'points' function. But how to do it in a pairs plot? Thank you for your help Best Marion Dumas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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 reading data
Dear R users I am runing into a problem in reading data in R This is the error information a-read.table(tt_mb_200409.txt,as.is=T) Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1653997 did not have 5 elements It seams that some lines don't have equal variables. I want to try a-read.table(tt_mb_200409.txt,as.is=T,fill=T) a[1653997,] V1 V2V3 V4 V5 1653997 00992 2777010 But, I want to delect the rows that do not have the same number of variables with others, how can I do this? Many thanks Ted -- View this message in context: http://www.nabble.com/problem-in-reading-data-tp23316321p23316321.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to skip rest of code
Dear R users, Suppose I have 2 R script files: 'test1.R' and 'test2.R' and one R file 'main.R' which sources each of them. I wonder if there is a way to skip rest of code in 'test1.R' once a condition is met but still continue to run rest of script from the 'main'R' file. A simple example is shown below. I hope only 'message1' and 'message3' can be shown up without using if(...) else statement for skipped part in 'test1.R'. #main.R: source(test1.R) source(test2.R) === #test1.R # In this example the goal is to skip executing the line of print(message2). # without using if() else statement. x - TRUE if (x) { print(message1) q() # want to skip rest of code in test1.R ONLY } # lots of lines can start from here. print(message2) === #test2.R print(message3) Thank you. Ming-chung Li [[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] gridding values in a data frame
Hi all, I have a data frame that looks like such: LATITUDE LONGITUDE TEMPERATURE TIME 36.73 -176.4358.32 1 50.9590.0074.39 1 -30.425.4523.26 1 15.81 -109.3152.44 1 -80.75-144.9566.19 2 90.00 100.5537.50 2 65.41 -4.49 29.83 2 and this goes on for a A LOT more records, until time=1200 I want to create a 5 degree by 5 degree grid of this data, with the value of temperature in the appropriate grid cell. I want one grid for each time value. For each time value, this works out to be a 36x72 grid with 2592 cells because the longitude spans -180 to 180 and latitude spans 90 to -90 and they would be in increments of 5 degrees. If there are no temperatures available to be put into a grid cell, than that cell should get a missing value, NA, put into it. Also, could the gridded result for each time be written to a text file before processing the next time value? Hope this is clear. Thanks in advance. dxc13 -- View this message in context: http://www.nabble.com/gridding-values-in-a-data-frame-tp23319190p23319190.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] Evaluation of an expression as function argument
Thanks Uwe and Baptiste *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 Uwe Ligges wrote: Sebastien Bihorel wrote: Dear R-users, I would like to know if is it possible to set a function argument as an evaluated expression. I have tried several syntaxes, including the following example, but could not get it anything to run. The plot function is used here but I would like to later apply the same approach to other functions. ## items - c(expression(col=2),expression(pch=2)) for (in in seq(2)) { plot(1:10, eval(items[i])) } ## Way 1: for(i in seq(2)) do.call(plot, c(list(1:10), as.list(items[i]))) Way 2 is perhaps easier for you: items - list(col=2, pch=2) for (i in seq(2)) do.call(plot, c(list(1:10), items[i])) Ways 3...n up to others... Uwe Ligges Thanks in advance for your input. Sebastien __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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] problem in reading data
What kind of .txt file is it? If it's a tab-delimited file, try read.delim(tt_mb_200409.txt) Dimitri On Thu, Apr 30, 2009 at 9:28 AM, tedzzx zengzhenx...@gmail.com wrote: Dear R users I am runing into a problem in reading data in R This is the error information a-read.table(tt_mb_200409.txt,as.is=T) Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1653997 did not have 5 elements It seams that some lines don't have equal variables. I want to try a-read.table(tt_mb_200409.txt,as.is=T,fill=T) a[1653997,] V1 V2 V3 V4 V5 1653997 00992 2777010 But, I want to delect the rows that do not have the same number of variables with others, how can I do this? Many thanks Ted -- View this message in context: http://www.nabble.com/problem-in-reading-data-tp23316321p23316321.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. -- Dimitri Liakhovitski MarketTools, Inc. dimitri.liakhovit...@markettools.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] font size relative to graphic
In my particular situation, the trick was to figure out what worked for one set of bars, then determine how bar widths changed when various graphing parameters changed. Then I used that information to decide on a cex (character expansion) multiplier that worked perfectly for every example I produced (this was called bar_cex in my R code, which is shown below). There are a couple of neat things about the horizontal bar plot that everyone can use in choosing their cex. First, when there are n sets of m bars per set, then the vertical distance from the lower side of the bottom bar to the top side of the top bar is divided into n*(m+1)-1 equal-height regions and every bar width (vertical distance for horizontal bars, used to determine character height) is 1/(n*(m+1)-1) times that total vertical distance. So just find the right cex for one set of bars, say n=3, m=2, so that n*(m+1)-1 = 7, then use bar_cex = cex*7/(n*(m+1)-1) for other values of n and m. In my situation, using pdf with letter paper, height=11, width=8.5, I also used a variable number of inches empty on the top of the page. I called that number of inches top_inches. I then figured out the correct cex when the plot height was at a max of .78 and used (.78-top_inches/11) to figure cex for other values of top_inches. After a little arithmetic I came up with the equation appended below for bar_cex. It works for me, but it won't work for other people. This probably will work for other situations: bar_cex - C/(n*(m+1)-1) Where an appropriate value of C that works for one collection of horizontal bars (n sets of m bars per set) will work for other sets of bars. Mike bar_cex - (51/(n*(m+1)-1))*(.78-top_inches/11) # generate the horizontal bar plot and store values for later use x.bar.plot - barplot(as.matrix(x), col=rep(rev(bar.colors[1:m]),n), horiz=TRUE, beside=TRUE, xlim=c(0,100), main=bar.main.title, xlab=bar.x.label, las=1, cex.names=min( c(1, 16/L) ), legend=labels.legend) # add numbers to bars text(as.matrix(x), x.bar.plot-.1, as.character(as.matrix(round(x))), pos=2, offset=0.1, col=black, cex=bar_cex) If I don't subtract .1 from x.bar.plot, the text is positioned too high (vertically) on the horizontal bar. On Fri, 24 Apr 2009, David Winsemius wrote: On Apr 24, 2009, at 4:10 PM, Mike Miller wrote: On Fri, 24 Apr 2009, David Winsemius wrote: On Apr 24, 2009, at 3:14 PM, Mike Miller wrote: I am printing numbers onto horizontal bars in a bar plots, but I am finding it difficult to make the number always the right size. If there are more bars, the bars get narrower and the font is too big. I also find that if I change the size of the graph, the bars will get wider or narrower and the font stays about the same size. The result depends on whether I view the graph in X11 or in postscript. Is there a way to specify font size relative to bar width, or at least specify font size relative to graph coordinates? Here's a bit of what I've been doing: x.bar.plot - barplot(as.matrix(x), horiz=TRUE, beside=TRUE, xlim=c(0,100), xlab=Score, las=1) text(as.matrix(x), x.bar.plot-.07, as.character(as.matrix(round(x))), pos=2, col=black) The -.07 is something I added to make the numbers align well with the bars under one condition, but it doesn't always help. Any tips would be greatly appreciated. Thanks in advance. The values returned from the barplot function are the locations of the bars. Why not call barplot, collect the values, and then use the length of the result to determine your sizes and widths? That is exactly the kind of thing I want to do, but I don't know how the font size can be specified so that it fits. My bars are horizontal and yours (from code below) are vertical. Your barplot output was called mp and mine was called x.bar.plot and here is what they looked like: mp [,1] [,2] [,3] [,4] [,5] [1,] 1.5 6.5 11.5 16.5 21.5 [2,] 2.5 7.5 12.5 17.5 22.5 [3,] 3.5 8.5 13.5 18.5 23.5 [4,] 4.5 9.5 14.5 19.5 24.5 x.bar.plot [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] 1.5 4.5 7.5 10.5 13.5 16.5 19.5 22.5 25.5 28.5 31.5 34.5 [2,] 2.5 5.5 8.5 11.5 14.5 17.5 20.5 23.5 26.5 29.5 32.5 35.5 They are pretty similar numbers. It seems that [1,1] element is always 1.5 and consecutive elements in the same column differ by 1.0, but in the rows we see something different: mine are 3.0 apart and yours are 5.0 apart. So what does this tell me? I think fonts are specified in points which correspond to 1/72 inches, while bars are specified in coordinates that are independent of inches. So I need to know how coordinates correspond to inches before I can get this fixed. They do not correspond to inches, but the the numeric scale of the values. Here is your plot with the numbers moved so they are to the right of the bar ends: txt - 1.5 4.5 7.5 10.5 13.5
[R] unloading loaded packages
I can't seem to find info on how to unload packages that have been loaded. My goal in doing so is to gain access to functions that have been masked out by those packages. Or is there another way to do so? Thanks in advance. Jim Bouldin, PhD Research Ecologist Department of Plant Sciences, UC Davis Davis CA, 95616 530-554-1740 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] overlaying several subsets of data frame in pairs plot
Dear Marion, Take a look at the first example in ?pairs. HTH, Jorge On Thu, Apr 30, 2009 at 7:21 AM, Marion Dumas mario...@gmail.com wrote: Hello I have a multivariate data frame giving various responses for several treatments. I would like to plot the relationship in the responses in a pairs plot with different symbols for the different treatments. In a regular plot I would have used 'matplot' or just added the new treatments with the 'points' function. But how to do it in a pairs plot? Thank you for your help Best Marion Dumas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] problem in reading data
In some cases the missing values have been replaced by NAs so you can look for those. On Thu, Apr 30, 2009 at 9:28 AM, tedzzx zengzhenx...@gmail.com wrote: Dear R users I am runing into a problem in reading data in R This is the error information a-read.table(tt_mb_200409.txt,as.is=T) Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 1653997 did not have 5 elements It seams that some lines don't have equal variables. I want to try a-read.table(tt_mb_200409.txt,as.is=T,fill=T) a[1653997,] V1 V2V3 V4 V5 1653997 00992 2777010 But, I want to delect the rows that do not have the same number of variables with others, how can I do this? Many thanks Ted -- View this message in context: http://www.nabble.com/problem-in-reading-data-tp23316321p23316321.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to skip rest of code
?try see if: try(source('file')) works when you use 'stop()' instead of 'q()' in your example. On Thu, Apr 30, 2009 at 10:24 AM, Ming-Chung Li m...@emmes.com wrote: Dear R users, Suppose I have 2 R script files: 'test1.R' and 'test2.R' and one R file 'main.R' which sources each of them. I wonder if there is a way to skip rest of code in 'test1.R' once a condition is met but still continue to run rest of script from the 'main'R' file. A simple example is shown below. I hope only 'message1' and 'message3' can be shown up without using if(...) else statement for skipped part in 'test1.R'. #main.R: source(test1.R) source(test2.R) === #test1.R # In this example the goal is to skip executing the line of print(message2). # without using if() else statement. x - TRUE if (x) { print(message1) q() # want to skip rest of code in test1.R ONLY } # lots of lines can start from here. print(message2) === #test2.R print(message3) Thank you. Ming-chung Li [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] use of input in system()
Mike Miller wrote: On Fri, 24 Apr 2009, Duncan Murdoch wrote: On 4/24/2009 10:29 AM, Mike Miller wrote: First, it looks like there is bug in the documentation... According to the documentation for system(): http://stat.ethz.ch/R-manual/R-patched/library/base/html/system.html input if a character vector is supplied, this is copied one string per line to a temporary file, and the standard input of command is redirected to the file This seems to mean that the standard input of command is redirected *from* the file. From the file, to the command. Example: The redirection is done *to* the file handle. The fact that input is read from that handle is a different issue. Thanks very much for the reply. After seeing your response, I'm sure the document isn't wrong (not a bug) but it is a very terse explanation that I think many people will find hard to follow, as I did. it doesn't seem to be the usual way of explaining the matters. the bash reference manual [1, sec. 3.6.1] (see also man bash) says: Redirection of input causes the file whose name results from the expansion of word to be opened for reading on file descriptor |n|, or the standard input (file descriptor 0) if |n| is not specified. The general format for redirecting input is: [n]word it definitely not saying 'redirection to'. even more contrary to what duncan says is man page of the sh shell (man sh): [n] file Redirect standard input (or n) from file. note the *from*. in peters' expert shell scripting [1, ch. 9, p. 60] it is stated: expression file: Redirect the contents of file into the expression. while r's standard input of command is redirected to the file can certainly be read correctly once one knows what it really means, it is an unfortunate and misleading expression, and it might be a good idea to fix it. yet another example of how creative documentation is not necessarily good documentation. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Overlaying graphs from different datasets with ggplot
Dear R-users, I recently began using the ggplot2 package and I am still in the process of getting used to it. My goal would be to plot on the same grid a number of curves derived from two distinct datasets. The first dataset (called molten.data) looks like this : Column names : Perc, Week, Weight P10 21 333.3554 P90 21 486.0480 P10 22 452.6347 P90 22 563.8263 P10 23 575.0960 P90 23 661.6841 P10 24 700.4449 P90 24 779.4067 P10 25 828.4966 P90 25 917.1222 The second dataset (called skj) looks like this: Column names : Week, Perc, Weight 211 317.5 221 392.5 231 467.5 241 542.5 251 617.5 261 697.5 212 535.0 222 632.5 232 737.5 242 855.0 252 980.0 262 1115.0 213 425.0 223 512.5 233 602.5 243 697.5 253 800.0 263 907.5 Now, I plot my graphs using (with the Perc column in skj being a factor) : p - ggplot(molten.data, aes(x=Week, y=Weight, group=Perc)) ; p - p + geom_line(aes(colour = Perc,size=1,linetype=Perc)) ; p + geom_line(data=skj,mapping=aes(x=Week,y=Weight,group=Perc,linetype=Perc)) ; This yields the following error message: ## Error in data.frame(c(#FF6C91FF, #00C1A9FF), c(solid, 22, 42, : arguments imply differing number of rows: 2, 5 ## If I remove the linetype=Perc argument, I get a graph, but also a warning: ## Warning message: In data$arrow - NULL : Coercing LHS to a list ## So, what am I doing wrong in this situation? I thank you sincerely for your help, Luc -- View this message in context: http://www.nabble.com/Overlaying-graphs-from-different-datasets-with-ggplot-tp23322409p23322409.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] use of input in system()
Wacek Kusnierczyk wrote and forgot to add references: it doesn't seem to be the usual way of explaining the matters. the bash reference manual [1, sec. 3.6.1] (see also man bash) says: [1] http://www.gnu.org/software/bash/manual/bashref.html in peters' expert shell scripting [2, ch. 9, p. 60] it is stated: [2] Ron Peters, Expert Shell Scripting, Apress 2009 vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unloading loaded packages
See the seventh example under ?library. If the masked package has a namespace you can access functions via the '::' operator. Say the function foo in package bar was masked by package baz, and bar has a namespace. You can access foo thusly: bar::foo() Best, Jim Jim Bouldin wrote: I can't seem to find info on how to unload packages that have been loaded. My goal in doing so is to gain access to functions that have been masked out by those packages. Or is there another way to do so? Thanks in advance. Jim Bouldin, PhD Research Ecologist Department of Plant Sciences, UC Davis Davis CA, 95616 530-554-1740 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- James W. MacDonald, M.S. Biostatistician Douglas Lab University of Michigan Department of Human Genetics 5912 Buhl 1241 E. Catherine St. Ann Arbor MI 48109-5618 734-615-7826 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using 'aggregate' when dependent on row value increments
jim == jim holtman jholt...@gmail.com writes: Is this what you want: aggregate(x$Sim_1986, list(trunc(x$Latitude)), mean) Group.1 x 1 82 55.04276 2 83 60.26186 3 84 39.40297 4 85 22.12000 You could also use cut to convert Latitude to a factor: aggregate(x$Sim_1986, cut(x$Latitude, breaks=seq(-55,85,by=1)), mean) Mike values between where Latitude 85, 84, 83, 82. The maximum latitude in the dataset as a whole is 83.75 and the minimum is -55.75. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] postscript printer breaking up long strings
For a long string in an axis title, or main title the postscript device breaks apart the long strings into smaller strings. For example, postscript('linebreaktest.eps') plot(1,xlab='aReallyLongStringToSeeHowItBreaks',ylab='aReallyLongStringToSeeHowItBreaks') for(i in c(.6,1,1.4))text(i,i,'aReallyLongStringToSeeHowItBreaks') dev.off() produces the attached output. http://www.nabble.com/file/p23322197/linebreaktest.eps linebreaktest.eps The most important lines from the eps source are at the end of the file: 309.70 36.72 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 30.96 212.50 (aReallyLongStr) 90 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 77.04 91.44 743.76 534.96 cl /Font1 findfont 12 s 0 setgray 1.03 104.76 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 309.70 310.10 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 618.36 515.43 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr *** Each string is broken into 4 chunks. Has anyone else had this problem? Thanks! -- View this message in context: http://www.nabble.com/postscript-printer-breaking-up-long-strings-tp23322197p23322197.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] Creating datasets in packages
I am developing an R package which includes datasets. The build and install works correctly. However, when I access the dataset (BowRiver), I get: data(BowRiver) BowRiver Error: object BowRiver not found. However, I can access the dataset from data Example R datasets (such as USArrests) are loaded and can be accessed by the dataset name: data(USArrests) USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California9.0 276 91 40.6 ... What am I doing wrong? Thanks in advance, Dave [[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] odbcConnectAccess function
Steve: I am already using it importing data from Access to R but was wondering if it can be used the other way around, creating a subroutine in an access module and using the RODBC functions from there. --- On Thu, 4/30/09, steve_fried...@nps.gov steve_fried...@nps.gov wrote: From: steve_fried...@nps.gov steve_fried...@nps.gov Subject: Re: [R] odbcConnectAccess function To: mazatlanmex...@yahoo.com Cc: r-h...@stat.math.ethz.ch, r-help-boun...@r-project.org Date: Thursday, April 30, 2009, 7:38 AM Feilipe, You should look at the RODBC package It works great ! Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Felipe Carrillo mazatlanmex...@y ahoo.com To Sent by: r-h...@stat.math.ethz.ch r-help-boun...@r- cc project.org Subject [R] odbcConnectAccess function 04/30/2009 07:17 AM MST Please respond to mazatlanmex...@ya hoo.com HI: Is it possible to use the RODBC package within MS Access. I have been using from R but was just wondering if it could be used along with R(D)COM. Something like this: Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim myApp As StatConnector Set myApp = New StatConnector myApp.GetErrorText myApp.Init R myApp.EvaluateNoReturn library(RODBC) myApp.EvaluateNoReturn myDB - odbcConnectAccess(CurrentDb) 'query the database and save it as R object 'a' myApp.EvaluateNoReturn a - sqlQuery(CurrentDb, Paste(select * From Sample)) myApp.EvaluateNoReturn plot(a) Thanks in advance Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating datasets in packages
The key question: What am I doing wrong? We don't know what you _did_. How did you save the data? Did you follow the directions in the Writing R Extensions manual? Does ls() show the dataset? etc. You can access the dataset from data - do you mean that you can load the data directly from the data directory within your package? How? Sarah On Thu, Apr 30, 2009 at 4:03 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am developing an R package which includes datasets. The build and install works correctly. However, when I access the dataset (BowRiver), I get: data(BowRiver) BowRiver Error: object BowRiver not found. However, I can access the dataset from data Example R datasets (such as USArrests) are loaded and can be accessed by the dataset name: data(USArrests) USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California 9.0 276 91 40.6 ... What am I doing wrong? Thanks in advance, Dave -- 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] Creating datasets in packages
In developing the package, I have associated datasets (*.rda) stored in the data sub-directory. I built and installed the package successfully. When I load the BowRiver dataset and USArrests data(BowRiver) data(USArrests) ls() [1] data USArrests Why is mine stored as data and not BowRiver? -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Thursday, April 30, 2009 1:18 PM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] Creating datasets in packages The key question: What am I doing wrong? We don't know what you _did_. How did you save the data? Did you follow the directions in the Writing R Extensions manual? Does ls() show the dataset? etc. You can access the dataset from data - do you mean that you can load the data directly from the data directory within your package? How? Sarah On Thu, Apr 30, 2009 at 4:03 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am developing an R package which includes datasets. The build and install works correctly. However, when I access the dataset (BowRiver), I get: data(BowRiver) BowRiver Error: object BowRiver not found. However, I can access the dataset from data Example R datasets (such as USArrests) are loaded and can be accessed by the dataset name: data(USArrests) USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California 9.0 276 91 40.6 ... What am I doing wrong? Thanks in advance, Dave -- 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] postscript printer breaking up long strings
On 30-Apr-09 18:50:38, tommers wrote: For a long string in an axis title, or main title the postscript device breaks apart the long strings into smaller strings. For example, postscript('linebreaktest.eps') plot(1,xlab='aReallyLongStringToSeeHowItBreaks', ylab='aReallyLongStringToSeeHowItBreaks') for(i in c(.6,1,1.4))text(i,i,'aReallyLongStringToSeeHowItBreaks') dev.off() produces the attached output. http://www.nabble.com/file/p23322197/linebreaktest.eps linebreaktest.eps In the graph shown in your URL above, the xlab and the ylab appear in their entirety, unbroken. So does the one plotted in the middle of the graph. I get the same when I run your code. The texts you plotted at the first and third of the positions (i,i) also are not (I think) unbroken -- they are simply not entirely visible. The one at bottom left is missing its start aReallyLongSt, and the one at top right is missing its end eHowItBreaks. These apparent truncations arise because the beginning of the first, and the end of the second, are outside the plotting area, and so when the postcript() driver puts a BoundingBox at the border of the potting area this has the effect of clipping these strings when they are displayed. The apparently broken strings in the PostScript code you quote below are perfectly normal in PostScript. When dealing with text in a variable-width font, a PS driver will typically split continuous text into chunks, to allow for effects like kerning (or other adjustments of spacing) between the chunks. You will note that all five instances of the string are split in the same places, despite the fact that at least three of them come out perfectly (according to the graph on your URL). So nothing is wrong. You will have to adjust the extent of your plotting area, or adjust the pos or just of your (i,i) labels, to be able to see them in their entirety. Hoping this helps, Ted. The most important lines from the eps source are at the end of the file: 309.70 36.72 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 30.96 212.50 (aReallyLongStr) 90 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 77.04 91.44 743.76 534.96 cl /Font1 findfont 12 s 0 setgray 1.03 104.76 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 309.70 310.10 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr 618.36 515.43 (aReallyLongStr) 0 ta 0.180 (ingT) tb -1.440 (oSeeHo) tb -0.180 (wItBreaks) tb gr *** Each string is broken into 4 chunks. Has anyone else had this problem? Thanks! -- E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 30-Apr-09 Time: 21:39:59 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating datasets in packages
On Thu, Apr 30, 2009 at 10:33 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: In developing the package, I have associated datasets (*.rda) stored in the data sub-directory. I built and installed the package successfully. When I load the BowRiver dataset and USArrests data(BowRiver) data(USArrests) ls() [1] data USArrests Why is mine stored as data and not BowRiver? Because you have named it 'data' when you saved it into the .rda file, haven't you? Gabor -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Thursday, April 30, 2009 1:18 PM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] Creating datasets in packages The key question: What am I doing wrong? We don't know what you _did_. How did you save the data? Did you follow the directions in the Writing R Extensions manual? Does ls() show the dataset? etc. You can access the dataset from data - do you mean that you can load the data directly from the data directory within your package? How? Sarah On Thu, Apr 30, 2009 at 4:03 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am developing an R package which includes datasets. The build and install works correctly. However, when I access the dataset (BowRiver), I get: data(BowRiver) BowRiver Error: object BowRiver not found. However, I can access the dataset from data Example R datasets (such as USArrests) are loaded and can be accessed by the dataset name: data(USArrests) USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California 9.0 276 91 40.6 ... What am I doing wrong? Thanks in advance, Dave -- 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. -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Additive Weighted Voronoi Diagrams
Dear R-users, I recently started programming in R in order to implement Voronoi diagrams (without weights) and to modify them afterwards. I used the deldir package. I'm looking now for a possibility to implement additive weighted Voronoi diagrams. Does anyone has experience in adapting the deldir package (I suppose that I have to modify some of the Fortran-subroutines)? Is there another possibility to create an additive weighted Voronoi diagram? I thank you sincerely for your help, Cathleen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Conditional plot labels
Here is one example that moves the axes to the outer margins, play with the different settings to see the effects: par(oma=c(3,3,3,3)+.1, mar=c(0,0,0,0)+0.1, mfrow=c(3,3)) for (i in 1:9) { plot( runif(10*i), runif(10*i), ann=FALSE, xlim=c(0,1), ylim=c(0,1), xaxt='n', yaxt='n' ) if( i %% 3 == 1 ) axis(2, outer=TRUE) if( (i-1) %/% 3 == 2 ) axis(1, outer=TRUE) } Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Christian Bustamante Sent: Saturday, April 25, 2009 6:31 PM To: r-help@r-project.org Subject: [R] Conditional plot labels Hi all, I'm trying to do multiple graphs in a window like this: ___ ___ ___ ylab |__| |__| |__| ___ ___ ___ ylab |__| |__| |__| ___ ___ ___ ylab |__| |__| |__| xl xl xl If I try to put the labels manually, some graphs become smaller than other and the output is really ugly. In the thread title I put the word conditional because I'm trying to do a function, and in that function I want to print ylabels if the plot positions is at first column of the graph matrix, and xlab if the position is at last row of matrix. How can i achive this two things? Thanks for your help -- CdeB __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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] Creating datasets in packages
Yup :( Thanks! -Original Message- From: csardi.ga...@gmail.com [mailto:csardi.ga...@gmail.com] On Behalf Of Gábor Csárdi Sent: Thursday, April 30, 2009 1:45 PM To: Hutchinson,David [PYR] Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] Creating datasets in packages On Thu, Apr 30, 2009 at 10:33 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: In developing the package, I have associated datasets (*.rda) stored in the data sub-directory. I built and installed the package successfully. When I load the BowRiver dataset and USArrests data(BowRiver) data(USArrests) ls() [1] data USArrests Why is mine stored as data and not BowRiver? Because you have named it 'data' when you saved it into the .rda file, haven't you? Gabor -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Thursday, April 30, 2009 1:18 PM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] Creating datasets in packages The key question: What am I doing wrong? We don't know what you _did_. How did you save the data? Did you follow the directions in the Writing R Extensions manual? Does ls() show the dataset? etc. You can access the dataset from data - do you mean that you can load the data directly from the data directory within your package? How? Sarah On Thu, Apr 30, 2009 at 4:03 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am developing an R package which includes datasets. The build and install works correctly. However, when I access the dataset (BowRiver), I get: data(BowRiver) BowRiver Error: object BowRiver not found. However, I can access the dataset from data Example R datasets (such as USArrests) are loaded and can be accessed by the dataset name: data(USArrests) USArrests Murder Assault UrbanPop Rape Alabama 13.2 236 58 21.2 Alaska 10.0 263 48 44.5 Arizona 8.1 294 80 31.0 Arkansas 8.8 190 50 19.5 California 9.0 276 91 40.6 ... What am I doing wrong? Thanks in advance, Dave -- 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. -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What is the R version of the S function fac.design?
Smith, Phil (CDC/CCID/NCIRD) wrote: Hi R Community: What is the R version of the S function fac.design()? As far as I can tell, it doesn't exist. There's a bit of a discussion from 2001 (!) https://stat.ethz.ch/pipermail/r-help/2001-November/016753.html where Martin Maechler describes writing plot.design() . There are other little bits (RSiteSearch(fac.design)) that get the FrF2 package, and the conf.design package. But it doesn't look like there is a drop-in replacement. Ben Bolker -- View this message in context: http://www.nabble.com/What-is-the-R-version-of-the-S-function-fac.design--tp23316774p23325010.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] Multi-variate rcs() error
Hi, My code, output, error message, and sample data are all below. As always, all help is appreciated. Code: library(Design); library(lattice) df = read.table(./data_cub4.txt, header=TRUE, nrows=100) attach(df); dd = datadist(df); options(datadist = 'dd'); describe(df); m = (y1 ~ ( rcs(x1,3) + rcs(x2,3) ) ) f = ols(m, data=df) print(f) print( Function(f) ) detach(df) Output: == Linear Regression Model ... n Model L.R. d.f. R2 Sigma 100 720.7 4 0.9993 82.44 Residuals: Min 1Q Median 3Q Max -113.21 -70.46 -20.09 65.77 214.77 Coefficients: Value Std. Error t Pr(|t|) Intercept 757.85 1.647e+17 4.601e-151 x1 35.58 9.080e+14 3.919e-141 x1'85.92 6.475e+14 1.327e-131 x2NA 1.797e+14NA NA x2' NA 6.475e+14NA NA Residual standard error: 82.44 on 95 degrees of freedom Adjusted R-Squared: 0.9992 Error in if (coef[i] 0 (i 2 | coef[1] != 0 | Intc != 0)) + else NULL : missing value where TRUE/FALSE needed Sample data: = config benchmark y1 x1 x2 noise 1 verify2 1008.2 1 10000.72 2 verify2 10192 999 1.6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multi-variate rcs() error
x wrote: Hi, My code, output, error message, and sample data are all below. As always, all help is appreciated. Code: library(Design); library(lattice) df = read.table(./data_cub4.txt, header=TRUE, nrows=100) attach(df); dd = datadist(df); options(datadist = 'dd'); describe(df); m = (y1 ~ ( rcs(x1,3) + rcs(x2,3) ) ) f = ols(m, data=df) print(f) print( Function(f) ) detach(df) Output: == Linear Regression Model ... n Model L.R. d.f. R2 Sigma 100 720.7 4 0.9993 82.44 Residuals: Min 1Q Median 3Q Max -113.21 -70.46 -20.09 65.77 214.77 Coefficients: Value Std. Error t Pr(|t|) Intercept 757.85 1.647e+17 4.601e-151 x1 35.58 9.080e+14 3.919e-141 x1'85.92 6.475e+14 1.327e-131 x2NA 1.797e+14NA NA x2' NA 6.475e+14NA NA Residual standard error: 82.44 on 95 degrees of freedom Adjusted R-Squared: 0.9992 Error in if (coef[i] 0 (i 2 | coef[1] != 0 | Intc != 0)) + else NULL : missing value where TRUE/FALSE needed Sample data: = config benchmark y1 x1 x2 noise 1 verify2 1008.2 1 10000.72 2 verify2 10192 999 1.6 It just appears that you have perfect prediction, so you have quite an unusual dataset to be doing inference on. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] gridding values in a data frame
dxc13 wrote: Hi all, I have a data frame that looks like such: LATITUDE LONGITUDE TEMPERATURE TIME 36.73 -176.4358.32 1 and this goes on for a A LOT more records, until time=1200 I want to create a 5 degree by 5 degree grid of this data, with the value of temperature in the appropriate grid cell. I want one grid for each time value. dxc13 The following appears to work, but is most definitely *not* in the spirit of R -- it's more like a C program written in R. Undoubtedly someone will come up with a much more clever method. (This is always my problem; I come up with a workable solution, but it's not elegant.) Note: the grid has to have 37 rows, since latitude -90 to +90 (inclusive) takes 37 5-degree increments; since -180 and +180 longitude are the same, you would never have them as separate numbers. d - read.csv(weather.csv) for (i in 1:1200) { x - d[d$TIME==i,] if (length(x$TIME) 0) { print(sprintf(# of elements for time %d: %d, i, length(x$TIME))) grid - matrix(NA, nrow=37, ncol=72) for (j in 1:length(x$TIME)) { lat - 1 + trunc((90 + x$LATITUDE[j]) / 5) long - 1 + trunc((180 + x$LONGITUDE[j]) / 5) grid[lat,long] - x$TEMPERATURE[j] } write(t(grid), file=sprintf(time%d.csv, i), ncolumns=72, sep=,) } } -- View this message in context: http://www.nabble.com/gridding-values-in-a-data-frame-tp23319190p23325204.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] gridding values in a data frame
It's hard to check without a reproducible example, but the following code should give you a 3d array of lat x long x time: library(reshape) df$lat - round_any(df$LATITUDE, 5) df$long - round_any(df$LONGITUDE, 5) df$value - df$TIME cast(df, lat ~ long ~ time, mean) On Thu, Apr 30, 2009 at 10:55 AM, dxc13 dx...@health.state.ny.us wrote: Hi all, I have a data frame that looks like such: LATITUDE LONGITUDE TEMPERATURE TIME 36.73 -176.43 58.32 1 50.95 90.00 74.39 1 -30.42 5.45 23.26 1 15.81 -109.31 52.44 1 -80.75 -144.95 66.19 2 90.00 100.55 37.50 2 65.41 -4.49 29.83 2 and this goes on for a A LOT more records, until time=1200 I want to create a 5 degree by 5 degree grid of this data, with the value of temperature in the appropriate grid cell. I want one grid for each time value. For each time value, this works out to be a 36x72 grid with 2592 cells because the longitude spans -180 to 180 and latitude spans 90 to -90 and they would be in increments of 5 degrees. If there are no temperatures available to be put into a grid cell, than that cell should get a missing value, NA, put into it. Also, could the gridded result for each time be written to a text file before processing the next time value? Hope this is clear. Thanks in advance. dxc13 -- View this message in context: http://www.nabble.com/gridding-values-in-a-data-frame-tp23319190p23319190.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. -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-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 do I set the working directory when using ESS and R under windows?
Hi, While I'm a devoted vim user, I'm testing ESS :) How do I set the working directory when using ESS and R under windows? When I try to launch R, it asks for a directory. In windows, it simply doesn't let you pick a directory on the 'open' dialog. It may be a problem with windows server 2008 64 bit, though, as it seems really basic. Thanks. Best, -Jose -- Jose Quesada, PhD. Max Planck Institute, Center for Adaptive Behavior and Cognition -ABC-, Lentzeallee 94, office 224, 14195 Berlin http://www.josequesada.name/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 key boxes in xyplot
On Apr 30, 2009, at 10:35 AM, steve_fried...@nps.gov wrote: I thought I mimicked the coded correctly, but find an error/omission somewhere in the xyplot function shown below. eggs # alligator egg fate dput(round(eggs, 2), file = ) structure(list(Year = c(1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000), NumEggs = c(323, 1729, 1127, 104, 267, 291, 352, 478, 532, 569, 263, 490, 244, 428, 527, 670), Failed = c(183, 199, 257, 503, 99, 139, 273, NA, 0, 55, 237, 581, 271, 144, 117, 43), Mean = c(0.29, 0.49, 0.55, 0.45, 0.26, 0.34, 0, 0.49, 0.77, 0.57, 0.77, NA, 0.69, 0.64, 0.51, 0.66), Eggs.p = c(0.19, 1, 0.65, 0.06, 0.15, 0.17, 0.2, 0.28, 0.31, 0.33, 0.15, 0.28, 0.14, 0.25, 0.3, 0.39), Fail.p = c(0.31, 0.34, 0.44, 0.87, 0.17, 0.24, 0.47, NA, 0, 0.09, 0.41, 1, 0.47, 0.25, 0.2, 0.07)), .Names = c(Year, NumEggs, Failed, Mean, Eggs.p, Fail.p), row.names = c(1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000), class = data.frame) xyplot(Eggs.p + Fail.p + Mean ~ Year , data = eggs, cex = 0.8, pch = c(2, 5), panel = panel.superpose.2, main = Alligator Nest Fate, ylab = Prop. of Total Number of Hatched Eggs \n Prop. of Total Flooded Eggs, legend = list(right = list(fun = grid::textGrob(Mean HSI, rot=90))), col=(1:3), type = c(b, b, h), key = list(text = list(c(Proportion Hatched R^2 = 0.13, Proportion Flooded R^2 = -0.23, Mean HSI)), col = c(black,red, green)), columns = 3) It runs without error on my machine ... after loading lattice. Perhaps you ought to provide the error message and the other usual needed information. See that nice compact but very imformative message at the bottom of this reply. -- David David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Hmisc: xYplot and panel.lines
Using the Hmisc package, I tried to create an xYplot (single panel only) and was confused to find that I could not add anything else to the plot (abline, lines, etc.). Thankfully, [1] points out panel functions. This works as expected for panel.abline, but as soon as I'm using panel.lines (or llines or lpoints) from the lattice package (version 0.17-17 with R 2.8.1), it seems that it is not using the coordinate system that the original plot used, i.e. the graph does not work at all. My code: pfunc - function(x,y,...) { panel.xYplot(x, y, ...) panel.abline(h=4.0, col = grey) # works fine panel.lines(-d$chosenValveSetting, col=orange) # in the wrong place } xYplot(I(AmountInTank) + I(-UserOutFlow+UserInFlow) + I(EnvirInFlow) ~ Time.Step, data=subset(h, Version==Linear increase), nx=F, method=smean.cl.boot, type='b',lty.bands=c(2,2), ylim=c(-20,20), panel=pfunc) What am I doing wrong? Hmisc 3.6.0, but older versions reacted similarly. Thanks for your help! [1] http://tolstoy.newcastle.edu.au/R/help/06/01/18860.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting Element from S4 objects
I don't think very many of us have a version that is quite that old. Sorry; David. On Apr 29, 2009, at 4:37 PM, tbigdeli wrote: Are there internal methods available for R2.6 (I'm using the mac os x gui) for extracting (or subsetting) S4 objects? Using the independence_test() function implemented in the COIN package, I can't seem to select out p-values upon completion of each iteration of a loop. Sorry if my search was incomplete beforehand. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] newbie HWRITER package question
Hi, I am playing with hwriter examples given in example page. Here's what I've done: library (hwriter) p = openPage ('table.html') hwrite (1:5, p) hwrite (iris[1:3, 1:3], p, row.bgcolor='#ffdc98') closePage (p) browseURL('table.html') What I get is not as nice as what I see via the example page. I looked at the html source for the example page and got a notion maybe I should stick this line between head and /head: link rel=stylesheet type=text/css href=hwriter.css/link (I had copied this file into the current working directory.) and bingo! Yeeehaa! My page suddenly looks so much nicer! So, here's today's newbie quesion: How can I get R to insert such line into the head section of html file being generated under hwriter? I would appreciate your guidance. Thank you. Regards, Tena Sakai tsa...@gallo.ucsf.edu [[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] Hmisc: xYplot and panel.lines
On Apr 30, 2009, at 6:49 PM, David Reitter wrote: This works as expected for panel.abline, but as soon as I'm using panel.lines (or llines or lpoints) from the lattice package (version 0.17-17 with R 2.8.1), it seems that it is not using the coordinate system that the original plot used, i.e. the graph does not work at all. Disregard my message: I managed to figure it out. panel.lines insists on x and y rather than y ~ x or y (x are just discrete steps). The question that remains is whether it is possible to draw to a panel directly using the normal plotting functions in cases where only one panel is shown. The latest version of Hmisc seems to disallow this (error: plot.new has not been called yet), and with earlier versions I had said problems about ablines appearing in the wrong locations. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] gridding values in a data frame
Thank you for your input. I will give it a try and see how it works out. I always have the same problem when programming...I always make things more complicated than they really are :-). Much appreciated. jdeisenberg wrote: dxc13 wrote: Hi all, I have a data frame that looks like such: LATITUDE LONGITUDE TEMPERATURE TIME 36.73 -176.4358.32 1 and this goes on for a A LOT more records, until time=1200 I want to create a 5 degree by 5 degree grid of this data, with the value of temperature in the appropriate grid cell. I want one grid for each time value. dxc13 The following appears to work, but is most definitely *not* in the spirit of R -- it's more like a C program written in R. Undoubtedly someone will come up with a much more clever method. (This is always my problem; I come up with a workable solution, but it's not elegant.) Note: the grid has to have 37 rows, since latitude -90 to +90 (inclusive) takes 37 5-degree increments; since -180 and +180 longitude are the same, you would never have them as separate numbers. d - read.csv(weather.csv) for (i in 1:1200) { x - d[d$TIME==i,] if (length(x$TIME) 0) { print(sprintf(# of elements for time %d: %d, i, length(x$TIME))) grid - matrix(NA, nrow=37, ncol=72) for (j in 1:length(x$TIME)) { lat - 1 + trunc((90 + x$LATITUDE[j]) / 5) long - 1 + trunc((180 + x$LONGITUDE[j]) / 5) grid[lat,long] - x$TEMPERATURE[j] } write(t(grid), file=sprintf(time%d.csv, i), ncolumns=72, sep=,) } } -- View this message in context: http://www.nabble.com/gridding-values-in-a-data-frame-tp23319190p23325394.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.