Re: [R] unique sets of factors

2006-10-19 Thread Gabor Grothendieck
If DF is a data frame containing the rows then: unique(t(apply(DF, 1, function(x) as.numeric(factor(x, levels = unique(x)) On 10/19/06, Tony Long <[EMAIL PROTECTED]> wrote: > All: > > I have a matrix, X, with a LARGE number of rows. Consider the > following three rows of that matrix: > > 1

Re: [R] demo()

2006-10-19 Thread Gabor Grothendieck
One variation of this is: "?" <- function(...) invisible(0) ?"this command illstrates blah, blah" sin(pi) rm("?") On 10/19/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 10/19/2006 6:16 PM, Yurii Aulchenko wrote: > > Dear All, > > > > I am programming a demo for an R package (say, the name

Re: [R] pass additional parameters to function

2006-10-19 Thread Gabor Grothendieck
f <- function(f1, ...) { args <- list(...) lapply(args, print) f1(...) } f(sin, pi) On 10/19/06, Weiwei Shi <[EMAIL PROTECTED]> wrote: > how do i assign "1" or "2" to some destination variable? > i mean, how do i use something to represent ... in

Re: [R] pass additional parameters to function

2006-10-19 Thread Gabor Grothendieck
Try this: f <- function(f1, ...) f1(...) f(sin, 1) f(max, 1, 2) On 10/19/06, Weiwei Shi <[EMAIL PROTECTED]> wrote: > Hi, > > I have a function like this: > > f <- function(f1) { ...} > > f1 is a function name itself. > I have two candidates for f1, and each of them have different numbers > of ar

Re: [R] bi-directional sockets

2006-10-19 Thread Gabor Grothendieck
ss I must be even > dumber than I previously thought! > > Any help would still be welcome. > > > On 10/19/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > Check out these packages: > > - Ryacas (on omegahat) -- sockets between R and yacas > >

Re: [R] bi-directional sockets

2006-10-19 Thread Gabor Grothendieck
Check out these packages: - Ryacas (on omegahat) -- sockets between R and yacas - mimR (on CRAN) -- sockets between R and mim (Windows only) On 10/19/06, Grateful Frog <[EMAIL PROTECTED]> wrote: > Hello R-helpers! > > I am new to R, but having a rough time with the socketConnection function. I >

Re: [R] out.format for chron

2006-10-19 Thread Gabor Grothendieck
For your second question: x <- chron(1) x <- chron(x, out.format = ddmm) using the ddmm from below. On 10/19/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > As discussed the Help Desk article in R News 4/1, the 2 vs 4 year > length is controlled by the chron.yea

Re: [R] out.format for chron

2006-10-19 Thread Gabor Grothendieck
As discussed the Help Desk article in R News 4/1, the 2 vs 4 year length is controlled by the chron.year.abb option, e.g. options(chron.year.abb = FALSE) chron(20) however, as also discussed there its not really recommended that you use this option so try this instead: ddmm <- func

Re: [R] use date as x-axis

2006-10-18 Thread Gabor Grothendieck
Make sure that the Date column is actually of class "Date": DF$Date <- as.Date(DF$Date, "%d-%b-%y") plot(DF) See ?as.Date . Also read the Help Desk article in R News 4/1 to learn more about dates. On 10/18/06, tom soyer <[EMAIL PROTECTED]> wrote: > Hi, > > I have the following data in two colum

[R] [R-pkgs] New version of batchfiles 0.2-9

2006-10-18 Thread Gabor Grothendieck
There is a new version, 0.2-9, of the Windows XP batchfiles distribution. It is a zip file containing a set of Windows XP batch scripts useful in conjunction with R. The latest release adds sweave.bat which will 1. run sweave, 2. run pdflatex and then 3. view the pdf in sequence. If sweave or pd

Re: [R] how to manipulate counts matrix?

2006-10-18 Thread Gabor Grothendieck
"(8.01,Inf]") # 1 library(gsubfn) colMeans(strapply(rn, "[^\][(),]+", as.numeric, simplify = TRUE)) # 2 library(gsubfn) strapply(rn, "^.([^,]+), *(.+).$", ~ (as.numeric(x) + as.numeric(y))/2, backref = -2, simplify = TRUE) # 3 with(read.table(textConnection(

Re: [R] selectively load some objects from old workspace

2006-10-18 Thread Gabor Grothendieck
Either 1. in your old workspace create a separate file using save that contains only the variables you want to transfer (see ?save) and then load that or 2. load the whole thing into an environment e <- new.env() load("myspace.rda", e) and then copy out all the variables you want and delete e (th

Re: [R] how to manipulate counts matrix?

2006-10-18 Thread Gabor Grothendieck
Here are three solutions: # Assume rn holds the rownames of the table # rn <- rownames(my.table) rn <- c("[-11.9,-10.6]", "(-10.6,-9.3]", "(-9.3,-8.01]", "(-8.01,-6.73]") # 1 library(gsubfn) colMeans(strapply(rn, "[-.0-9]+", as.numeric, simplify = TRUE)) # 2 library(gsubfn) strapply(rn, "([-.0

Re: [R] multiline string continuation

2006-10-18 Thread Gabor Grothendieck
May this: gsub("\n", "", " X:/level1/level2 /level3/level4/ level5/level6 ") On 10/18/06, Erik Chang <[EMAIL PROTECTED]> wrote: > Dear R experts, > > I wonder how can one input a string variable in multiple lines in a R > script. I've seen solution to the command line continuation in the > non-st

[R] Aggregating a data frame (was: Re: new R-user needs help)

2006-10-18 Thread Gabor Grothendieck
Please use an informative subject for sake of the archives. Here are several solutions: aggregate(DF[4:8], DF[2], mean) library(doBy) summaryBy(x1 + x2 + x3 + x4 + x5 ~ name, DF, FUN = mean) # if Exp, name and id columns are factors then this can be reduced to library(doBy) summaryBy(. ~ name,

Re: [R] Input buffer overflow

2006-10-17 Thread Gabor Grothendieck
rings 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 us

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.

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: >

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 e

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] 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] 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

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 w

Re: [R] New package Ryacas

2006-10-17 Thread Gabor Grothendieck
Just one other comment. If you want to try running Linux over Windows you might want to check out how the AndLinux project (google to find) is progressing. I had tried it about a year ago and it was much faster than VMware although at that time it was still a bit immature. On 10/17/06, Gabor

Re: [R] New package Ryacas

2006-10-17 Thread Gabor Grothendieck
Maybe there are timing problems using that setup with sockets? I once tried VMware (not with Ryacas but just to try it out) and found it slow as can be expected with an emulated environment. Since you have Windows XP just use the Windows version of Ryacas directly. On 10/17/06, Simon Blomberg <[E

Re: [R] New package Ryacas

2006-10-16 Thread Gabor Grothendieck
> 0 , 1 ) ) > > > > Thanks for your attention! > > > Cleber Borges > > > > > >Here is a slightly shorter way to do it although it > involves passing > >a yacas string directly: > > > >>yacas("a * Identity(3)") > > > >expression(list(list(a,

Re: [R] [R-pkgs] 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), Li

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

2006-10-16 Thread Gabor Grothendieck
econdly, > Is there a way to send R'objects (variables) to yacas and make > symbolic > operations?? > for example: > > d <- diag(3) > a <- "A" > > yacas( d * a ) > > Thanks, > Cleber Borges > > > Gabor Grothendieck wrote: > > &

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]

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

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 f

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. > > >

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.

[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 artif

[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] 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)])

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. > > He

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

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 co

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 som

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

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

Re: [R] weight cases?

2006-10-14 Thread Gabor Grothendieck
y.data$var1, my.data$var2)) > round(unweighted*total$weight, 0) > > > Yet another question: how would the weight variable be applied to correlate > two numerical variables? > > Best, > Adrian > > On Saturday 14 October 2006 16:00, Gabor Grothendieck wrote: > &g

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 ap

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

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] 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] 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) O

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] 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 Rcmd.ex

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

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.FAC

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) {integrat

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 datase

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

Re: [R] Function that operates on functions: it's ok, but the display isn't

2006-10-10 Thread Gabor Grothendieck
You need to substitute it into yourself. Also note that displaying a function will display its source attribute which may get unsynchronized with the actual function if the function was constructed yourself so NULL it out to be sure what you are seeing is what the unction actually is: # g is the

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

2006-10-10 Thread Gabor Grothendieck
tin wrote: > > > > Gabor Grothendieck wrote: > >> 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

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

2006-10-10 Thread Gabor Grothendieck
12, x1 = gl(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: &g

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") eva

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] 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"

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 k

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 resu

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 de

Re: [R] lattice: adding text to plots

2006-10-09 Thread Gabor Grothendieck
l there should be two lines, but this > has just one (group lost). > > 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 &quo

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] 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, M

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

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/

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...l

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 =

Re: [R] Sum of Bernoullis with varying probabilities

2006-10-07 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

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 se

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] 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] 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 exp

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

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) O

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] [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 lo

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. x1>x2.

Re: [R] How to get the function names

2006-10-05 Thread Gabor Grothendieck
ist(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 giv

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 &

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 PROTEC

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] 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.

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

2006-10-05 Thread Gabor Grothendieck
longfun3 work perfect for my "very > untypical" problem. As I have many local variables, usual functions > 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: > > > lo

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 o

Re: [R] Plotting text with lattice

2006-10-05 Thread Gabor Grothendieck
> On 9/29/06, Deepayan Sarkar <[EMAIL PROTECTED]> 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 x

Re: [R] help with script

2006-10-04 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,

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

2006-10-04 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-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,

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

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 attribute

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
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 n

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(

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 > pleas

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. > > Give

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 confu

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