Re: [R] not sure if this intended behavior in column referencing

2006-11-14 Thread Gabor Grothendieck
Please make your examples minimal. That includes not using huge variable names that make it harder to work with. This is not a zoo object with one column. Its is a zoo object based on a vector. zoo(matrix(1:3, 3, 1)) is not the same as zoo(1:3) The former has one column but the latter does n

Re: [R] putting a column name on a zoo object

2006-11-14 Thread Gabor Grothendieck
Unfortunately that's wrong. Look at ?zoo . The first argument must be a numeric vector, matrix or factor. A data frame is not allowed. On 11/14/06, Horace Tso <[EMAIL PROTECTED]> wrote: > Mark, it's not the most elegant solution but here it is, > > I have a zoo with a vector of numeric values,

Re: [R] putting a column name on a zoo object

2006-11-14 Thread Gabor Grothendieck
First, read the last line of every message to r-help. The code below is not self contained nor reproducible. You can only put a column name on a zoo object that has columns! That means its data portion must be an nx1 matrix, not a vector. On 11/14/06, Leeds, Mark (IED) <[EMAIL PROTECTED]> wrote

Re: [R] Error in str(its-object)

2006-11-14 Thread Gabor Grothendieck
A workaround if you need to multiply an its object by a number would be to convert the its object to zoo, do the multiply on the zoo object and then convert the resulting zoo object back to its. Using im from Martin's example: library(its) library(zoo) im as.its(3 * as.zoo(im)) On 11/14/06, Mart

Re: [R] greatest common substring

2006-11-14 Thread Gabor Grothendieck
Try: V1 <- c("Welfare_Group_1024", "Welfare_Group_1536", "Welfare_Group_160") V2 <- c("xxxWelfare_Group_1024", "yWelfare_Group_1536", "zWelfare_Group_160") lcs <- function(ff) { L <- ff[1]; for(f in ff) L <- lcs2(f,L); L } lcs(V1) lcs(V2) where lcs2 was posted here: http://finzi.psych.upenn

Re: [R] Question on applying vectors to data.frames by row

2006-11-13 Thread Gabor Grothendieck
Here are a couple of possibilities: as.data.frame(t(t(df) * vct)) df * rep(vct, each = nrow(df)) On 11/13/06, RDM <[EMAIL PROTECTED]> wrote: > # Newbie alert > # I am wanting to multiply the rows in a dataframe by a vector. > # However, the default behavior appears to be for the vector to

Re: [R] Can I execute the content of a character vector?

2006-11-13 Thread Gabor Grothendieck
On 11/13/06, Roger Bivand <[EMAIL PROTECTED]> wrote: > On Mon, 13 Nov 2006, Luiz Rodrigo Tozzi wrote: > > > Hi > > > > I want to know if there is any possibility of "executing" the content of a > > vector, for example: > > > > example=c("Test",1,0,0,0,"seq(14,42,by=2)",0,0,1) > > > > i want to know

Re: [R] Computing time for matrix addition or subtraction

2006-11-12 Thread Gabor Grothendieck
This is slightly faster but not by much: ad <- function(m, a) { diag(m) <- diag(m) + a; m } R <- ad(P %*% P - t(P) - P, 1) On 11/12/06, YONGWAN CHUN <[EMAIL PROTECTED]> wrote: > Hello, > > > I wonder by chance if there is a way to reduce computing time for matrix > addition or subtraction. With

Re: [R] missing symbols for mathplot

2006-11-10 Thread Gabor Grothendieck
Try this: plot(0, main = quote(P(X ~ "|" ~ A ~ intersect(B On 11/10/06, stortignauz <[EMAIL PROTECTED]> wrote: > > Hi all, > > I'm trying to write an axis label > that sounds P( X | K and Xb ) (probability of X given K and Xb ) > but I need the intersection symbol > (the "\cap" in latex) > A

Re: [R] Why do I get a linebreak in the legend?

2006-11-09 Thread Gabor Grothendieck
Try: legend("topleft", expression(R[adj]^2 == 0.66)) On 11/9/06, CG Pettersson <[EMAIL PROTECTED]> wrote: > Dear all, > > W2k, R2.4.0 > > I want to place a legend in a regression plot, stating the adjusted > R-square value. After some struggle with the coding I am nearly there, but > only nearly

Re: [R] Plotting symbols with two positions?

2006-11-09 Thread Gabor Grothendieck
Aside from the answers to use text you could use letters instead of numbers which would allow you to continue to use a single character and might have advantages in terms of saving space on the chart: pch = letters[trial_no] pch = c(letters, LETTERS)[trial_no] pch = c(1:9, letters, LETTERS)[trial_

Re: [R] axis command and excel time format

2006-11-09 Thread Gabor Grothendieck
You are using two different x's and one has nothing to do with the other. All of your examples are simply internally inconsistent so there is no reason to think they would work. On 11/9/06, Carmen Meier <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck schrieb: > > Please pro

Re: [R] axis command and excel time format

2006-11-08 Thread Gabor Grothendieck
Please provide a complete self contained example. I can't follow the partial code below; however, its likely you are plotting one thing and creating axes using another so there is no reason it should come out right. On 11/8/06, Carmen Meier <[EMAIL PROTECTED]> wrote: > Gabor Grothe

Re: [R] axis command and excel time format

2006-11-08 Thread Gabor Grothendieck
Your code plots x which has nothing to do with xt. On 11/8/06, Carmen Meier <[EMAIL PROTECTED]> wrote: > Yes this one works, but (sorry) in the OP there was a plot without data > to define the range > So I tried to use your working suggestion in that manner: > > library(zoo) > library(chron) > tim

Re: [R] Numerical Integration

2006-11-08 Thread Gabor Grothendieck
You could approximate it with splines and then integrate that: x <- 0:10/10 f <- function(x) 1 + x + x^2 + x^3 + x^4 y <- f(x) fs <- splinefun(x, y) integrate(fs, 0, 1) integrate(f, 0, 1) On 11/8/06, Xiaofan Cao <[EMAIL PROTECTED]> wrote: > Hi everyone, > > I'm trying to integrate f(x) over x whe

Re: [R] axis command and excel time format

2006-11-08 Thread Gabor Grothendieck
You indicated that one of the solutions did not work for you but I am not clear which one you were referring to. To avoid confusion I have deleted all my and your comments except for the following which works for me if I paste it into a fresh session using Edit | Paste commands only menu in Win

Re: [R] axis command and excel time format

2006-11-08 Thread Gabor Grothendieck
<- 12 > xt <- times(seq(mn, mx, length = n)) > xt <- times(unique(sub("..$", "00", xt))) > plot(z, xaxt = "n") > axis(1, xt, sub(":00$", "", xt)) > R.version.string [1] "R version 2.4.0 Patched (2006-10-24 r39722)" &

Re: [R] axis command and excel time format

2006-11-08 Thread Gabor Grothendieck
works fine in any configuration. > but I would prefer an "automatic" input. > That means that I would like to use the datafield[1] for the minimum > time and the datafield[max] (means the last one) for the maximum time. > divided into x steps.The datafiled size could reach more tha

Re: [R] Convert ordinary dates into POSIX

2006-11-08 Thread Gabor Grothendieck
There is a discussion and code in the R News 4/1 help desk article. On 11/8/06, Ivan Kalafatic <[EMAIL PROTECTED]> wrote: > Does anyone know where I can find any tool for Windows that converts > dates from ordinary formats into POSIX? > I need it to import sime time series from Excel into R and us

Re: [R] axis command and excel time format

2006-11-08 Thread Gabor Grothendieck
Try this: plot(z, xaxt = "n") xt <- paste("23", seq(5, 50, 5), sep = ":") axis(1, times(paste(xt, 0, sep = ":")), xt) On 11/8/06, Carmen Meier <[EMAIL PROTECTED]> wrote: > Hi to all, > I have some problems to get the times-scale to the x-axis the times are > coming from an excel sheet f. e > [1]

Re: [R] Reformat a data frame

2006-11-07 Thread Gabor Grothendieck
In addition to the reshape solution posted one could use melt from the reshape package: melt(df1, id = 1:2) On 11/7/06, Thorsten Muehge <[EMAIL PROTECTED]> wrote: > > Hello Experts, > how do I reformat a data frame in the way described below: > > > df1: > IDdesc resist thick temp > 1

Re: [R] Gregexpr - extract results with lapply

2006-11-07 Thread Gabor Grothendieck
Try this: library(gsubfn) s <-c("ABC", "this WOUld be gOOD") strapply(s, "[A-Z]{3}", perl = TRUE) See: http://code.google.com/p/gsubfn/ On 11/7/06, Lapointe, Pierre <[EMAIL PROTECTED]> wrote: > Gregexpr - extract results with lapply > > Hello, > > I need to extract sequences of three upper case

Re: [R] Date, date, POSIX question

2006-11-05 Thread Gabor Grothendieck
I personally follow those recommendations. On 11/5/06, Joe Byers <[EMAIL PROTECTED]> wrote: > Gabor, > > Thank you very much. That is a wonderful article and will help very > much. Might I ask which date schema do you prefer? > > Thank you > Joe > > > Gabor

Re: [R] clear screen

2006-11-05 Thread Gabor Grothendieck
There are a few versions for Windows here: http://tolstoy.newcastle.edu.au/R/help/06/02/21634.html On 11/5/06, Mauricio Cardeal <[EMAIL PROTECTED]> wrote: > Hello ! > > Please, how can I clear the RConsole screen ? Is there any "clear" command ? > > Thanks, > Mauricio ___

Re: [R] Date, date, POSIX question

2006-11-05 Thread Gabor Grothendieck
See the help desk article in R News 4/1 for a discussion on how to choose. On 11/5/06, Joe W. Byers <[EMAIL PROTECTED]> wrote: > I have been working with R extensively for several months. I switched > from SAS and Matlab to R. My question is > > Can anyone explain the benefits and detractions of

Re: [R] struggling to plot subgroups

2006-11-05 Thread Gabor Grothendieck
To plot this with classic graphics convert data frame from long to wide format using one of the three alternatives below and then plot: # 1. subset DFm <- subset(DF, gender == "m") DFf <- subset(DF, gender == "f") DFw <- cbind(DFm[1], xBar.m = DFm[,3], xBar.f = DFf[,3]) # 2. reshape DFw <- reshap

Re: [R] difference in using with() and the "data" argument in glm call

2006-11-03 Thread Gabor Grothendieck
It looks into the data argument first and if not found there it looks into environment(formula). Thus to pick it out of the 'with' try this: with(KK, glm(fo, data = environment()) Also you could try this: environment(fo) <- KK glm(fo) On 11/3/06, vito muggeo <[EMAIL PROTECTED]> wrote: > Dear

Re: [R] help needed on data management

2006-11-02 Thread Gabor Grothendieck
First create your running sum function and then tapply it to the groups: runsum <- function(x, k = 3) diff(c(rep(0, k), cumsum(x)), k) DF$back <- unlist(tapply(DF$plays, DF$Userid, runsum)) Note that there is a survey of running sum/mean/etc. here: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/

Re: [R] Simple question about Lists

2006-11-02 Thread Gabor Grothendieck
Try this: > L <- list(matrix(1:10, 10)) > L [[1]] [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 > plot(L[[1]]) If your object is somehow different then please display it like this: dput(x, control = "all") where x i

Re: [R] splitting very long character string

2006-11-02 Thread Gabor Grothendieck
You could use the file= argument on cat to avoid the two calls to sink: cat(tmp, file = tmp.file) On 11/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > thanks a lot for your help on splitting the string to get a numeric vector. > I'm now writign the string to a tempfile and read

Re: [R] subsetting, aggregating and zoo

2006-11-02 Thread Gabor Grothendieck
aggregate can also be used: aggregate(d, list(d = d), length) # output is data frame or using zoo: library(zoo) aggregate(zoo(as.vector(d)), d, length) # output is a zoo object If what you actually have is a zoo object such as this one: z <- zoo(1:10, d) then the last statement co

Re: [R] Calling an arbitrarily named data frame + variable

2006-11-01 Thread Gabor Grothendieck
Try this: f <- function(DF, vnam) { if (is.character(DF)) DF <- get(DF) head(DF[[vnam]]) } f(iris, "Species") f("iris", "Species") On 11/1/06, Jonathan Greenberg <[EMAIL PROTECTED]> wrote: > If I want to pass a data frame variable name and a specific component name > of the data frame to a

Re: [R] matrix manipulation with a for loop

2006-11-01 Thread Gabor Grothendieck
Try this where m is the matrix: 100 * colMeans(m > 5 & m < 9, na.rm = TRUE) On 11/1/06, antonio rodriguez <[EMAIL PROTECTED]> wrote: > Hi, > > Having a matrix F.zoo (6575,189) with NA's in some columns I'm trying to > extract from each column the percent of days within an specific range, > so I'

Re: [R] xyplot: Plotting two variables, one as points - the other as line. Can that be done without explicitly using panel functions

2006-11-01 Thread Gabor Grothendieck
If the x values are unique, as in this example, then xyplot.zoo can do it without a panel function (or perhaps more accurately the default panel function in xyplot.zoo can do it). Note that a zoo object is a vector or matrix with a time index attached to it. You don't really have to be familiar wi

Re: [R] strange algorithm needed

2006-11-01 Thread Gabor Grothendieck
Try: rep(1:3, length = 17) or as.numeric(gl(3, 1, 17)) or y <- 1:17 replace(y, TRUE, 1:3) # ignore warning On 11/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > i need a strange algorithm that i can easily do in a loop but need > o do without looping. > > suppose i have a vector of

Re: [R] [ggplot] controlling axis and major/minor tick marks

2006-10-31 Thread Gabor Grothendieck
If you are willing to use grid you can set the color of the tick marks, labels and place a box around the chart like this: x <- 1:10 y <- x*x # create box around plot library(ggplot) qplot(x, y) # black border around plot grid.edit("grill-border", height = unit(.99, "npc"), width = unit(.99,

Re: [R] read.fwf and header

2006-10-31 Thread Gabor Grothendieck
I also have to deal with fixed format files from time to time. Generally I have no control over the format in those cases. On 10/31/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > "Archaic" it may be, but I still have to deal with fixed format data > files on a daily basis. > > David L. Reiner

Re: [R] plotting question

2006-10-31 Thread Gabor Grothendieck
I think you will have to ensure that lt has the same set of times as the prior plot to do it that way. Since time(lt) is a subset of time(aggfxdata) it would be good enough to do this: par(new = TRUE) lt2 <- merge(zoo(, time(aggfxdata)), lt) plot(lt2, type = "l", lty = 2) On 10/31/06, Leeds, Mar

Re: [R] generic pasting of strings

2006-10-31 Thread Gabor Grothendieck
On 10/31/06, Robert Lischke <[EMAIL PROTECTED]> wrote: > Hi there, > > is there a way to make the following code generic, so that i can paste() > the columns in tmp1 depending on the dimensions given in embed()? > > > tmp1 <- embed(as.vector(shrinkTable$AOIname), dimension = 2); > > tmp1 > [,

Re: [R] Odd behaviour of removing 'nothing' from an array or data frame

2006-10-31 Thread Gabor Grothendieck
But what if you wanted to get the subset of those rows containing heights over 250 -- you would want zero rows to be returned: On 10/31/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I've just found some behaviour which strikes me as odd, but I'm not sure > whether it's a bug or a feature. If

Re: [R] match lists

2006-10-31 Thread Gabor Grothendieck
Try this: A <- list(matrix(c(2,3,3,1,2,2), 3, dimnames = list(NULL, letters[1:2])), matrix(c(3,3,2,5,1,3), 3, dimnames = list(NULL, letters[3:4]))) B <- list(matrix(c(1:5, 20*(1:5), 10+20*(1:5)), 5, dimnames = list(NULL, letters[5:7])), matrix(c(1:5, 10*(1:5), 10+

Re: [R] as.zoo question

2006-10-30 Thread Gabor Grothendieck
It should be zoo, not as.zoo. We are constructing a zoo object from scratch here, not converting a time series object of a different class to zoo. On 10/30/06, Leeds, Mark (IED) <[EMAIL PROTECTED]> wrote: > oops, for the pasting to work, > You would have to get rid of the blank line that occurs d

Re: [R] POSIXct time zone and daylight savings issues

2006-10-30 Thread Gabor Grothendieck
I don't know the answer to your question but if you are using dates with no times and don't need time zones (both of which appear to be the case here) then you could use "Date" class and avoid the issue altogether. See the help desk article in R News 4/1 where there is a discussion of how to choos

Re: [R] reading only some columns from a table

2006-10-30 Thread Gabor Grothendieck
Sorry, here it is fixed up. The c should have been list: Lines <- "conid person construct 1 1 offence 2 1 insight" read.table(textConnection(Lines), header = TRUE, colClasses = list(person = NULL)) On 10/30/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Here is a

Re: [R] which duplicated rows to delete

2006-10-30 Thread Gabor Grothendieck
Try this. The first line breaks it up into lists and the second line drops any list that is not greater than 1 in length: out <- tapply(seq(x), x, function(x)x) out[sapply(out, length) > 1] On 10/30/06, Søren Merser <[EMAIL PROTECTED]> wrote: > Hi > Say I've this vector with several duplicates >

Re: [R] reading only some columns from a table

2006-10-30 Thread Gabor Grothendieck
lt change slightly but not into desired one. > > > > Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > See the colClasses argument of read.table. > > e.g. > > read.table("myfile", header = TRUE, colClasses = c(person = NULL)) > > assuming you don't want

Re: [R] reading only some columns from a table

2006-10-30 Thread Gabor Grothendieck
See the colClasses argument of read.table. e.g. read.table("myfile", header = TRUE, colClasses = c(person = NULL)) assuming you don't want the column labelled person in the header. On 10/30/06, Amir Safari <[EMAIL PROTECTED]> wrote: > > >Dear R users, > Sometimes it is needed to read on

Re: [R] for importing "data"

2006-10-30 Thread Gabor Grothendieck
Move to the appropriate directory first (or else move your file to where you are now). For example, 1. if the file is in \ then setwd("/") 2. or getwd() which shows where you are now and then you can move your file to that spot. 3. Another possibility is: read.delim(file.choose())

Re: [R] Debugging R's code: boxplot.stats

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, Matthew Walker <[EMAIL PROTECTED]> wrote: > On Sun, 2006-10-29 at 18:47 -0500, Duncan Murdoch wrote: > [snip] > > > Hi Duncan, > > > > > > Thanks for your reply. > > > > > > How do you know that (i) boxplot.stats lives in the grDevices namespace? > > > > getAnywhere(boxplot.stats) star

Re: [R] Debugging R's code: boxplot.stats

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 10/29/2006 6:08 PM, Matthew Walker wrote: > > On Sat, 2006-10-28 at 08:03 -0400, Duncan Murdoch wrote: > >> On 10/27/2006 11:06 PM, Matthew Walker wrote: > >>> Hi everyone, > >>> > >>> I think I have found a minor issue with the R function

Re: [R] Debugging R's code: boxplot.stats

2006-10-29 Thread Gabor Grothendieck
t; > 5. Finally, the function traceback() lists the call-stack. How do I > know which one of the two "boxplot.stats" functions was called? I think you need to refer to the search list or your knowledge of how it works in other cases. > > Thanks, > > Matthew > >

Re: [R] subsetting, aggregating and zoo

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, antonio rodriguez <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck escribió: > Thanks Gabor! Now it's OK (nice the output of dput. I was reluctant to > paste all data because is 6575 days long!) > You can write the following, say, to display just a bit: dput(

Re: [R] subsetting, aggregating and zoo

2006-10-29 Thread Gabor Grothendieck
sum(table(idx))[idx]] aggregate(z, starts, mean) By the way, dput(v, control = "all") will output variable v in a form easily pastable by someone else into their session. On 10/29/06, antonio rodriguez <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck escribió: > > Try

Re: [R] Problem with very old dates

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, Marc Schwartz <[EMAIL PROTECTED]> wrote: > On Sun, 2006-10-29 at 10:31 -0600, tom soyer wrote: > > Hi, > > > > I noticed that as.Date() could not convert date string to date type if the > > dates are very old. For example, if the date string is "1-Mar-50", then > > as.Date() would conv

Re: [R] Rgui.exe fix for "console not found" buffer overflow problem

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 10/29/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > On 10/29/2006 8:23 AM, Gabor Grothendieck wrote: > > > On 10/29/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > >> On 10/29/2006

Re: [R] Rgui.exe fix for "console not found" buffer overflow problem

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 10/29/2006 8:23 AM, Gabor Grothendieck wrote: > > On 10/29/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > >> On 10/29/2006 5:52 AM, Duncan Murdoch wrote: > >>> On 10/29/2006 1:12 AM, Jesse Al

Re: [R] Rgui.exe fix for "console not found" buffer overflow problem

2006-10-29 Thread Gabor Grothendieck
On 10/29/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 10/29/2006 5:52 AM, Duncan Murdoch wrote: > > On 10/29/2006 1:12 AM, Jesse Albert Canchola wrote: > >> Here's how the problem started. In Rgui.exe, I attempted to get more > >> visible output in the buffer (I wanted to be able to scroll u

Re: [R] labelling of horizontal axis in acf function

2006-10-28 Thread Gabor Grothendieck
Its because of the frequency. The lower the frequency number the higher will be the numbers on the scale axis. > as.ts(aggfxdata[,"bid"]) Time Series: Start = 1144713660 End = 1144716960 Frequency = 0.0167 [1] 118.4800 NA 118.4760 NA 118.4600 118.4367 118.4171 118.3810 [

Re: [R] subsetting, aggregating and zoo

2006-10-28 Thread Gabor Grothendieck
ds <- time(z)[cumsum(table(idx))[idx]] # average over each run using the time of the end of run for the result # replace ends with starts if that is preferred aggregate(z, ends, mean) On 10/28/06, antonio rodriguez <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck escribió: > >

Re: [R] subsetting, aggregating and zoo

2006-10-28 Thread Gabor Grothendieck
On 10/28/06, antonio rodriguez <[EMAIL PROTECTED]> wrote: > Hi, > > Having an zoo object I can subset it to obtain the days where I have the > values within some range: > > is.zoo(z) > TRUE > > subset(z[,1], z[,1]>=5 & z[,1]<= 10) #Yields: Year(day) > > 1988(13) 1988(14) 1988(16) 1988(20) 1988(

Re: [R] Package development on Windows - latest guidance?

2006-10-28 Thread Gabor Grothendieck
On 10/28/06, Michael Prager <[EMAIL PROTECTED]> wrote: > Thanks to Gabor G., Duncan M., and Hong O. for helpful > replies. I've made some progress, but have two questions. > > Can anyone explain *how* R CMD searches for latex? I have > provided a batch file (shell script) and and alias (I use a >

Re: [R] Package development on Windows - latest guidance?

2006-10-28 Thread Gabor Grothendieck
There are pointers to information in the links section of: http://code.google.com/p/batchfiles/ and some XP batch files that facilitate using R and building packages on XP. Regarding LaTeX, use MiKTeX. On 10/28/06, Michael Prager <[EMAIL PROTECTED]> wrote: > I would like to start building R p

Re: [R] Debugging R's code: boxplot.stats

2006-10-27 Thread Gabor Grothendieck
The edit operations does not change the boxplot.stats that you are debugging. It creates a new boxplot.stats (i.e. now there are two) and the new one does not have debugging turned on. Try getAnywhere("boxplot.stats") and it finds two. If you remove the one you just created using rm debugging r

Re: [R] really strange problem - has to be logic but i can't find it

2006-10-27 Thread Gabor Grothendieck
gt; so my guess is that if I just unique it first, everything will work > fine. Oh geez. Thanks so much. > > > -Original Message- > From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] > Sent: Friday, October 27, 2006 10:03 PM > To: Leeds, Mark (IED) > Cc: r-help@stat.math.

Re: [R] really strange problem - has to be logic but i can't find it

2006-10-27 Thread Gabor Grothendieck
zoo objects must have unique index values but the last two in the head output below are the same: > head(fxdata) bid ask 2006-04-03 03:30:00 27.21 27.26 2006-04-03 03:46:42 27.21 27.26 2006-04-03 03:46:54 27.25 27.26 2006-04-03 03:57:08 27.55 27.26 2006-04-03 04:00:00 27.50

Re: [R] POSIXct time zone and daylight savings issues

2006-10-27 Thread Gabor Grothendieck
Try this: gmtDiff <- function(time) time - as.POSIXct(format(time), tz = "GMT") gmtDiff(Sys.time()) gmtDiff(as.POSIXct("2006-10-27", tz = "GMT")) which both give me the correct answer currently. The expression after the minus sign comes from the table at the end of the help desk article in R Ne

Re: [R] scanning a pdf scan

2006-10-27 Thread Gabor Grothendieck
I don't have specific experience with this but strapply of package gsubfn can extract information from a string by content as opposed to delimiters. e.g. > library(gsubfn) > strapply("abc34def56xyz", "[0-9]+", c)[[1]] [1] "34" "56" On 10/27/06, roger koenker <[EMAIL PROTECTED]> wrote: > I have a

Re: [R] Adding shading to background of Time series plot

2006-10-26 Thread Gabor Grothendieck
There is an example here using plot http://www.mayin.org/ajayshah/KB/R/html/g5.html and an example here using xyplot.zoo: library(zoo) ?xyplot.zoo that would also work with xyplot.ts On 10/26/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello All, > > Thank you in advance. >

Re: [R] Progress Monitor in R / looping

2006-10-25 Thread Gabor Grothendieck
This is easy to do with the proto package. Here is a basic version: library(proto) ml <- proto(start = 1, end = 5, val = NULL, it = function(.) { if (is.null(.$val)) return(.$val <- .$start) else .$val <- .$val + 1 if (.$val > .$end) return(FALSE) else .$val }) # test 1 while(ml$it()) ca

Re: [R] write a help file for my own function

2006-10-25 Thread Gabor Grothendieck
Note the R command, prompt, which will generate an outline of the help page for you. Also you might want to look through the existing help files for many examples. On 10/25/06, Weiwei Shi <[EMAIL PROTECTED]> wrote: > Hi, > > I am wondering how I can write a help page for my own function so when >

Re: [R] variables with dynamic names?

2006-10-25 Thread Gabor Grothendieck
With the style of whole objects encouraged for R that code looks like this: rowString <- LETTERS[1:3]; cols <- 3 # test data mat <- outer(rowString, formatC(1:cols, flag = "0", width = 2), paste, sep = "") mat <- paste(mat, "csv", sep = ".") sapply(mat, function(el) { if (exists(el)) { DF <- read

Re: [R] Recurrence plot in package "tseriesChaos"

2006-10-25 Thread Gabor Grothendieck
In terms of non-R software there is a review of software packages in this JSS article: http://www.jstatsoft.org/v07/i09/JSS_055.pdf On 10/25/06, pucicu <[EMAIL PROTECTED]> wrote: > > Hello! > > As far as I know, there is not yet any package for R, which can compute the > RQA measures you mentione

Re: [R] How to start R with a file loaded?

2006-10-24 Thread Gabor Grothendieck
Read the ?Startup help file. On 10/24/06, Grateful Frog <[EMAIL PROTECTED]> wrote: > Hi! > > Thanks for your reply. > > Indeed, I'm on Linux. > > I tried to do what you said, but nothing happened. > > I made a file called First.R in my work directory. It contains this code > > .First<-function(){

Re: [R] extract certain values from a ts

2006-10-24 Thread Gabor Grothendieck
;- cumsum(r$lengths) idx.first <- idx.last - r$lengths + 1 # and the first and last times of each run being tt <- time(nhtemp) cbind(tt[idx.first], tt[idx.last]) On 10/24/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 10/24/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:

Re: [R] extract certain values from a ts

2006-10-24 Thread Gabor Grothendieck
On 10/24/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > # Consider the builtin in nhtemp "ts" series > # Then the runs below above and below the mean are > r <- rle(as.vector(nmtemp > mean(nhtemp))) > r > > # with the first and last indexes of ea

Re: [R] extract certain values from a ts

2006-10-24 Thread Gabor Grothendieck
# Consider the builtin in nhtemp "ts" series # Then the runs below above and below the mean are r <- rle(as.vector(nmtemp > mean(nhtemp))) r # with the first and last indexes of each # runs being given by: idx.last <- cumsum(r$lengths) idx.first <- idx.last - r$lengths + 1 # and the first and la

Re: [R] variables with dynamic names?

2006-10-24 Thread Gabor Grothendieck
Here is a third way to do the loop: rows <- match(substring(filenames, 1, 1), LETTERS) cols <- as.numeric(substring(filenames, 2, 3)) m[cbind(rows, cols)] <- sapply(DFs, F) On 10/24/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 10/24/06, Gabor Grothendieck <[EM

Re: [R] variables with dynamic names?

2006-10-24 Thread Gabor Grothendieck
On 10/24/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Try something like this (untested): > > # replace with your function that inputs a data frame and outputs a number > F <- function(x) length(x) > # replace with setwd to appropriate path > setwd("

Re: [R] variables with dynamic names?

2006-10-24 Thread Gabor Grothendieck
Try something like this (untested): # replace with your function that inputs a data frame and outputs a number F <- function(x) length(x) # replace with setwd to appropriate path setwd("/") filenames <- dir(pattern = "[.]csv$") # DFs is a list of data frames; names(DFs) will be the filenames DFs

Re: [R] how to create a vector with different categories in a simple way?

2006-10-24 Thread Gabor Grothendieck
Or as factors: blockrowfac <- gl(12, 4 * 16) blockcolfac <- gl(4, 16, 4 * 16 * 12) On 10/24/06, Petr Pikal <[EMAIL PROTECTED]> wrote: > Hi > > If you just want a specific sequences added to your data and you have > your data ordered as shown why not to use simply > > blockrow <- rep(1:12, each=64

Re: [R] R tcl/tk

2006-10-23 Thread Gabor Grothendieck
On 10/23/06, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 10/23/2006 10:11 AM, Alberto Monteiro wrote: > > This must be dumbest question ever asked, but... > > > > When I ask help.search("tcltk"), I get a reference to tcltk-package. > > > > When I ask help("tcltk-package"), I get "rtfm(s) in 'R_H

Re: [R] Recipe: Print a Color Sampler

2006-10-22 Thread Gabor Grothendieck
erfere with text > size cex. >text(xy[,1]+.5, xy[,2]+.2, i, col = colors(), cex = 0.7) >if (n > 0) > colors()[identify(xy, n = n, labels = colors(), plot = FALSE)] > } > # test > printColorSampler(0) > printColorSampler(1) > printColorSampler(pch

Re: [R] Recipe: Print a Color Sampler

2006-10-22 Thread Gabor Grothendieck
quot;, ylab = "") text(xy[,1]+.5, xy[,2]+.2, i, col = colors(), cex = 0.7) if (n > 0) colors()[identify(xy, n = n, labels = colors(), plot = FALSE)] } # test printColorSampler(0) printColorSampler(1) On 10/22/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: &g

Re: [R] Recipe: Print a Color Sampler

2006-10-22 Thread Gabor Grothendieck
I have removed the dots, vectorized it and changed the argument to the number points to be identified (default 0): getColorName <- function(colorNumber) colors()[colorNumber] printColorSampler <- function(n = 0) { i <- seq(colors()) k <- ceiling(sqrt(length(i))) xy <- cbind(floor(i/k)*2,

Re: [R] least median squares

2006-10-21 Thread Gabor Grothendieck
Try this using builtin data set BOD: medsq <- function(p, DF) median((p[1] + p[2] * DF[[1]] - DF[[2]])^2) init <- coef(lm(demand ~ Time, BOD)) optim(init, medsq, DF = BOD) library(MASS) lqs(demand ~ Time, BOD, method = "lms") On 10/22/06, Pedro Mardones <[EMAIL PROTECTED]> wrote: > Does anyon

Re: [R] how do I find the row index number, or row name, of a given value in a vector?

2006-10-21 Thread Gabor Grothendieck
?which.max On 10/21/06, tom soyer <[EMAIL PROTECTED]> wrote: > Hi, > > I noticed that max(x) returns the maximum value of a vector, but the > function doesn't give the user the option of retrieving the row index number > instead. If I used max(x) to find the maximum value of vector x, then is > th

Re: [R] Filling in a series

2006-10-21 Thread Gabor Grothendieck
Actually I think its last _observation_ carried forward. On 10/21/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > The zoo package has na.locf (last occurrernce carried foward) > for this purpose: > > > x > [1] 1 NA NA NA NA 2 NA NA NA NA 3 NA NA > > library(

Re: [R] Filling in a series

2006-10-21 Thread Gabor Grothendieck
The zoo package has na.locf (last occurrernce carried foward) for this purpose: > x [1] 1 NA NA NA NA 2 NA NA NA NA 3 NA NA > library(zoo) > na.locf(x) [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 On 10/21/06, Dennis Fisher <[EMAIL PROTECTED]> wrote: > Colleagues > > After reading in some clinical data, I

Re: [R] help with coef

2006-10-20 Thread Gabor Grothendieck
ich we see that the only difference in their internal representation is the addition of the names attribute. On 10/21/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On 10/21/06, tom soyer <[EMAIL PROTECTED]> wrote: > > Gabor, > > > > Thanks for the code exampl

Re: [R] help with coef

2006-10-20 Thread Gabor Grothendieck
or(a) > > is.vector(a) > [1] TRUE > > a[2] > [1] -7.2875 > > As you can see, although coef() returns a vector already, only after > as.vector(a) is used, did a[2] include the slope without the name of the > slope. Why is that, and what happened to the name of the slope

Re: [R] help with coef

2006-10-20 Thread Gabor Grothendieck
Using the builtin BOD data frame: as.vector(coef(lm(demand ~ Time, BOD)))[2] On 10/21/06, tom soyer <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to get R to return just the slope of a linear regression line, > but it seems that R has to return both the slope and the name of the slope. > For

Re: [R] x tick labels - sparse?

2006-10-20 Thread Gabor Grothendieck
27; > } # BTW, could this syntax be more succint? > axis(1, x, labels=xtickLabels) > > > I see only the first tick label (-100) and nothing else. > > Thanks, Darren > > > > > > On 8/11/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > Try this

Re: [R] R-2.4.0 and MS Vista OS - installing packages

2006-10-20 Thread Gabor Grothendieck
I run XP, not Vista, but have always installed R in c:\Program Files\R\R... and have never had a problem with the space in Program Files so I doubt that that would be the problem. On 20 Oct 2006 22:31:09 +0200, Peter Dalgaard <[EMAIL PROTECTED]> wrote: > "Charles Annis, P.E." <[EMAIL PROTECTED]>

Re: [R] Aggregate with multiple statistics?

2006-10-20 Thread Gabor Grothendieck
Try summaryBy in package doBy. e.g. using the built in dataset CO2: summaryBy(uptake ~ Plant, CO2, FUN = c(mean, min, max)) On 10/20/06, Jonathan Greenberg <[EMAIL PROTECTED]> wrote: > Is there a way to calculate, say, the mean, min and max using aggregate > using one line of code? Or do I need

Re: [R] summing elements in a list of functions

2006-10-20 Thread Gabor Grothendieck
ttt is a list of functions so each function in ttt is passed in turn to the anonymous function as argument f. On 10/20/06, James Foadi <[EMAIL PROTECTED]> wrote: > Many thanks to those who have answered my question. > Could I ask Gabor and Peter the meaning of: > > > sum(sapply(ttt,function(f) f(x

Re: [R] How to evaluate a Variable Name?

2006-10-20 Thread Gabor Grothendieck
Create a function f which, given Species s, calculates the residual sum of squares and then sapply it to all Species. In your case Species is the month and the levels of the Species correspond to the months 1:12 # calculate rss for Species s f <- function(s) { iris.lm <- lm(Sepal.Width ~ Sepal

Re: [R] summing elements in a list of functions

2006-10-20 Thread Gabor Grothendieck
Try this: L <- list(function(x) 1, function(x) x, sin, cos) sumL <- function(x) sum(sapply(L, function(f) f(x))) sumL(pi) # pi On 10/20/06, James Foadi <[EMAIL PROTECTED]> wrote: > Dear all, > I have looked for an answer for a couple of days, but can't come with any > solution. > > I have a set

Re: [R] Generating start values for nls

2006-10-19 Thread Gabor Grothendieck
This has been discussed a number of times in the past, e.g. see this thread: http://tolstoy.newcastle.edu.au/R/e2/help/06/09/0980.html On 10/20/06, Paul Brewin <[EMAIL PROTECTED]> wrote: > Dear R-listers, > > I would like to know if there is a way to programmatically generate > parameter start va

Re: [R] how to replace the second "-"

2006-10-19 Thread Gabor Grothendieck
Try this: sub("(-[^-]*)-", "\\10", c("1-1-1", "1-1-2", "1-2-1")) On 10/19/06, ronggui <[EMAIL PROTECTED]> wrote: > I have a string vector like these: > [1] "1-1-1" "1-1-2" "1-2-1" > > And I wanna replace the second "-" with "0", that is, I wanna get the result > like: [1] "1-101" "1-102" "1-201"

Re: [R] unique sets of factors

2006-10-19 Thread Gabor Grothendieck
Or since that messes up the values: u <- unique(t(apply(DF, 1, function(x) as.numeric(factor(x, levels = unique(x)) DF[rownames(u), ] On 10/19/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > If DF is a data frame containing the rows then: > > unique(t(apply(DF, 1, func

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