[R] unique combinations
Hi there, I have a vector and would like to create a data frame, which contains all unique combination of two elements, regardless of order. myVec - c(1,2,3) what expand.grid does: 1,1 1,2 1,3 2,1 2,2 2,3 3,1 3,2 3,3 what I would like to have 1,1 1,2 1,3 2,2 2,3 3,3 Can anybody help? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] access sublists by a variable
Dear list, I'd like to access the elements of a list within another list with the help of a variable. dict - list( 24 = c(1,2,3,6,12,24,48,72,96,120,144,168,720), 168 = c(1,12,24,48,72,96,120,144,168,336,504,672), 8760 = c(1,24,168,730,4380,8760) ) dict$24 works fine, but a - 24 dict$a returns NULL Unfortunately dict[a] does not work for me, because I see no possibility to access the inner elements of list 24 in that case i.e. dict[a][1] returns the whole list and not the first element. What is the correct syntax to access those elements with the help of a variable? Thanks in advance Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to find position in bin-data?
Hi there, probably there is a very simple solution, but I cannot think of one... I have a vector with values: data - c(1,6,3,4,8,4,2,9) and I have a vector with bin breaks: bins - c(1,3,5,7,9,11) Now, I'd like to get for each data point the index of the bin-vector where the value falls in (or equals the lower bin break). In the example case, I'd like to get: c(1,3,2,2,4,1,5) How would you solve it? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find position in bin-data?
Thanks a lot! That's what I was looking for :-) A On 19 March 2011 13:56, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 11-03-19 8:18 AM, Antje Niederlein wrote: Hi there, probably there is a very simple solution, but I cannot think of one... I have a vector with values: data- c(1,6,3,4,8,4,2,9) and I have a vector with bin breaks: bins- c(1,3,5,7,9,11) Now, I'd like to get for each data point the index of the bin-vector where the value falls in (or equals the lower bin break). In the example case, I'd like to get: c(1,3,2,2,4,1,5) How would you solve it? Use cut. For example, data - c(1,6,3,4,8,4,2,9) bins - c(1,3,5,7,9,11) result - cut(data, breaks=bins, right=FALSE) as.numeric(result) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] model fine, predict gives an error
Yes, I did send an attachment - but I forgot that attachments might be removed, no? Here it is: http://rapidshare.com/files/452815636/drmData.RData Antje On 16 March 2011 12:19, Mike Marchywka marchy...@hotmail.com wrote: Date: Wed, 16 Mar 2011 08:17:49 +0100 From: niederlein-rs...@yahoo.de To: r-help@r-project.org Subject: Re: [R] model fine, predict gives an error Anybody who can help me with this issue? did you post your data? I was curious so I thought I may look but you need to post data so people can determine if they can produce and fix your problem. Any complaints about bad/ singular matricies are likely to depend on data being bad in some way. On 15 March 2011 14:15, Antje Niederlein wrote: Hi there, I try to model some dose response curves (drc-package). In most cases it is fine but now I got some data which produces me the following error: load(drmData.RData) library(drc) drmObj - drm(value ~ concentration, cmpd_respvar, data = drmData, fct = LL.4()) predict(drmObj) Error in chol.default(0.99 * object$fit$hessian + 0.01 * diag(dim(object$fit$hessian)[1])) : the leading minor of order 2 is not positive definite Error in resultMat[, 2] - estSE : replacement has length zero Can anybody explain to me why the calculation of the dose response model works but the prediction fails? Anything I can do in this case? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] model fine, predict gives an error
Anybody who can help me with this issue? On 15 March 2011 14:15, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hi there, I try to model some dose response curves (drc-package). In most cases it is fine but now I got some data which produces me the following error: load(drmData.RData) library(drc) drmObj - drm(value ~ concentration, cmpd_respvar, data = drmData, fct = LL.4()) predict(drmObj) Error in chol.default(0.99 * object$fit$hessian + 0.01 * diag(dim(object$fit$hessian)[1])) : the leading minor of order 2 is not positive definite Error in resultMat[, 2] - estSE : replacement has length zero Can anybody explain to me why the calculation of the dose response model works but the prediction fails? Anything I can do in this case? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] model fine, predict gives an error
Hi there, I try to model some dose response curves (drc-package). In most cases it is fine but now I got some data which produces me the following error: load(drmData.RData) library(drc) drmObj - drm(value ~ concentration, cmpd_respvar, data = drmData, fct = LL.4()) predict(drmObj) Error in chol.default(0.99 * object$fit$hessian + 0.01 * diag(dim(object$fit$hessian)[1])) : the leading minor of order 2 is not positive definite Error in resultMat[, 2] - estSE : replacement has length zero Can anybody explain to me why the calculation of the dose response model works but the prediction fails? Anything I can do in this case? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Console output
Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Console output
Thanks for every helpful answer :-) ! I thought it was something easier but as long as there is a solution it's fine for me. Ciao, Antje On 21 February 2011 13:12, Martin Maechler maech...@stat.math.ethz.ch wrote: Ted Harding ted.hard...@wlandres.net on Mon, 21 Feb 2011 11:08:19 - (GMT) writes: That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). In principle, there would be a true solution, but as you see, it's not quite possibly (by that means): op - options(width=7) Error in options(width = 7) : invalid 'width' parameter, allowed 10...1 op - options(width=10) 1:10 [1] 1 2 [3] 3 4 [5] 5 6 [7] 7 8 [9] 9 10 1000+ 0:9 ## works for these [1] 1000 [2] 1001 [3] 1002 [4] 1003 [5] 1004 [6] 1005 [7] 1006 [8] 1007 [9] 1008 [10] 1009 --- In principle, the lower bound (10) for the width option could be lowered a bit more, as I think 10 had been a somewhat arbitrary choice protecting useRs from hanging themselves.. Martin Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fitdistr question
Hi Ingmar, hi Dennis, okay, you're right. I was expecting that the result would give the best fit to my data even if it's not a real poisson distribution. It looks somehow similar... But how to judge the goodness of fit? I was using the residual sum of squares. I'm not a statistician, so I'm not sure whether this method is the one to choose... If I estimate lambda with mle2() and use the RSS as criteria to minimize, my lambda is much smaller that with fitdistr(). I'm happy about any suggestion! Antje On 11 February 2011 09:16, Ingmar Visser i.vis...@uva.nl wrote: The ML estimate of lambda is the mean, so no need for (iterative) optimization. See eg: http://mathworld.wolfram.com/MaximumLikelihood.html hth, Ingmar On Fri, Feb 11, 2011 at 8:52 AM, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hello, I tried to fit a poisson distribution but looking at the function fitdistr() it does not optimize lambda but simply estimates the mean of the data and returns it as lambda. I'm a bit confused because I was expecting an optimization of this parameter to gain a good fit... If I would use mle() of stats4 package or mle2() of bbmle package, I would have to write the function by myself which should be optimized. But what shall I return? -sum((y_observed - y_fitted)^2) ? Any other suggestions or comments on my solution? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fitdistr question
Yes, I understand. If I have a distribution which is not listed in fitdistr() but I still would like to you compute the ML estimate. Would it be correct to maximize the following function? sum( log( dens_mydistr(x, my_distr_param))) As I said, I try to step into this field by reading and trying things and I'm not sure whether I got it right how to find the ML-function of a more complex distribution... Antje On 11 February 2011 10:14, Ingmar Visser i.vis...@uva.nl wrote: Antje, On Fri, Feb 11, 2011 at 9:58 AM, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hi Ingmar, hi Dennis, okay, you're right. I was expecting that the result would give the best fit to my data even if it's not a real poisson distribution. It looks somehow similar... The ML estimate is of course made under the assumption that the data stems from a Poisson distribution, and under that assumption, the ML estimate is most efficient and unbiased compared with other estimates. Best, Ingmar But how to judge the goodness of fit? I was using the residual sum of squares. I'm not a statistician, so I'm not sure whether this method is the one to choose... If I estimate lambda with mle2() and use the RSS as criteria to minimize, my lambda is much smaller that with fitdistr(). I'm happy about any suggestion! Antje On 11 February 2011 09:16, Ingmar Visser i.vis...@uva.nl wrote: The ML estimate of lambda is the mean, so no need for (iterative) optimization. See eg: http://mathworld.wolfram.com/MaximumLikelihood.html hth, Ingmar On Fri, Feb 11, 2011 at 8:52 AM, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hello, I tried to fit a poisson distribution but looking at the function fitdistr() it does not optimize lambda but simply estimates the mean of the data and returns it as lambda. I'm a bit confused because I was expecting an optimization of this parameter to gain a good fit... If I would use mle() of stats4 package or mle2() of bbmle package, I would have to write the function by myself which should be optimized. But what shall I return? -sum((y_observed - y_fitted)^2) ? Any other suggestions or comments on my solution? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] fitdistr question
Hello, I tried to fit a poisson distribution but looking at the function fitdistr() it does not optimize lambda but simply estimates the mean of the data and returns it as lambda. I'm a bit confused because I was expecting an optimization of this parameter to gain a good fit... If I would use mle() of stats4 package or mle2() of bbmle package, I would have to write the function by myself which should be optimized. But what shall I return? -sum((y_observed - y_fitted)^2) ? Any other suggestions or comments on my solution? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question mle again
Thanks a lot to everybody who answered! Sorry for not mentioning the package I used (I am aware of this fact but I simply forgot to put it to the example code) Thanks a lot for explaning the problem to me. I was pretty sure that it ist something like this but I thought, I've made a mistake in how to use mle() correctly. I think, I'll look into Bens mle2() method and figure out whether this is a more elegant way :-) Ciao, Antje On 7 February 2011 21:39, Ben Bolker bbol...@gmail.com wrote: Antje Niederlein niederlein-rstat at yahoo.de writes: A few day ago, I was looking for an answer to my question but didn't get one. Anybody who can help now? Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: I will point out that this is one of the reasons I wrote mle2 (in the bbmle package), which differs from mle in taking an explicit 'data' argument. I *think* the following does what you want (although I admit I haven't looked at the output closely): library(plyr) library(bbmle) lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle2(ll,data=data.frame(x,y)) coef(fit) }) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mle question
Hello, is there somebody who can help me with my question (see below)? Antje On 1 February 2011 09:09, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mle question
Hello, is there somebody who can help me with my question (see below)? Antje On 1 February 2011 09:09, Antje Niederlein niederlein-rs...@yahoo.de wrote: Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] question mle again
A few day ago, I was looking for an answer to my question but didn't get one. Anybody who can help now? Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mle question
Hello, I tried to use mle to fit a distribution(zero-inflated negbin for count data). My call is very simple: mle(ll) ll() takes the three parameters, I'd like to be estimated (size, mu and prob). But within the ll() function I have to judge if the current parameter-set gives a nice fit or not. So I have to apply them to observation data. But how does the method know about my observed data? The mle()-examples define this data outside of this method and it works. For a simple example, it was fine but when it comes to a loop (tapply) providing different sets of observation data, it doesn't work anymore. I'm confused - is there any way to do better? Here is a little example which show my problem: # R-code - lambda.data - runif(10,0.5,10) ll - function(lambda = 1) { cat(x in ll(),x,\n) y.fit - dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data - rpois(100,lambda.data[x]) freqTab - count(raw.data) x - freqTab$x y - freqTab$freq / sum(freqTab$freq) cat(x in lapply, x,\n) fit - mle(ll) coef(fit) }) Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Warning with mle
Hi Ben, thanks a lot for your answer. There are four reasonable solutions to your problems: 1. ignore the warnings, as long as they are all of the same type (NaNs/NAs being produced by dbinom or dpois), and as long as the final results look sensible. probably fine for me. The fit for my dummy data was nice, but for the real data it's not so nice... (see below - other ideas...) 2. use method=L-BFGS-B and set lower and upper bounds on your parameters (this can be a little bit finicky because L-BFGS-B will often try parameters *on* the boundary, and it can't handle NAs or infinities, so you may have to set the lower and upper bounds a little bit in from their theoretical limits (e.g. 0.002 instead of 0). I tried it but even if I use the following statement, I get the warnings with confint() fit - mle(ll, method = L-BFGS-B, lower = c(0.001,0), upper = c(Inf,1)) I added the output of the current parameters for my ll-function and obviously the second parameter goes far beyond the limit. Is there anything wrong with how I tried to set the limits? Is it possible that mle() takes the boundaries into account but confint() does not? 3. Fit your parameters on the transformed scale (typically logit for probabilities, log for Poisson intensities). This will cause problems if the parameter really lies on the boundary, e.g. if the best estimate of your zero-inflation parameter is zero or very close to it. Not my prefered solution (I'm too new to this area and afraid to do anything wrong) 4. Use the pscl package, which has reasonably robust and efficient built-in functions for fitting zero-inflated (and hurdle) models. I played around with it but I cannot find a way how to simply estimate the parameters for my distribution. My data is simply discrete histogram data (counts) and I'm probably too stupid to put it into a model... If you can give me any hint - I would be happy. Other ideas concerning my approach: Do I use the right criteria to minimize on (so far I use the sum of squared errors). May it make sense to use the pearsons chi-squared test? (Is there any easy way to do it in R?) Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Warning with mle
Hi Ben, thanks a lot for your answer. There are four reasonable solutions to your problems: 1. ignore the warnings, as long as they are all of the same type (NaNs/NAs being produced by dbinom or dpois), and as long as the final results look sensible. probably fine for me. The fit for my dummy data was nice, but for the real data it's not so nice... (see below - other ideas...) 2. use method=L-BFGS-B and set lower and upper bounds on your parameters (this can be a little bit finicky because L-BFGS-B will often try parameters *on* the boundary, and it can't handle NAs or infinities, so you may have to set the lower and upper bounds a little bit in from their theoretical limits (e.g. 0.002 instead of 0). I tried it but even if I use the following statement, I get the warnings with confint() fit - mle(ll, method = L-BFGS-B, lower = c(0.001,0), upper = c(Inf,1)) I added the output of the current parameters for my ll-function and obviously the second parameter goes far beyond the limit. Is there anything wrong with how I tried to set the limits? Is it possible that mle() takes the boundaries into account but confint() does not? 3. Fit your parameters on the transformed scale (typically logit for probabilities, log for Poisson intensities). This will cause problems if the parameter really lies on the boundary, e.g. if the best estimate of your zero-inflation parameter is zero or very close to it. Not my prefered solution (I'm too new to this area and afraid to do anything wrong) 4. Use the pscl package, which has reasonably robust and efficient built-in functions for fitting zero-inflated (and hurdle) models. I played around with it but I cannot find a way how to simply estimate the parameters for my distribution. My data is simply discrete histogram data (counts) and I'm probably too stupid to put it into a model... If you can give me any hint - I would be happy. Other ideas concerning my approach: Do I use the right criteria to minimize on (so far I use the sum of squared errors). May it make sense to use the pearsons chi-squared test? (Is there any easy way to do it in R?) Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Warning with mle
Hi there, I'm pretty new to the field of fitting (anything). I try to fit a distribution with mle, because my real data seems to follow a zero-inflated poisson distribution. So far, I tried a simple example to see whether I understand how to do it or not: # example count data x - 0:10 y - dpois(x, lambda = 1.4) # zero-inflated poisson zip - function(x, lambda, prop) { (1 - prop)*dpois(x,0) + prop*dpois(x,lambda) } ll - function(lambda = 2, prop = 0.9) { y.fit - zip(x, lambda, prop) sum( (y - y.fit)^2 ) } fit - mle(ll) So far, so good. The result gives me lambda prop 1.41.0 which is pretty nice. But what goes wrong if I want to display confidence intervals? I get a lot of warnings but I simply don't know why... confint(fit) Has it something to do with constraints for my parameters (lambda should be than zero and prop should range from 0 to 1)? Do I have to put it into the ll-function? Is there any general comment on what I'm doing? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calculate mean slope of a function
Hallo, hope you can help me with this question: I have calculated a function using f-smooth.spline(data) and approxfun(f). Now I want to calculate the mean slope of the resulting function. Haven't found the right R command yet, maybe you can give me a hint. Thanx, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Changing style for groups in xyplot
Hello, I have a (hopefully) quick question concerning the xyplot function. The xyplot works very fine for me - I am using it to display functions of two variates depending on several other factors. I am therefor also using the groups argument, so that the symbols in each panel appear in different colors. Now I would like to change how the different groups are displayed - now they are circles in different colors, and I would like to change those colors. Can you tell me how to do this? my complete xyplot command right now looks like this: xyplot(a ~ b| t*h, groups=r, xlab=Zyklen, ylab=Riss [%], auto.key=list(lab=levels(r),columns=3)) Thank you very much, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] explanation for left-side behaviour
Hi Don, thanks for your answer. Okay, I should have mentioned the error messages I get for case 1 and 2 - sorry. I was just surprised because the following does not give an error (though I feed with the factor vector): substr(values,2,3) [1] bc bc bc cd cd cd de de de Obviously, the factor vector is converted to character somewhere, no? I get the same result when typing: substr(as.character(values),2,3) So, the restriction that substr cannot take anything else than a character vector seems to be only in case I want to use the replace functionality instead of just extracting a substring. At least, that is my guess.. Ciao, Antje Don MacQueen wrote: Read the help page for substr(). It says that the first argument should be a character vector. The only one that works is the one where you gave it a character vector. You said only third one works. But you didn't explain what you mean by works. It's always a good idea on r-help to show both what you expected, and what you actually got, so that people can understand exactly what the question is. To explain a little further, let me number your three approaches. [1] substr(values,2,3) - .. [2] substr(as.character(values),2,3) - .. values - as.character(values) [3] substr(values,2,3) - .. With regard to case [1] It makes no sense to replace character substrings in a factor. factors are really numbers, not characters. It's just that they have additional attributes that make them (sometimes) print as if the were characters. But they're not. And the error message (that you didn't report) says exactly that. With regard to case [2]: values and as.character(values) are not the same thing. Therefore, replacing substrings in as.character(values) is not the same as replacing substrings in values. In this case, I would interpret the error message to indicate that R is trying to replace characters in a function. That makes sense, because you supplied a function, namely, as.character(). Case [3] works because you supplied a character vector. -Don At 9:57 AM +0100 12/1/09, Antje wrote: Hi there, I'm pretty sure that it's written down somewhere but I cannot find it so far. The little example shows different approaches to replace a substring. Only the last one works. I think it has something to do with the fact that substr is used on the left side. Can anybody refer to an explanation for this behaviour? Thanks a lot in advance! Antje values - factor(c(rep(abc,3), rep(bcd,3), rep(cde,3))) substr(values,2,3) - .. substr(as.character(values),2,3) - .. values - as.character(values) substr(values,2,3) - .. __ R-help@r-project.org mailing list https://*stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] explanation for left-side behaviour
Hi there, I'm pretty sure that it's written down somewhere but I cannot find it so far. The little example shows different approaches to replace a substring. Only the last one works. I think it has something to do with the fact that substr is used on the left side. Can anybody refer to an explanation for this behaviour? Thanks a lot in advance! Antje values - factor(c(rep(abc,3), rep(bcd,3), rep(cde,3))) substr(values,2,3) - .. substr(as.character(values),2,3) - .. values - as.character(values) substr(values,2,3) - .. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] HTML help missing?
Thanks a lot for the hint! Antje Duncan Murdoch wrote: On 20/11/2009 7:11 AM, Antje wrote: Hey there, I'm running R 2.10 on Windows XP (Professional) and I was wondering where the HTML help window disappeared? With earlier versions everything was fine. Now I get only this old-fashioned text windows without any links when I type ?some_function Can anybody help me? Edit the R_HOME/etc/Rprofile.site file to uncomment the line options(help_type=html) (or just install the patched version, this installer bug was discovered after release). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot question
Peter Ehlers wrote: If there's been an answer to this, I've missed it. Here's my take. Antje wrote: Hi there, I was wondering if anybody can explain to me why the boxplot ends up with different results in the following case: I have some integer data as a vector and I compare the stats of boxplot with the same data divided by a factor. I've attached a csv file with both data present (d1, d2). The factor is 34.16667. If I run the boxplot function on d1 I get the following stats: 0.848... 0.907... 0.936... 0.965... 1.024... For d2 I get these stats: 29 31 32 33 36 If I convert the stats of d1 with the factor, I get 29 31 32 33 35 Obviously different for the upper whisker. But why??? Antje Antje: Three comments: 1. I think your 'factor' is actually 205/6, not 34.16667. 2. This looks like another case of FAQ 7.31: # Let's take your d2 and create d1; I'll call them x and y: x - rep(c(29:38, 40), c(7, 24, 50, 71, 24, 12, 14, 7, 13, 5, 1)) y - x * 6 / 205 # x is your d2, sorted # y is your d1, sorted # The critical values are x[202:203] and y[202:203]; x[201:204] #[1] 35 35 36 36 # The boxplot stats are: sx - boxplot.stats(x)$stats sy - boxplot.stats(y)$stats # Calculate potential extent of upper whisker: ux - sx[4] + (sx[4] - sx[2]) * 1.5 #36 uy - sy[4] + (sy[4] - sy[2]) * 1.5 #1.053658536585366 # Is y[203] = uy? y[203] = uy #[1] FALSE #!!! y[202] = uy #[1] TRUE # For x: x[203] = ux #[1] TRUE And there's your answer: for y the whisker goes to y[202], not y[203], due to the inevitable imprecision in machine calculation. 3. last comment: I would not use boxplots for data like this. -Peter Ehlers Hi Peter, thanks a lot for your explanation! Now I understand the difference. I was using the boxplot statistic to filter outliers from my data. Do you have any suggestion for me what to use instead? (I tried to improve the estimation of mean and sd, when iteratively removing outliers by boxplot stats...) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] boxplot question
Hi there, I was wondering if anybody can explain to me why the boxplot ends up with different results in the following case: I have some integer data as a vector and I compare the stats of boxplot with the same data divided by a factor. I've attached a csv file with both data present (d1, d2). The factor is 34.16667. If I run the boxplot function on d1 I get the following stats: 0.848... 0.907... 0.936... 0.965... 1.024... For d2 I get these stats: 29 31 32 33 36 If I convert the stats of d1 with the factor, I get 29 31 32 33 35 Obviously different for the upper whisker. But why??? Antje ,d1,d2 1,0.936585365853659,32 2,0.936585365853659,32 3,0.936585365853659,32 4,0.936585365853659,32 5,0.907317073170732,31 6,1.08292682926829,37 7,1.08292682926829,37 8,1.02439024390244,35 9,1.08292682926829,37 10,1.05365853658537,36 11,0.936585365853659,32 12,1.08292682926829,37 13,0.936585365853659,32 14,0.907317073170732,31 15,0.936585365853659,32 16,0.907317073170732,31 17,1.02439024390244,35 18,0.878048780487805,30 19,1.08292682926829,37 20,1.02439024390244,35 21,0.936585365853659,32 22,0.936585365853659,32 23,1.08292682926829,37 24,1.02439024390244,35 25,1.05365853658537,36 26,1.02439024390244,35 27,0.936585365853659,32 28,1.11219512195122,38 29,0.878048780487805,30 30,1.02439024390244,35 31,0.995121951219512,34 32,1.11219512195122,38 33,0.936585365853659,32 34,0.995121951219512,34 35,0.936585365853659,32 36,1.02439024390244,35 37,0.965853658536585,33 38,0.965853658536585,33 39,0.995121951219512,34 40,0.848780487804878,29 41,0.907317073170732,31 42,0.907317073170732,31 43,0.907317073170732,31 44,1.05365853658537,36 45,0.878048780487805,30 46,0.878048780487805,30 47,0.878048780487805,30 48,0.936585365853659,32 49,0.936585365853659,32 50,0.878048780487805,30 51,0.936585365853659,32 52,1.05365853658537,36 53,0.878048780487805,30 54,1.17073170731707,40 55,0.907317073170732,31 56,0.995121951219512,34 57,0.907317073170732,31 58,0.907317073170732,31 59,0.936585365853659,32 60,0.965853658536585,33 61,0.965853658536585,33 62,0.936585365853659,32 63,0.936585365853659,32 64,0.878048780487805,30 65,0.907317073170732,31 66,1.08292682926829,37 67,0.907317073170732,31 68,0.848780487804878,29 69,0.907317073170732,31 70,0.965853658536585,33 71,0.936585365853659,32 72,0.936585365853659,32 73,1.08292682926829,37 74,0.936585365853659,32 75,0.936585365853659,32 76,1.11219512195122,38 77,0.878048780487805,30 78,0.965853658536585,33 79,0.907317073170732,31 80,0.936585365853659,32 81,0.907317073170732,31 82,0.878048780487805,30 83,0.936585365853659,32 84,0.965853658536585,33 85,0.907317073170732,31 86,1.02439024390244,35 87,0.995121951219512,34 88,0.965853658536585,33 89,0.936585365853659,32 90,0.936585365853659,32 91,1.11219512195122,38 92,0.907317073170732,31 93,0.907317073170732,31 94,0.936585365853659,32 95,0.907317073170732,31 96,0.907317073170732,31 97,0.936585365853659,32 98,0.936585365853659,32 99,0.936585365853659,32 100,0.907317073170732,31 101,0.907317073170732,31 102,0.848780487804878,29 103,0.907317073170732,31 104,0.965853658536585,33 105,0.936585365853659,32 106,0.907317073170732,31 107,0.878048780487805,30 108,1.02439024390244,35 109,0.907317073170732,31 110,1.11219512195122,38 111,1.02439024390244,35 112,0.907317073170732,31 113,0.936585365853659,32 114,0.878048780487805,30 115,0.907317073170732,31 116,0.936585365853659,32 117,0.936585365853659,32 118,1.05365853658537,36 119,0.907317073170732,31 120,0.878048780487805,30 121,0.936585365853659,32 122,1.02439024390244,35 123,0.965853658536585,33 124,0.965853658536585,33 125,0.936585365853659,32 126,0.936585365853659,32 127,0.936585365853659,32 128,0.907317073170732,31 129,0.907317073170732,31 130,0.878048780487805,30 131,0.936585365853659,32 132,1.02439024390244,35 133,0.936585365853659,32 134,0.936585365853659,32 135,0.995121951219512,34 136,0.965853658536585,33 137,0.965853658536585,33 138,0.907317073170732,31 139,0.936585365853659,32 140,0.936585365853659,32 141,0.878048780487805,30 142,0.907317073170732,31 143,0.965853658536585,33 144,0.936585365853659,32 145,0.936585365853659,32 146,0.995121951219512,34 147,1.02439024390244,35 148,1.08292682926829,37 149,0.878048780487805,30 150,0.936585365853659,32 151,0.848780487804878,29 152,0.907317073170732,31 153,0.907317073170732,31 154,0.907317073170732,31 155,0.965853658536585,33 156,1.02439024390244,35 157,0.995121951219512,34 158,0.995121951219512,34 159,0.936585365853659,32 160,1.08292682926829,37 161,0.907317073170732,31 162,0.907317073170732,31 163,0.936585365853659,32 164,0.907317073170732,31 165,0.907317073170732,31 166,0.907317073170732,31 167,0.907317073170732,31 168,1.05365853658537,36 169,1.05365853658537,36 170,0.936585365853659,32 171,0.965853658536585,33 172,0.965853658536585,33 173,0.936585365853659,32 174,0.907317073170732,31 175,0.878048780487805,30 176,0.995121951219512,34 177,0.936585365853659,32 178,0.936585365853659,32 179,0.907317073170732,31 180,1.08292682926829,37
[R] HTML help missing?
Hey there, I'm running R 2.10 on Windows XP (Professional) and I was wondering where the HTML help window disappeared? With earlier versions everything was fine. Now I get only this old-fashioned text windows without any links when I type ?some_function Can anybody help me? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mac question
Hi Steve, Steve Lianoglou wrote: Hi, On Nov 3, 2009, at 2:41 AM, Antje wrote: Hi there, currently, I've updated R on my Mac (OS X) to version 2.10. I was wondering if I have to install all additional packages again??? In Windows, I just needed to copy the library folder of the old installation but how does it work with Mac? This isn't really a mac or windows thing, actually. Although this method may have worked for you in the past, it's generally not recommended to use libraries compiled from one R version in another. Using the same libraries between 2.9.X to 2.9.X+n is fine, but doing the same when going from 2.9 to 2.10 is not a good idea. for Windows, the FAQ tells exactly this way when upgrading the R version (http://cran.mirroring.de/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f) Or did I missunderstood anything? So, in short, you should updated/reinstall your packages now that you've updated R. An easy way to do that would have been to save a file of all packages installed from 2.9, then use that file to reinstall those packages from within 2.10. Here's a recipe to do that now (assuming R 2.9 is still installed on your system). You can use RSwitch to switch which version of R is active at a time, available here: http://r.research.att.com/RSwitch-1.1.dmg 1. Fire up RSwitch and pick R 2.9 1.5. I have these two functions I use when I want to be lazy: installedPackages - function(to=~/R.packages.dump.txt) { writeLines(installed.packages()[,1], con=to) } reloadPackages - function(from=~/R.packages.dump.txt) { source(http://bioconductor.org/biocLite.R;) packages - readLines(from) biocLite(packages) } 2. Call installedPackages() from within R 2.9 and quit 3. Use rswitch to make R 2.10 active 4. Open R 2.10 and run reloadPackages() biocLite is a function to install bioconductor packages, but it also installs normal cran packages. You can likely replace the call to biocLite with a call to install.packages(packages) if you don't have any bioc packages to install, if you like, although it shouldn't be necessary. It might take a while to d/l all your packages again, but it should just work Thanks a lot for this recommendation. I'm just afraid it won't help this time. It seems to me that the old version was overwritten with the new installation but I don't know how to find out... Next time, I might do it this way... -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mac question
Hi there, currently, I've updated R on my Mac (OS X) to version 2.10. I was wondering if I have to install all additional packages again??? In Windows, I just needed to copy the library folder of the old installation but how does it work with Mac? Can anybody give me a hint? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rbind with different columns
Karl Ove Hufthammer wrote: In article 4addc1d0.2040...@yahoo.de, niederlein-rs...@yahoo.de says... In every list entry is a data.frame but the columns are only partially the same. If I have exactly the same columns, I could do the following command to combine my data: do.call(rbind, myList) but of course it does not work with differnt column names. Is there any easy way to retrieve a combined table like this: You're in luck. 'rbind.fill' in the 'plyr' package does exactly what you want. Thanks a lot for your hint. I'll give it a look :-) So far, I have solved it with basic tools like this (it's less work than I thought): availableColumns - unique(unlist(sapply(myList, names))) myList - lapply(myList, FUN = function(entry) { missingColumns - availableColumns[which(!availableColumns %in% names(entry))] entry[, missingColumns] - NA entry }) do.call(rbind, myList) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rbind with different columns
Hello there, with the following dummy code I'd like to give you an idea how my data looks like: df1 - data.frame(a = rnorm(10), b = rnorm(10)) df2 - data.frame(a = rnorm(10), c = rnorm(10)) df3 - data.frame(a = rnorm(10), b = rnorm(10), c = rnorm(10)) myList - list(df1, df2, df3) # (myList is representing the data structure I have to handle, it's read from single files with lapply) In every list entry is a data.frame but the columns are only partially the same. If I have exactly the same columns, I could do the following command to combine my data: do.call(rbind, myList) but of course it does not work with differnt column names. Is there any easy way to retrieve a combined table like this: a b c 1 -0.54586587 -0.3607873 NA 2 1.10876842 1.1439414 NA 3 0.57357988 -1.2117743 NA 4 -1.40975759 -1.2390305 NA 5 0.03371093 -1.8860748 NA 6 -1.27682961 0.9990840 NA 7 -1.78715858 0.8400642 NA 8 -0.22663310 1.5224016 NA 9 0.45703787 0.0599217 NA 10 -1.21984635 1.1991689 NA 11 -2.58848301 NA 0.2394272 12 0.71155177 NA -0.7107332 13 -2.16440676 NA -0.1744845 14 1.33043121 NA 0.5951272 15 1.51034297 NA 0.1956956 16 1.00844947 NA 0.6726101 17 0.78693840 NA 1.2189904 18 0.68622170 NA 1.2230500 19 -1.09376863 NA 0.4267472 20 2.23647873 NA 0.7328574 21 -0.38144792 0.1532647 1.4824618 22 0.27078024 -0.4264737 0.1317450 23 1.10812086 1.2550117 0.1677935 24 0.14881701 -0.2928157 -1.4081529 25 -1.00635045 -0.7885968 -0.3502532 26 0.32024094 0.4681016 -1.5477557 27 0.82974710 0.2345186 -0.6572728 28 0.49608133 1.7463265 0.6493405 29 -0.33022738 1.9510503 -1.7930093 30 -0.62615365 0.7330671 -0.4032405 The only thing I can think about is checking the names of each list entry and adding NA-columns before combining them. Is there any other way to do so? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problems with code containing a for loop
The following code isn't working and we can't figure out why.. letters = c(A,B,C,D,E,F,G,H,I,J) numbers = 1:3 for(i in 1:6){ #6 letters for (j in 1:3) { #3 numbers for (k in -1:1) { #answer -1,right or +1 fn = paste (i,j,k,.bmp,sep=) bmp(file = fn) plot(x = 10, y = 10, ylim=c(0,1), xlim=c(0,1), axes=FALSE, ylab=, xlab=) text(0.5,0.5, text = paste(letters[i], +, numbers[j],=, letters [i+j+k]) dev.off() } } } We get the following errors: Error: unexpected symbol in: text(0.5,0.5, text = paste(letters[i], +, numbers[j],=, letters [i+j+k]) dev.off } Error: unexpected '}' in } } Error: unexpected '}' in} } Error: unexpected '}' in} -- View this message in context: http://www.nabble.com/Problems-with-code-containing-a-for-loop-tp25823173p25823173.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Levelplot without margins
Hello, I'm not very experienced with lattice and I was wondering whether I get get some hints from you how to create a pure heatmap (using levelplot), without any axis, title, legend, margin at all... I just want to see the coloured squares, nothing else. Any suggestions? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Levelplot without margins
I had a bit success with the following usage: my.padding - list(layout.heights = list( top.padding = 0, main.key.padding = 0, key.axis.padding = 0, axis.xlab.padding = 0, xlab.key.padding = 0, key.sub.padding = 0), layout.widths = list( left.padding = 0, key.ylab.padding = 0, ylab.axis.padding = 0, axis.key.padding = 0, right.padding = 0) ) levelplot(..., scales = list(draw = FALSE), colorkey = FALSE, xlab = NULL, ylab = NULL, par.settings = my.padding) But still I have a upper and lower margin (left and right margins are gone) What else do I have to do? Antje Antje wrote: Hello, I'm not very experienced with lattice and I was wondering whether I get get some hints from you how to create a pure heatmap (using levelplot), without any axis, title, legend, margin at all... I just want to see the coloured squares, nothing else. Any suggestions? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Levelplot without margins
I had a bit success with the following usage: my.padding - list(layout.heights = list( top.padding = 0, main.key.padding = 0, key.axis.padding = 0, axis.xlab.padding = 0, xlab.key.padding = 0, key.sub.padding = 0), layout.widths = list( left.padding = 0, key.ylab.padding = 0, ylab.axis.padding = 0, axis.key.padding = 0, right.padding = 0) ) levelplot(..., scales = list(draw = FALSE), colorkey = FALSE, xlab = NULL, ylab = NULL, par.settings = my.padding) But still I have a upper and lower margin (left and right margins are gone) What else do I have to do? Antje Antje wrote: Hello, I'm not very experienced with lattice and I was wondering whether I get get some hints from you how to create a pure heatmap (using levelplot), without any axis, title, legend, margin at all... I just want to see the coloured squares, nothing else. Any suggestions? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] nls - find good starting values
Hi Bill, thanks for your answer. I don't see what you mean with fitting a gaussian distribution... I'm pretty sure, that I'd like to fit a gaussian probability density function :-) (not normalized, for example with a mean around -4 and a standard deviation of 0.5) I'm not sure if I understand your solution with the quadratic regession model... Maybe my approach is completely wrong but I didn't know any other solution. Anyhow, I've solved the issue so far with the while-construct. Antje bill.venab...@csiro.au wrote: It is not at all clear what you are trying to do. Fitting a gaussian distribution is the simplest problem in all of statistics: the sample mean and sample variance (divisor n) are the mle's of the two parameters involved. No non-linear regresson is required. If what you are really trying to do is fit a (normalized?) gaussian probability density function as a form of non-linear regression, i.e. by least squares, that is an entirely different problem. I'm a bit stumped as to how this form of non-linear regresion should arise, particularly with equal variance both for values near the mode as well as in the tails, but stranger things have happened, I suppose. What I would do is, if you response values are non-negative, take logs and regress using a quadratic regression model, and then identify the approximate mean and variance parameters, which should then be reasonable starting values for the non-linear regression. Negative responses will pose a problem, of course. Bill Venables. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Antje [niederlein-rs...@yahoo.de] Sent: 14 July 2009 17:21 To: r-h...@stat.math.ethz.ch Subject: [R] nls - find good starting values Hi there, it might be a very simple question and I'd be glad to even get a link to some useful documentation... I have several data sets, I'd like to fit to a gaussian distribution. I've tried to give an estimate of the mean and the sd of this distribution but still, I run into problems if these estimates are not close enough. For example, nls() breaks with this message: singular gradient matrix at initial parameter estimates I don't know how to avoid these bad start values because their estimate is automated. Better start values are often quite close. I was wondering whether there is any way to test several start-values as long as nls does not succeed. I would do it with a while construct but maybe there is another approach? Any hint is very welcome! Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Counting the number of cycles in a temperature test
Hello dear R-users, today I have a question that I completely do not know how to solve (R-newbie!). In a temperature chamber I have measured temperature over time. The result is shown in the attached eps-file (if attachments are shown): There are two temperature levels, 150°C and -40°C. A complete cycle includes about 30 minutes upper temperature, quick change to the lower level, 30 minutes hold at lower level. Then the temperature rises again to the upper level and a new cycle begins. About 500 cycles have been completed. How can I count the number of cycles that have been completed? The data does not only include perfect temperature cycles. Once in a while the machine would stand still and for a day or so the temperature would remain at room temperature. So I cannot simply divide the measured time by the duration of a cycle... Thanks a lot for your support, if necessary I could also provide the dataset. Antje Temperaturzyklen.eps __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nls with weights
Hi there, I don't have much experience with fitting at all and I'd like to get some advice how to use the weights-argument with nls correctly. I have created some data with a sigmoidal curve shape. Each y-Value was generated by the mean of three values. A standard deviation was calculated too. Now, I'd like to weight the data points respective to its standard deviation. If this is very high, the datapoint should be considered less important than a datapoint with a low standard deviation. I've tested it with the following code but I'd like to know whether I should change anything applying the weights. I've only guessed what could give a nice result... Further, I'd like to know, why I get an error message, if I change the bottom-parameter to min(yData)??? Can anybody explain, why it ends up with: singular gradient 8 --- 8 sigmoid - function(x, bottom, top, slope, logec50) { bottom + (top - bottom) / (1 + 10^((logec50-x)*slope)) } xData - seq(-10,10,1.2) yData1 - sigmoid(xData,10,1,-0.2,3) + rnorm(1:length(xData), sd = 0.5) yData2 - sigmoid(xData,10,1,-0.2,3) + rnorm(1:length(xData), sd = 0.2) yData3 - sigmoid(xData,10,1,-0.2,3) + rnorm(1:length(xData), sd = 1.1) yMat - rbind(yData1, yData2, yData3) yData - apply(yMat, 2, mean) yDataSd - apply(yMat, 2, sd) plot(yData ~ xData, ylim = c(min(yData - yDataSd), max(yData + yDataSd))) arrows(xData, yData - yDataSd, xData, yData + yDataSd, angle = 90, length = 0.1, code = 3) # without weights model - nls(yData ~ sigmoid(xData,bottom, top, slope, logec50), start = list(bottom = yData[1], top = max(yData), slope = 0.5, logec50 = median(xData)), trace = TRUE) lines(xData, predict(model), col =blue) # with weights model - nls(yData ~ sigmoid(xData,bottom, top, slope, logec50), start = list(bottom = yData[1], top = max(yData), slope = 0.5, logec50 = median(xData)), weights = 1 / (yDataSd^2), trace = TRUE) lines(xData, predict(model), col =green) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Heatmap without levelplot
Hi Uwe, thanks a lot for your answer! And thanks a lot to all others helping me with this issue! Uwe Ligges schrieb: Antje wrote: Hi Uwe, I tried to explain my problem with the given example. I don't see any documentation which tells me that the length of col.regions should be one less than at. (At least I assume now that it should be this way...) If it's equal or longer some colors (in the middle of the color-vector) are simply not used. Just try the example below with rainbow(5) and rainbow(6) and compare the results... both plot will use 5 colors! Sorry, but this behaviour is not really self-explaining to me... maybe I'm to blind to find the documentation which says that only one color less will ensure the usage of all colors. Well, of you have 5 at locations (i.e. breaks), then you have 4 intervals in between and that's the amount of colors that is sensible. From the documentation this was not really clear to me (though it makes sense, I agree) (It is so important for me because I need to display a heatmap with colors let's say * all lower data outliers green, * all higher data outliers blue and * everything else within the color range yellow to red. I've seen that some values do not get blue or green though they are outliers... I've attached one graph, I've generated - maybe it helps to understand) Any wrong assumption? Maybe: Say you want everything below -1 be considered as a lower outlier and all above 1 is a higher outlier, then you can say: levelplot(matrix(c(1,2,0,-2), nrow=2), at = c(-Inf, seq(-1, 1, length=10), Inf), col.regions = c(rgb(0,1,0), hcl(seq(20, 80, length=10), c=400), rgb(0,0,1))) Then below -1 is green (rgb(0,1,0)), above 1 is blue (rgb(0,0,1)) and in between we have 10 regions from -1 to 1 each with a color between some kind of yellow and red in hcl() space. Thank you for this little example. Just two comments: 1) I was not aware of the possibility to use Inf - it just has the disadvantage that these colors are not displayed at the color vector (maybe this can be adjusted somehow) 2) if you replace one number of the matrix with -1, it will be displayed green. So it would be considered as an outlier. From the documentation it was also not clear to me that the lower endpoint of the interval is always excluded (except for the very first value of the at-vector), while the upper endpoint will be included. (This also makes sense but in this case I have to slightly modify my data because I'd like to include both endpoints of my non-outlier-range...) Anyway, I guess, I solved all problems and found a workable solution :-) Ciao, Antje Uwe Ligges Ciao, Antje Uwe Ligges schrieb: Antje wrote: Hi there, as I'm not sure to understand the coloring levelplot uses, I'm looking for another easy way to create a heatmap like this: library(lattice) mat - matrix(seq(1,5, length.out = 12), nrow = 3) mat[1,2] - 3.5 my.at - seq(0.5,5.5, length.out = 6) my.col.regions - rainbow(5) graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = my.col.regions) print(graph) Can anybody help me with some hints or little examples? Dear Antje, since you are asking the same question again now, maybe you can explain what you are going to get? In fact, I do not undertsand where your problem is. R places the colors according to the values in your matrix very well including the legend and I thought up to today that the plot is self explaining. Best wishes, Uwe Ligges Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] levelplot question
Hi Greg and all the others, thanks for your answer. The color-vector has the same length like the at-vector but the recycling cannot be the reason, because only values slightly above my threshold doe not appear blue. I cannot find a good explanation of which colors are assigned to which value ranges. I've made little example: # mat - matrix(seq(1,5, length.out = 12), nrow = 3) mat[1,2] - 3.5 my.at - seq(0.5,5.5) my.col.regions - rainbow(6) graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = my.col.regions) print(graph) windows() plot(1:10) legend(topleft, legend = as.character(my.col.regions), col = my.col.regions, pch = 18) # As you can see the green (position 3 in my.col.regions) disappears completely in the levelplot (look at the color range at the right side!). I guess it might also happen in my case... I've tested several cases and it looks like the length of the color-vector should be one less than the at vector (which would make sense). Then, the rule might apply: [ at[1],at[2] ] = color[1] ( at[2],at[3] ] = color[2] ... ( at[n-1],at[n] ] = color[n-1] Please correct me if I'm wrong!!! Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Heatmap without levelplot
Hi there, as I'm not sure to understand the coloring levelplot uses, I'm looking for another easy way to create a heatmap like this: library(lattice) mat - matrix(seq(1,5, length.out = 12), nrow = 3) mat[1,2] - 3.5 my.at - seq(0.5,5.5, length.out = 6) my.col.regions - rainbow(5) graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = my.col.regions) print(graph) Can anybody help me with some hints or little examples? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Heatmap without levelplot
Hi Uwe, I tried to explain my problem with the given example. I don't see any documentation which tells me that the length of col.regions should be one less than at. (At least I assume now that it should be this way...) If it's equal or longer some colors (in the middle of the color-vector) are simply not used. Just try the example below with rainbow(5) and rainbow(6) and compare the results... both plot will use 5 colors! Sorry, but this behaviour is not really self-explaining to me... maybe I'm to blind to find the documentation which says that only one color less will ensure the usage of all colors. (It is so important for me because I need to display a heatmap with colors let's say * all lower data outliers green, * all higher data outliers blue and * everything else within the color range yellow to red. I've seen that some values do not get blue or green though they are outliers... I've attached one graph, I've generated - maybe it helps to understand) Any wrong assumption? Ciao, Antje Uwe Ligges schrieb: Antje wrote: Hi there, as I'm not sure to understand the coloring levelplot uses, I'm looking for another easy way to create a heatmap like this: library(lattice) mat - matrix(seq(1,5, length.out = 12), nrow = 3) mat[1,2] - 3.5 my.at - seq(0.5,5.5, length.out = 6) my.col.regions - rainbow(5) graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = my.col.regions) print(graph) Can anybody help me with some hints or little examples? Dear Antje, since you are asking the same question again now, maybe you can explain what you are going to get? In fact, I do not undertsand where your problem is. R places the colors according to the values in your matrix very well including the legend and I thought up to today that the plot is self explaining. Best wishes, Uwe Ligges Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] levelplot question
Hi there, I have a question concerning the behaviour of the colouring with levelplot. (I hope, I manage to explain) If I give the parameters at and col.regions like this: at - c(1,2,3,4,5,6) col.regions - c(blue,blue,blue,yellow,yellow,yellow) Which color would have the value 3.5? I would have expected yellow, no? In my more complex example I wanted to create a heatmap (like yellow to red) up to a fixed threshold. All values above should get another color (like blue). Automatically, I generated both vectors like this: at -c(vectorOfLowerValues, myThreshold, vectorOfHigherValues) col.regions - c(vectorOfHeatmapColors, lastHeatmapColor, vectorOfColorblue) But I get some values above the threshold which are not blue... Can anybody explain me why? (I've checked the length of both vectors and it's parts - this is correct - so 'myThreshold' would get 'lastHeatmapColor' by the same vector position) I'm very confused... Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] levelplot question
@Dieter: You implicitly expect round(). Your question implies that you may also susceptible to the problem of R FAQ 7.31, Why doesn't R think these numbers are equal? No, I guess, you misunderstood my question. These vectors (at and col.regions) are given to levelplot together with some data which should be visualized. I don't know how exactly levelplot works (I was asking for help to understand it) but somehow it creates something like bins from at and uses col.regions to display all datavalues within the same bin with the according color. I'd like to know, which color to expect from levelplot for a certain datavalue (3.5) Did I explain it somehow clear now? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] boxplot - margin settings
Hi there, I'm trying to solve a boxplot problem (should be simple, but I cannot find the solution...): data - list(long_name1_xxx = rnorm(100), long_name2_yy = rnorm(200)) boxplot(data , las = 2, mar = c(20,4,4,4)) Why does the margin not change whatever I put there??? With other plots it worked for me, why not in this case? I just want to see the whole label... I'm really sorry if I've missed a very obvious reason for this behaviour. Maybe someone can help me? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot - margin settings
I knew the solution would be kind of simple... Thanks a lot, Sarah! Sarah Goslee schrieb: boxplot() isn't passing extra parameters in the way you'd expect. If you set par() first, it works fine. mar.orig - par()$mar # save the original values par(mar = c(20,4,4,4)) # set your new values boxplot(data, las = 2) par(mar = mar.orig) # put the original values back Sarah On Wed, Apr 29, 2009 at 10:06 AM, Antje niederlein-rs...@yahoo.de wrote: Hi there, I'm trying to solve a boxplot problem (should be simple, but I cannot find the solution...): data - list( long_name1_xxx = rnorm(100), long_name2_yy = rnorm(200)) boxplot(data , las = 2, mar = c(20,4,4,4)) Why does the margin not change whatever I put there??? With other plots it worked for me, why not in this case? I just want to see the whole label... I'm really sorry if I've missed a very obvious reason for this behaviour. Maybe someone can help me? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot with nested x-labels
Hi Jim, is this plotrix package version higher than 2.2-7 ? Antje Jim Lemon schrieb: Antje wrote: Hi there, I was wondering wether it is possible to creeate plots with nested lables like in excel? If yes, could anyone provide me the information how to do it? I've attached an image of an Excel plot to show you, what I'd like to plot with R :-) Hi Antje, The very question asked by Ofir Levy that led to the new hierobarp function in the plotrix package. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot with nested x-labels
Hi there, I was wondering wether it is possible to creeate plots with nested lables like in excel? If yes, could anyone provide me the information how to do it? I've attached an image of an Excel plot to show you, what I'd like to plot with R :-) Ciao, Antje inline: plot.png__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] svDialogs
Hi there, I was using Open/Save-dialogs from the package svDialogs (SciViews). But now the package has dissapeared? How do I have to set up my R-installation to further use these dialogs??? (beside copying my old packages to the new installation). Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Axis-question
Hi there, I was wondering wether it's possible to generate an axis with groups (like in Excel). So that you can have something like this as x-axis (for example for the levelplot-method of the lattice package): --- | X1 | X2 | X3 | X1 | X2 | X3 | X1 | ... | group1 | group2 | group3 ... .. .. .. I hope you understand what I'm looking for? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Axis-question
solved by grouping... (see my next mail) Antje schrieb: Hi there, I was wondering wether it's possible to generate an axis with groups (like in Excel). So that you can have something like this as x-axis (for example for the levelplot-method of the lattice package): --- | X1 | X2 | X3 | X1 | X2 | X3 | X1 | ... | group1 | group2 | group3 ... .. .. .. I hope you understand what I'm looking for? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] levelplot help needed
Hi there, I'm looking for someone who can give me some hints how to make a nice levelplot. As an example, I have the following code: # create some example data # -- xl - 4 yl - 10 my.data - sapply(1:xl, FUN = function(x) { rnorm( yl, mean = x) }) x_label - rep(c(X Label 1, X Label 2, X Label 3, X Label 4), each = yl) y_label - rep(paste(Y Label , 1:yl, sep=), xl) df - data.frame(x_label = factor(x_label),y_label = factor(y_label), values = as.vector(my.data)) df1 - data.frame(df, group = rep(Group 1, xl*yl)) df2 - data.frame(df, group = rep(Group 2, xl*yl)) df3 - data.frame(df, group = rep(Group 3, xl*yl)) mdf - rbind(df1,df2,df3) # plot # -- graph - levelplot(mdf$values ~ mdf$x_label * mdf$y_label | mdf$group, aspect = xy, layout = c(3,1), scales = list(x = list(labels = substr(levels(factor(mdf$x_label)),0,5), rot = 45))) print(graph) # -- (I need to put this strange x-labels, because in my real data the values of the x-labels are too long and I just want to display the first 10 characters as label) My questions: * I'd like to start with Y Label 1 in the upper row (that's a more general issue, how can I have influence on the order of x,y, and groups?) * I'd like to put the groups at the bottom Can anybody give me some help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Statistic community?
Hi there, I'm very glad to use the R-help mailing list for R-related question but more and more often I face general statistical problems. Does anyone know by chance a community (mailinglist, forum, ...) where I can ask these kind of questions? I'm glad for any link or hint :-) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R running as a server on windows?
I might have formulated my question a bit misleading. If you are asking about ways to run R as a server on a windows machine, Yes, that's exactly what I was asking for. So, I'll check out this nws package as well as the RServe. Of course, I might ask Knime people as well but my question not primarily bound to this software. Thanks a lot for all answers! Antje Antje schrieb: Nobody can help with this question (or tell me where I can find help) ? Antje schrieb: Hi there, I'm not sure whether this is the right mailing list to put this question... if not, please tell me where I can find help. I have a spare dual-core machine which run Windows XP Professional and is nearly unused (nearly! Unfortunately, I cannot change OS). And I'm investigating Knime (knime.org) to set up data analysis workflows. They have some nodes to execute R on a remote machine. Is it possible to run R on this windows machine, so that I can call it from somewhere else? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R running as a server on windows?
Nobody can help with this question (or tell me where I can find help) ? Antje schrieb: Hi there, I'm not sure whether this is the right mailing list to put this question... if not, please tell me where I can find help. I have a spare dual-core machine which run Windows XP Professional and is nearly unused (nearly! Unfortunately, I cannot change OS). And I'm investigating Knime (knime.org) to set up data analysis workflows. They have some nodes to execute R on a remote machine. Is it possible to run R on this windows machine, so that I can call it from somewhere else? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R running as a server on windows?
Hi there, I'm not sure whether this is the right mailing list to put this question... if not, please tell me where I can find help. I have a spare dual-core machine which run Windows XP Professional and is nearly unused (nearly! Unfortunately, I cannot change OS). And I'm investigating Knime (knime.org) to set up data analysis workflows. They have some nodes to execute R on a remote machine. Is it possible to run R on this windows machine, so that I can call it from somewhere else? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] need some lattice help
Hello everybody, I just started with lattice plots and I was wondering why it behaves different than expected. If I generated multiple plots in the past, I just used some code like this: lapply(..., { windows() plot(...) }) I got multiple windows, each containing one plot. Now, I tried the same with levelplot (instead of plot) and I see all windows are created but the plots are only drawn in one window, one on top of the other... Can anybody give me a hint, why it behaves like this and what should I change? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] need some lattice help
I guess, I got the answer. (http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f) Ciao, Antje Antje schrieb: Hello everybody, I just started with lattice plots and I was wondering why it behaves different than expected. If I generated multiple plots in the past, I just used some code like this: lapply(..., { windows() plot(...) }) I got multiple windows, each containing one plot. Now, I tried the same with levelplot (instead of plot) and I see all windows are created but the plots are only drawn in one window, one on top of the other... Can anybody give me a hint, why it behaves like this and what should I change? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] heatmap with levelplot
Hi there, I'd like to create a heatmap from my matrix with a) a defined color range (lets say from yellow to red) b) using striking colors above and below a certain threshold (above = green, below = blue) Example matrix (there should be a few outliers generated...) + simple levelplot without outliers marked: library(lattice) my.mat - matrix(rnorm(800), nrow = 40) threshold - c(-1,1) # should be used for the extreme colors colorFun - colorRampPalette(c(yellow,red)) levelplot(my.mat, col.regions = colorFun(50)) I don't know how to handle the extrem values... Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap with levelplot
I played a little bit around and got the following solution which works for now, though it seems to be too complicated to me. If anybody else know another solution - please let me know!!! library(lattice) my.mat - matrix(rnorm(800), nrow = 40) colorFun - colorRampPalette(c(yellow,red)) b - boxplot(my.mat, plot = FALSE) thr - c(b$stats[1],b$stats[5]) col.bins - 100 step - abs(thr[2] - thr[1])/50 limit - ifelse(min(my.mat) thr[1] - step, min(my.mat) - step, min(my.mat)) lp - rev(seq(thr[1] - step, limit - step, -step)) mp - seq(thr[1], thr[2], step) limit - ifelse(max(my.mat) thr[2] + step, max(my.mat) + step, max(my.mat)) up - seq(thr[2] + step, limit + step, step) my.at - c(lp,mp,up) my.col.regions - c(rep(green, length(lp)), colorFun(length(mp)), rep(blue, length(up)) ) levelplot(my.mat, at = my.at, col.regions = my.col.regions) Antje schrieb: Hi there, I'd like to create a heatmap from my matrix with a) a defined color range (lets say from yellow to red) b) using striking colors above and below a certain threshold (above = green, below = blue) Example matrix (there should be a few outliers generated...) + simple levelplot without outliers marked: library(lattice) my.mat - matrix(rnorm(800), nrow = 40) threshold - c(-1,1) # should be used for the extreme colors colorFun - colorRampPalette(c(yellow,red)) levelplot(my.mat, col.regions = colorFun(50)) I don't know how to handle the extrem values... Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] merging several dataframes from a list
Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Gabor Grothendieck schrieb: What version of R are you using? R version 2.8.1 (2008-12-22) (running Windows) I get this: do.call(cbind, mylist) df1.pos df1.data df2.pos df2.data df3.pos df3.data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 R.version.string [1] R version 2.8.1 Patched (2008-12-26 r47350) In which case ALL - do.call(cbind, mylist) ALL - ALL[regexpr(data, names(ALL)) 0] names(ALL) - sub([.].*, , names(ALL)) ALL df1 df2 df3 1 2 6 9 2 6 2 3 3 3 9 6 4 1 7 2 5 9 5 1 On Wed, Jan 21, 2009 at 3:19 AM, Antje niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Henrique Dallazuanna schrieb: Try this also: cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data, names(data.frame(mylist)))]) Hi Henrique, cool solution - that's seems to be the easiest way! though I thought there should be some possibiliy of multiple merge Anyway, this will do it for now! Thank you! On Wed, Jan 21, 2009 at 6:19 AM, Antje niederlein-rs...@yahoo.de mailto:niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] from matrix to data.frame
Hello, I have a question how to reshape a given matrix to a data frame. # -- a - matrix(1:25, nrow=5) a [,1] [,2] [,3] [,4] [,5] [1,]16 11 16 21 [2,]27 12 17 22 [3,]38 13 18 23 [4,]49 14 19 24 [5,]5 10 15 20 25 colnames(a) - LETTERS[1:5] rownames(a) - as.character(1:5) a A B C D E 1 1 6 11 16 21 2 2 7 12 17 22 3 3 8 13 18 23 4 4 9 14 19 24 5 5 10 15 20 25 # --- This is an example on how my matrix looks like. Now, I'd like to reshape the data that I get a data frame with three columns: - the row name of the enty (X1) - the column name of the entry (X2) - the entry itself (X3) like: X1 X2 X3 1 A 1 2 A 2 3 A 3 1 B 6 2 B 7 5 E 25 How would you solve this problem in an elegant way? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] from matrix to data.frame
Wow, there are a lot of possibilities... thank you all very much!!! I guess, I'll go for as.data.frame.table, because it's one line and does exactly what I want :-) Ciao, Antje Antje schrieb: Hello, I have a question how to reshape a given matrix to a data frame. # -- a - matrix(1:25, nrow=5) a [,1] [,2] [,3] [,4] [,5] [1,]16 11 16 21 [2,]27 12 17 22 [3,]38 13 18 23 [4,]49 14 19 24 [5,]5 10 15 20 25 colnames(a) - LETTERS[1:5] rownames(a) - as.character(1:5) a A B C D E 1 1 6 11 16 21 2 2 7 12 17 22 3 3 8 13 18 23 4 4 9 14 19 24 5 5 10 15 20 25 # --- This is an example on how my matrix looks like. Now, I'd like to reshape the data that I get a data frame with three columns: - the row name of the enty (X1) - the column name of the entry (X2) - the entry itself (X3) like: X1X2X3 1A1 2A2 3A3 1B6 2B7 5E25 How would you solve this problem in an elegant way? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Find all numbers in a certain interval
Thanks a lot for every answer I got! I could solve my problem! Greg, your proposal seems to be quite useful for me :-) Thank you. Ciao, Antje Antje schrieb: Hi all, I'd like to know, if I can solve this with a shorter command: a - rnorm(100) which(a -0.5 a 0.5) # would give me all indices of numbers greater than -0.5 and smaller than +0.5 I have something similar with a dataframe and it produces sometimes quite long commands... I'd like to have something like: which(within.interval(a, -0.5, 0.5)) Is there anything I could use for this purpose? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Find all numbers in a certain interval
Hi, sorry, but it shouldn't be different. The result should be the same but I was looking if there is a method I can use... # having a function defined like baptiste proposed: isIn - function (interval, x) { (x min(interval)) (x max(interval)) } #-- a - rnorm(100) # it's simply more human readable if I can write which( isIn( c(-0.5, 0.5), a) ) # instead of which( a -0.5 a 0.5 ) Thanks to baptiste! So there is no method available doing this and I have to define this by myself. That's all I wanted to know :-) Antje markle...@verizon.net schrieb: hi: could you explain EXACTLY what you want to do with the dataframe because it shouldn't be that different ? On Tue, Dec 16, 2008 at 5:09 AM, Antje wrote: Hi all, I'd like to know, if I can solve this with a shorter command: a - rnorm(100) which(a -0.5 a 0.5) # would give me all indices of numbers greater than -0.5 and smaller than +0.5 I have something similar with a dataframe and it produces sometimes quite long commands... I'd like to have something like: which(within.interval(a, -0.5, 0.5)) Is there anything I could use for this purpose? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Find all numbers in a certain interval
Hi all, I'd like to know, if I can solve this with a shorter command: a - rnorm(100) which(a -0.5 a 0.5) # would give me all indices of numbers greater than -0.5 and smaller than +0.5 I have something similar with a dataframe and it produces sometimes quite long commands... I'd like to have something like: which(within.interval(a, -0.5, 0.5)) Is there anything I could use for this purpose? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Find all numbers in a certain interval
Hi David, thanks a lot for your proposal. I got a lot of useful hints from all of you :-) David Winsemius schrieb: It's not entirely clear what you are asking for, since which(within.interval(a, -0.5, 0.5)) is actually longer than which(a -0.5 a 0.5). Right but in case 'a' is something with a long name and '0.5' is a variable you might end up with something like this (for the data frame example): DF[which( DF$myReallyLongColumnName -myReallyLongThreshold DF$myReallyLongColumnName -myReallyLongThreshold ), ] instead of: DF[which( within.interval(DF$myReallyLongColumnName, myReallyLongThreshold), ] You mention that you want a solution that applies to dataframes. Using indexing you can get entire rows of dataframes that satisfy multiple conditions on one of its columns: DF - data.frame(a = rnorm(20), b= LETTERS[1:20], c = letters[20:1], stringsAsFactors=FALSE) DF[which( DF$a -0.5 DF$a 0.5 ), ] # note that one needs to avoid DF[which(a -0.5 a0.5) , ] # the a vector is not the same as the a column vector within DF a b c 3 -0.47310672 C r 6 -0.49784460 F o 9 0.02571058 I l 10 0.16893759 J k 11 -0.11963322 K j 12 0.39378887 L i 16 0.03712263 P e Could get the indices that satisfy more than one condition: which(DF$a 0.5 DF$b K) [1] 1 2 6 10 Or you can get rows of DF that satisfy conditions on multiple columns with the subset function: subset(DF, a 0.5 b K) a b c 1 2.2500997 A t 2 0.7251357 B s 6 0.7845355 F o 10 1.0685649 J k Or if you wanted a within.interval function within.interval - function(x,a,b) { x a x b} which(within.interval(DF$a, -0.5, 0.5)) [1] 3 4 7 8 9 13 14 17 20 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legend and Main Title positioning
Thank you very much for your help! That code does exactly what I was looking for ( I don't have experience with lattice yet ) Ciao, Antje [EMAIL PROTECTED] schrieb: layout(matrix(c(1,2,3,4), nrow = 2, byrow = TRUE)) plot(rnorm(100)) plot(rnorm(200)) plot(rnorm(300)) plot(rnorm(400)) Now, I'd like to create a legend below each plot and generate a common title. How can I do that? If you are laying plots out in grids like this then lattice graphics are generally the way to go, but here's a solution based upon base graphics. The trick is to include extra potting space in your layout for the legends. The code is messy, since it requires you to manually specify which cell of the layout to plot into, but I'm sure guven some thought you can automate this. #4 space for plots, 4 for legends layout(matrix(1:8, nrow = 4, byrow = TRUE), heights=rep(c(3,1),4)) #Check the layout looks suitable layout.show(8) #Avoid clipping problems, and create space for your title par(xpd=TRUE, oma=c(0,0,2,0)) #First plot plot(rnorm(100)) #Move down and plot the first legend par(mfg=c(2,1)) legend(0,0, legend=foo, pch=1) #Repeat for the other plots and legends par(mfg=c(1,2)) plot(rnorm(200)) par(mfg=c(2,2)) legend(0,0, legend=bar, pch=1) par(mfg=c(3,1)) plot(rnorm(300)) par(mfg=c(4,1)) legend(0,0, legend=baz, pch=1) par(mfg=c(3,2)) plot(rnorm(400)) par(mfg=c(4,2)) legend(0,0, legend=quux, pch=1) #Title for all the plots title(main=4 plots, outer=TRUE) Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential information intended for the addressee(s) only. If this message was sent to you in error, you must not disseminate, copy or take any action in reliance on it and we request that you notify the sender immediately by return email. Opinions expressed in this message and any attachments are not necessarily those held by the Health and Safety Laboratory or any person connected with the organisation, save those by whom the opinions were expressed. Please note that any messages sent or received by the Health and Safety Laboratory email system may be monitored and stored in an information retrieval system. Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal at www.marshal.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Legend and Main Title positioning
Hi folks, can anybody give me a hint how to solve the following problem? I have several plots in one window like this: layout(matrix(c(1,2,3,4), nrow = 2, byrow = TRUE)) plot(rnorm(100)) plot(rnorm(200)) plot(rnorm(300)) plot(rnorm(400)) Now, I'd like to create a legend below each plot and generate a common title. How can I do that? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] levels update
Hello, I hope this question is not too stupid. I would like to know how to update levels after subsetting data from a data.frame. df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4)) names(df) - c(X1,X2,X3) my.sub - subset(df, X1 == a | X1 == b) levels(my.sub$X1) # still gives me a,b,c, though the subset does not contain entries with c anymore I guess, the solution is rather simple, but I cannot find it. Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] levels update
Thanks a lot!!! the drop thing was exactly what I was looking for (I already used it some time ago but forgot about it). Thanks to everybody else too. Antje Prof Brian Ripley schrieb: On Fri, 5 Dec 2008, jim holtman wrote: try this: df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4)) names(df) - c(X1,X2,X3) my.sub - subset(df, X1 == a | X1 == b) levels(my.sub$X1) [1] a b c my.sub$X1 - factor(my.sub$X1) I find my.sub$X1 - my.sub$X1[drop=TRUE] a lot more self-explanatory. See ?[.factor. However, if you find yourself wanting to do this, ask why you have a factor (rather than a character vector) in the first place. levels(my.sub$X1) [1] a b On Fri, Dec 5, 2008 at 7:50 AM, Antje [EMAIL PROTECTED] wrote: Hello, I hope this question is not too stupid. I would like to know how to update levels after subsetting data from a data.frame. df - data.frame(factor(c(a,a,c,b,b)), c(4,5,6,7,8), c(9,1,2,3,4)) names(df) - c(X1,X2,X3) my.sub - subset(df, X1 == a | X1 == b) levels(my.sub$X1) # still gives me a,b,c, though the subset does not contain entries with c anymore I guess, the solution is rather simple, but I cannot find it. Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Colors in barplot
Hello, Can anybody help me to find out which colors are used automatically when calling barplot (e.g. 3 series beside each other will get different gray values). I want to apply a legend but I don't know the colors used... Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Colors in barplot
Hi Benjamin, thanks for the hint. In barplot.default I found grey.colors(nrow(height)) :-) (I had the same problem with the help file for grey.colors) Ciao, Antje Nutter, Benjamin schrieb: I believe the defaults in barplot are found using grey.colors{GrDevices}. ?grey.colors (For some reason my machine won't pull up the help files for grey.colors from the command line, but I can still access it through the html help). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Antje Sent: Thursday, December 04, 2008 6:32 AM To: [EMAIL PROTECTED] Subject: [R] Colors in barplot Hello, Can anybody help me to find out which colors are used automatically when calling barplot (e.g. 3 series beside each other will get different gray values). I want to apply a legend but I don't know the colors used... Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News World Report (2008). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Switch language
Hi there, I've installed R somewhen in German but I'd like to have it in English. The installation of a new version does not change the language setting though I think I've chosen English in the installation process (this choice was available, right?). Can anybody give me a hint? (Error-Messages in German are not easy to get a solution for...) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Switch language
Hello Annette, that explains everything... Thank you! I just thought having an English version of Windows would be enough but indeed my Regional and Language-Setting are set to German... Ciao, Antje Annette Heisswolf schrieb: Hei, in the FAQ on R for Windows it says: 3.4 I selected English for installation but R runs in Chinese. Precisely, you selected English for installation! The language of the installer has nothing to do with the language used to run R: this is completely standard Windows practice (and necessary as different users of the computer may use different languages). The language R uses for menus and messages is determined by the locale: please read the appropriate manual (the R Installation and Administration Manual) for the details. You can ensure that R uses English messages by appending LANGUAGE=en to the shortcut you use to start R, or setting it in the Rconsole file. That should apply to your problem, too... Annette Antje schrieb: Hi there, I've installed R somewhen in German but I'd like to have it in English. The installation of a new version does not change the language setting though I think I've chosen English in the installation process (this choice was available, right?). Can anybody give me a hint? (Error-Messages in German are not easy to get a solution for...) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot via plot command
Hi, thank you both for your response. I don't want to do anything like this - I just got some code like this from someone else and was wondering about the result. I would have used another approach to create a boxplot like this... Ciao, Antje [EMAIL PROTECTED] schrieb: hi: i'm not well versed in the OO mechanism behind R but you've created a dataframe with one column being factors so, when the plot command sees this, there must be code in the plot generic that decided that the best thing to use is a boxplot. I'm not sure what you want since you have 3 factors but below is a guess ? I split by the factor and then plot the values seperately with the colors denoting the factors ? if it's not what you want, then i would resend your question to the list explaining what you do want because there are others on this list that can probably help you more than i can. good luck. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(l=as.factor(l), x) print(df) print(str(df)) temp - split(df,df$l) plot(temp[[1]]$x,ylim=c(min(temp[[1]]$x,temp[[2]]$x,temp[[3]]$x), max(temp[[1]]$x,temp[[2]]$x,temp[[3]]$x)),col=green) lines(temp[[2]]$x,type=p,col=blue) lines(temp[[3]]$x,type=p,col=red) On Tue, Dec 2, 2008 at 3:30 AM, Antje wrote: Hi folks, I've just discovered that the following code leads to boxplot (surprisingly to me). Can anybody explain to me why? Is this documented somewhere? I've never consider this option before. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(as.factor(l), x) plot(df) Thank you! Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] boxplot via plot command
Hi folks, I've just discovered that the following code leads to boxplot (surprisingly to me). Can anybody explain to me why? Is this documented somewhere? I've never consider this option before. x - rnorm(300) l - c(rep(label1,100), rep(label2,50), rep(label3,150)) df - data.frame(as.factor(l), x) plot(df) Thank you! Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Question to regular expressions
Hi there, I know, this question is not directly an R-help question but probably someone can give me a hint how to deal with the following problem. I have a vector with file/folder names and want to filter for all entries which have 6 numbers in a row and nothing else. folders - c(folder1, f2, F234562, 12345678, 234567, 912345, 333) I'd like to get only 234567 and 912345. Can anybody help me creating a regex for this??? For example this regex: regexpr([^:digit:$]{6}, folders) would match F234562, 12345678, 234567, 912345 Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question to regular expressions
Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... Ciao, Antje Gabor Grothendieck schrieb: Try this: folders - c(folder1, f2, F234562, 12345678, 234567, 912345, 333) grep(^[0-9]{6}$, folders, value = TRUE) [1] 234567 912345 On Tue, Dec 2, 2008 at 10:32 AM, Antje [EMAIL PROTECTED] wrote: Hi there, I know, this question is not directly an R-help question but probably someone can give me a hint how to deal with the following problem. I have a vector with file/folder names and want to filter for all entries which have 6 numbers in a row and nothing else. folders - c(folder1, f2, F234562, 12345678, 234567, 912345, 333) I'd like to get only 234567 and 912345. Can anybody help me creating a regex for this??? For example this regex: regexpr([^:digit:$]{6}, folders) would match F234562, 12345678, 234567, 912345 Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question to regular expressions
Thanks a lot again to all of you!!! Antje Antje schrieb: Hi Gabor, it works! Thank you very much! But I still don't understand the difference between [0-9] and [:digit:]... Ciao, Antje Gabor Grothendieck schrieb: Try this: folders - c(folder1, f2, F234562, 12345678, 234567, 912345, 333) grep(^[0-9]{6}$, folders, value = TRUE) [1] 234567 912345 On Tue, Dec 2, 2008 at 10:32 AM, Antje [EMAIL PROTECTED] wrote: Hi there, I know, this question is not directly an R-help question but probably someone can give me a hint how to deal with the following problem. I have a vector with file/folder names and want to filter for all entries which have 6 numbers in a row and nothing else. folders - c(folder1, f2, F234562, 12345678, 234567, 912345, 333) I'd like to get only 234567 and 912345. Can anybody help me creating a regex for this??? For example this regex: regexpr([^:digit:$]{6}, folders) would match F234562, 12345678, 234567, 912345 Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] duplicate values
Hei R Users, i have the following dataframe: Datetime Temperature and many more collumns 12008-6-1 00:00:00 5 22008-6-1 02:00:00 5 32008-6-1 03:00:00 6 42008-6-1 03:00:00 0 52008-6-1 04:00:00 6 62008-6-1 04:00:00 0 72008-6-1 05:00:00 7 82008-6-1 06:00:00 7 ... ... ... 3000 2008-8-31 00:00:003 the problem is that row 3 4 and row 5 6 have the same Datetime value but they differ in the values of the Temperature column. Now for the whole dataframe i would like to delete rows that have the same Datetime value as the prior row. I have tried unique(dataframe), but it does not work here because the rows are no real duplicates of each other. thanks in advance for your help! Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] par(new = TRUE) - overplotting
Hi everybody, I want to create some boxplots (as png) within an lapply method. To get nice gridlines behind the boxplot, I plotted it twice and therefore I set par(new=TRUE). This works nicely for the first plot but the second does plot on the first plot too and creates a mess... How can I force to start with a blank plot again??? lapply(c(1,2), FUN=function(i) { png(filename = test.png, width = 450, height = 600) gridlines - seq(0.1,2.0,0.1) par(mar=c(12, 4, 5, 2)) bpars - list(yaxt = n, las = 2 ) boxplot(mydata[i], pars= bpars ) abline(h = gridlines, col=lightgray, lty=2) abline(h = 1, col=red, lwd=3) par(new=TRUE) boxplot(mydata[i], pars= bpars, main = title) dev.off() }) Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] par(new = TRUE) - overplotting
Hi Dieter, thanks a lot for looking inside my code though it was not executable...(sorry for that). Finally, I found a rather stupid mistake. My original code did not use the variable i for the second boxplot. So the second round actually plotted two different data at the two calls... so it had nothing to do with the par(new...) here some executable bug-free code :-) mydata - list(rnorm(100, mean=0.5, sd=0.1), rnorm(100, mean=0.7, sd=0.15)) lapply(c(1,2), FUN=function(i) { windows(7,7) use_col - c(blue) gridlines - seq(0.1,2.0,0.1) par(mar=c(12, 4, 5, 2)) bpars - list(yaxt = n, las = 2 ) boxplot(data.frame(mydata[[i]]), col=use_col, pars= bpars ) abline(h = gridlines, col=lightgray, lty=2) abline(h = 1, col=red, lwd=3) par(new=TRUE) boxplot(data.frame(mydata[i]), col=use_col, pars= bpars) }) ciao, Antje Dieter Menne schrieb: Antje niederlein-rstat at yahoo.de writes: I want to create some boxplots (as png) within an lapply method. To get nice gridlines behind the boxplot, I plotted it twice and therefore I set par(new=TRUE). This works nicely for the first plot but the second does plot on the first plot too and creates a mess... How can I force to start with a blank plot again??? lapply(c(1,2), FUN=function(i) { png(filename = test.png, width = 450, height = 600) gridlines - seq(0.1,2.0,0.1) par(mar=c(12, 4, 5, 2)) bpars - list(yaxt = n, las = 2 ) boxplot(mydata[i], pars= bpars ) abline(h = gridlines, col=lightgray, lty=2) abline(h = 1, col=red, lwd=3) par(new=TRUE) boxplot(mydata[i], pars= bpars, main = title) dev.off() }) I do not fully understand what you want to do, but in each case you overwrite your files. Try something like: png(filename = paste(test,i,.png), width = 450, height = 600) and think over again why you need the par(new=TRUE). And please, make your examples self-running, for example by adding mydata = rnorm(100) even if you probably have more complex data. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] horizontal boxplot + xlim
Hi there, I get a strange behaviour of a boxplot with the following code. There seems to be a problem with the xlim-parameter. Did I do anything wrong? What else can I do to force the boxplot to have a defined x-range? x - rnorm(100) boxplot(x, notch=TRUE, xlab=parameter, xlim - c(-4,4), horizontal = TRUE) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] horizontal boxplot + xlim
[EMAIL PROTECTED] schrieb: I get a strange behaviour of a boxplot with the following code. There seems to be a problem with the xlim-parameter. Did I do anything wrong? What else can I do to force the boxplot to have a defined x-range? x - rnorm(100) boxplot(x, notch=TRUE, xlab=parameter, xlim - c(-4,4), horizontal = TRUE) Did you mean xlim = c(-4,4) in that statement, rather than '-'? True, I made a mistake here. Still, I have problems to visualize my data (not the example code I used). I just see a flat line instead a proper plot... Another example code with creating a strange plot: x - rnorm(100) + 100 maxval - max(x) boxplot(x, notch=TRUE, xlim = c(0,maxval), horizontal = TRUE) Any idea? Antje Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential information intended for the addressee(s) only. If this message was sent to you in error, you must not disseminate, copy or take any action in reliance on it and we request that you notify the sender immediately by return email. Opinions expressed in this message and any attachments are not necessarily those held by the Health and Safety Laboratory or any person connected with the organisation, save those by whom the opinions were expressed. Please note that any messages sent or received by the Health and Safety Laboratory email system may be monitored and stored in an information retrieval system. Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal at www.marshal.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to set rownames / colnames for matrices in a list
Thanks for the hint with the dimnames. I found a rather similar problem in the mailing list solved like this: x - matrix(1:4,2) y - matrix(5:8,2) z - list(x,y) nm - c(a,b) nms - list(nm,nm) z - lapply(z,function(x){ dimnames(x)-nms x }) Is there anything wrong using a list instead of an array??? Antje Alain Guillet schrieb: Hi, If all your matrices have the same size, you should work with an array and not with a list. Then you can use dimnames to set the names of the rows, columns, and so on.. Alain Antje wrote: Hello, I have another stupid question. I hope you can give me a hint how to solve this: I have a list and one element is again a list containing matrices, all of the same dimensions. Now, I'd like to set the dimnames for all matrices: example code: m1 - matrix(1:25, nrow=5) m2 - matrix(26:50, nrow=5) # ... there can be much more than two matrices l - list() l[[1]] - list(m1,m2) r_names - LETTERS[1:5] c_names - LETTERS[6:10] ? how can I apply these names to any number of matrices within this list-list ? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] paste with list
Hello, I guess the solution is rather simple but whatever I tried, I don't manage to get the result as I want to have it: I have several vectors of equal length in a list and I'd like to combine all first elements to a single string, all second elements to a single string, ..., all n-th elements to a single string. # Example code (how it should look like): t1 - c(1,2,3) t2 - c(3.4,5.5,1.1) paste(t1,t2, sep=\t) # and now how the data is available tl - list(t1,t2) ??? what do I have to do to get the same output ??? Can anybody help me? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] paste with list
Great! That's exactly what I was looking for. (I see, I still have to learn a lot...) Thank you! Antje Dimitris Rizopoulos schrieb: try this: t1 - c(1, 2, 3) t2 - c(3.4, 5.5, 1.1) tl - list(t1, t2) do.call(paste, c(tl, sep = \t)) I hope it helps. Best, Dimitris Antje wrote: Hello, I guess the solution is rather simple but whatever I tried, I don't manage to get the result as I want to have it: I have several vectors of equal length in a list and I'd like to combine all first elements to a single string, all second elements to a single string, ..., all n-th elements to a single string. # Example code (how it should look like): t1 - c(1,2,3) t2 - c(3.4,5.5,1.1) paste(t1,t2, sep=\t) # and now how the data is available tl - list(t1,t2) ??? what do I have to do to get the same output ??? Can anybody help me? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to set rownames / colnames for matrices in a list
Hello, I have another stupid question. I hope you can give me a hint how to solve this: I have a list and one element is again a list containing matrices, all of the same dimensions. Now, I'd like to set the dimnames for all matrices: example code: m1 - matrix(1:25, nrow=5) m2 - matrix(26:50, nrow=5) # ... there can be much more than two matrices l - list() l[[1]] - list(m1,m2) r_names - LETTERS[1:5] c_names - LETTERS[6:10] ? how can I apply these names to any number of matrices within this list-list ? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] tryCatch question
Hi there, I have a nested call of lapply in which I do a tryCatch statement like this lapply(1:length(p_names), function(w_idx) { r - as.numeric(pos_r[[w_idx]][1]) c - as.numeric(pos_c[[w_idx]][1]) pos - c(r,c) lapply(1:length(p_names[[w_idx]]), function(p_idx, pos) { parameter - p_names[[w_idx]][[p_idx]] value - p_vals[[w_idx]][[p_idx]] tryCatch({ as.numeric(value) }, warning = function(ex) { value}) oad$resultValues[[parameter]][pos[1],pos[2]] - value NULL }, pos) }) (sorry, that I don't have a simple test code here...) the tryCatch shall convert a value in a number if this makes sense (so 3.3 should be converted, but not hello; all values are strings) if I simply execute something like this: value - 3.3 tryCatch({ as.numeric(value) }, warning = function(ex) { value}) it works pretty nice. but within the lapply construct I always end up with strings. Does anybody have an idea why? (I can try to create a simple testcode for this but maybe there is already someone who knows what's wrong? Ciao, Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] another XML package question
Hi there, does anybody know how to return the xmlPath from a node? For example, at several location in the xml file, I have nodes with the same name and I'd like to process only the nodes from a certain path. Any idea? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] another XML package question
Hi Duncan, thanks a lot for your explanations. I tried the following now to understand a bit more: data - getNodeSet(doc, //Data) xmlName(data[[1]]) xmlName(xmlRoot(data[[1]])) xpathApply(data[[1]], ./*, xmlName) Is it right that using data in the xpathApply() somehow sets the current node but does not change the root? So looking for a subnode at all levels below my current node is not possible with the xPath syntax? (search on all levels starting from root is possible with //nodename) Antje Duncan Temple Lang schrieb: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Antje wrote: Hi there, does anybody know how to return the xmlPath from a node? For example, at several location in the xml file, I have nodes with the same name and I'd like to process only the nodes from a certain path. Any idea? As with your previous question, there are ways to do this with either XPath queries or R functions that operate on the nodes from the earlier queries. By xmlPath, let's assume you mean the ordered collection of nodes from the node to the root node of the document, i.e. the collection of ancestor nodes. So using XPath, you could use a = getNodeSet( node, ancestor::*) where node is the R variable containing the node within the tree whose ancestors you want, e.g. getNodeSet(doc, //val)[[1]] The nodes in are in reverse order. You can do the same thing with the R function xmlParent(). To get the ancestors, tmp = xmlParent(node) ans = list() while( !is.null(tmp)) { ans = c(ans, tmp) tmp = xmlParent(tmp) } and of course in your case you could terminate the loop at any point. But a different approach to the problem is to use a more specific XPath query in the first place to get only the nodes of interest. For example, to get the val nodes in the second data node of your example, you could use getNodeSet(doc, //data[2]/val) or to find all val nodes which have the attribute i = t2, getNodeSet(doc, //[EMAIL PROTECTED]'t2']) Or to find all val nodes with an ancestor which have an ancestor with an attribute name loc getNodeSet(doc, //[EMAIL PROTECTED]'1']//val) ( The sample XML document was root data loc=1 val i=t1 22 /val val i=t2 45 /val /data data loc=2 val i=t1 44 /val val i=t2 11 /val /data /root ) D. Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkjE+fQACgkQ9p/Jzwa2QP6KBwCeImMuyCL0kpF/0eRqo77ywZj/ AloAn3HRWaD+RDV+ZETRagtfV7zlJpk6 =JtiD -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] another XML package question
Duncan Temple Lang schrieb: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Antje wrote: Hi Duncan, thanks a lot for your explanations. I tried the following now to understand a bit more: data - getNodeSet(doc, //Data) xmlName(data[[1]]) xmlName(xmlRoot(data[[1]])) xpathApply(data[[1]], ./*, xmlName) Is it right that using data in the xpathApply() somehow sets the current node but does not change the root? The answer is it depends, specifically on what version of the XML package you have. In version 1.96-0 (the latest release), yes. There is code also in the package (but overriden) that creates a new temporary tree with the given node as the root of the new tree (but without copying the nodes). But the former is most likely what is desired. So looking for a subnode at all levels below my current node is not possible with the xPath syntax? It is possible getNodeSet( data[[1]], .//*) allright, I didn't try this (I assumed that the // means everything below root...) Now, I can do what I was looking for. Thanks a lot for everything! does that. The // means any level. BTW, it doesn't match text nodes, so you might want .//*|.//text()|.//processing-instruction() for completeness (or maybe not!) The key thing is that when you supply a node (and not the document) as the first argument of getNodeSet() or xpathApply(), the XPath query should be a relative query, e.g. .//* rather than //*. And the reason for keeping the root the same is so that we can do getNodeSet(data[[1]], ancestor::*) or getNodeSet(data[[1]], ../foo) i.e. have an XPath expression that refers to nodes higher up the tree. D. (search on all levels starting from root is possible with //nodename) Antje Duncan Temple Lang schrieb: Antje wrote: Hi there, does anybody know how to return the xmlPath from a node? For example, at several location in the xml file, I have nodes with the same name and I'd like to process only the nodes from a certain path. Any idea? As with your previous question, there are ways to do this with either XPath queries or R functions that operate on the nodes from the earlier queries. By xmlPath, let's assume you mean the ordered collection of nodes from the node to the root node of the document, i.e. the collection of ancestor nodes. So using XPath, you could use a = getNodeSet( node, ancestor::*) where node is the R variable containing the node within the tree whose ancestors you want, e.g. getNodeSet(doc, //val)[[1]] The nodes in are in reverse order. You can do the same thing with the R function xmlParent(). To get the ancestors, tmp = xmlParent(node) ans = list() while( !is.null(tmp)) { ans = c(ans, tmp) tmp = xmlParent(tmp) } and of course in your case you could terminate the loop at any point. But a different approach to the problem is to use a more specific XPath query in the first place to get only the nodes of interest. For example, to get the val nodes in the second data node of your example, you could use getNodeSet(doc, //data[2]/val) or to find all val nodes which have the attribute i = t2, getNodeSet(doc, //[EMAIL PROTECTED]'t2']) Or to find all val nodes with an ancestor which have an ancestor with an attribute name loc getNodeSet(doc, //[EMAIL PROTECTED]'1']//val) ( The sample XML document was root data loc=1 val i=t1 22 /val val i=t2 45 /val /data data loc=2 val i=t1 44 /val val i=t2 11 /val /data /root ) D. Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkjFQLMACgkQ9p/Jzwa2QP5mSwCffr3WDFAAvEQ+PDhIl65R8uQb EvUAn0bHeUqZSKQzUlDO4qaCV69tMuNg =y6Eo -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] XML - get node by name
Hi there, I try to rewrite some Java-code with R. It deals with reading XML files. I started with the XML package. In Java, I had a very useful method which gave me a node by using: name of the node index of appearance start point: global (false) / local (true) So, I could do something like this. setCurrentChildNode(data, 0); getValueOfElement(val,1,true); -- gives 45 setCurrentChildNode(data, 1); getValueOfElement(val,1,true); -- gives 11 getValueOfElement(val,1,false); -- gives 45 root data loc=1 val i=t1 22 /val val i=t2 45 /val /data data loc=2 val i=t1 44 /val val i=t2 11 /val /data /root Now, I'd like to do something like this in R. Most important would be to retrieve a node just by its name, not by the whole path. How is it possible? Can anybody help me with this issue? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] XML - get node by name
Thanks a lot to Gabor and Duncan! I didn't know that XPath is a standard. I'll give it a deeper look to better understand it. Oh, I guess I understand a bit more xpathApply(doc, //val, function(n) xmlValue(n)) would search globally for all nodes named val and return its values :-) So that's excactly what I was looking for. Not caring about the exact location of a node. I think, in my case it should be okay, to parse for nodes just by their names. Thanks again! @ Ajay: Sorry, but I was looking for a solution with R @ Dirk: I already used the XML package but didn't know the possibilities to access data as I was used to. Antje schrieb: Hi there, I try to rewrite some Java-code with R. It deals with reading XML files. I started with the XML package. In Java, I had a very useful method which gave me a node by using: name of the node index of appearance start point: global (false) / local (true) So, I could do something like this. setCurrentChildNode(data, 0); getValueOfElement(val,1,true); -- gives 45 setCurrentChildNode(data, 1); getValueOfElement(val,1,true); -- gives 11 getValueOfElement(val,1,false); -- gives 45 root data loc=1 val i=t1 22 /val val i=t2 45 /val /data data loc=2 val i=t1 44 /val val i=t2 11 /val /data /root Now, I'd like to do something like this in R. Most important would be to retrieve a node just by its name, not by the whole path. How is it possible? Can anybody help me with this issue? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] warning with hist
Hello everybody, I don't understand the warning I get when executing the following code: x - rnorm(100) h - hist(x, plot= FALSE, freq = FALSE) If I don't use the plot-argument, I don't get a warning... Any explanations for me? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] warning with hist
[EMAIL PROTECTED] schrieb: I don't understand the warning I get when executing the following code: x - rnorm(100) h - hist(x, plot= FALSE, freq = FALSE) The warning is Warning message: In hist.default(x, plot = FALSE, freq = FALSE) : argument ‘freq’ is not made use of The explanation is pretty simple. freq determines whether or not the histogram is of counts or probability densities. Since you used plot=FALSE, you aren't plotting anything, so freq does nothing. Oh, I didn't realize that it's a pure display parameter. I thought calculation would depend on this parameter. Anyway, I had a strange problem but currently I cannot reproduce, which led me somehow to this warning (I had problems to get a customized y-range). Thanks a lot! Antje Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential information intended for the addressee(s) only. If this message was sent to you in error, you must not disseminate, copy or take any action in reliance on it and we request that you notify the sender immediately by return email. Opinions expressed in this message and any attachments are not necessarily those held by the Health and Safety Laboratory or any person connected with the organisation, save those by whom the opinions were expressed. Please note that any messages sent or received by the Health and Safety Laboratory email system may be monitored and stored in an information retrieval system. Scanned by MailMarshal - Marshal's comprehensive email content security solution. Download a free evaluation of MailMarshal at www.marshal.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.