Re: [R] Additional arguments in S3 method produces a warning
> "HenrikB" == Henrik Bengtsson <[EMAIL PROTECTED]> > on Thu, 16 Mar 2006 07:48:49 +0100 writes: HenrikB> It is even better/more generic(!) to have: HenrikB> extract <- function(...) UseMethod("extract") HenrikB> "Specifying the object argument or the method HenrikB> arguments of a generic function will restrict any HenrikB> other methods with the same name to have the same HenrikB> argument. By also excluding the object argument, HenrikB> default functions such as search() will also be HenrikB> called if the generic function is called without HenrikB> any arguments." HenrikB> [http://www.maths.lth.se/help/R/RCC/] HenrikB> /Henrik Hmm, sorry, but that is Henrik's own ``style sheet'' which contains some views that I (and AFAIK other R-core members) do not share. The grain of truth in Henrik's statement is that for a generic function, S3 or S4, one should carefully consider which arguments should be shared by all methods and which not. But having at least one `` non-... '' argument should be the rule, and is even a necessity for S4. Hence I'd strongly discourage defining generic functions with only a (...) argument list. HenrikB> On 3/15/06, Gabor Grothendieck HenrikB> <[EMAIL PROTECTED]> wrote: >> Define extract like this: >> >> extract <- function(e, n, ...) UseMethod("extract") >> >> # test -- no warning >> extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) yes, I agree with Gabor Martin Maechler, ETH Zurich > On 3/15/06, Philippe Grosjean <[EMAIL PROTECTED]> wrote: > > Hello, > > I just notice this: > > > x <- c(1:4,0:5, 4, 11) > > > library(pastecs) > > Loading required package: boot > > > tp <- turnpoints(x) > > > extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) > > [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE > > FALSE > > Warning message: > > arguments after the first two are ignored in: UseMethod("extract", e, n, > > ...) > > > extract(tp) > > [1] 0 0 0 1 -1 0 0 0 0 1 -1 0 > > Warning message: > > arguments after the first two are ignored in: UseMethod("extract", e, n, > > ...) > > > > My extract.turnpoints() function produces warnings. I can easily spot > > the origin of this warning: > > > > > extract > > function (e, n, ...) > > UseMethod("extract", e, n, ...) > > > extract.turnpoints > > function (e, n, no.tp = 0, peak = 1, pit = -1, ...) > > { > > if (missing(n)) > > n <- length(e) > > res <- rep(no.tp, length.out = e$n) > > res[e$pos[e$peaks]] <- peak > > res[e$pos[e$pits]] <- pit > > if (n < length(res) & n > 0) > > res <- res[1:n] > > res > > } > > > > This is because my extract.turnpoints() method defines more arguments > > than 'e' and 'n' in the generic function. However, > > > > 1) I though that the '...' argument in S3 generic function was there to > > allow defining/passing additional arguments in/to S3 methods. Is this > > correct? If yes, why the warning? > > > > 2) Despite the warning says arguments after the first two are ignored, > > this appears not to be the case: in this example, 'no.tp', 'peak' and > > 'pit' arguments are taken into account, as you can see (different > > behaviour if you give other values to them). > > > > I am a little bit lost. Could someone help me, please. > > > > Best, > > > > Philippe Grosjean > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Additional arguments in S3 method produces a warning
It is even better/more generic(!) to have: extract <- function(...) UseMethod("extract") "Specifying the object argument or the method arguments of a generic function will restrict any other methods with the same name to have the same argument. By also excluding the object argument, default functions such as search() will also be called if the generic function is called without any arguments." [http://www.maths.lth.se/help/R/RCC/] /Henrik On 3/15/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Define extract like this: > > extract <- function(e, n, ...) UseMethod("extract") > > # test -- no warning > extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) > > On 3/15/06, Philippe Grosjean <[EMAIL PROTECTED]> wrote: > > Hello, > > I just notice this: > > > x <- c(1:4,0:5, 4, 11) > > > library(pastecs) > > Loading required package: boot > > > tp <- turnpoints(x) > > > extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) > > [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE > > FALSE > > Warning message: > > arguments after the first two are ignored in: UseMethod("extract", e, n, > > ...) > > > extract(tp) > > [1] 0 0 0 1 -1 0 0 0 0 1 -1 0 > > Warning message: > > arguments after the first two are ignored in: UseMethod("extract", e, n, > > ...) > > > > My extract.turnpoints() function produces warnings. I can easily spot > > the origin of this warning: > > > > > extract > > function (e, n, ...) > > UseMethod("extract", e, n, ...) > > > extract.turnpoints > > function (e, n, no.tp = 0, peak = 1, pit = -1, ...) > > { > > if (missing(n)) > > n <- length(e) > > res <- rep(no.tp, length.out = e$n) > > res[e$pos[e$peaks]] <- peak > > res[e$pos[e$pits]] <- pit > > if (n < length(res) & n > 0) > > res <- res[1:n] > > res > > } > > > > This is because my extract.turnpoints() method defines more arguments > > than 'e' and 'n' in the generic function. However, > > > > 1) I though that the '...' argument in S3 generic function was there to > > allow defining/passing additional arguments in/to S3 methods. Is this > > correct? If yes, why the warning? > > > > 2) Despite the warning says arguments after the first two are ignored, > > this appears not to be the case: in this example, 'no.tp', 'peak' and > > 'pit' arguments are taken into account, as you can see (different > > behaviour if you give other values to them). > > > > I am a little bit lost. Could someone help me, please. > > > > Best, > > > > Philippe Grosjean > > > > > > -- > > ..<°}))>< > > ) ) ) ) ) > > ( ( ( ( (Prof. Philippe Grosjean > > ) ) ) ) ) > > ( ( ( ( (Numerical Ecology of Aquatic Systems > > ) ) ) ) ) Mons-Hainaut University, Pentagone (3D08) > > ( ( ( ( (Academie Universitaire Wallonie-Bruxelles > > ) ) ) ) ) 8, av du Champ de Mars, 7000 Mons, Belgium > > ( ( ( ( ( > > ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.30.54 > > ( ( ( ( (email: [EMAIL PROTECTED] > > ) ) ) ) ) > > ( ( ( ( (web: http://www.umh.ac.be/~econum > > ) ) ) ) ) http://www.sciviews.org > > ( ( ( ( ( > > .. > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- Henrik Bengtsson Mobile: +46 708 909208 (+1h UTC) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] ANCOVA with random factor
I would like to know if there is a way of directly calculating the F-ratio of a random effect using the "aov" function. I have 2 factors in my model, "population" which is random and "length" which is the length of female fish within each population. The dependent variable is "diam" which is the average diameter of eggs produced by each female. At present I set up the model like this: >model <- aov(diam~population*length, data=data) >anova(model) then using the output: >ratio=MS-population/MS-interaction >1-pf(ratio, df-population,df-interaction) Is there a way of getting r to calculate the correct F-ratio for a random factor and present it in the original output? Thanks, David Semmens. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] running median and smoothing splines for robust surface fitting
Hi, Are there any multidimenstional versions of runmed() and smooth.spline() functions? I need to fit surface into quite noisy 3D data. Below is an example (2D) of kind of fittings I do. Thank you, Vlad #=generating complex x,y dataset with gaussian & uniform noise== x <- seq(1:1) x2 <- rep(NA,2*length(x)) y2 <- rep(NA,2*length(x)) x2[seq(1,length(x2),2)] <- x x2[seq(2,length(x2),2)] <- x y2[seq(1,length(x2),2)] <- sin(4*pi*x/length(x)) + rnorm(length(x)) y2[seq(2,length(x2),2)] <- runif(length(x),min=-5,max=5) #=== #=robust & smooth fit=== y3 <- runmed(y2,51,endrule="median") #first round of running median y4 <- smooth.spline(x2,y3,df=10) #second round of smoothing splines #=== #=ploting data== plot(x2,y2,pch=19,cex=0.1) points(x2,y3,col="red",pch=19,cex=0.1) #running median points(y4,col="green",pch=19,cex=0.1) #smoothing splines #=== __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] lapply vs. for (was: Incrementing a counter in lapply)
On 3/15/06, Thomas Lumley <[EMAIL PROTECTED]> wrote: > On Wed, 15 Mar 2006, Philippe Grosjean wrote: > > > the for() loop is very slow in S-PLUS. This is probably one of the > > motivation of developing the apply() family of functions (as well as the > > ugly For() loop) under this system. > > > > Now, for() loops are much faster in R. Also, if you look at the R code > > in apply(), you will realize that there is a for() loop in it! > > > > lapply(), on the other hand, can be faster than a loop. That's why it went > from being a loop to being internal C code. > > -thomas Thanks to all for this insights on *apply vs. for loop! -- Lep pozdrav / With regards, Gregor Gorjanc University of Ljubljana PhD student Biotechnical Faculty Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan Groblje 3mail: gregor.gorjanc bfro.uni-lj.si SI-1230 Domzaletel: +386 (0)1 72 17 861 Slovenia, Europe fax: +386 (0)1 72 17 888 "One must learn by doing the thing; for though you think you know it, you have no certainty until you try." Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] handling warning messages
Is there any way to store the value of warnings but avoid printing them? A simplified example: > out <- c(0.2,0.3,0.4) > var <- c(2,3,4) > outcome <- glm(out ~ var, family=binomial()) Warning message: non-integer #successes in a binomial glm! in: eval(expr, envir, enclos) I don't like the warning printed, but I would like to be able to check it's value after the top-level function has completed and than decide weather to print it or not. Thanks, Sigal Blay Statistical Genetics Working Group Department of Statistics and Actuarial Science Simon Fraser University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] "\r" with RSQLite
Thanks for the tip. I've attempted the alternative approach of using write.table, which allows you to see the file and import it directly. Would the carriage returns be visible with notepad or with the edit command? Because I don't see the /r in the text file, but still get it when I query the database: > library(RSQLite) Loading required package: DBI > a <- (5:10) > b <- (LETTERS[5:10]) > df <- as.data.frame(cbind(a, b)) > library(RSQLite) > drv <- dbDriver("SQLite") > con <- dbConnect(drv, dbname = "Test") > write.table(df, file = "df.txt", quote = FALSE, row.names = FALSE) > dbWriteTable(con, "DF", "df.txt", header = TRUE, row.names = FALSE, overwrite = TRUE) [1] TRUE > df2 <- dbGetQuery(con, "SELECT DISTINCT * FROM DF") > dbDisconnect(con) [1] TRUE > df2 a_b 1 5 E\r 2 6 F\r 3 7 G\r 4 8 H\r 5 9 I\r 6 10 J\r Also, this time it doesn't recognise that I didn't want the rownames. I've attempted to go throught the source code, but can't trace the problem with the carriage return. Mikkel --- bogdan romocea <[EMAIL PROTECTED]> wrote: > \r is a carriage return character which some editors > may use as a line > terminator when writing files. My guess is that > RSQLite writes your > data frame to a temp file using \r as a line > terminator and then runs > a script to have SQLite import the data (together > with \r - this would > be the problem), but I have no idea if that's really > the case. Check > the documentation or ask the maintainer. > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On > Behalf Of Mikkel Grum > > Sent: Wednesday, March 15, 2006 1:46 PM > > To: r-help@stat.math.ethz.ch > > Cc: [EMAIL PROTECTED] > > Subject: [R] "\r" with RSQLite > > > > What am I doing wrong, or is the \r that I'm > getting > > in the example below a bug? > > > > > a <- (1:10) > > > b <- (LETTERS[1:10]) > > > df <- as.data.frame(cbind(a, b)) > > > > > > df > > a b > > 1 1 A > > 2 2 B > > 3 3 C > > 4 4 D > > 5 5 E > > 6 6 F > > 7 7 G > > 8 8 H > > 9 9 I > > 10 10 J > > > library(RSQLite) > > > drv <- dbDriver("SQLite") > > > con <- dbConnect(drv, dbname = "Test") > > > dbWriteTable(con, "DF", df, row.names = > FALSE, > > overwrite = TRUE) > > [1] TRUE > > > df2 <- dbGetQuery(con, "SELECT DISTINCT * > FROM > > DF") > > > dbDisconnect(con) > > [1] TRUE > > > df2 > > a b > > 1 1 A\r > > 2 2 B\r > > 3 3 C\r > > 4 4 D\r > > 5 5 E\r > > 6 6 F\r > > 7 7 G\r > > 8 8 H\r > > 9 9 I\r > > 10 10 J\r > > > > > sessionInfo() > > R version 2.2.1, 2005-12-20, i386-pc-mingw32 > > > > attached base packages: > > [1] "methods" "stats" "graphics" > "grDevices" > > "utils" "datasets" > > [7] "base" > > > > other attached packages: > > RSQLite DBI > > "0.4-1" "0.1-10" > > > > > > Mikkel Grum > > Genetic Diversity > > International Plant Genetic Resources Institute > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] excluding factor levels with read.table() and colClasses=
Hi, I am reading a "|" delimited text file into R using read.table(). I am using colClasses= to specify some variables as factors. Some of these variables include missing values coded as "NA". Unfortunately the R code I am using (pasted bellow) includes "NA" as one of the factor levels. Is it possible to remove the "NA" level from a factor with in read.table()? If not what is the most efficient way of doing this? inrange<-read.table("C://...",header=T,sep="|",colClasses=c( id="factor")) Thanks for your help. Peter __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to get correct proportions/bounding box for latex figure?
context grey wrote: > That's approximately right, but the individual > scatterplots > are slightly stretched horizontally. > > Is there not any way to have the plots have true 1:1 > aspect ratio > (given that the range of the data is the same on both > axes) > and still get a bounding box?. What do you mean by 1:1 aspect ratio? Do you mean the physical measurement of one vertical unit should match the physical measurement of one horizontal unit? If so, use aspect="iso" in your calls to xyplot. If you mean that the boxes should be square, use aspect=1. (I hope I've got these right; I don't use lattice much.) In both cases, R is not that good at calculating the bounding box: it will often include a lot of white space. (In this case it looks as though it is believing the values passed in the trellis.device call, but with other args to the postscript device it will do other things.) I generally use GSview's PS to EPS function to recalculate it when this sort of thing matters. Duncan Murdoch And, without getting > out > a ruler and manually calculating width/height values? > > (I'm guessing you arrived at width=12,height=4 just > by "eyeballing" it.?) > > --- Martin Sandiford <[EMAIL PROTECTED]> wrote: > > >>Does this do what you want? >> >>library(lattice) >> >>rand1 <- rnorm(50) >>rand2 <- rnorm(50) >>theplot <- xyplot(rand1 ~ rand2, xlab="x axis", >>ylab="y axis") >> >>thefile <- "plotproblem.eps" >>trellis.device(postscript, file=thefile, color=F, >>horizontal=FALSE, width=12, height=4, >>paper="special") >>print(theplot, split=c(1,1,3,1), more=T) >>print(theplot, split=c(2,1,3,1), more=T) >>print(theplot, split=c(3,1,3,1), more=F) >>dev.off() >> >>(Paper size and type specified in trellis.device >>call). >> >> >>Martin >> >>On 15/03/2006, at 2:44 PM, context grey wrote: >> >> >>> >>>--- Duncan Murdoch <[EMAIL PROTECTED]> wrote: >>> The R graphics model is that the drawing surface >> >>is >> established first, then the things you draw are adjusted to fit in >> >>it. >> R won't change the shape of the display because you are drawing more things on it. >>> >>>Thanks, this comment clarifies things somewhat. >>>Though I find it >>>an odd design choice for R, since it seems to >> >>entail >> >>>then that >>>the user has figure out the aspect ratio of the >>>resulting plot, >>>something that R could easily keep track of as it >> >>is >> >>>drawing. >>> >>>Here's example code, producing 3 scatterplots >>>side-by-side >>>(here reusing the same plot for simplicity). >>> >>>What's desired is that the individual scatterplots >>>have the >>>natural aspect, e.g. square, with the axis units >> >>being >> >>>the >>>same for X, Y. And to do this while producing a >>>correct >>>bounding box in the .eps file. >>> >>>As it stands the example code produces a correct >>>bounding box, >>>but the scatterplots are too stretched to be >> >>usable. >> >>>Inserting >>>aspect=1/1 in the xyplot() seems to cause the >> >>bounding >> >>>box >>>to be incorrect. >>> >>> >>> >>>library(lattice) >>> >>>rand1 <- rnorm(50) >>>rand2 <- rnorm(50) >>>theplot <- xyplot(rand1 ~ rand2, xlab="x axis", >>>ylab="y axis") >>> >>>thefile <- "plotproblem.eps" >>>trellis.device(postscript, file=thefile, color=F, >>>horizontal=FALSE) >>>print(theplot, split=c(1,1,3,1), more=T) >>>print(theplot, split=c(2,1,3,1), more=T) >>>print(theplot, split=c(3,1,3,1), more=F) >>>dev.off() >>> >>>--- >>> >>> >>> I don't think I understand exactly what you want >> >>to >> achieve; sample code that produces something close would be helpful >> >>(even >> if it comes out the wrong shape). >>> >>>__ >>>R-help@stat.math.ethz.ch mailing list >>>https://stat.ethz.ch/mailman/listinfo/r-help >>>PLEASE do read the posting guide! >>>http://www.R-project.org/posting-guide.html >>> >> >> > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Having trouble with plot.survfit and fun="cloglog"
I'm having trouble getting fun="cloglog" to work with plot on a survfit object. Here are the data I used for the commands that follow. days status 2 0 2 0 5 1 9 0 14 1 16 0 16 0 17 0 29 1 30 0 37 1 37 0 39 1 44 0 44 0 58 0 60 1 67 1 68 1 82 1 82 1 86 0 86 0 89 1 93 0 97 1 100 0 100 0 100 0 > library(survival) Loading required package: splines > eg1.km <- survfit(Surv(days,status),data=eg1) > plot(eg1.km,mark.time=FALSE,conf.int=FALSE) # Works > plot(eg1.km,mark.time=FALSE,conf.int=FALSE,fun="cumhaz") # Works > plot(eg1.km,mark.time=FALSE,conf.int=FALSE,fun="cloglog") # Error Error in rep.default(2, n2 - 1) : invalid number of copies in rep() In addition: Warning message: 2 x values <= 0 omitted from logarithmic plot in: xy.coords(x, y, xlabel, ylabel , log) The axes are set and drawn up but nothing else is plotted. > plot(eg1.km,mark.time=FALSE,conf.int=FALSE,fun="cumhaz",log="xy") # OK Warning messages: 1: 2 x values <= 0 omitted from logarithmic plot in: xy.coords(x, y, xlabel, yla bel, log) 2: 1 y value <= 0 omitted from logarithmic plot in: xy.coords(x, y, xlabel, ylab el, log) This does display the right plot but I am confused about how the xaxis is computed. The first tick mark is labeled with 100, the next with 200 right up to 600, but the entire plot is drawn between 0 and 100. Please elighten me as to what I'm not understanding about fun="cloglog" and log scales. > R.version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status Patched major2 minor2.1 year 2006 month03 day 13 svn rev 37540 language R The survival package is version 2.21 Thank you, Kevin -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Department of Public Health Sciences Faculty of Medicine, University of Toronto email: [EMAIL PROTECTED] Tel: 416.946.8081 Fax: 416.946.3297 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] comparing AIC values of models with transformed, untransformed, and weighted variables
Patrick Baker sci.monash.edu.au> writes: What I'd like to get some advice or insight on is whether > there is an appropriate way to rescale the AIC values to permit > comparisons across these models. Any suggestions would be very welcome. > Cheers, Patrick Baker > > Not a complete solution, but you could take a look at the likelihoods associated with Box-Cox transformations (e.g. Venables and Ripley MASS pp. 170-172). Ben Bolker __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] concatenating factor from list
On 3/15/06, Sebastian Luque <[EMAIL PROTECTED]> wrote: > Sebastian Luque <[EMAIL PROTECTED]> wrote: > > "Gabor Grothendieck" <[EMAIL PROTECTED]> wrote: > > >> Is this ok or is it what you are trying to avoid: > > >> factor(unlist(lapply(cutYield, as.character))) > > > Thank you Gabor. The problem with that is what if some levels do not > > appear in any member of cutYield? > > This addition to your code takes care of that, although it's a bit > expensive: > > factor(unlist(lapply(cutYield, as.character)), > levels = unique(unlist(lapply(test, levels > > In thinking about this a bit more here is another solution which does not disassemble and reassemble the factors and so may be more along the lines you were looking for: do.call("rbind", lapply(cutYield, function(x) data.frame(x = x)))$x __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem compiling R-Patched
Liaw, Andy wrote: > Could it be that you have the environment variable R_HOME (or something like > that) defined somewhere? Just a wild guess... No, R_HOME is not defined in the shell I was compiling in, but R_LIBS was! Brilliant "wild guess." Thanks, Kevin > Andy > > From: Kevin E. Thorpe > >>I downloaded R-Patched today (to see if another problem I >>want to ask about is still present or if its just me - as per >>the posting guide). I ran "tools/rsync-recommended" >>successfully. I then ran "configure --enable-R-shlib" >>successfully. Then make stops with the following error. >> >>gcc -shared -L/usr/local/lib -o tools.so text.o init.o Rmd5.o md5.o >>-L../../../../lib -lR >>mkdir -p -- ../../../../library/tools/libs >>make[5]: Leaving directory `/home/src/R-patched/src/library/tools/src' >>make[4]: Leaving directory `/home/src/R-patched/src/library/tools/src' >>Error in file(datafile, "wb") : unable to open connection >>In addition: Warning message: >>cannot open file '/usr/local/lib/R/library/tools/R/tools.rdb', reason >>'Permission denied' >>Execution halted >>make[3]: *** [all] Error 1 >>make[3]: Leaving directory `/home/src/R-patched/src/library/tools' >>make[2]: *** [R] Error 1 >>make[2]: Leaving directory `/home/src/R-patched/src/library' >>make[1]: *** [R] Error 1 >>make[1]: Leaving directory `/home/src/R-patched/src' >>make: *** [R] Error 1 >> >>The tools.rdb file is on my system from a previous build >> >>-rw-r--r-- 1 root root 90486 2005-08-04 18:54 >>/usr/local/.../tools.rdb >> >>As you can see from the output above, I am not trying to build in >>/usr/local/... at all so I am puzzled as to why anything is >>being done in /usr/local/ before the "make install". Can >>anyone suggest what I >>should try? I am compiling on SuSE Linux version 9.2. >> >>Thank you. >> >>Kevin -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Department of Public Health Sciences Faculty of Medicine, University of Toronto email: [EMAIL PROTECTED] Tel: 416.946.8081 Fax: 416.946.3297 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem compiling R-Patched
Could it be that you have the environment variable R_HOME (or something like that) defined somewhere? Just a wild guess... Andy From: Kevin E. Thorpe > > I downloaded R-Patched today (to see if another problem I > want to ask about is still present or if its just me - as per > the posting guide). I ran "tools/rsync-recommended" > successfully. I then ran "configure --enable-R-shlib" > successfully. Then make stops with the following error. > > gcc -shared -L/usr/local/lib -o tools.so text.o init.o Rmd5.o md5.o > -L../../../../lib -lR > mkdir -p -- ../../../../library/tools/libs > make[5]: Leaving directory `/home/src/R-patched/src/library/tools/src' > make[4]: Leaving directory `/home/src/R-patched/src/library/tools/src' > Error in file(datafile, "wb") : unable to open connection > In addition: Warning message: > cannot open file '/usr/local/lib/R/library/tools/R/tools.rdb', reason > 'Permission denied' > Execution halted > make[3]: *** [all] Error 1 > make[3]: Leaving directory `/home/src/R-patched/src/library/tools' > make[2]: *** [R] Error 1 > make[2]: Leaving directory `/home/src/R-patched/src/library' > make[1]: *** [R] Error 1 > make[1]: Leaving directory `/home/src/R-patched/src' > make: *** [R] Error 1 > > The tools.rdb file is on my system from a previous build > > -rw-r--r-- 1 root root 90486 2005-08-04 18:54 > /usr/local/.../tools.rdb > > As you can see from the output above, I am not trying to build in > /usr/local/... at all so I am puzzled as to why anything is > being done in /usr/local/ before the "make install". Can > anyone suggest what I > should try? I am compiling on SuSE Linux version 9.2. > > Thank you. > > Kevin > > -- > Kevin E. Thorpe > Biostatistician/Trialist, Knowledge Translation Program > Assistant Professor, Department of Public Health Sciences > Faculty of Medicine, University of Toronto > email: [EMAIL PROTECTED] Tel: 416.946.8081 Fax: 416.946.3297 > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem compiling R-Patched
I downloaded R-Patched today (to see if another problem I want to ask about is still present or if its just me - as per the posting guide). I ran "tools/rsync-recommended" successfully. I then ran "configure --enable-R-shlib" successfully. Then make stops with the following error. gcc -shared -L/usr/local/lib -o tools.so text.o init.o Rmd5.o md5.o -L../../../../lib -lR mkdir -p -- ../../../../library/tools/libs make[5]: Leaving directory `/home/src/R-patched/src/library/tools/src' make[4]: Leaving directory `/home/src/R-patched/src/library/tools/src' Error in file(datafile, "wb") : unable to open connection In addition: Warning message: cannot open file '/usr/local/lib/R/library/tools/R/tools.rdb', reason 'Permission denied' Execution halted make[3]: *** [all] Error 1 make[3]: Leaving directory `/home/src/R-patched/src/library/tools' make[2]: *** [R] Error 1 make[2]: Leaving directory `/home/src/R-patched/src/library' make[1]: *** [R] Error 1 make[1]: Leaving directory `/home/src/R-patched/src' make: *** [R] Error 1 The tools.rdb file is on my system from a previous build -rw-r--r-- 1 root root 90486 2005-08-04 18:54 /usr/local/.../tools.rdb As you can see from the output above, I am not trying to build in /usr/local/... at all so I am puzzled as to why anything is being done in /usr/local/ before the "make install". Can anyone suggest what I should try? I am compiling on SuSE Linux version 9.2. Thank you. Kevin -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Department of Public Health Sciences Faculty of Medicine, University of Toronto email: [EMAIL PROTECTED] Tel: 416.946.8081 Fax: 416.946.3297 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Surv object in data.frame
On Thu, 16 Mar 2006, Heinz Tuechler wrote: > > Thank you, Thomas. You are right, it works, but why then I find on the help > page for Surv{survival} the following sentence: > "To include a survival object inside a data frame, use the I() function. > Surv objects are implemented as a matrix of 2 or 3 columns." > That was probably true when it was written, but that was a long time ago. I will change it. -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Surv object in data.frame
At 11:59 15.03.2006 -0600, Robert Baer wrote: >This does work: >coxph(survobj~group, data=df.test[[1]]) # this works like your original > >To get insight compare: >str(survobj) >str(df.test) >str(df.test[[1]]) Thank you for your answer. It seems to me that your solution only works, as long as the original objects are in the search path. If I do rm(survobj, group) then coxph(survobj~group, data=df.test[[1]]) does not work, because it is not found in data=df.test[[1]]. As long as the objects are present also data=data.frame(NULL) works. ## example data starttime <- rep(0,5) stoptime <- 1:5 event <- c(1,0,1,1,1) group <- c(1,1,1,2,2) ## Surv object survobj <- Surv(starttime, stoptime, event) ## put Surv object in data.frame df.test <- data.frame(survobj=I(survobj), group) ## following Robert Baer coxph(survobj~group, data=df.test[[1]]) # this works like your original coxph(survobj~group, data=data.frame(NULL)) # give an empty data frame ## remove objects to verify that df.test is used rm(starttime, stoptime, event, group, survobj) coxph(survobj~group, data=df.test[[1]]) # now it doesn't work > >Then note the 2nd sentence of the following from ?coxph >Arguments: > > formula: a formula object, with the response on the left of a '~' > operator, and the terms on the right. The response must be a > survival object as returned by the 'Surv' function. I know that the "response must be a survival object as returned by the 'Surv' function". The following sentence on the help page for Surv{survival}: "To include a survival object inside a data frame, use the I() function. Surv objects are implemented as a matrix of 2 or 3 columns." gave me the impression that a survival object retains its class if it is included via I() in a data frame. I was in error. Heinz > > > >Robert W. Baer, Ph.D. >Associate Professor >Department of Physiology >A. T. Still University of Health Science >800 W. Jefferson St. >Kirksville, MO 63501-1497 USA > > >Dear All, > >a Surv object I put in a data frame behaves somehow unexpected (see >example). >If I do a Cox regression on the original Surv object it works. If I put it >in a data.frame and do the regression on the data frame it does not work. >Seemingly it has to do with the class attribute, because if I change the >class attribute to let "Surv" appeare first, again it works. >Is this known? Should I have found information on it? >Any comments? > >Thanks > >Heinz Tüchler > >## example data >starttime <- rep(0,5) >stoptime <- 1:5 >event <- c(1,0,1,1,1) >group <- c(1,1,1,2,2) >## Surv object >survobj <- Surv(starttime, stoptime, event) >## Cox-regression >coxph(survobj~group) # this works >## put Surv object in data.frame >df.test <- data.frame(survobj=I(survobj), group) >## Cox-regression on data.frame >coxph(survobj~group, data=df.test) # this does not work >attr(df.test$survobj, 'class') # survobject has class "AsIs", "Surv" >attr(df.test$survobj, 'class') <- c('Surv', 'AsIs') # put Surv first >attr(df.test$survobj, 'class') # survobject has class "Surv", "AsIs" >coxph(survobj~group, data=df.test) # now it works > >__ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] concatenating factor from list
Sebastian Luque <[EMAIL PROTECTED]> wrote: "Gabor Grothendieck" <[EMAIL PROTECTED]> wrote: >> Is this ok or is it what you are trying to avoid: >> factor(unlist(lapply(cutYield, as.character))) > Thank you Gabor. The problem with that is what if some levels do not > appear in any member of cutYield? This addition to your code takes care of that, although it's a bit expensive: factor(unlist(lapply(cutYield, as.character)), levels = unique(unlist(lapply(test, levels Thanks! -- Sebastian P. Luque __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Surv object in data.frame
At 09:23 15.03.2006 -0800, Thomas Lumley wrote: >On Wed, 15 Mar 2006, Heinz Tuechler wrote: > >> Dear All, >> >> a Surv object I put in a data frame behaves somehow unexpected (see example). >> If I do a Cox regression on the original Surv object it works. If I put it >> in a data.frame and do the regression on the data frame it does not work. >> Seemingly it has to do with the class attribute, because if I change the >> class attribute to let "Surv" appeare first, again it works. >> Is this known? Should I have found information on it? > >Well, this is the sort of thing that happens when you use kludges like >AsIs. > >The problem is with [.AsIs >survobj[,1] is supposed to be a vector of times (that's what [.Surv >returns), but [.AsIs sticks the original class attribute on to it. > >> str(survobj[,1]) > num [1:5] 0 0 0 0 0 >> str(I(survobj)[,1]) >Classes 'AsIs', 'Surv' num [1:5] 0 0 0 0 0 > >The solution is not to use I() -- there's no problem with putting survival >objects in a data frame >> df.right<-data.frame(survobj,group) >> df.right > survobj group >1 (0,1 ] 1 >2 (0,2+] 1 >3 (0,3 ] 1 >4 (0,4 ] 2 >5 (0,5 ] 2 > > > -thomas Thank you, Thomas. You are right, it works, but why then I find on the help page for Surv{survival} the following sentence: "To include a survival object inside a data frame, use the I() function. Surv objects are implemented as a matrix of 2 or 3 columns." Heinz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] concatenating factor from list
Since all components of cutYield have the same levels, one could do this to ensure that all levels are represented: factor(unlist(lapply(cutYield, as.character)), levels = levels(cutYield[[1]])) On 3/15/06, Sebastian Luque <[EMAIL PROTECTED]> wrote: > "Gabor Grothendieck" <[EMAIL PROTECTED]> wrote: > > > Is this ok or is it what you are trying to avoid: > > > factor(unlist(lapply(cutYield, as.character))) > > Thank you Gabor. The problem with that is what if some levels do not > appear in any member of cutYield? In that case, the factor created above > would contain fewer levels than those present in every member of cutYield. > > Cheers, > > -- > Sebastian P. Luque > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] concatenating factor from list
"Gabor Grothendieck" <[EMAIL PROTECTED]> wrote: > Is this ok or is it what you are trying to avoid: > factor(unlist(lapply(cutYield, as.character))) Thank you Gabor. The problem with that is what if some levels do not appear in any member of cutYield? In that case, the factor created above would contain fewer levels than those present in every member of cutYield. Cheers, -- Sebastian P. Luque __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (no subject)
Hi there, Can R use "principal component analysis (PCA)" to do the clustering? Or does PCA only be used to pick up the important variables? Thank you! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] concatenating factor from list
Is this ok or is it what you are trying to avoid: factor(unlist(lapply(cutYield, as.character))) On 3/15/06, Sebastian Luque <[EMAIL PROTECTED]> wrote: > Hi, > > I've run into a ridiculous problem I can't find any solutions for in the > archives or help pages: > > data(barley) > cutYield <- with(barley, by(yield, variety, cut, breaks = c(0, 30, 60, 90))) > > As in this example, I'm using 'by' to return a factor for each level of > another factor. The problem is that 'by' returns a list of the factors, > and I need all these factors concatenated. No problem, I said: > > unlist(cutYield) > > which returns an 'integer' class object, so it's no longer a factor. The > same happens with: > > do.call(c, cutYield) > > I could recreate the factor from the integer level codes returned above, > but this is not good because this means redoing the job already done by > the function called in 'by', making the code more prone to errors. > > Thanks in advance for any pointers, > > -- > Sebastian > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to get correct proportions/bounding box for latex figure?
That's approximately right, but the individual scatterplots are slightly stretched horizontally. Is there not any way to have the plots have true 1:1 aspect ratio (given that the range of the data is the same on both axes) and still get a bounding box?. And, without getting out a ruler and manually calculating width/height values? (I'm guessing you arrived at width=12,height=4 just by "eyeballing" it.?) --- Martin Sandiford <[EMAIL PROTECTED]> wrote: > Does this do what you want? > > library(lattice) > > rand1 <- rnorm(50) > rand2 <- rnorm(50) > theplot <- xyplot(rand1 ~ rand2, xlab="x axis", > ylab="y axis") > > thefile <- "plotproblem.eps" > trellis.device(postscript, file=thefile, color=F, > horizontal=FALSE, width=12, height=4, > paper="special") > print(theplot, split=c(1,1,3,1), more=T) > print(theplot, split=c(2,1,3,1), more=T) > print(theplot, split=c(3,1,3,1), more=F) > dev.off() > > (Paper size and type specified in trellis.device > call). > > > Martin > > On 15/03/2006, at 2:44 PM, context grey wrote: > > > > > > > --- Duncan Murdoch <[EMAIL PROTECTED]> wrote: > >> The R graphics model is that the drawing surface > is > >> established first, > >> then the things you draw are adjusted to fit in > it. > >> R won't change the > >> shape of the display because you are drawing more > >> things on it. > > > > Thanks, this comment clarifies things somewhat. > > Though I find it > > an odd design choice for R, since it seems to > entail > > then that > > the user has figure out the aspect ratio of the > > resulting plot, > > something that R could easily keep track of as it > is > > drawing. > > > > Here's example code, producing 3 scatterplots > > side-by-side > > (here reusing the same plot for simplicity). > > > > What's desired is that the individual scatterplots > > have the > > natural aspect, e.g. square, with the axis units > being > > the > > same for X, Y. And to do this while producing a > > correct > > bounding box in the .eps file. > > > > As it stands the example code produces a correct > > bounding box, > > but the scatterplots are too stretched to be > usable. > > Inserting > > aspect=1/1 in the xyplot() seems to cause the > bounding > > box > > to be incorrect. > > > > > > > > library(lattice) > > > > rand1 <- rnorm(50) > > rand2 <- rnorm(50) > > theplot <- xyplot(rand1 ~ rand2, xlab="x axis", > > ylab="y axis") > > > > thefile <- "plotproblem.eps" > > trellis.device(postscript, file=thefile, color=F, > > horizontal=FALSE) > > print(theplot, split=c(1,1,3,1), more=T) > > print(theplot, split=c(2,1,3,1), more=T) > > print(theplot, split=c(3,1,3,1), more=F) > > dev.off() > > > > --- > > > > > >> I don't think I understand exactly what you want > to > >> achieve; sample code > >> that produces something close would be helpful > (even > >> if it comes out the > >> wrong shape). > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] concatenating factor from list
Hi, I've run into a ridiculous problem I can't find any solutions for in the archives or help pages: data(barley) cutYield <- with(barley, by(yield, variety, cut, breaks = c(0, 30, 60, 90))) As in this example, I'm using 'by' to return a factor for each level of another factor. The problem is that 'by' returns a list of the factors, and I need all these factors concatenated. No problem, I said: unlist(cutYield) which returns an 'integer' class object, so it's no longer a factor. The same happens with: do.call(c, cutYield) I could recreate the factor from the integer level codes returned above, but this is not good because this means redoing the job already done by the function called in 'by', making the code more prone to errors. Thanks in advance for any pointers, -- Sebastian __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Surface plot
Hi, thanks for the help but I'm still having issues. Basically, I have two matrices of equal dimension, one should produce something similar to a heatmap.. The 2nd matrix should be the "heights" for each value of the heatmap - producing a sort of surface plot. Viewing this seems like a problem too, as I need to scale the x axis so that ~140 labels are visible. Maybe wireframe isn't the way to go? I've tried persp() too. Thank you!! ~Tanya -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 14, 2006 3:22 AM To: Cashorali, Tanya Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Wireframe axis labels Cashorali, Tanya wrote: > Hi, > I'm trying to do a surface plot using the wireframe function. > Everything is working beautifully except that I want to be able to > re-scale it a LOT so that I can fit ~145 labels on the x-axis or y-axis. > I've tried using zoom, scales, aspect, .. nothing seems to work. The > help on wireframe in R says that you can input a list of labels for > any of the axes, but this has also failed. H, you can do so, but I do not believe you really want 145 labels: g <- expand.grid(x = 1:145, y = 1:145, gr = 1:2) g$z <- log((g$x^g$g + g$y^2) * g$gr) wireframe(z ~ x * y, data = g, groups = gr, scales = list(arrows = FALSE, at=1:145)) Uwe Ligges > Thanks for any help! > -Tanya > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] lapply vs. for (was: Incrementing a counter in lapply)
On Wed, 15 Mar 2006, Philippe Grosjean wrote: > the for() loop is very slow in S-PLUS. This is probably one of the > motivation of developing the apply() family of functions (as well as the > ugly For() loop) under this system. > > Now, for() loops are much faster in R. Also, if you look at the R code > in apply(), you will realize that there is a for() loop in it! > lapply(), on the other hand, can be faster than a loop. That's why it went from being a loop to being internal C code. -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] lapply vs. for (was: Incrementing a counter in lapply)
In my opinion the main issue between using 'for' and an apply function is the simplicity of the code. If it is simpler and more understandable to use 'lapply' than a 'for' loop in a situation, then use 'lapply'. If in a different situation it is the 'for' loop that is simpler, then use the 'for' loop. In modern day R whatever timing differences there may be are likely to be slight, and virtually certain not to be critical. Where the confusion comes in is because in the olden days of S-PLUS, the timing differences could be quite substantial in some cases. The hangover from that is that apply functions are too often recommended in R. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Gregor Gorjanc wrote: >>From: Thomas Lumley >> >> >>>On Tue, 14 Mar 2006, John McHenry wrote: >>> >>> >>> Thanks, Gabor & Thomas. Apologies, but I used an example that obfuscated the question that I wanted to ask. I really wanted to know how to have extra arguments in >>>functions that >>> >>> would allow, per the example code, for something like a >>>counter to be >>> >>> incremented. Thomas's suggestion of using mapply >>>(reproduced below with >>> >>> corrections) is probably closest. >>>It is probably worth pointing out here that the R >>>documentation does not >>>specify the order in which lapply() does the computation. >>> >>>If you could work out how to increment a counter (and you could, with >>>sufficient effort), it would not necessarily work, because the 'i'th >>>evaluation would not necessarily be of the 'i'th element. >>> >>>[lapply() does in fact start at the beginning, go on until it >>>gets to the >>>end, and then stop, but this isn't documented. Suppose R became >>>multithreaded, for example] >>> >>> >>The corollary, it seems to me, is that sometimes it's better to leave the >>good old for loop alone. It's not always profitable to turn for loops into >>some *apply construct. The trick is learning to know when to do it and when >>not to. >> >> > >Can someone share some of this tricks with me? Up to now I have always >done things with for loop. Just recently I started to pay attention to >*apply* constructs and I already wanted to start implementing them >instead of good old for, but then a stroke of lightning came from this >thread. Based on words from Thomas, lapply should not be used for tasks >where order is critical. Did I get this clear enough. Additionally, I >have read notes (I lost link, but was posted on R-help, I think) from >Thomas on R and he mentioned that it is commonly assumed that *apply* (I >do not remember which one of *apply*) is faster than loop, but that this >is not true. Any additional pointers to literature? > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] lapply vs. for (was: Incrementing a counter in lapply)
the for() loop is very slow in S-PLUS. This is probably one of the motivation of developing the apply() family of functions (as well as the ugly For() loop) under this system. Now, for() loops are much faster in R. Also, if you look at the R code in apply(), you will realize that there is a for() loop in it! So, why would you prefer using apply() or the like? 1) If you write code to be run both in S-PLUS and R, 2) If you want more concise code (much "housekeeping" is done by apply() and co), 3) Because the apply() family is more in the phylosophy of vectorized calculation, that is, the favored approach in S language. Take care, however, that the optimal approach is not just to replace for() loops with apply() and co, but to *rethink* completelly your algorithm in a vectorized way. This often ends up with a very different solution! Best, Philippe Grosjean Gregor Gorjanc wrote: >>From: Thomas Lumley >> >>>On Tue, 14 Mar 2006, John McHenry wrote: >>> >>> Thanks, Gabor & Thomas. Apologies, but I used an example that obfuscated the question that I wanted to ask. I really wanted to know how to have extra arguments in >>> >>>functions that >>> would allow, per the example code, for something like a >>> >>>counter to be >>> incremented. Thomas's suggestion of using mapply >>> >>>(reproduced below with >>> corrections) is probably closest. >>> >>>It is probably worth pointing out here that the R >>>documentation does not >>>specify the order in which lapply() does the computation. >>> >>>If you could work out how to increment a counter (and you could, with >>>sufficient effort), it would not necessarily work, because the 'i'th >>>evaluation would not necessarily be of the 'i'th element. >>> >>>[lapply() does in fact start at the beginning, go on until it >>>gets to the >>>end, and then stop, but this isn't documented. Suppose R became >>>multithreaded, for example] >> >>The corollary, it seems to me, is that sometimes it's better to leave the >>good old for loop alone. It's not always profitable to turn for loops into >>some *apply construct. The trick is learning to know when to do it and when >>not to. > > > Can someone share some of this tricks with me? Up to now I have always > done things with for loop. Just recently I started to pay attention to > *apply* constructs and I already wanted to start implementing them > instead of good old for, but then a stroke of lightning came from this > thread. Based on words from Thomas, lapply should not be used for tasks > where order is critical. Did I get this clear enough. Additionally, I > have read notes (I lost link, but was posted on R-help, I think) from > Thomas on R and he mentioned that it is commonly assumed that *apply* (I > do not remember which one of *apply*) is faster than loop, but that this > is not true. Any additional pointers to literature? > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] lapply vs. for (was: Incrementing a counter in lapply)
> From: Thomas Lumley >> >> On Tue, 14 Mar 2006, John McHenry wrote: >> >> > Thanks, Gabor & Thomas. >> > >> > Apologies, but I used an example that obfuscated the question that I >> > wanted to ask. >> > >> > I really wanted to know how to have extra arguments in >> functions that >> > would allow, per the example code, for something like a >> counter to be >> > incremented. Thomas's suggestion of using mapply >> (reproduced below with >> > corrections) is probably closest. >> >> It is probably worth pointing out here that the R >> documentation does not >> specify the order in which lapply() does the computation. >> >> If you could work out how to increment a counter (and you could, with >> sufficient effort), it would not necessarily work, because the 'i'th >> evaluation would not necessarily be of the 'i'th element. >> >> [lapply() does in fact start at the beginning, go on until it >> gets to the >> end, and then stop, but this isn't documented. Suppose R became >> multithreaded, for example] > > The corollary, it seems to me, is that sometimes it's better to leave the > good old for loop alone. It's not always profitable to turn for loops into > some *apply construct. The trick is learning to know when to do it and when > not to. Can someone share some of this tricks with me? Up to now I have always done things with for loop. Just recently I started to pay attention to *apply* constructs and I already wanted to start implementing them instead of good old for, but then a stroke of lightning came from this thread. Based on words from Thomas, lapply should not be used for tasks where order is critical. Did I get this clear enough. Additionally, I have read notes (I lost link, but was posted on R-help, I think) from Thomas on R and he mentioned that it is commonly assumed that *apply* (I do not remember which one of *apply*) is faster than loop, but that this is not true. Any additional pointers to literature? -- Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana PhD student Biotechnical Faculty Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan Groblje 3 mail: gregor.gorjanc bfro.uni-lj.si SI-1230 Domzale tel: +386 (0)1 72 17 861 Slovenia, Europefax: +386 (0)1 72 17 888 -- "One must learn by doing the thing; for though you think you know it, you have no certainty until you try." Sophocles ~ 450 B.C. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] generating RANDOM ROWS from matrix
?sample You must use replace=FALSE to guarantee 1000 different rows mymatrix[sample(12000,1000,replace=FALSE),] -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of mark salsburg > Sent: Wednesday, March 15, 2006 1:02 PM > To: R-help@stat.math.ethz.ch > Subject: [R] generating RANDOM ROWS from matrix > > Dear group, > > I would like to generate a 1000 random rows from a MATRIX > with dimensions > 12,000 by 20 (i.e. to generate a 1000 by 20 matrix of random rows) > > Does the function sample() work for this??? > > thank you in advance > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] generating RANDOM ROWS from matrix
Is something like this what your looking for: x <- matrix(c(rnorm(100)),ncol=10) sub <- sample(5, replace=TRUE) # For sampling with replacement x[sub,] Harold -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of mark salsburg Sent: Wednesday, March 15, 2006 4:02 PM To: R-help@stat.math.ethz.ch Subject: [R] generating RANDOM ROWS from matrix Dear group, I would like to generate a 1000 random rows from a MATRIX with dimensions 12,000 by 20 (i.e. to generate a 1000 by 20 matrix of random rows) Does the function sample() work for this??? thank you in advance [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Additional arguments in S3 method produces a warning
Define extract like this: extract <- function(e, n, ...) UseMethod("extract") # test -- no warning extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) On 3/15/06, Philippe Grosjean <[EMAIL PROTECTED]> wrote: > Hello, > I just notice this: > > x <- c(1:4,0:5, 4, 11) > > library(pastecs) > Loading required package: boot > > tp <- turnpoints(x) > > extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) > [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE > FALSE > Warning message: > arguments after the first two are ignored in: UseMethod("extract", e, n, > ...) > > extract(tp) > [1] 0 0 0 1 -1 0 0 0 0 1 -1 0 > Warning message: > arguments after the first two are ignored in: UseMethod("extract", e, n, > ...) > > My extract.turnpoints() function produces warnings. I can easily spot > the origin of this warning: > > > extract > function (e, n, ...) > UseMethod("extract", e, n, ...) > > extract.turnpoints > function (e, n, no.tp = 0, peak = 1, pit = -1, ...) > { > if (missing(n)) > n <- length(e) > res <- rep(no.tp, length.out = e$n) > res[e$pos[e$peaks]] <- peak > res[e$pos[e$pits]] <- pit > if (n < length(res) & n > 0) > res <- res[1:n] > res > } > > This is because my extract.turnpoints() method defines more arguments > than 'e' and 'n' in the generic function. However, > > 1) I though that the '...' argument in S3 generic function was there to > allow defining/passing additional arguments in/to S3 methods. Is this > correct? If yes, why the warning? > > 2) Despite the warning says arguments after the first two are ignored, > this appears not to be the case: in this example, 'no.tp', 'peak' and > 'pit' arguments are taken into account, as you can see (different > behaviour if you give other values to them). > > I am a little bit lost. Could someone help me, please. > > Best, > > Philippe Grosjean > > > -- > ..<°}))>< > ) ) ) ) ) > ( ( ( ( (Prof. Philippe Grosjean > ) ) ) ) ) > ( ( ( ( (Numerical Ecology of Aquatic Systems > ) ) ) ) ) Mons-Hainaut University, Pentagone (3D08) > ( ( ( ( (Academie Universitaire Wallonie-Bruxelles > ) ) ) ) ) 8, av du Champ de Mars, 7000 Mons, Belgium > ( ( ( ( ( > ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.30.54 > ( ( ( ( (email: [EMAIL PROTECTED] > ) ) ) ) ) > ( ( ( ( (web: http://www.umh.ac.be/~econum > ) ) ) ) ) http://www.sciviews.org > ( ( ( ( ( > .. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] generating RANDOM ROWS from matrix
Dear group, I would like to generate a 1000 random rows from a MATRIX with dimensions 12,000 by 20 (i.e. to generate a 1000 by 20 matrix of random rows) Does the function sample() work for this??? thank you in advance [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Additional arguments in S3 method produces a warning
Hello, I just notice this: > x <- c(1:4,0:5, 4, 11) > library(pastecs) Loading required package: boot > tp <- turnpoints(x) > extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE) [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE Warning message: arguments after the first two are ignored in: UseMethod("extract", e, n, ...) > extract(tp) [1] 0 0 0 1 -1 0 0 0 0 1 -1 0 Warning message: arguments after the first two are ignored in: UseMethod("extract", e, n, ...) My extract.turnpoints() function produces warnings. I can easily spot the origin of this warning: > extract function (e, n, ...) UseMethod("extract", e, n, ...) > extract.turnpoints function (e, n, no.tp = 0, peak = 1, pit = -1, ...) { if (missing(n)) n <- length(e) res <- rep(no.tp, length.out = e$n) res[e$pos[e$peaks]] <- peak res[e$pos[e$pits]] <- pit if (n < length(res) & n > 0) res <- res[1:n] res } This is because my extract.turnpoints() method defines more arguments than 'e' and 'n' in the generic function. However, 1) I though that the '...' argument in S3 generic function was there to allow defining/passing additional arguments in/to S3 methods. Is this correct? If yes, why the warning? 2) Despite the warning says arguments after the first two are ignored, this appears not to be the case: in this example, 'no.tp', 'peak' and 'pit' arguments are taken into account, as you can see (different behaviour if you give other values to them). I am a little bit lost. Could someone help me, please. Best, Philippe Grosjean -- ..<°}))>< ) ) ) ) ) ( ( ( ( (Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( (Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Pentagone (3D08) ( ( ( ( (Academie Universitaire Wallonie-Bruxelles ) ) ) ) ) 8, av du Champ de Mars, 7000 Mons, Belgium ( ( ( ( ( ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.30.54 ( ( ( ( (email: [EMAIL PROTECTED] ) ) ) ) ) ( ( ( ( (web: http://www.umh.ac.be/~econum ) ) ) ) ) http://www.sciviews.org ( ( ( ( ( .. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] which.minimums not which.min
On Wed, 2006-03-15 at 21:45 +0100, Philippe Grosjean wrote: > What Fred is looking for is local minima/maxima, also known as turning > points, or pits/peaks in a series. You can look at ?turnpoints in > pastecs library. > > > x <- c(1:4,0:5, 4, 11) > > x > [1] 1 2 3 4 0 1 2 3 4 5 4 11 > > tp <- turnpoints(x) > > summary(tp) > Turning points for: x > > nbr observations : 12 > nbr ex-aequos : 0 > nbr turning points: 4 (first point is a peak) > E(p) = 6.67 Var(p) = 1.81 (theoretical) > >point type proba info > 1 4 peak 0.1 3.3219281 > 2 5 pit 0.002380952 8.7142455 > 310 peak 0.005952381 7.3923174 > 411 pit 0.7 0.5849625 > > plot(tp) # Only useful for a longer and more complex series! > > # Get the position of peaks > > (1:length(x))[extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE)] > [1] 4 10 > Warning message: > arguments after the first two are ignored in: UseMethod("extract", e, n, > ...) > > (1:length(x))[extract(tp, no.tp = FALSE, peak = FALSE, pit = TRUE)] > [1] 5 11 > Warning message: > arguments after the first two are ignored in: UseMethod("extract", e, n, > ...) > > # By the way, there are warnings although it works well (I ask on R-Help) > > Now, you can easily code your which.minima() function using turnpoints: > > x <- c(1:4,0:5, 4, 11) > x > tp <- turnpoints(x) > summary(tp) > plot(tp) # Only useful for a longer and more complex series! > # Get the position of peaks > (1:length(x))[extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE)] > (1:length(x))[extract(tp, no.tp = FALSE, peak = FALSE, pit = TRUE)] > # By the way, there are warnings although it works well (I ask on R-Help) > > which.minima <- function(x) { > if (!require(pastecs)) stop("pastecs library is required!") > x <- as.vector(x) > (1:length(x))[extract(turnpoints(x), no.tp = FALSE, peak = FALSE, pit = > TRUE)] > } > > which.minima(x) > > Of course, you could optimize this code. This is just a rough solution! > Best, > > Philippe Grosjean Philippe, Thanks for the clarification. As with Andy's reply, it seems that my closing thoughts were correct. I was confused since the actual result of which.max() in Fred's post did not match the data provided. Best regards, Marc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] which.minimums not which.min
What Fred is looking for is local minima/maxima, also known as turning points, or pits/peaks in a series. You can look at ?turnpoints in pastecs library. > x <- c(1:4,0:5, 4, 11) > x [1] 1 2 3 4 0 1 2 3 4 5 4 11 > tp <- turnpoints(x) > summary(tp) Turning points for: x nbr observations : 12 nbr ex-aequos : 0 nbr turning points: 4 (first point is a peak) E(p) = 6.67 Var(p) = 1.81 (theoretical) point type proba info 1 4 peak 0.1 3.3219281 2 5 pit 0.002380952 8.7142455 310 peak 0.005952381 7.3923174 411 pit 0.7 0.5849625 > plot(tp) # Only useful for a longer and more complex series! > # Get the position of peaks > (1:length(x))[extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE)] [1] 4 10 Warning message: arguments after the first two are ignored in: UseMethod("extract", e, n, ...) > (1:length(x))[extract(tp, no.tp = FALSE, peak = FALSE, pit = TRUE)] [1] 5 11 Warning message: arguments after the first two are ignored in: UseMethod("extract", e, n, ...) > # By the way, there are warnings although it works well (I ask on R-Help) Now, you can easily code your which.minima() function using turnpoints: x <- c(1:4,0:5, 4, 11) x tp <- turnpoints(x) summary(tp) plot(tp) # Only useful for a longer and more complex series! # Get the position of peaks (1:length(x))[extract(tp, no.tp = FALSE, peak = TRUE, pit = FALSE)] (1:length(x))[extract(tp, no.tp = FALSE, peak = FALSE, pit = TRUE)] # By the way, there are warnings although it works well (I ask on R-Help) which.minima <- function(x) { if (!require(pastecs)) stop("pastecs library is required!") x <- as.vector(x) (1:length(x))[extract(turnpoints(x), no.tp = FALSE, peak = FALSE, pit = TRUE)] } which.minima(x) Of course, you could optimize this code. This is just a rough solution! Best, Philippe Grosjean ..<°}))>< ) ) ) ) ) ( ( ( ( (Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( (Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Pentagone (3D08) ( ( ( ( (Academie Universitaire Wallonie-Bruxelles ) ) ) ) ) 8, av du Champ de Mars, 7000 Mons, Belgium ( ( ( ( ( ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.30.54 ( ( ( ( (email: [EMAIL PROTECTED] ) ) ) ) ) ( ( ( ( (web: http://www.umh.ac.be/~econum ) ) ) ) ) http://www.sciviews.org ( ( ( ( ( .. Marc Schwartz (via MN) wrote: > On Wed, 2006-03-15 at 11:32 -0800, Fred J. wrote: > >> Hi >> >> Is there a function which determines the location, i.e., index of >>the all minimums or maximums of a numeric vector. >> Which.min(x) only finds the (first) of such. >> >> > x <- c(1:4,0:5, 4, 11) >> > x >> [1] 1 2 3 4 0 1 2 3 4 5 4 11 >> > which.min(x) >> [1] 5 >> > which.max(x) >> [1] 11 >> > >> >> but I need >> which.min(x) to be 5 11 >> which.max(x) to be 4 10 >> >> thanks >> > > > There is something wrong with your example code versus data here, since: > > >>x > > [1] 1 2 3 4 0 1 2 3 4 5 4 11 > > >>which.min(x) > > [1] 5 > > >>which.max(x) > > [1] 12 > > > There is one one minimum value of 0 in that vector and only one maximum > value of 11. > > If you had a vector 'x': > > >>x <- c(1:4, 0:5, 4, 0, 5) > > >>x > > [1] 1 2 3 4 0 1 2 3 4 5 4 0 5 > > > You could then do the following to get the indices of the multiple > min/max values: > > >>which(x == min(x)) > > [1] 5 12 > > >>which(x == max(x)) > > [1] 10 13 > > > The only other thing that I can think you might be considering would be > local minima/maxima in the vector and if that is what you want using: > > RSiteSearch("local minima") > > or > > RSiteSearch("peaks") > > > should lead you to some solutions that have been discussed previously. > > HTH, > > Marc Schwartz > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] which.minimums not which.min
What you want seems to be the valleys and peaks in the data. If so, try: RSiteSearch("find peaks") which points to a post by Philippe Grosjean, pointing to the pastesc package: > library(pastecs) Loading required package: boot > tp <- turnpoints(x) > which(tp$peaks) [1] 4 10 > which(tp$pits) [1] 5 11 Andy From: Fred J. > > Hi > > Is there a function which determines the location, i.e., > index of the all minimums or maximums of a numeric vector. > Which.min(x) only finds the (first) of such. > > > x <- c(1:4,0:5, 4, 11) > > x >[1] 1 2 3 4 0 1 2 3 4 5 4 11 > > which.min(x) > [1] 5 > > which.max(x) > [1] 11 > > > > but I need > which.min(x) to be 5 11 > which.max(x) to be 4 10 > > thanks > > > __ > > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] which.minimums not which.min
On Wed, 2006-03-15 at 11:32 -0800, Fred J. wrote: > Hi > > Is there a function which determines the location, i.e., index of > the all minimums or maximums of a numeric vector. > Which.min(x) only finds the (first) of such. > > > x <- c(1:4,0:5, 4, 11) > > x >[1] 1 2 3 4 0 1 2 3 4 5 4 11 > > which.min(x) > [1] 5 > > which.max(x) > [1] 11 > > > > but I need > which.min(x) to be 5 11 > which.max(x) to be 4 10 > > thanks > There is something wrong with your example code versus data here, since: > x [1] 1 2 3 4 0 1 2 3 4 5 4 11 > which.min(x) [1] 5 > which.max(x) [1] 12 There is one one minimum value of 0 in that vector and only one maximum value of 11. If you had a vector 'x': > x <- c(1:4, 0:5, 4, 0, 5) > x [1] 1 2 3 4 0 1 2 3 4 5 4 0 5 You could then do the following to get the indices of the multiple min/max values: > which(x == min(x)) [1] 5 12 > which(x == max(x)) [1] 10 13 The only other thing that I can think you might be considering would be local minima/maxima in the vector and if that is what you want using: RSiteSearch("local minima") or RSiteSearch("peaks") should lead you to some solutions that have been discussed previously. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R icon image file
http://www.r-project.org/Rlogo.jpg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Erin Hodgess Sent: Wednesday, March 15, 2006 2:39 PM To: r-help@stat.math.ethz.ch Subject: [R] R icon image file Dear R People: I would like to include a link to the R home page on a web page for students. I would like to have the "R" icon as part of the link. Where is the image file please? (for the icon) Thanks, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] which.minimums not which.min
Try order(x, decreasing=TRUE/FALSE) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fred J. Sent: Wednesday, March 15, 2006 2:32 PM To: r-help@stat.math.ethz.ch Subject: [R] which.minimums not which.min Hi Is there a function which determines the location, i.e., index of the all minimums or maximums of a numeric vector. Which.min(x) only finds the (first) of such. > x <- c(1:4,0:5, 4, 11) > x [1] 1 2 3 4 0 1 2 3 4 5 4 11 > which.min(x) [1] 5 > which.max(x) [1] 11 > but I need which.min(x) to be 5 11 which.max(x) to be 4 10 thanks __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] "\r" with RSQLite
\r is a carriage return character which some editors may use as a line terminator when writing files. My guess is that RSQLite writes your data frame to a temp file using \r as a line terminator and then runs a script to have SQLite import the data (together with \r - this would be the problem), but I have no idea if that's really the case. Check the documentation or ask the maintainer. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Mikkel Grum > Sent: Wednesday, March 15, 2006 1:46 PM > To: r-help@stat.math.ethz.ch > Cc: [EMAIL PROTECTED] > Subject: [R] "\r" with RSQLite > > What am I doing wrong, or is the \r that I'm getting > in the example below a bug? > > > a <- (1:10) > > b <- (LETTERS[1:10]) > > df <- as.data.frame(cbind(a, b)) > > > > df > a b > 1 1 A > 2 2 B > 3 3 C > 4 4 D > 5 5 E > 6 6 F > 7 7 G > 8 8 H > 9 9 I > 10 10 J > > library(RSQLite) > > drv <- dbDriver("SQLite") > > con <- dbConnect(drv, dbname = "Test") > > dbWriteTable(con, "DF", df, row.names = FALSE, > overwrite = TRUE) > [1] TRUE > > df2 <- dbGetQuery(con, "SELECT DISTINCT * FROM > DF") > > dbDisconnect(con) > [1] TRUE > > df2 > a b > 1 1 A\r > 2 2 B\r > 3 3 C\r > 4 4 D\r > 5 5 E\r > 6 6 F\r > 7 7 G\r > 8 8 H\r > 9 9 I\r > 10 10 J\r > > > sessionInfo() > R version 2.2.1, 2005-12-20, i386-pc-mingw32 > > attached base packages: > [1] "methods" "stats" "graphics" "grDevices" > "utils" "datasets" > [7] "base" > > other attached packages: > RSQLite DBI > "0.4-1" "0.1-10" > > > Mikkel Grum > Genetic Diversity > International Plant Genetic Resources Institute > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] R icon image file
Dear R People: I would like to include a link to the R home page on a web page for students. I would like to have the "R" icon as part of the link. Where is the image file please? (for the icon) Thanks, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] which.minimums not which.min
Hi Is there a function which determines the location, i.e., index of the all minimums or maximums of a numeric vector. Which.min(x) only finds the (first) of such. > x <- c(1:4,0:5, 4, 11) > x [1] 1 2 3 4 0 1 2 3 4 5 4 11 > which.min(x) [1] 5 > which.max(x) [1] 11 > but I need which.min(x) to be 5 11 which.max(x) to be 4 10 thanks __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] click on graph and select data points?
I think you ca try >identify() - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] manipulating weeks dates
I meant there are more than 7 * 52 days in a year. On 3/15/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Given that there are more than 7 * 52 days in a week you may > need to think about what it is that you want. > > This will give you Jan 1 for Week 1, Jan 8 for Week 2, etc. > > as.Date(paste(YEAR,1,1,sep="-")) + 7 * (WEEK - 1) > > That or some variation of that might be suitable. See the help > desk article in R News 4/1 for more info on dates. > > > On 3/15/06, Ronaldo Reis-Jr. <[EMAIL PROTECTED]> wrote: > > Em Quarta 15 Março 2006 10:26, Gabor Grothendieck escreveu: > > > as.Date(paste(YEAR, WEEK, 0), "%Y %U %w") > > > > Hi, > > > > it works, but it use a year with 53 weeks, I need to use with 52 weeks, how > > to > > change this? > > > > Thanks > > Ronaldo > > -- > > Errigal Mountains <--> Tailoring manure > >-- anagrama > > -- > > |> // | \\ [***] > > | ( õ õ ) [Ronaldo Reis Júnior] > > |> V [UFV/DBA-Entomologia] > > |/ \ [36570-000 Viçosa - MG ] > > |> /(.''`.)\ [Fone: 31-3899-4007 ] > > | /(: :' :)\ [EMAIL PROTECTED]] > > |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] > > |( `- ) [***] > > |>> _/ \_Powered by GNU/Debian Woody/Sarge > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] manipulating weeks dates
Given that there are more than 7 * 52 days in a week you may need to think about what it is that you want. This will give you Jan 1 for Week 1, Jan 8 for Week 2, etc. as.Date(paste(YEAR,1,1,sep="-")) + 7 * (WEEK - 1) That or some variation of that might be suitable. See the help desk article in R News 4/1 for more info on dates. On 3/15/06, Ronaldo Reis-Jr. <[EMAIL PROTECTED]> wrote: > Em Quarta 15 Março 2006 10:26, Gabor Grothendieck escreveu: > > as.Date(paste(YEAR, WEEK, 0), "%Y %U %w") > > Hi, > > it works, but it use a year with 53 weeks, I need to use with 52 weeks, how to > change this? > > Thanks > Ronaldo > -- > Errigal Mountains <--> Tailoring manure >-- anagrama > -- > |> // | \\ [***] > | ( õ õ ) [Ronaldo Reis Júnior] > |> V [UFV/DBA-Entomologia] > |/ \ [36570-000 Viçosa - MG ] > |> /(.''`.)\ [Fone: 31-3899-4007 ] > | /(: :' :)\ [EMAIL PROTECTED]] > |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] > |( `- ) [***] > |>> _/ \_Powered by GNU/Debian Woody/Sarge > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (newbie) Weighted qqplot?
On 3/15/2006 1:38 PM, Vivek Satsangi wrote: > Folks, > I am documenting what I finally did, for the next person who comes along... > > Following Dr. Murdoch's suggestion, I looked at qqplot. The following > approach might be helpful to get to the same information as given by > qqplot. > To summarize the ask: given x, y, xw and yw, show (visually is okay) > whether a and b are from the same distribution. xw is the weight of > each x observation and yw is the weight of each y observation. > > Put x and xw into a dataframe. > Sort by x. > Calculate cumulative x weights, normalized to total 1. > > Put y and yw into a dataframe. > Sort by y > Calculate cumulative weights, normalized to total 1. > > Plot x and y against cumulative normalized weights. The shapes of the > two lines should be similar (to the eye)-- or the distribution is > "different". One variation that would make the result more like a qqplot: you could work out a vector of weights w (perhaps the cumulative weights from x or from y or perhaps something else) and plot y(w) versus x(w), where y(w) and x(w) are the linear interpolation values that approx gives you. Duncan Murdoch > > Vivek > > On 3/15/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: >> On 3/15/2006 8:31 AM, Vivek Satsangi wrote: >> > Folks, >> > Normally, in a data frame, one observation counts as one observation >> > of the distribution. Thus one can easily produce a CDF and (in Splus >> > atleast) use cdf.compare to compare the CDF (BTW: what is the R >> > equivalent of the SPlus cdf.compare() function, if any?) >> > >> > However, if each point should not count equally, how can I weight the >> > points before comparing the distributions? I was thinking of somehow >> > creating multiple observations for each actual observation based on >> > weights and creating a new dataframe etc. -- but that seem excessive. >> > Surely there is a simpler way? >> > >> >> x <- rnorm(100) >> >> y <- rnorm(10) >> >> xw <- rnorm(100) * 1.73 # The weights. These won't add up to 1 or N or >> >> anything because of missing values. >> >> yw <- rnorm(10) * 6.23 # The weights. These won't add up to 1 or to the >> >> same number as xw. >> >> # The question to answer is, how can I create a qq plot or cdf compare of >> >> x vs. y, weighted by their weights, xw and yw (to eventually figure out >> >> if y comes from the population x, similar to Kolmogorov-Smirnov GOF)? >> >> qqplot(x,y) # What now? >> >> qqplot doesn't support weights, but it's a simple enough function that >> you could write a version that did. Look at the cases where length(x) >> is not equal to length(y): e.g. if length(y) < length(x), qqplot >> constructs a linear approximation to a function mapping 1:nx onto the >> sorted x values, then takes length(y) evenly spaced values from that >> function. You want to do the same sort of thing, except that instead of >> even spacing, you want to look at the cumulative sums of the weights. >> >> You might want to use some kind of graphical indicator of whether points >> are heavily weighted or not, but I don't know what to recommend for that. >> >> By the way, your example above will give negative weights in xw and yw; >> you probably won't like the results if you do that. >> >> Duncan Murdoch >> > > > -- > -- Vivek Satsangi > Student, Rochester, NY USA > > Life is short, the art long, opportunity fleeting, experiment > treacherous, judgement difficult. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] "\r" with RSQLite
What am I doing wrong, or is the \r that I'm getting in the example below a bug? > a <- (1:10) > b <- (LETTERS[1:10]) > df <- as.data.frame(cbind(a, b)) > > df a b 1 1 A 2 2 B 3 3 C 4 4 D 5 5 E 6 6 F 7 7 G 8 8 H 9 9 I 10 10 J > library(RSQLite) > drv <- dbDriver("SQLite") > con <- dbConnect(drv, dbname = "Test") > dbWriteTable(con, "DF", df, row.names = FALSE, overwrite = TRUE) [1] TRUE > df2 <- dbGetQuery(con, "SELECT DISTINCT * FROM DF") > dbDisconnect(con) [1] TRUE > df2 a b 1 1 A\r 2 2 B\r 3 3 C\r 4 4 D\r 5 5 E\r 6 6 F\r 7 7 G\r 8 8 H\r 9 9 I\r 10 10 J\r > sessionInfo() R version 2.2.1, 2005-12-20, i386-pc-mingw32 attached base packages: [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base" other attached packages: RSQLite DBI "0.4-1" "0.1-10" Mikkel Grum Genetic Diversity International Plant Genetic Resources Institute __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (newbie) Weighted qqplot?
Folks, I am documenting what I finally did, for the next person who comes along... Following Dr. Murdoch's suggestion, I looked at qqplot. The following approach might be helpful to get to the same information as given by qqplot. To summarize the ask: given x, y, xw and yw, show (visually is okay) whether a and b are from the same distribution. xw is the weight of each x observation and yw is the weight of each y observation. Put x and xw into a dataframe. Sort by x. Calculate cumulative x weights, normalized to total 1. Put y and yw into a dataframe. Sort by y Calculate cumulative weights, normalized to total 1. Plot x and y against cumulative normalized weights. The shapes of the two lines should be similar (to the eye)-- or the distribution is "different". Vivek On 3/15/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 3/15/2006 8:31 AM, Vivek Satsangi wrote: > > Folks, > > Normally, in a data frame, one observation counts as one observation > > of the distribution. Thus one can easily produce a CDF and (in Splus > > atleast) use cdf.compare to compare the CDF (BTW: what is the R > > equivalent of the SPlus cdf.compare() function, if any?) > > > > However, if each point should not count equally, how can I weight the > > points before comparing the distributions? I was thinking of somehow > > creating multiple observations for each actual observation based on > > weights and creating a new dataframe etc. -- but that seem excessive. > > Surely there is a simpler way? > > > >> x <- rnorm(100) > >> y <- rnorm(10) > >> xw <- rnorm(100) * 1.73 # The weights. These won't add up to 1 or N or > >> anything because of missing values. > >> yw <- rnorm(10) * 6.23 # The weights. These won't add up to 1 or to the > >> same number as xw. > >> # The question to answer is, how can I create a qq plot or cdf compare of > >> x vs. y, weighted by their weights, xw and yw (to eventually figure out if > >> y comes from the population x, similar to Kolmogorov-Smirnov GOF)? > >> qqplot(x,y) # What now? > > qqplot doesn't support weights, but it's a simple enough function that > you could write a version that did. Look at the cases where length(x) > is not equal to length(y): e.g. if length(y) < length(x), qqplot > constructs a linear approximation to a function mapping 1:nx onto the > sorted x values, then takes length(y) evenly spaced values from that > function. You want to do the same sort of thing, except that instead of > even spacing, you want to look at the cumulative sums of the weights. > > You might want to use some kind of graphical indicator of whether points > are heavily weighted or not, but I don't know what to recommend for that. > > By the way, your example above will give negative weights in xw and yw; > you probably won't like the results if you do that. > > Duncan Murdoch > -- -- Vivek Satsangi Student, Rochester, NY USA Life is short, the art long, opportunity fleeting, experiment treacherous, judgement difficult. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] map question
On Tue, 14 Mar 2006, Dean Sonneborn wrote: > Would anyone with experience with the map functions know how to divide > Czechoslovakia into the Czech Republic and Slovakia. They have been two > separate countries for some time now. I'm thinking about the worldhires > map database in particular. > There are several borders in that database that are missing, although the country polygons are useful for people mapping cold-war data! I think most users tend to need the coastlines more than country polygons, so the data sets are very useful anyway. Adding borders can be done manually by adding the longitude,latitude coordinates to the input data shipped with the source package, then rebuild the database. If you don't need a large area, but a smaller set of country borders, there has been a discussion recently on the R-sig-geo list about this, and I'd suggest your following up there: https://stat.ethz.ch/pipermail/r-sig-geo/2006-March/thread.html at "Adding some data as colors to world map" > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] display postal codes for Germany on a map
On Tue, 14 Mar 2006, Stefan Pohl wrote: > Hi, > > is there an R package with which is it possible to display postal codes > for Germany on a map? If you know the geographical or projected coordinates of the postcodes, then there are plenty of possibilities, but this kind of data is typically only available commercially and is not provided within R or its contributed packages. If you do have, have a look at the classes and methods in the sp package. Since this is the second query from within the EU about postcode coordinates and open acces to geospatial data in a short time, I'm providing a link to: http://okfn.org/geo/manifesto.php and you may also refer to the EU INSPIRE initiative, but Europe is already so far behind the US that I'm not optimistic about sensible access to public geospatial data any time soon. > > Thanks, > > Stefan. > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] zeros to the left of the decimal point
Hi, This one is quick: how to ask R to print "0.1" as ".1", i.e, what I want is > 0.1 .1 Many thanks, Dimitri __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Address matching (was R-help Digest, Vol 37, Issue 12)
On Sun, 12 Mar 2006, Ferran Carrascosa wrote: > Hi r-users, > > I would like to know if R have any solution to the "Address standardization". > The problem is to classify a database of addresses with the real > addresses of a streets of Spain. Ideally, I would like to assign > Postal code, census data and other geographic information. There are no such built-in databases in R, and commercial solutions are typically costly. I assume you have addresses, and need a spatial index or key to associate the addresses with polygon containers like postcodes or census tracts. If there are not too many and they are all close to each other, a GPS and a bike are very effective ... Watch out for false positives in commercial automatic address matching, they may be about 10% (mostly typing errors in input data, but can be honest errors in the software). > > If this is not possible I would like to know solutions in R about text > mining, text classification, distance within text data,... > RSiteSearch("text mining") is quite productive. > Any help will be appreciate > > Thanks in advance > > Ferran Carrascosa > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Surv object in data.frame
This does work: coxph(survobj~group, data=df.test[[1]]) # this works like your original To get insight compare: str(survobj) str(df.test) str(df.test[[1]]) Then note the 2nd sentence of the following from ?coxph Arguments: formula: a formula object, with the response on the left of a '~' operator, and the terms on the right. The response must be a survival object as returned by the 'Surv' function. Robert W. Baer, Ph.D. Associate Professor Department of Physiology A. T. Still University of Health Science 800 W. Jefferson St. Kirksville, MO 63501-1497 USA Dear All, a Surv object I put in a data frame behaves somehow unexpected (see example). If I do a Cox regression on the original Surv object it works. If I put it in a data.frame and do the regression on the data frame it does not work. Seemingly it has to do with the class attribute, because if I change the class attribute to let "Surv" appeare first, again it works. Is this known? Should I have found information on it? Any comments? Thanks Heinz Tüchler ## example data starttime <- rep(0,5) stoptime <- 1:5 event <- c(1,0,1,1,1) group <- c(1,1,1,2,2) ## Surv object survobj <- Surv(starttime, stoptime, event) ## Cox-regression coxph(survobj~group) # this works ## put Surv object in data.frame df.test <- data.frame(survobj=I(survobj), group) ## Cox-regression on data.frame coxph(survobj~group, data=df.test) # this does not work attr(df.test$survobj, 'class') # survobject has class "AsIs", "Surv" attr(df.test$survobj, 'class') <- c('Surv', 'AsIs') # put Surv first attr(df.test$survobj, 'class') # survobject has class "Surv", "AsIs" coxph(survobj~group, data=df.test) # now it works __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
Thanks everyone. Obvious when you think about it, and you check that both the matrices your trying it with are actually matrices... instead of one being a list. On Wed, 2006-15-03 at 06:03 -0500, tom wright wrote: > Can someone please give me a pointer here. > I have two matrices > > matA > A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB > A B C > 1 TRUEFALSE TRUE > 2 FALSE TRUETRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding entry > in matB == TRUE (or FALSE), perferably in vector form. > > Many thanks > tom > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Question about 'lables' & ect.
On Wed, 2006-03-15 at 17:54 +0100, jia ding wrote: > Hi, > > I have a file named: > test_R.txt > aaa 2 > bbb 5 > ccc 7 > sss 3 > xxx 8 > > I want to have a plot: > test<-read.table("test_R.txt",col.name=c("Name","Score")) > par(mfrow=c(1,2)) It's not clear what the purpose is here, at least in this example. Do you plan on creating a second plot? > barplot(test$Score) > name<-test$Name > axis(1,at=1:length(test$Name),labels=paste(name)) > > Q1, if you try the script above,you will get 5 bars, the axis only shows > "aaa", "ccc","xxx", but where are "bbb"&"sss"? The easiest way to do this is to use the 'names.arg' argument in barplot(): barplot(test$Score, names.arg = as.character(test$Name)) Note that the 'Name' column in the 'test' data frame will be a factor by default, so you need to convert it to a character vector here. > Q2, pls have a look this x-axis again, you will find the middle of the bars > are not pointing to the x-axes. Note that in the Value section of ?barplot, it indicates that barplot() returns the bar midpoints, which are not at integer values along the x axis. You would need to do something like: mp <- barplot(test$Score) axis(1, at = mp, labels = as.character(test$Name)) > Q3, how can i change the width of the bars? I feel they are too "fat". You can use the 'space' argument: barplot(test$Score, names.arg = as.character(test$Name), space = 0.5) See the descriptions of the 'width' and 'space' arguments in ?barplot for some of the subtleties here. See ?barplot for more information and further examples. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Question about 'lables' & ect.
Try something like: xp <- barplot(test$Score, space=.5) axis(1, at=xp, labels=as.character(test$Name)) See ?barplot more more detail. Andy From: jia ding > > Hi, > > I have a file named: > test_R.txt > aaa 2 > bbb 5 > ccc 7 > sss 3 > xxx 8 > > I want to have a plot: > test<-read.table("test_R.txt",col.name=c("Name","Score")) > par(mfrow=c(1,2)) > barplot(test$Score) > name<-test$Name > axis(1,at=1:length(test$Name),labels=paste(name)) > > Q1, if you try the script above,you will get 5 bars, the axis > only shows "aaa", "ccc","xxx", but where are "bbb"&"sss"? > > Q2, pls have a look this x-axis again, you will find the > middle of the bars are not pointing to the x-axes. > > Q3, how can i change the width of the bars? I feel they are too "fat". > > Thanks! > Nina > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Surv object in data.frame
On Wed, 15 Mar 2006, Heinz Tuechler wrote: > Dear All, > > a Surv object I put in a data frame behaves somehow unexpected (see example). > If I do a Cox regression on the original Surv object it works. If I put it > in a data.frame and do the regression on the data frame it does not work. > Seemingly it has to do with the class attribute, because if I change the > class attribute to let "Surv" appeare first, again it works. > Is this known? Should I have found information on it? Well, this is the sort of thing that happens when you use kludges like AsIs. The problem is with [.AsIs survobj[,1] is supposed to be a vector of times (that's what [.Surv returns), but [.AsIs sticks the original class attribute on to it. > str(survobj[,1]) num [1:5] 0 0 0 0 0 > str(I(survobj)[,1]) Classes 'AsIs', 'Surv' num [1:5] 0 0 0 0 0 The solution is not to use I() -- there's no problem with putting survival objects in a data frame > df.right<-data.frame(survobj,group) > df.right survobj group 1 (0,1 ] 1 2 (0,2+] 1 3 (0,3 ] 1 4 (0,4 ] 2 5 (0,5 ] 2 -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] installation problem with Biobase
Haleh, This question would be better asked on the Bioconductor mailing list. You haven't told us what version of R you are using. I suspect you have a version mismatch. With R 2.2.x you should be able to do the following to get MergeMaid installed: >From the R prompt do: source("http://bioconductor.org/biocLite.R";) biocLite("MergeMaid") And if you have further questions, please review the posting guide__ and then send a msg to the bioc list! __ http://www.bioconductor.org/docs/postingGuide.html Best, + seth __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Setting xlim in lattice plots
Mike White wrote: > I am having difficulty setting different xlim values in the lattice > histogram plot function. > An example is shown below. I think I need to convert the limits data.frame > to a list of paired values but don't know how. Any help would be > appreciated. > > library(lattice) > mat <- as.data.frame(matrix(abs(c(rnorm(100), > 10*rnorm(100),20*rnorm(100),30*rnorm(100))),ncol=4)) > colnames(mat)<-c("C1","C2","C3","C4") > mat2<-stack(mat) > > limits<-cbind(rep(0, ncol(mat)),apply(mat,2,max)) > histogram(~ values | ind, data=mat2, xlim=limits, > scales=list(x=list(relation="free"))) > > Thanks > Mike White > I think you want a breaks=NULL in your call to histogram: library(lattice) set.seed(42) mat <- data.frame(C1 = abs(rnorm(100)), C2 = abs(10 * rnorm(100)), C3 = abs(20 * rnorm(100)), C4 = abs(30 * rnorm(100))) mat2 <- stack(mat) histogram(~ values | ind, data = mat2, breaks = NULL, scales = list(x = list(relation = "free"))) HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] manipulating weeks dates
Em Quarta 15 Março 2006 10:26, Gabor Grothendieck escreveu: > as.Date(paste(YEAR, WEEK, 0), "%Y %U %w") Hi, it works, but it use a year with 53 weeks, I need to use with 52 weeks, how to change this? Thanks Ronaldo -- Errigal Mountains <--> Tailoring manure -- anagrama -- |> // | \\ [***] | ( õ õ ) [Ronaldo Reis Júnior] |> V [UFV/DBA-Entomologia] |/ \ [36570-000 Viçosa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [EMAIL PROTECTED]] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] |( `- ) [***] |>> _/ \_Powered by GNU/Debian Woody/Sarge __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Question about 'lables' & ect.
Hi, I have a file named: test_R.txt aaa 2 bbb 5 ccc 7 sss 3 xxx 8 I want to have a plot: test<-read.table("test_R.txt",col.name=c("Name","Score")) par(mfrow=c(1,2)) barplot(test$Score) name<-test$Name axis(1,at=1:length(test$Name),labels=paste(name)) Q1, if you try the script above,you will get 5 bars, the axis only shows "aaa", "ccc","xxx", but where are "bbb"&"sss"? Q2, pls have a look this x-axis again, you will find the middle of the bars are not pointing to the x-axes. Q3, how can i change the width of the bars? I feel they are too "fat". Thanks! Nina [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] setMethod confusion -best reference for S4 programming
You might also wish to read the relevant chapter of V&R's S PROGRAMMING. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Stephen Henderson > Sent: Wednesday, March 15, 2006 4:28 AM > To: r-help@stat.math.ethz.ch > Cc: Henrik Bengtsson; Martin Maechler > Subject: Re: [R] setMethod confusion -best reference for S4 > programming > > Thanks I think you have both answered my question (reckon Ill go S3 on > that). As an adjunct to this do you know what might be the best > reference to the S4 methods current implementation. > > I have ordered the Chambers book "Programming with Data", and I have a > short tutorial-- "S4 Classes in 15 pages, more or less". > > Have I missed any other useful resources? > > Stephen Henderson > Wolfson Inst. for Biomedical Research > Cruciform Bldg., Gower Street > University College London > United Kingdom, WC1E 6BT > +44 (0)207 679 6827 > > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Henrik Bengtsson > Sent: 15 March 2006 10:59 > To: Martin Maechler > Cc: Stephen Henderson; r-help@stat.math.ethz.ch > Subject: Re: [R] setMethod confusion > > On 3/15/06, Martin Maechler <[EMAIL PROTECTED]> wrote: > > > "Stephen" == Stephen Henderson <[EMAIL PROTECTED]> > > > on Tue, 14 Mar 2006 16:32:56 - writes: > > > > Stephen> Hello I've checked through previous postings but > > Stephen> don't see a fully equivalent problem-just a few > > Stephen> hints. I have been trying to set a new method for > > Stephen> the existing function "table" or > > Stephen> "as.data.frame.table" for my class "tfSites". > > Stephen> Taking out all the useful code and just returning > > Stephen> the input class I get the error > > > > >> setMethod("table", "tfSites", function(.Object) .Object) > > > > Stephen> Error in conformMethod(signature, mnames, fnames, > > Stephen> f) : In method for function "table": formal > > Stephen> arguments omitted in the method definition cannot > > Stephen> be in the signature (exclude = "tfSites") > > > > > > >> setMethod("as.data.frame.table", "tfSites", > > >> function(.Object) .Object ) > > > > Stephen> Error in conformMethod(signature, mnames, fnames, > > Stephen> f) : In method for function "as.data.frame.table": > > Stephen> formal arguments omitted in the method definition > > Stephen> cannot be in the signature (x = "tfSites") > > > > Stephen> What does this mean? Is there something peculiar > > Stephen> about the table function? Is it because it takes > > Stephen> arguments beginning table(..., etc) > > > > Yes. Since table's argument list starts with "..." > > you cannot directly write S4 methods for it. > > Although not fully tested, but a workaround could be to i) define an > S4 method tableS4(), then ii) rename table() to table.default() and > iii) make table() an S3 generic function, and finally iv) define > table.tfSites() to call tableS4(). Would this work? If so, step > (ii)-(iv) can be done in one step using the R.oo package. Example: > > library(R.oo) > setClass("fSites", representation(x="numeric", y="numeric")) > setGeneric("tableS4", function(.Object, ...) > standardGeneric("tableS4")) > setMethod("tableS4", "fSites", function(.Object) .Object) > setMethodS3("table", "fSites", function(.Object, ...) tableS4(.Object, > ...)) > > Test; > > x <- new("fSites") > > table(x) > An object of class "fSites" > Slot "x": > numeric(0) > > Slot "y": > numeric(0) > > > X <- rpois(20, 1) > > table(X) > X > 0 1 2 3 > 10 7 2 1 > > But, what's wrong with S3 in the first place? ;) > > /Henrik > > > > > > One could consider changing table's argument list to become > > (x, ..., exclude = c(NA, NaN), dnn = list.names(...), > deparse.level > = 1) > > but that's not entirely trivial to do back compatibly, since > > table() produces *named* dimnames from its arguments in "..." > > and we'd want to make sure that this continues to work as now > > even when the first argument is formally named 'x'. E.g., > > > > > X <- rpois(20, 1) > > > table(X) > > X > > 0 1 2 3 > > 7 10 2 1 > > > > > > > should continue to contain "X" as names(dimnames(.)). > > > > Of course this has now become a topic for R-devel rather > > than R-help. > > > > Martin Maechler, > > ETH Zurich > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > > > > -- > Henrik Bengtsson > Mobile: +46 708 909208 (+1h UTC) > > ** > This email and any fil
[R] Surv object in data.frame
Dear All, a Surv object I put in a data frame behaves somehow unexpected (see example). If I do a Cox regression on the original Surv object it works. If I put it in a data.frame and do the regression on the data frame it does not work. Seemingly it has to do with the class attribute, because if I change the class attribute to let "Surv" appeare first, again it works. Is this known? Should I have found information on it? Any comments? Thanks Heinz Tüchler ## example data starttime <- rep(0,5) stoptime <- 1:5 event <- c(1,0,1,1,1) group <- c(1,1,1,2,2) ## Surv object survobj <- Surv(starttime, stoptime, event) ## Cox-regression coxph(survobj~group) # this works ## put Surv object in data.frame df.test <- data.frame(survobj=I(survobj), group) ## Cox-regression on data.frame coxph(survobj~group, data=df.test) # this does not work attr(df.test$survobj, 'class') # survobject has class "AsIs", "Surv" attr(df.test$survobj, 'class') <- c('Surv', 'AsIs') # put Surv first attr(df.test$survobj, 'class') # survobject has class "Surv", "AsIs" coxph(survobj~group, data=df.test) # now it works __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Setting xlim in lattice plots
I am having difficulty setting different xlim values in the lattice histogram plot function. An example is shown below. I think I need to convert the limits data.frame to a list of paired values but don't know how. Any help would be appreciated. library(lattice) mat <- as.data.frame(matrix(abs(c(rnorm(100), 10*rnorm(100),20*rnorm(100),30*rnorm(100))),ncol=4)) colnames(mat)<-c("C1","C2","C3","C4") mat2<-stack(mat) limits<-cbind(rep(0, ncol(mat)),apply(mat,2,max)) histogram(~ values | ind, data=mat2, xlim=limits, scales=list(x=list(relation="free"))) Thanks Mike White __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
Dear tom, is the following what you are looking for? > a=matrix(runif(9),3,3) > a [,1] [,2] [,3] [1,] 0.9484247 0.9765431 0.6169739 [2,] 0.8423545 0.3137295 0.4031847 [3,] 0.6724235 0.1076373 0.2356923 > b<-matrix(sample(c(TRUE,FALSE),size=9,replace=TRUE),3,3) > b [,1] [,2] [,3] [1,] FALSE TRUE TRUE [2,] TRUE TRUE TRUE [3,] FALSE FALSE FALSE > a[b] [1] 0.8423545 0.9765431 0.3137295 0.6169739 0.4031847 > best, vito tom wright wrote: > Can someone please give me a pointer here. > I have two matrices > > matA > A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB > A B C > 1 TRUEFALSE TRUE > 2 FALSE TRUETRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding entry > in matB == TRUE (or FALSE), perferably in vector form. > > Many thanks > tom > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
This is really elementary indexing in S language: matA[matB] Best, Philippe Grosjean tom wright wrote: > Can someone please give me a pointer here. > I have two matrices > > matA > A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB > A B C > 1 TRUEFALSE TRUE > 2 FALSE TRUETRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding entry > in matB == TRUE (or FALSE), perferably in vector form. > > Many thanks > tom > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
matA[matB] or matA[!matB] Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "tom wright" <[EMAIL PROTECTED]> To: "R-Stat Help" Sent: Wednesday, March 15, 2006 12:03 PM Subject: [R] matrix indexing > Can someone please give me a pointer here. > I have two matrices > > matA > A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB > A B C > 1 TRUE FALSE TRUE > 2 FALSE TRUE TRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding > entry > in matB == TRUE (or FALSE), perferably in vector form. > > Many thanks > tom > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of tom wright > Sent: Wednesday, March 15, 2006 6:04 AM > To: R-Stat Help > Subject: [R] matrix indexing > > > Can someone please give me a pointer here. > I have two matrices > > matA > A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB > A B C > 1 TRUEFALSE TRUE > 2 FALSE TRUETRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding entry > in matB == TRUE (or FALSE), perferably in vector form. Lie this? matA <- matrix(c(5,2,1,2,4,2,4,3,4),3,3) matB <- matrix(c(T,F,F,F,T,F,T,T,F),3,3) matA[matB] matA[!matB] > > Many thanks > tom > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
On Wed, 2006-03-15 at 06:03 -0500, tom wright wrote: > Can someone please give me a pointer here. > I have two matrices > > matA > A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB > A B C > 1 TRUEFALSE TRUE > 2 FALSE TRUETRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding entry > in matB == TRUE (or FALSE), perferably in vector form. > > Many thanks > tom The subsetting/indexing is premised on the index values being TRUE, thus: > matA[matB] [1] 5 4 4 3 > matA[!matB] [1] 2 1 2 2 4 HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix indexing
Try this: matA[c(matB)] In fact even this works for your example although in general it couldbe problematic since a two column matrix index has special meaning: matA[matB] On 3/15/06, tom wright <[EMAIL PROTECTED]> wrote: > Can someone please give me a pointer here. > I have two matrices > > matA >A B C > 1 5 2 4 > 2 2 4 3 > 3 1 2 4 > > matB >A B C > 1 TRUEFALSE TRUE > 2 FALSE TRUETRUE > 3 FALSE FALSE FALSE > > how do I extract all the values from matA where the coresponding entry > in matB == TRUE (or FALSE), perferably in vector form. > > Many thanks > tom > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] installation problem with Biobase
Hello, I wanted to install MergeMaid package in v 2.2.1. I could install it but couldn't use without its dependant, Biobase. at biobase installation, I got the following error message In method for function "split": expanding the signature to include omitted arguments in definition: drop = "missing" Error in .MakeSignature(new("signature"), def, signature) : the names in signature for method (x, f, ) do not match function's arguments (x, f, drop) Execution halted ERROR: execution of package source for 'Biobase' failed ** Removing '/usr/lib/R/library/Biobase' Do you know any solution? Regards, haleh - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] matrix indexing
Can someone please give me a pointer here. I have two matrices matA A B C 1 5 2 4 2 2 4 3 3 1 2 4 matB A B C 1 TRUEFALSE TRUE 2 FALSE TRUETRUE 3 FALSE FALSE FALSE how do I extract all the values from matA where the coresponding entry in matB == TRUE (or FALSE), perferably in vector form. Many thanks tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] par(mfrow, fin) incompatibility?
Hello, I want a 2x1 multi-figure, with each plot 5" square. Test code: x<-rnorm(10,0,1) y<-rnorm(10,0,1) par(pty="s", mfrow=c(2,1), fin=c(5,5)) plot(x,y) plot(y,x) but this does not work (overplots the two figures). Substituting pin for fin works, but is not what I want. Are mfrow and fin incompatible? I am basing my code on Fig. 4.6 in MASS4. Running R 2.2.1 & WinXP. Thanks Dan Bebber Department of Plant Sciences University of Oxford __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (newbie) Weighted qqplot?
On 3/15/2006 8:31 AM, Vivek Satsangi wrote: > Folks, > Normally, in a data frame, one observation counts as one observation > of the distribution. Thus one can easily produce a CDF and (in Splus > atleast) use cdf.compare to compare the CDF (BTW: what is the R > equivalent of the SPlus cdf.compare() function, if any?) > > However, if each point should not count equally, how can I weight the > points before comparing the distributions? I was thinking of somehow > creating multiple observations for each actual observation based on > weights and creating a new dataframe etc. -- but that seem excessive. > Surely there is a simpler way? > >> x <- rnorm(100) >> y <- rnorm(10) >> xw <- rnorm(100) * 1.73 # The weights. These won't add up to 1 or N or >> anything because of missing values. >> yw <- rnorm(10) * 6.23 # The weights. These won't add up to 1 or to the same >> number as xw. >> # The question to answer is, how can I create a qq plot or cdf compare of x >> vs. y, weighted by their weights, xw and yw (to eventually figure out if y >> comes from the population x, similar to Kolmogorov-Smirnov GOF)? >> qqplot(x,y) # What now? qqplot doesn't support weights, but it's a simple enough function that you could write a version that did. Look at the cases where length(x) is not equal to length(y): e.g. if length(y) < length(x), qqplot constructs a linear approximation to a function mapping 1:nx onto the sorted x values, then takes length(y) evenly spaced values from that function. You want to do the same sort of thing, except that instead of even spacing, you want to look at the cumulative sums of the weights. You might want to use some kind of graphical indicator of whether points are heavily weighted or not, but I don't know what to recommend for that. By the way, your example above will give negative weights in xw and yw; you probably won't like the results if you do that. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] errorbars with xyplot
Ronny Hannemann wrote: > Hi everyone, > > I'm very new to R and I like to learn a lot... actually I have a little > problem concerning errorbars with xyplot. > > My data look like > run target hemi x > 1 1 Nichts Links 0.0007743240 > 2 2 Nichts Links -0.0008153365 > 3 1 Target Links -0.0015825950 > 4 2 Target Links 0.0088743785 > 5 1 Nichts Rechts 0.0015898995 > 6 2 Nichts Rechts -0.0011465190 > 7 1 Target Rechts -0.005320 > 8 2 Target Rechts 0.0039010500 > > these data I plotted with xyplot(data=dummyy, > x~hemi|target,groups=run,type="p") > > the same I do have with standard errors of means... > > How could I attach errorbars to the datapoints? I found some R-code from > Dec 2002 but I dont work (and I did not understand it...) > > Thanks for helping me, maybe others out there will find it usefull too. > > Best > Ronny library(Hmisc) ?xYplot Frank Harrell -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] create a list of vectors
Try this: L <- list(letters, head(LETTERS)) L[[2]][[4]] # D sapply(L, length) # 26 6 L <- c(L, 1:4) L[[3]][[2]] # 2 L <- c(L, list(1:5)) On 3/15/06, Arnau Mir Torres <[EMAIL PROTECTED]> wrote: > Hello. > > I want to create a list of vectors but each component of the list has a > different length. > > For example: > > Example=list() > Example=list(Example,c(1,2,3)) > Example=list(Example,c(11,12,13,14,15)) > > If I want the first component of the Example list, I have to write: > > Example[[1]][[2]]. R responses > 1 2 3 > > The second component: > Example[[2]]: > 11 12 13 14 15 > > If I iterate the previous example, Example=list(Example,c(...)) and I > want the components, I have to write: > Example[[1]][[1]]...i times...[[1]][[2]] (first component) > Example[[1]]...(i-1)times[[1]][[2]] (second component) > ... > > Can I make it in some other way? > > > Thanks, > > Arnau. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (newbie) Weighted qqplot?
Folks, Normally, in a data frame, one observation counts as one observation of the distribution. Thus one can easily produce a CDF and (in Splus atleast) use cdf.compare to compare the CDF (BTW: what is the R equivalent of the SPlus cdf.compare() function, if any?) However, if each point should not count equally, how can I weight the points before comparing the distributions? I was thinking of somehow creating multiple observations for each actual observation based on weights and creating a new dataframe etc. -- but that seem excessive. Surely there is a simpler way? > x <- rnorm(100) > y <- rnorm(10) > xw <- rnorm(100) * 1.73 # The weights. These won't add up to 1 or N or > anything because of missing values. > yw <- rnorm(10) * 6.23 # The weights. These won't add up to 1 or to the same > number as xw. > # The question to answer is, how can I create a qq plot or cdf compare of x > vs. y, weighted by their weights, xw and yw (to eventually figure out if y > comes from the population x, similar to Kolmogorov-Smirnov GOF)? > qqplot(x,y) # What now? Thanks for any help, -- -- Vivek Satsangi Student, Rochester, NY USA Life is short, the art long, opportunity fleeting, experiment treacherous, judgement difficult. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (no subject)
Hello all, I'm trying to calculate the Maximum likelihood of individuals to get the ancestry. I mixd 3 populations 15 generations in proportion of 20% 20% 60% when each population sorce have diferent genome (0 1 and 2) with frequencies for each one. So now i have individuals looks like 0 0 2 1 1 2 0 . and i don't now how to calculate the mle although i try to figure out from the package state4. can somebody help me please? Thanks [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] manipulating weeks dates
Try: as.Date(paste(YEAR, WEEK, 0), "%Y %U %w") On 3/15/06, Ronaldo Reis-Jr. <[EMAIL PROTECTED]> wrote: > Hi, > > I have these vectors: > > > WEEK <- rep(c(1:52),2) > > YEAR <- rep(c(2000,1999),c(52,52)) > > How to make a vector of Date with weeks in years? I try as.date from survival > package, but it dont work with weeks, just only with days, months etcs. > > Thanks > Ronaldo > -- > "Realmente minha cidade e muito facultativa" > > --Elivelton, ao repórter da Jovem Pan que falava das muitas > faculdades que existiam em sua cidade natal. > -- > |> // | \\ [***] > | ( õ õ ) [Ronaldo Reis Júnior] > |> V [UFV/DBA-Entomologia] > |/ \ [36570-000 Viçosa - MG ] > |> /(.''`.)\ [Fone: 31-3899-4007 ] > | /(: :' :)\ [EMAIL PROTECTED]] > |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] > |( `- ) [***] > |>> _/ \_Powered by GNU/Debian Woody/Sarge > > -- > Cerveja? Serve já! > -- > |> // | \\ [***] > | ( õ õ ) [Ronaldo Reis Júnior] > |> V [UFV/DBA-Entomologia] > |/ \ [36570-000 Viçosa - MG ] > |> /(.''`.)\ [Fone: 31-3899-4007 ] > | /(: :' :)\ [EMAIL PROTECTED]] > |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] > |( `- ) [***] > |>> _/ \_Powered by GNU/Debian Woody/Sarge > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] errorbars with xyplot
Hi everyone, I'm very new to R and I like to learn a lot... actually I have a little problem concerning errorbars with xyplot. My data look like run target hemi x 1 1 Nichts Links 0.0007743240 2 2 Nichts Links -0.0008153365 3 1 Target Links -0.0015825950 4 2 Target Links 0.0088743785 5 1 Nichts Rechts 0.0015898995 6 2 Nichts Rechts -0.0011465190 7 1 Target Rechts -0.005320 8 2 Target Rechts 0.0039010500 these data I plotted with xyplot(data=dummyy, x~hemi|target,groups=run,type="p") the same I do have with standard errors of means... How could I attach errorbars to the datapoints? I found some R-code from Dec 2002 but I dont work (and I did not understand it...) Thanks for helping me, maybe others out there will find it usefull too. Best Ronny [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] click on graph and select data points?
if you are interested in a solution using the tcltk package, then an idea is to base a solution on the code for the demo "tkcanvas". after installing the tcltk package, then require(tcltk) demo(tkcanvas) Katharine Mullen Department of Physics and Astronomy Faculty of Sciences Vrije Universiteit Amsterdam de Boelelaan 1081 1081 HV Amsterdam The Netherlands room: T.1.06 tel: +31 205987870 fax: +31 205987992 e-mail: [EMAIL PROTECTED] http://www.nat.vu.nl/~kate/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] manipulating weeks dates
Hi, I have these vectors: > WEEK <- rep(c(1:52),2) > YEAR <- rep(c(2000,1999),c(52,52)) How to make a vector of Date with weeks in years? I try as.date from survival package, but it dont work with weeks, just only with days, months etcs. Thanks Ronaldo -- "Realmente minha cidade e muito facultativa" --Elivelton, ao repórter da Jovem Pan que falava das muitas faculdades que existiam em sua cidade natal. -- |> // | \\ [***] | ( õ õ ) [Ronaldo Reis Júnior] |> V [UFV/DBA-Entomologia] |/ \ [36570-000 Viçosa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [EMAIL PROTECTED]] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] |( `- ) [***] |>> _/ \_Powered by GNU/Debian Woody/Sarge -- Cerveja? Serve já! -- |> // | \\ [***] | ( õ õ ) [Ronaldo Reis Júnior] |> V [UFV/DBA-Entomologia] |/ \ [36570-000 Viçosa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [EMAIL PROTECTED]] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] |( `- ) [***] |>> _/ \_Powered by GNU/Debian Woody/Sarge __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] manipulating weeks dates
Hi, I have these vectors: > WEEK <- rep(c(1:52),2) > YEAR <- rep(c(2000,1999),c(52,52)) How to make a vector of Date with weeks in years? I try as.date from survival package, but it dont work with weeks, just only with days, months etcs. Thanks Ronaldo -- "Realmente minha cidade e muito facultativa" --Elivelton, ao repórter da Jovem Pan que falava das muitas faculdades que existiam em sua cidade natal. -- |> // | \\ [***] | ( õ õ ) [Ronaldo Reis Júnior] |> V [UFV/DBA-Entomologia] |/ \ [36570-000 Viçosa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [EMAIL PROTECTED]] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] |( `- ) [***] |>> _/ \_Powered by GNU/Debian Woody/Sarge __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] GAM using R tutorials?
On Tue, 2006-03-14 at 23:52 -0800, Michael wrote: > Hi all, > > I am trying to use GAM to work on some data... Are there any resources > providing hands-on tutorial/guide on how to do GAM on data in R? > Specifically, I am not sure about which model to choose, and smooth models > with which effective degree-of-freedom shall I use... > > I knew there is a book titled: GAM: an introduction using R. Unfornately our > local library does not have it... so that's not an option given time > constraint. > > Thanks a lot for your pointers! > > Michael. Michael, Please learn to use the search tools provided for you! You have posted numerous emails to the list recently, many of which you could have solved for yourself if only you'd heeded peoples' advice and searched for yourself. For this problem; 1) I'd suggest to the local library that they might consider buying the book, but in the meantime... 2) ...in R, do RSiteSearch("GAM") and look at the list shown in your browser. The first hit is the help page for package mgcv. Look at the references included on that help page - most are technical/statistical papers, but a starting point might be the RNews article Simon Wood wrote. That should get yourself started. But if you'd done the search yourself, you wouldn't have had to wait for someone on the list to do it for you. Finally - Please read the posting guide - it is there for a reason. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] setMethod confusion -best reference for S4 programming
Thanks I think you have both answered my question (reckon Ill go S3 on that). As an adjunct to this do you know what might be the best reference to the S4 methods current implementation. I have ordered the Chambers book "Programming with Data", and I have a short tutorial-- "S4 Classes in 15 pages, more or less". Have I missed any other useful resources? Stephen Henderson Wolfson Inst. for Biomedical Research Cruciform Bldg., Gower Street University College London United Kingdom, WC1E 6BT +44 (0)207 679 6827 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Henrik Bengtsson Sent: 15 March 2006 10:59 To: Martin Maechler Cc: Stephen Henderson; r-help@stat.math.ethz.ch Subject: Re: [R] setMethod confusion On 3/15/06, Martin Maechler <[EMAIL PROTECTED]> wrote: > > "Stephen" == Stephen Henderson <[EMAIL PROTECTED]> > > on Tue, 14 Mar 2006 16:32:56 - writes: > > Stephen> Hello I've checked through previous postings but > Stephen> don't see a fully equivalent problem-just a few > Stephen> hints. I have been trying to set a new method for > Stephen> the existing function "table" or > Stephen> "as.data.frame.table" for my class "tfSites". > Stephen> Taking out all the useful code and just returning > Stephen> the input class I get the error > > >> setMethod("table", "tfSites", function(.Object) .Object) > > Stephen> Error in conformMethod(signature, mnames, fnames, > Stephen> f) : In method for function "table": formal > Stephen> arguments omitted in the method definition cannot > Stephen> be in the signature (exclude = "tfSites") > > > >> setMethod("as.data.frame.table", "tfSites", > >> function(.Object) .Object ) > > Stephen> Error in conformMethod(signature, mnames, fnames, > Stephen> f) : In method for function "as.data.frame.table": > Stephen> formal arguments omitted in the method definition > Stephen> cannot be in the signature (x = "tfSites") > > Stephen> What does this mean? Is there something peculiar > Stephen> about the table function? Is it because it takes > Stephen> arguments beginning table(..., etc) > > Yes. Since table's argument list starts with "..." > you cannot directly write S4 methods for it. Although not fully tested, but a workaround could be to i) define an S4 method tableS4(), then ii) rename table() to table.default() and iii) make table() an S3 generic function, and finally iv) define table.tfSites() to call tableS4(). Would this work? If so, step (ii)-(iv) can be done in one step using the R.oo package. Example: library(R.oo) setClass("fSites", representation(x="numeric", y="numeric")) setGeneric("tableS4", function(.Object, ...) standardGeneric("tableS4")) setMethod("tableS4", "fSites", function(.Object) .Object) setMethodS3("table", "fSites", function(.Object, ...) tableS4(.Object, ...)) Test; > x <- new("fSites") > table(x) An object of class "fSites" Slot "x": numeric(0) Slot "y": numeric(0) > X <- rpois(20, 1) > table(X) X 0 1 2 3 10 7 2 1 But, what's wrong with S3 in the first place? ;) /Henrik > One could consider changing table's argument list to become > (x, ..., exclude = c(NA, NaN), dnn = list.names(...), deparse.level = 1) > but that's not entirely trivial to do back compatibly, since > table() produces *named* dimnames from its arguments in "..." > and we'd want to make sure that this continues to work as now > even when the first argument is formally named 'x'. E.g., > > > X <- rpois(20, 1) > > table(X) > X > 0 1 2 3 > 7 10 2 1 > > > > should continue to contain "X" as names(dimnames(.)). > > Of course this has now become a topic for R-devel rather > than R-help. > > Martin Maechler, > ETH Zurich > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- Henrik Bengtsson Mobile: +46 708 909208 (+1h UTC) ** This email and any files transmitted with it are confidentia...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] rational and the roundoff error
On 3/15/2006 3:21 AM, Fred J. wrote: > Hi > > > I have a list of 12000 rational numbers as inputs, running some of R > functions will surly accumulate some round-off errors, Is there a way to > have R do its calculations using rational numbers as input to minimize the > round-off error? R has no internal support for rational numbers, but several packages support calculations using rationals. Try RSiteSearch('rational numbers'). Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] variance from correlated observations
You need to know the covariance of the Xs. The sum is just a linear function of the Xs, so its variance is a function of a quadratic form involving the covariance matrix of the Xs. Andy From: Antonio, Fabio Di Narzo > > Hi all. > A statistical question. I have to estimate the variance of the sum: > > X(1) + X(2) + ...+ X(n) > > from an observed sample, where X(i) are *correlated* and not > necessarly identically distributed. Someone can suggest a > simple strategy (I hope by exploiting some already present R > package) for obtaining such estimate from an observed vector X[1:n]? > > Tnx all, > Antonio, Fabio Di Narzo. > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R-help Digest, Vol 37, Issue 15
Mi nueva dirección de correo es: [EMAIL PROTECTED] New e-mail address: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] setMethod confusion
On 3/15/06, Martin Maechler <[EMAIL PROTECTED]> wrote: > > "Stephen" == Stephen Henderson <[EMAIL PROTECTED]> > > on Tue, 14 Mar 2006 16:32:56 - writes: > > Stephen> Hello I've checked through previous postings but > Stephen> don't see a fully equivalent problem-just a few > Stephen> hints. I have been trying to set a new method for > Stephen> the existing function "table" or > Stephen> "as.data.frame.table" for my class "tfSites". > Stephen> Taking out all the useful code and just returning > Stephen> the input class I get the error > > >> setMethod("table", "tfSites", function(.Object) .Object) > > Stephen> Error in conformMethod(signature, mnames, fnames, > Stephen> f) : In method for function "table": formal > Stephen> arguments omitted in the method definition cannot > Stephen> be in the signature (exclude = "tfSites") > > > >> setMethod("as.data.frame.table", "tfSites", > >> function(.Object) .Object ) > > Stephen> Error in conformMethod(signature, mnames, fnames, > Stephen> f) : In method for function "as.data.frame.table": > Stephen> formal arguments omitted in the method definition > Stephen> cannot be in the signature (x = "tfSites") > > Stephen> What does this mean? Is there something peculiar > Stephen> about the table function? Is it because it takes > Stephen> arguments beginning table(..., etc) > > Yes. Since table's argument list starts with "..." > you cannot directly write S4 methods for it. Although not fully tested, but a workaround could be to i) define an S4 method tableS4(), then ii) rename table() to table.default() and iii) make table() an S3 generic function, and finally iv) define table.tfSites() to call tableS4(). Would this work? If so, step (ii)-(iv) can be done in one step using the R.oo package. Example: library(R.oo) setClass("fSites", representation(x="numeric", y="numeric")) setGeneric("tableS4", function(.Object, ...) standardGeneric("tableS4")) setMethod("tableS4", "fSites", function(.Object) .Object) setMethodS3("table", "fSites", function(.Object, ...) tableS4(.Object, ...)) Test; > x <- new("fSites") > table(x) An object of class "fSites" Slot "x": numeric(0) Slot "y": numeric(0) > X <- rpois(20, 1) > table(X) X 0 1 2 3 10 7 2 1 But, what's wrong with S3 in the first place? ;) /Henrik > One could consider changing table's argument list to become > (x, ..., exclude = c(NA, NaN), dnn = list.names(...), deparse.level = 1) > but that's not entirely trivial to do back compatibly, since > table() produces *named* dimnames from its arguments in "..." > and we'd want to make sure that this continues to work as now > even when the first argument is formally named 'x'. E.g., > > > X <- rpois(20, 1) > > table(X) > X > 0 1 2 3 > 7 10 2 1 > > > > should continue to contain "X" as names(dimnames(.)). > > Of course this has now become a topic for R-devel rather > than R-help. > > Martin Maechler, > ETH Zurich > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- Henrik Bengtsson Mobile: +46 708 909208 (+1h UTC) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to use the result of hclust?
?cutree > > Hi all, > > Does hclust provide concrete clustered results? I could not > see how to use it to make 6 clusters... and it does not give > the 6 cluster labels... > > How to use the result of hclust? > > thanks a lot, > > Michael. > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to use the result of hclust?
?cutree ?plot.hclust & ?identify.hclust hc<- hclust(dist(tab, "manhattan"), "ward") plot(hc, hang=-1) (x <- identify(hc)) cutree(hc, 2) Michael a écrit : >Hi all, > >Does hclust provide concrete clustered results? I could not see how to use >it to make 6 clusters... and it does not give the 6 cluster labels... > >How to use the result of hclust? > >thanks a lot, > >Michael. > > [[alternative HTML version deleted]] > >__ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] variance from correlated observations
Hi all. A statistical question. I have to estimate the variance of the sum: X(1) + X(2) + ...+ X(n) from an observed sample, where X(i) are *correlated* and not necessarly identically distributed. Someone can suggest a simple strategy (I hope by exploiting some already present R package) for obtaining such estimate from an observed vector X[1:n]? Tnx all, Antonio, Fabio Di Narzo. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] how to use the result of hclust?
Hi all, Does hclust provide concrete clustered results? I could not see how to use it to make 6 clusters... and it does not give the 6 cluster labels... How to use the result of hclust? thanks a lot, Michael. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] click on graph and select data points?
> Now I want to select the best clustered class, how can I click on the data > point, and the program returns the index of that cluster(its class number, > or color number)? Have a look at identify() cu Philipp -- Dr. Philipp PagelTel. +49-8161-71 2131 Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186 Technical University of Munich Science Center Weihenstephan 85350 Freising, Germany and Institute for Bioinformatics / MIPS Tel. +49-89-3187 3675 GSF - National Research Center Fax. +49-89-3187 3585 for Environment and Health Ingolstädter Landstrasse 1 85764 Neuherberg, Germany http://mips.gsf.de/staff/pagel __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] X11 fonts problem with ubuntu breezy
Hello I have big trouble getting R to work correctly with X11 fonts on Ubuntu Breezy 5.10. I was hoping somebody could help me with this issue. The first part of the problem is that I get the error "could not find any X11 fonts" for any command with graphical ouput, for example "demo(graphics)": --- R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.1 (2005-12-20 r36812) ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] > demo (graphics); demo(graphics) Type to start : > require(graphics) [1] TRUE > require(datasets) [1] TRUE > if (dev.cur() <= 1) get(getOption("device"))() Error in get(getOption("device"))() : could not find any X11 fonts Check that the Font Path is correct. --- After some googling, I found out that apparently this can be fixed by clearing the LANG environment variable: LANG= export LANG (By default on my machine, the environment contains "LANG=en_US.UTF-8" and "LANGUAGE=en_NL:en") However, when I try again, I get a different error, like "X11 font at size 14 could not be loaded" --- > demo(graphics) demo(graphics) Type to start : > require(graphics) [1] TRUE > require(datasets) [1] TRUE > if (dev.cur() <= 1) get(getOption("device"))() > opar <- par(ask = interactive() && (.Device %in% c("X11", "GTK", "gnome", "windows", "quartz"))) > x <- rnorm(50) > opar <- c(opar, par(bg = "white")) > plot(x, ann = FALSE, type = "n") Hit to see next plot: > abline(h = 0, col = gray(0.9)) > lines(x, col = "green4", lty = "dotted") > points(x, bg = "limegreen", pch = 21) > title(main = "Simple Use of Color In a Plot", xlab = "Just a Whisper of a Label", col.main = "blue", col.lab = gray(0.8), cex.main = 1.2, cex.lab = 1, font.main = 4, font.lab = 3) Error in title(main = "Simple Use of Color In a Plot", xlab = "Just a Whisper of a Label", : X11 font at size 14 could not be loaded > --- Any idea what the problem might be? I run in this problem both with the R 2.1.1. binary package from ubuntu, and when I build 2.2.1 myself from source. regards, Martijn van Iersel __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Log Cholesky parametrization in lme
Dear R-Users I used the nlme library to fit a linear mixed model (lme). The random effect standard errors and correlation reported are based on a Log-Cholesky parametrization. Can anyone tell me how to get the Covariance matrix of the random effects, given the above mentioned parameters based on the Log-Cholesky parametrization?? Thanks in advance Pryseley - Find great deals to the top 10 hottest destinations! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] difftime arguments
Dear Fred You should change your code from > x <- strptime(ts, "%m/%d/%y %I:%M:%S %p") to > x <- strptime(ts, "%m/%d/%Y %I:%M:%S %p") "Y" instead of "y", since your year includes the century (2006 and not 06) Then it should work. Regards, Christoph -- Christoph Buser <[EMAIL PROTECTED]> Seminar fuer Statistik, LEO C13 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-44-632-4673 fax: 632-1228 http://stat.ethz.ch/~buser/ -- Fred J. writes: > Hi > I just started using RGui.exe under widnows. > I have a text file containing date arranged in columns and rows, each > column has the same format, each row with different formats. 3 of the > columns are something like this 1/12/2006 3:59:45 PM > I need to calculate the different in seconds between 2 selected periods > using their row?s index > > My solution: > Read the file in a data frame and collect the columns in concern in a > variable. > data1 <- read.table("C:\\path\\data.txt", header=TRUE) > ts <- paste(data1[[1]], data1[[3]], data1[[7]]) > > #ts now looks like this > #... "1/12/2006 3:59:45 PM" "1/12/2006 3:59:57 PM" ... > > #now convert between character representations and object of classes > "POSIXct" > x <- strptime(ts, "%m/%d/%y %I:%M:%S %p") > > this last code line is putting out NA, what did I do wrong? > > After this then I do > z <- as.POSIXct(x) > > Is my whole approach efficient? > Then I can use difftime, because using it without the above preparations > gives this > > > difftime(c("1/12/2006 3:59:45 PM", "1/12/2006 3:59:57 PM"), format > ="%m/%d/%y %I:%M:%S %p") > Error in difftime(c("1/12/2006 3:59:45 PM", "1/12/2006 3:59:57 PM"), > format = "%m/%d/%y %I:%M:%S %p") : > unused argument(s) (format ...) > > Thanks > > __ > > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] create a list of vectors
Hello, I don't know if it is the most efficient way to do but my solution is: x <- vector("list", 10) #creates a list with a length = 10 then in my loop (where i is iterated) : x[[i]] <- my.vector I hope this could help you François Michonneau Hello. I want to create a list of vectors but each component of the list has a different length. For example: Example=list() Example=list(Example,c(1,2,3)) Example=list(Example,c(11,12,13,14,15)) If I want the first component of the Example list, I have to write: Example[[1]][[2]]. R responses 1 2 3 The second component: Example[[2]]: 11 12 13 14 15 If I iterate the previous example, Example=list(Example,c(...)) and I want the components, I have to write: Example[[1]][[1]]...i times...[[1]][[2]] (first component) Example[[1]]...(i-1)times[[1]][[2]] (second component) ... Can I make it in some other way? Thanks, Arnau. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html