Re: [R] Review process for new packages

2006-10-17 Thread Gabor Grothendieck
One thing you might want to do is an R CMD CHECK with both the development and released versions of R since CRAN will check it against both: http://cran.r-project.org/src/contrib/checkSummary.html On 10/17/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 10/17/2006 2:22 AM, Andreas Wittmann

Re: [R] Finding out about objects and classes

2006-10-17 Thread Gabor Grothendieck
apropos(loess) help.search(loess) methods(class = loess) class?loess # in this case it does not return anything but sometimes it does RiteSearch(loess) On 10/17/06, michael watson (IAH-C) [EMAIL PROTECTED] wrote: When R help simply states something like: Value: An object of class

Re: [R] barplot error

2006-10-17 Thread Gabor Grothendieck
On 10/17/06, Farrel Buchinsky [EMAIL PROTECTED] wrote: I created a dataframe called OSA here is what it looks like no.surgery surgery 00.4 6.9 60.2 0.3 I have also attached it as an R data file I cannot understand why I am getting the following error.

Re: [R] Variance of Y_hat in a linear model

2006-10-17 Thread Gabor Grothendieck
Using the builtin BOD data set try this: predict(lm(demand ~., BOD), se.fit = TRUE) On 10/17/06, Li Zhang [EMAIL PROTECTED] wrote: Y X Z 42.07.0 33.0 33.04.0 41.0 75.0 16.07.0 28.03.0 49.0 91.0 21.05.0 55.08.0 31.0

Re: [R] looking for a cleaner way to do something

2006-10-17 Thread Gabor Grothendieck
Try this: X - structure(11:15, .Names = letters[1:5]) Y - structure(21:25, .Names = letters[1:5]) rbind(group1 = X, group2 = Y) tab - rbind(group1 = X, group2 = Y) tab[,-1] / tab[,1] On 10/17/06, Leeds, Mark (IED) [EMAIL PROTECTED] wrote: I have two numeric vectors each of length 17 and each

Re: [R] looking for a cleaner way to do something

2006-10-17 Thread Gabor Grothendieck
Sorry there was an extra line in there. It should be: X - structure(11:15, .Names = letters[1:5]) Y - structure(21:25, .Names = letters[1:5]) tab - rbind(group1 = X, group2 = Y) tab[,-1] / tab[,1] On 10/17/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: X - structure(11:15

Re: [R] cluster in R

2006-10-17 Thread Gabor Grothendieck
Go the R home page (google for R), click on CRAN in left pane, choose a mirror, click on Task Views in left pane and choose Cluster. On 10/17/06, Weiwei Shi [EMAIL PROTECTED] wrote: hi, is there some good summary on clustering methods in R? It seems there are many packages involving it. And

Re: [R] Input buffer overflow

2006-10-17 Thread Gabor Grothendieck
which can be parsed. On 10/15/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: In gsubfn I replace matches with strings that represent calls to a function and then perform paste(eval(parse(text= ...)), collapse = ) on the result. One user of gsubfn is using it with very long strings (over 20,000

Re: [R] NULL or NA for missing function arguments?

2006-10-16 Thread Gabor Grothendieck
There is also a third way, namely use the missing function in the code: f - function(x) if (missing(x)) print(missing) else print(x) f() On 10/16/06, Hans-Peter [EMAIL PROTECTED] wrote: Hi, I am troubled by the use of NULL or NA to indicate missing/non-specified function arguments. In the

Re: [R] grep function with patterns list...

2006-10-16 Thread Gabor Grothendieck
Try this: grep(b|c|d, letters, value = TRUE) [1] b c d On 10/16/06, Stéphane CRUVEILLER [EMAIL PROTECTED] wrote: Dear R-users, is there a way to pass a list of patterns to the grep function? I vaguely remember something with %in% operator... Thanks, Stéphane. -- La science a

Re: [R] grep function with patterns list...

2006-10-16 Thread Gabor Grothendieck
DF - data.frame(pat = letters[1:3]) grep(paste(DF$pat, collapse = |), letters, value = TRUE) [1] a b c On 10/16/06, Stéphane CRUVEILLER [EMAIL PROTECTED] wrote: Ooops sorry for html tags... Just forgot to edit the message before sending it... So back to my question: Thx for the hint, but

Re: [R] NULL or NA for missing function arguments?

2006-10-16 Thread Gabor Grothendieck
On 10/16/06, Hans-Peter [EMAIL PROTECTED] wrote: 2006/10/16, Duncan Murdoch [EMAIL PROTECTED]: As Gabor said, the third way is to give no default, but test missing() in the code. I forgot this one, thank you. In my case it is probably not suited as I just pass the arguments to a C (Pascal)

Re: [R] Misunderstanding escape (backslash)

2006-10-16 Thread Gabor Grothendieck
On 10/16/06, Frank McCown [EMAIL PROTECTED] wrote: Forgive my ignorance, but shouldn't '\\' be converted into '\' in my string? In my output (below), you can see that '\\' remains '\\'. term = mother\'s day term [1] mother's day term = mother\\\'s day term [1] mother\\'s day

Re: [R] [R-pkgs] New package Ryacas

2006-10-16 Thread Gabor Grothendieck
?? for example: d - diag(3) a - A yacas( d * a ) Thanks, Cleber Borges Gabor Grothendieck wrote: Ryacas is an R interface to the free yacas computer algebra system. Ryacas allows one to send R expressions, unprocessed yacas strings and certain other R objects to a separate yacas

Re: [R] [R-pkgs] New package Ryacas

2006-10-16 Thread Gabor Grothendieck
) | || | ( 0 ) ( 0 ) ( a ) | \/ On 10/16/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Its pretty limited right now but you can do this: library(Ryacas) d - List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1)) a - Sym(a) a * d expression(list(list(a, 0, 0

Re: [R] New package Ryacas

2006-10-16 Thread Gabor Grothendieck
) | || | ( 0 ) ( a ) ( 0 ) | || | ( 0 ) ( 0 ) ( a ) | \/ On 10/16/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Its pretty limited right now but you can do this: library(Ryacas) d - List(List(1, 0, 0), List(0, 1, 0), List

Re: [R] executing strings

2006-10-15 Thread Gabor Grothendieck
Try this: eval(parse(text = pi + 3)) On 10/14/06, Lloyd Lubet [EMAIL PROTECTED] wrote: I'd like to excute character strings such as z-plot( objects()[1]; eval(z) and viola I'd have a plot of my first dataframe in the first frame. Unfortunately this approach no longer works. Help? Lloyd

Re: [R] Hide line ends behind unfilled circles?

2006-10-15 Thread Gabor Grothendieck
Here is a completely different solution using gplot in sna. We create an edge matrix, edges, and plot it. library(sna) edges - replace(matrix(0, 8, 8), cbind(match(x0, xx), match(x1, xx)), 1) gplot(edges, coord = cbind(xx, yy), usearrows = FALSE, vertex.col = c(black, white)[factor(aa)]) On

[R] Input buffer overflow

2006-10-15 Thread Gabor Grothendieck
In gsubfn I replace matches with strings that represent calls to a function and then perform paste(eval(parse(text= ...)), collapse = ) on the result. One user of gsubfn is using it with very long strings (over 20,000 characters) and the parse is giving an input buffer overflow. Here is an

[R] [R-pkgs] New package Ryacas

2006-10-15 Thread Gabor Grothendieck
?Ryacas --- Rob Goedman, goedman at mac dot com Gabor Grothendieck, ggrothendieck at gmail dot com Søren Højsgaard, Soren.Hojsgaard at agrsci dot dk Ayal Pinkus, apinkus at xs4all dot nl ___ R-packages mailing list R-packages@stat.math.ethz.ch https

Re: [R] weight cases?

2006-10-14 Thread Gabor Grothendieck
Try this: table(lapply(my.data, rep, my.data$weight)[1:2]) On 10/14/06, Adrian Dusa [EMAIL PROTECTED] wrote: Dear all, This is probably a stupid question for which I have a solution, which unfortunately is not as straighforward as I'd like. I wonder if there's a simple way to apply a

Re: [R] weight cases?

2006-10-14 Thread Gabor Grothendieck
On Saturday 14 October 2006 16:00, Gabor Grothendieck wrote: Try this: table(lapply(my.data, rep, my.data$weight)[1:2]) On 10/14/06, Adrian Dusa [EMAIL PROTECTED] wrote: Dear all, This is probably a stupid question for which I have a solution, which unfortunately

Re: [R] weight cases?

2006-10-14 Thread Gabor Grothendieck
I missed your second question. See ?cov.wt On 10/14/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this (and round the result to make to it comparable to your calculation): xtabs(weight ~ var1 + var2, my.data) On 10/14/06, Adrian Dusa [EMAIL PROTECTED] wrote: Thanks for this Gabor

Re: [R] glm cannot find valid starting values

2006-10-14 Thread Gabor Grothendieck
Try using OLS starting values: glm(Y~X,family=gaussian(link=log), start = coef(lm(Y~X))) On 10/14/06, Michael Dewey [EMAIL PROTECTED] wrote: At 15:31 13/10/2006, Ronaldo ReisJunior wrote: Hi, I have some similar problems. Some times ago this problem dont there existed. Look this simple

Re: [R] Fixing Variables in a Function

2006-10-14 Thread Gabor Grothendieck
Try this: f - function(x, y, z) (x + y + z)^2 integrate(f, 0, 1, x = 0, z = 0) # integrate f setting x=z=0 0.333 with absolute error 3.7e-15 On 10/14/06, Lorenzo Isella [EMAIL PROTECTED] wrote: Dear All, I am working with functions of several variables, e.g. f(x,y,z). At some point,

Re: [R] regression analyses using a vector of means and a variance-covariance matrix

2006-10-14 Thread Gabor Grothendieck
Here is another approach using the same data as in John Fox's reply. His is probably superior but this does have the advantage that its very simple. Note that it gives the same coefficients and R squared to several decimal places. We just simulate a data set with the given means and variance

Re: [R] regression analyses using a vector of means and a variance-covariance matrix

2006-10-14 Thread Gabor Grothendieck
There was a missing line: On 10/14/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here is another approach using the same data as in John Fox's reply. His is probably superior but this does have the advantage that its very simple. Note that it gives the same coefficients and R squared

Re: [R] bug: Editing function formals deletes the environment

2006-10-13 Thread Gabor Grothendieck
If you are just modifying an S3 method in a package you may not need to reinsert the method into the package since UseMethod first looks into the caller environment for methods anyways and only second does it look for methods in the package. Thus: HTML.data.frame - R2HTML:::HTML.data.frame

Re: [R] multiply two matrixes with the different dimension column by column

2006-10-13 Thread Gabor Grothendieck
Here are two ways: 1. Using inner from: http://tolstoy.newcastle.edu.au/R/help/05/04/3709.html try: array(inner(t(X), Y, *), c(4, 21)) 2. using model.matrix get all terms and interactions and eliminate the non-interactions: model.matrix(~ X * Y - X - Y - 1) On

Re: [R] loop, pipe connection, output objects

2006-10-13 Thread Gabor Grothendieck
read your data frame in all at once and then cut it on x[2] and split the result, e.g. split(iris, cut(iris$Sepal.Length, 4:8)) Please provide reproducible code. Without input its not reproducible. See last line of every message to r-help. On 10/13/06, Marco Grazzi [EMAIL PROTECTED] wrote:

Re: [R] cygwin script for Sweave

2006-10-13 Thread Gabor Grothendieck
On Windows you could just put this into sweave.bat, say, and then place that anywhere in your path (or in the current directory): set infile=%~sdpn1 set infile=%infile:\=/% cmd Rcmd Sweave %infile%.Rnw pdflatex %infile%.tex start %infile%.pdf On 10/13/06, Thomas Harte [EMAIL PROTECTED] wrote:

Re: [R] How to see if row names of a dataframe are stored compactly

2006-10-13 Thread Gabor Grothendieck
Try this: class(attributes(x)$row.names) [1] integer rownames(x) - as.character(rownames(x)) class(attributes(x)$row.names) [1] character On 10/13/06, Hsiu-Khuern Tang [EMAIL PROTECTED] wrote: Reading the list of changes for R version 2.4.0, I was happy to see that the row names of

Re: [R] impossible escape?

2006-10-11 Thread Gabor Grothendieck
On 10/11/06, Marc Schwartz [EMAIL PROTECTED] wrote: On Wed, 2006-10-11 at 13:30 -0400, Charles Annis, P.E. wrote: Greetings: I've searched the R archives with no luck. I want to print this to the screen as part of on-screen instructions as an example: default.FACTOR.labels -

Re: [R] Object attributes in R

2006-10-11 Thread Gabor Grothendieck
You can define your own class then define [ to act any way you would like: [.myobj - function(x, ...) { y - unclass(x)[...] attributes(y) - attributes(x) y } tm - structure(1:10, units = sec, class = myobj) tm tm[3:4] # still has attributes On 10/11/06, Michael

Re: [R] Rcmd not working on Windows

2006-10-11 Thread Gabor Grothendieck
That's a windows message which says it can't find the command you typed anywhere on its path. If you can't figure it out get Rcmd.bat from batchfiles: http://cran.r-project.org/contrib/extra/batchfiles/ and place that file anywhere on your path. It will find R in the registry and run

Re: [R] Rank Function

2006-10-10 Thread Gabor Grothendieck
Because y[1] and y[5] are not the same in Part1 but are in Part2: # using y from Part1 y[5] - y[1] [1] 1.110223e-16 You could round your numbers to 2 digits, say: rank(round(100*y)) # y is from Part1 [1] 3.5 5.0 1.0 2.0 3.5 On 10/10/06, Li Zhang [EMAIL PROTECTED] wrote: Does anyone know

Re: [R] read.table() and scientific notation

2006-10-10 Thread Gabor Grothendieck
Your example does not exhibit that behavior when I try it (below). Can you provide a reproducible example following the style shown here: Lines - a 1 2e-4 + b 2 3e-8 DF - read.table(textConnection(Lines)) str(DF) 'data.frame': 2 obs. of 3 variables: $ V1: Factor w/ 2 levels a,b: 1 2 $

Re: [R] find weighted group mean

2006-10-10 Thread Gabor Grothendieck
Here are two ways: f1 - function(i) weighted.mean(X[i,1], X[i,2]) aggregate(list(wmean = 1:nrow(X)), as.data.frame(X[,3:5]), f1) f2 - function(x) data.frame(wmean = weighted.mean(x[,1], x[,2]), x[1, 3:5]) do.call(rbind, by(X, as.data.frame(X[,3:5]), f2)) Also you check out the na.rm= argument

Re: [R] update.default evaluating in wrong environment?

2006-10-10 Thread Gabor Grothendieck
As a workaround use evaluate=FALSE argument to update and evaluate it yourself fetching the environment from the innards of the lm structure: f - function() { DF - data.frame(y = 1:12, x1 = gl(2, 1, 12), x2 = gl(2,6)) lm(y ~ x1, DF) } f.lm - f() e - attr(terms(f.lm), .Environment)

Re: [R] update.default evaluating in wrong environment?

2006-10-10 Thread Gabor Grothendieck
(2, 1, 12), x2 = gl(2,6)) f.lm - lm(y ~ x1, DF) f.lm$update - function(object = f.lm, ...) update(object, ...) f.lm } f.lm - f() f.lm$update(formula = y ~ x2) On 10/10/06, Martin C. Martin [EMAIL PROTECTED] wrote: Gabor Grothendieck wrote: As a workaround use evaluate=FALSE argument

Re: [R] update.default evaluating in wrong environment?

2006-10-10 Thread Gabor Grothendieck
Perhaps the evaluate= argument could be extended to allow an environment or an object for which environment(object) yields an environment, e.g. update(y ~ x2, evaluate = formula(f.lm)) On 10/10/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 10/10/2006 1:32 PM, Martin C. Martin wrote: Gabor

Re: [R] Including time in a zoo

2006-10-10 Thread Gabor Grothendieck
Its saying you are trying to pass a list to zoo (a data frame is a list); however, from ?zoo we see zoo takes a first argument of: a numeric vector, matrix or a factor. On 10/10/06, Horace Tso [EMAIL PROTECTED] wrote: dear list, I have these hourly price data over a 20 year period. Among other

Re: [R] during fitting of successive datasets, stall crashes iterations

2006-10-10 Thread Gabor Grothendieck
See ?try or ?tryCatch. The basic idiom is given here: https://stat.ethz.ch/pipermail/r-help/2005-May/072035.html On 10/10/06, Warren [EMAIL PROTECTED] wrote: Hi all, I am trying to do fitting of large sets of timeseries data, and error messages derail the process when I encounter a dataset

Re: [R] Using integrate() with vectors as boundaries rather than scalars

2006-10-10 Thread Gabor Grothendieck
Or just: lapply(x, integrate, f = dnorm, upper = Inf) On 10/11/06, Tobias [EMAIL PROTECTED] wrote: I think I have figured it out myself, would however like to know the opinion of more experienced coders. Is this a good way of approaching this: cumdnorm1 - function(x)

Re: [R] lattice: adding text to plots

2006-10-09 Thread Gabor Grothendieck
). This plot was produced with R 2.4 on windows and lattice 0.14-9. Thanks and regards, Ritwik. On 10/9/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Could you explain what does not work means. It seems to produce a graph with x-y numbers on it in R 2.4.0 on Windows. At any rate, I

Re: [R] Block comments in R?

2006-10-09 Thread Gabor Grothendieck
On 10/9/06, hadley wickham [EMAIL PROTECTED] wrote: Current .Rd documentation has some obvious problems: - the parser strips comments out of examples when it runs them - there's no way to put images into the documentation - the keywords aren't much use - there's isn't a definition

Re: [R] testing for error

2006-10-09 Thread Gabor Grothendieck
See: http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg09925.html On 10/9/06, Jonathan Williams [EMAIL PROTECTED] wrote: Dear R Helpers, I want to test if a procedure within a loop has produced an error or not. If the procedure has produced an error, then I want to ignore its result.

Re: [R] Sum of Bernoullis with varying probabilities

2006-10-08 Thread Gabor Grothendieck
Or perhaps its clearer (and saves a bit of space) to use apply...prod here instead of exp...log: fft(apply(mvfft(t(cbind(1-p,p,0,0,0))), 1, prod), inverse = TRUE)/5 On 10/7/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: One can get a one-line solution by taking the product of the FFTs

Re: [R] Sum of Bernoullis with varying probabilities

2006-10-08 Thread Gabor Grothendieck
On 10/8/06, Ted Harding [EMAIL PROTECTED] wrote: On 08-Oct-06 Gabor Grothendieck wrote: Or perhaps its clearer (and saves a bit of space) to use apply...prod here instead of exp...log: fft(apply(mvfft(t(cbind(1-p,p,0,0,0))), 1, prod), inverse = TRUE)/5 Yes, that's neat (in either

Re: [R] Sum of Bernoullis with varying probabilities

2006-10-08 Thread Gabor Grothendieck
On 10/8/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 10/8/06, Ted Harding [EMAIL PROTECTED] wrote: On 08-Oct-06 Gabor Grothendieck wrote: Or perhaps its clearer (and saves a bit of space) to use apply...prod here instead of exp...log: fft(apply(mvfft(t(cbind(1-p,p,0,0,0))), 1

Re: [R] Select range of dates

2006-10-08 Thread Gabor Grothendieck
And here is a fourth: as.numeric(format(dd, %Y)) + (quarters(dd) Q1) On 10/8/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are three alternative ways to get the fiscal year as a numeric value assuming: dd - as.Date(x$Date,%d/%m/%Y) # add one to year if month is past March

Re: [R] Windows/MAC difference (console)

2006-10-08 Thread Gabor Grothendieck
The Tinn-R editor on sourceforge can do that. There is also a useful intro here on setting up Tinn-R: http://genetics.agrsci.dk/~sorenh/misc/Rlive/index.html On 10/8/06, Lina Jansen [EMAIL PROTECTED] wrote: Hello, a colleague of mine uses R on his Mac and he has quite a nice feature: When he

Re: [R] read.zoo question

2006-10-08 Thread Gabor Grothendieck
Try read.zoo(myfile, sep = ,, FUN = as.POSIXct) or to.chron - function(x) { s - do.call(rbind, strsplit(format(x), )) chron(dates(s[,1], format = Y-M-D), times(s[,2])) } read.zoo(myfile, sep = ,, FUN = to.chron) depending on which class you want. On 10/8/06, Leeds, Mark (IED)

Re: [R] lattice: adding text to plots

2006-10-08 Thread Gabor Grothendieck
Could you explain what does not work means. It seems to produce a graph with x-y numbers on it in R 2.4.0 on Windows. At any rate, I would have done it like this although I think you can leave off the [1] on subscripts and it will still work. library(lattice) library(grid) xyplot(y1 + y2 ~ x |

Re: [R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Gabor Grothendieck
Try n - 1 f - if (n == 1) sin else cos f(pi) On 10/7/06, Alberto Vieira Ferreira Monteiro [EMAIL PROTECTED] wrote: Why this kind of assignment does not work? n - 1 f - ifelse(n == 1, sin, cos) f(pi) this must be rewritten as: n - 1 f - cos if (n == 1) f - sin f(pi) [oops.

Re: [R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Gabor Grothendieck
I have noticed that dispatch on functions seems not to work in another case too. We define + on functions (I have ignored the niceties of sorting out the environments as we don't really need it for this example) but when we try to use it, it fails even though in the second example if we run it

Re: [R] Sum of Bernoullis with varying probabilities

2006-10-07 Thread Gabor Grothendieck
One can get a one-line solution by taking the product of the FFTs. For example, let p - 1:4/8 be the probabilities. Then the solution is: fft(exp(rowSums(log(mvfft(t(cbind(1-p,p,0,0,0)), inverse = TRUE)/5 On 10/7/06, Ted Harding [EMAIL PROTECTED] wrote: Hi again. I had suspected that

Re: [R] can lm() automatically take in the independent variables without knowing the names in advance

2006-10-07 Thread Gabor Grothendieck
Try this: run.lm - function(DF, response = names(DF)[1], fo = y~.) { fo[[2]] - as.name(response) eval(substitute(lm(fo, DF))) } # test run.lm(iris) run.lm(iris, Sepal.Width) Another possibility is to rename the first column: On 10/7/06, HelponR [EMAIL PROTECTED] wrote:

Re: [R] Select range of dates

2006-10-07 Thread Gabor Grothendieck
Here are three alternative ways to get the fiscal year as a numeric value assuming: dd - as.Date(x$Date,%d/%m/%Y) # add one to year if month is past March as.numeric(format(dd, %Y)) + (format(dd, %m) 03) # same but using POSIXlt # (Even though there are no time zones involved I have seen #

Re: [R] Relative constraint using constrOptim?

2006-10-06 Thread Gabor Grothendieck
Reparameterize replacing x1 with x2+delta constraining delta to be positive or else replace x1 with x2 + delta^2 and no constraint. On 10/6/06, Felix Eggers [EMAIL PROTECTED] wrote: I am trying to optimize a likelihood function using constrOptim. I know from prior research that, e.g. x1x2. Is

Re: [R] [R-pkg] New packages pmg, gWidgets, gWidgetsRGtk2

2006-10-06 Thread Gabor Grothendieck
Hi, I need installation instructions. library(pmg) seems not to be enough. Thanks. library(pmg) Loading pmg() Loading required package: gWidgets Loading required package: gWidgetsRGtk2 Loading required package: RGtk2 Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to

Re: [R] Row comparisons to a new matrix?

2006-10-06 Thread Gabor Grothendieck
There is a generalized inner product here: http://tolstoy.newcastle.edu.au/R/help/05/04/3709.html On 10/6/06, Atte Tenkanen [EMAIL PROTECTED] wrote: Hi, Can somebody tell me, which is the fastest way to make comparisons between all rows in a matrix (here A) and put the results to the new

Re: [R] gregexpr in R 2.3.0 != gregexpr in R 2.4.0

2006-10-06 Thread Gabor Grothendieck
You can get that by using zero width lookahead assertions. They must match but are not consuming so the next match will not be forced to start past them. See ?regex and http://www.regular-expressions.info/lookaround.html for more. gregexpr( [a-z](?= [a-z] ), a b c d e f , perl = TRUE) On

Re: [R] searching for data.frame rows / processing of rows

2006-10-05 Thread Gabor Grothendieck
Grouping the data frame by the first two columns, apply colMeans and then rbind the resulting by-structure together: do.call(rbind, by(DF, DF[2:1], colMeans, na.rm = TRUE)) On 10/5/06, Greg Tarpinian [EMAIL PROTECTED] wrote: R 2.3.1, WinXP: I have a puzzling problem that I suspect may be

Re: [R] help with script

2006-10-05 Thread Gabor Grothendieck
On 10/4/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Also see package caTools. On 10/4/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See: http://tolstoy.newcastle.edu.au/R/help/04/10/5161.html On 10/4/06, JOHN VOIKLIS [EMAIL PROTECTED] wrote: Hello, I wrote the function

Re: [R] Plotting text with lattice

2006-10-05 Thread Gabor Grothendieck
] wrote: On 9/29/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are two possibilities. The first use trellis.focus/trellis/unfocus to add text subsequent to drawing the xyplot and the second uses a custom panel: xyplot(x ~ x, data = data.frame(x = 1:10)) trellis.focus

Re: [R] Block comments in R?

2006-10-05 Thread Gabor Grothendieck
There are two places that I find the current way it works to be less than ideal although its not that bad either: 1 .when one wants to define strings that have quotes then one must be careful to use double quoted strings to contain single quotes and single quoted strings to contain double quotes

Re: [R] (not so real) function (more like #include)

2006-10-05 Thread Gabor Grothendieck
with parameters are very uncomfortable, but the code you gave me is great! Meinhard On Oct 4, 2006, at 5:25 PM, Gabor Grothendieck wrote: longfun could just pass a, b and d to each of the individual functions and each of the individual functions could pass out back as a return value. f1 - f2

Re: [R] Plotting text with lattice

2006-10-05 Thread Gabor Grothendieck
I seem to have omitted g library(lattice) xyplot(x ~ x | g, data = data.frame(x = 1:12, g = gl(3,4)), panel = function(...) { panel.xyplot(...) panel.text(x=2, y=4, labels=which.packet()) }) On 10/5/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: This requires R 2.4.0. Its

Re: [R] How to get the function names

2006-10-05 Thread Gabor Grothendieck
Probably the best you can hope for is to cover most cases. This one uses match.call and handles a number of cases and perhaps if you spend more time on it might be able to add some cases where it fails such as the second L below: f - function(x) { if (!is.list(x)) x - list(x) if

Re: [R] How to get the function names

2006-10-05 Thread Gabor Grothendieck
I should have mentioned is that the way it works is that it uses the name of the list component, if any, otherwise it uses the name of the function if its given as a number and otherwise it uses the function itself or possibly the name of the list. On 10/5/06, Gabor Grothendieck [EMAIL PROTECTED

Re: [R] How to get the function names

2006-10-05 Thread Gabor Grothendieck
I should have mentioned is that the way it works is that it uses the name of the list component, if any, otherwise it uses the name of the function if its given as a name and otherwise it uses the function itself or possibly the name of the list. On 10/5/06, Gabor Grothendieck [EMAIL PROTECTED

Re: [R] How to get the function names

2006-10-05 Thread Gabor Grothendieck
(match.call()[-1][[1]])) } myfun(mean) myfun(list(mean, sd)) On 10/5/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: I should have mentioned is that the way it works is that it uses the name of the list component, if any, otherwise it uses the name of the function if its given as a name

Re: [R] how to generate matrices based on an indicator variable

2006-10-04 Thread Gabor Grothendieck
This produces a list whose ith element is matrix Xi : X4 - replace(matrix(0, 4, 4), cbind(4, 4), 1) lapply(1:4, function(i) replace(X4, cbind(i,i), 1)) On 10/4/06, Ya-Hsiu Chuang [EMAIL PROTECTED] wrote: Hi, I am trying to create matrices X's based on one indicator variable, r. Given a 4

Re: [R] integers to POSIXct

2006-10-04 Thread Gabor Grothendieck
Here are a few ways: now - Sys.time() Epoch - now - as.numeric(now) i + Epoch structure(i, class = c(POSIXt, POSIXct)) class(i) - c(POSIXt, POSIXct) On 10/4/06, paul sorenson [EMAIL PROTECTED] wrote: What is the recommended way to convert/coerce and integer to a POSIXct please? d -

Re: [R] (not so real) function (more like #include)

2006-10-04 Thread Gabor Grothendieck
longfun could just pass a, b and d to each of the individual functions and each of the individual functions could pass out back as a return value. f1 - f2 - function(a, b, d) a+b+d longfun1 - function() { a - b - d - 1 out - f1(a, b, d) out - f2(a, b, d) + out out } longfun1() # 6

Re: [R] how to convert all columns of a data frame into factors

2006-10-04 Thread Gabor Grothendieck
Try this: replace(BOD, TRUE, lapply(BOD, factor)) On 10/4/06, Weiwei Shi [EMAIL PROTECTED] wrote: Hi, I use apply apply(x, 2, factor) but it does not work. please help. thanks. -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. Did you always know? No, I did not. But I

Re: [R] Tabulation and missing values

2006-10-04 Thread Gabor Grothendieck
Is the idea here to have the NA entries be a factor level? Try this: table(format(EthnicCode)) with appropriate mods if you want to rearrange the levels. On 10/4/06, David Scott [EMAIL PROTECTED] wrote: I think this is one for Gabor. I don't seem to be able to find my way to an answer

Re: [R] how to convert all columns of a data frame into factors

2006-10-04 Thread Gabor Grothendieck
Just one small point on this. This may not matter to you but just in case it does, if L - lapply(BOD, factor) then replace(BOD, TRUE, L) data.frame(L) are not exactly the same in the case that BOD has additional attributes (which in this case it does). The first one will preserve the

Re: [R] help with script

2006-10-04 Thread Gabor Grothendieck
See: http://tolstoy.newcastle.edu.au/R/help/04/10/5161.html On 10/4/06, JOHN VOIKLIS [EMAIL PROTECTED] wrote: Hello, I wrote the function, below, in the hope of _quickly_ generating a sliding-window time series of the mean, sd, median, and mad values from a matrix of data. The script below

Re: [R] help with script

2006-10-04 Thread Gabor Grothendieck
Also see package caTools. On 10/4/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See: http://tolstoy.newcastle.edu.au/R/help/04/10/5161.html On 10/4/06, JOHN VOIKLIS [EMAIL PROTECTED] wrote: Hello, I wrote the function, below, in the hope of _quickly_ generating a sliding-window

Re: [R] rolling around rollapply in a zoo

2006-10-03 Thread Gabor Grothendieck
As indicated in ?rollmean there are only ts and zoo methods for rollapply. Try rollapply(zoo(1:10), 3, mean) Also note that as indicated in ?rollmean, rollmean does have a default method: rollmean(1:10, 3) On 10/3/06, Horace Tso [EMAIL PROTECTED] wrote: Hi list, I'm a little confused

Re: [R] aggregate function with 'NA'

2006-10-01 Thread Gabor Grothendieck
See ?mean and note the na.rm= argument: aggregate(frame[-1], frame[1:2], mean, na.rm = TRUE) On 10/1/06, Frank [EMAIL PROTECTED] wrote: Dear r-help reader, I have some problems with the aggregate function. My datframe looks like frame Day Time V1 V2 1 M0 3 NA 2 M0 4

Re: [R] xyplot Graphic Help

2006-10-01 Thread Gabor Grothendieck
That's note the only problem. The point (B, 14) is plotted at (C, 14). Your problem is that: factor(letters)[2:3, drop = TRUE] [1] b c Levels: b c so now b has level 1 and c has level 2 so if you try to plot b from the original factors where it was 2 it will show up above c and c will not

Re: [R] How to repeat vectors ?

2006-09-30 Thread Gabor Grothendieck
Here are 4 approaches in order from most compact to least. #1 only works for numeric matrices, # 2 is a shorter versio of your solution using rep.vec and # 3 is from Alex's post and is likely what I would use in practice. m - matrix(1:4, 2) # test matrix # 1 - m must be numeric for this one to

Re: [R] Print/Save/Cat/Write list

2006-09-30 Thread Gabor Grothendieck
Check out ?dput On 9/30/06, Ritwik Sinha [EMAIL PROTECTED] wrote: Hi, I would like to write a list to an ascii file. I tried the following y - list(a = 1, b = c(TRUE,FALSE), c = oops) save(y, file=y.data, ascii=TRUE) # Not satisfactory print does not have a file= option cat cannot

Re: [R] a decimal aligned column

2006-09-30 Thread Gabor Grothendieck
For the last line you could also consider the print.data.frame method: data.frame(Symbol = symbols, dolVol = dolVol.pretty) or data.frame(row.names = symbols, dolVol = dolVol.pretty) capture.output or sink could be used if you want to direct it to a file. On 9/30/06, BBands [EMAIL

Re: [R] How to repeat vectors ?

2006-09-30 Thread Gabor Grothendieck
it does is looping through each row(or col) , which would be slow for large matrix, right ? cheers - Original Message - From: Gabor Grothendieck [EMAIL PROTECTED] Date: Saturday, September 30, 2006 4:54 am Subject: Re: [R] How to repeat vectors ? To: Tong Wang [EMAIL PROTECTED] Cc

Re: [R] Can I avoid loops here ?

2006-09-30 Thread Gabor Grothendieck
Try: mapply(%*%, mylist1, mylist2, SIMPLIFY = FALSE) Please provide self-contained examples as requested on the last line of every message to r-help. That means the data for X1, X2, Y1, Y2 should be included so one can run the code you post. On 10/1/06, Tong Wang [EMAIL PROTECTED] wrote: Hi,

Re: [R] Evaluation of defaults in functions

2006-09-29 Thread Gabor Grothendieck
On 9/29/06, hadley wickham [EMAIL PROTECTED] wrote: But doesn't R has a rather limited force of lazy evaluation? - you have no control over it, apart from that arguments are evaluated lazily. This rather limited compared to other languages (no lazy lists etc) You do have more

Re: [R] Plotting text with lattice

2006-09-29 Thread Gabor Grothendieck
Here are two possibilities. The first use trellis.focus/trellis/unfocus to add text subsequent to drawing the xyplot and the second uses a custom panel: xyplot(x ~ x, data = data.frame(x = 1:10)) trellis.focus(panel, 1, 1) panel.text(x=2, y=4, labels=Text) trellis.unfocus() xyplot(x ~ x, data =

Re: [R] X-axis labels in histograms drawn by the truehist function

2006-09-29 Thread Gabor Grothendieck
Try this: f - function(x,xlab) truehist(x, xlab = xlab) mapply(f, as.data.frame(X), colnames(X)) On 9/29/06, Ravi Varadhan [EMAIL PROTECTED] wrote: Hi, I have a simple problem that I would appreciate getting some tips. I am using the truehist function within an apply call to plot

Re: [R] help with distance matrix

2006-09-29 Thread Gabor Grothendieck
Try: as.dist(mymatrix) On 9/29/06, Deming Mi [EMAIL PROTECTED] wrote: Dear R users, I have computed a diagonal distance matrix and it's in a matrix format (I did not use the dist() function). However hclust() does not take my distance matrix as correct input object. It seems that hclust()

Re: [R] how to retain time zone when doing c(POSIXct)

2006-09-28 Thread Gabor Grothendieck
Here is one way that does not require explicit assignment of tzone: rbind(data.frame(x=xx), data.frame(x=xx[1] - 60), data.frame(x=xx[2] + 60))[[1]] With xx from the post we get: rbind(data.frame(x=xx), data.frame(x=xx[1] - 60), data.frame(x=xx[2] + 60))[[1]] [1] 2006-09-26 12:00:00 GMT

Re: [R] Comparing entire row sets at once efficiently

2006-09-28 Thread Gabor Grothendieck
If Comparison and Candidates each have no duplicated rows (which is the situation in the example) then try this: tail(!duplicated(rbind(Comparison, Candidates)), nrow(Candidates)) On 9/28/06, Dirk Eddelbuettel [EMAIL PROTECTED] wrote: Dear useRs, I am having a hard time coming up with a

Re: [R] safe prediction from lm

2006-09-28 Thread Gabor Grothendieck
See ?SafePrediction for how it works in R. Also the example here: http://www.mayin.org/ajayshah/KB/R/html/o9.html On 9/28/06, Spencer Jones [EMAIL PROTECTED] wrote: I am fitting a regression model with a bs term and then making predictions based on the model. According to some info on the

Re: [R] Evaluation of defaults in functions

2006-09-28 Thread Gabor Grothendieck
foo2 could be written: foo3 - function(x, y = x) { force(y); x - 0; y } to make it clear that evaluation of y is being forced. See ?force On 9/28/06, Ulrich Keller [EMAIL PROTECTED] wrote: Hello, and sorry if this is already explained somewhere. I couldn't find anything. R (2.3.1,

Re: [R] control L to clear the Rgui screen in Windows

2006-09-28 Thread Gabor Grothendieck
See: http://tolstoy.newcastle.edu.au/R/help/06/02/21556.html On 9/28/06, Charles Annis, P.E. [EMAIL PROTECTED] wrote: Greetings R-ians: Searching the Searchable Mail Archives I discovered that ctrl L will clear the Rgui screen, which is what I'd like to do from a print (or some similar)

Re: [R] How to pass expression as an argument

2006-09-27 Thread Gabor Grothendieck
On 27 Sep 2006 10:57:15 +0200, Peter Dalgaard [EMAIL PROTECTED] wrote: Tong Wang [EMAIL PROTECTED] writes: Hi, I am writing a function and need to pass a function expression as an argument, for instance, myfun - function( express) { x- c(1,2,3)

Re: [R] exponential fitting

2006-09-27 Thread Gabor Grothendieck
# using this test data set.seed(1) x - 1:20/20 y - exp(2 + 3 * x) + rnorm(20) # if its ok to fit logs so that its linear exp(fitted(lm(log(y) ~ x))) 1 2 3 4 5 6 7 8 8.55615 9.94692 11.56376 13.44340 15.62857 18.16894

<    4   5   6   7   8   9   10   11   12   13   >