Re: [R] drawing outside a plot region

2006-02-05 Thread Gabor Grothendieck
Check xpd= in ?par On 2/5/06, ivo welch [EMAIL PROTECTED] wrote: Dear R wizards: First, thank you for all the responses to my earlier queries. Will keep me busy tomorrow morning. Can I add one graphics question to my ever changing set of bothering questions, please? plot( c(0,1), c(0,1)

Re: [R] Help In Sequence of Dates

2006-02-05 Thread Gabor Grothendieck
Try ?seq.Date On 2/6/06, Sumanta Basak [EMAIL PROTECTED] wrote: Dear R-users, First of all, I'm sorry if this is a simple question. I want a daily date series which will be a sequence. E.g. starting from 07/03/1962 to 12/03/1997. Thanks in advance. I want to paste this date series with

Re: [R] iteration history

2006-02-06 Thread Gabor Grothendieck
Check out: https://www.stat.math.ethz.ch/pipermail/r-devel/2006-January/036034.html On 2/6/06, Robert Mcfadden [EMAIL PROTECTED] wrote: Dear R Users I would like to use optim function to optimize a function. I read help but I couldn't find what I need: is it possible to get information after

Re: [R] novice questions about programming in R

2006-02-06 Thread Gabor Grothendieck
Try this: write.table(sprintf(%10.5f%10.5f, A, B), file = myfile.dat, quote = FALSE, row = FALSE, col = FALSE) plot(1:100, 1:100, log = xy) grid() # only if you want a grid ?plot.default has info on the log= argument. Use ? with the other commands to

Re: [R] plotting lines that break if data break

2006-02-07 Thread Gabor Grothendieck
It does break already. Try this: plot(1:10, c(1:5,NA,7:10), type = l) plot(c(1:5,NA,7:10), 1:10, type = l) On 2/7/06, Denis Chabot [EMAIL PROTECTED] wrote: Hi, Sometimes data series (not necessarily time series) suffer breaks where data were expected, but not collected. Often the regular

Re: [R] print formula on plot

2006-02-08 Thread Gabor Grothendieck
Also see ?bquote On 2/8/06, Thomas Steiner [EMAIL PROTECTED] wrote: I found it immediately after posting :( substitute is my friend: text(0.5,5,substitute(f[Sv] ==k*x^2, list(k=zf[1]))) __ R-help@stat.math.ethz.ch mailing list

Re: [R] Tranferring R results to word prosessors

2006-02-09 Thread Gabor Grothendieck
In Word use a fixed font such as Courier rather than a proportional font and it will look ok. On 2/9/06, Tom Backer Johnsen [EMAIL PROTECTED] wrote: I have just started looking at R, and are getting more and more irritated at myself for not having done that before. However, one of the things

Re: [R] main parameter in plot.default vs plot.formula

2006-02-09 Thread Gabor Grothendieck
I cannot explain it but I must have come across it since I noticed in various places in some of my code I have used, in terms of your example, the following: plot(y ~ x, main = as.expression(bquote(m[1] == .(a plot(y ~ x, main = list(bquote(m[1] == .(a both of which work as expected.

Re: [R] expand.grid without expanding

2006-02-10 Thread Gabor Grothendieck
I have made a few more improvements: expand.grid.id - function(id, ...) { vars - list(...) nv - length(vars) lims - sapply(vars,length) stopifnot(length(lims) 0, id = prod(lims), length(names(vars)) == nv) res - structure(vector(list,nv), .Names = names(vars)) if (nv 1) for(i in nv:2) {

Re: [R] Transferring R results to word prosessors

2006-02-10 Thread Gabor Grothendieck
Yes, the R2HTML route is probably the quickest. Its just one line of code (plus the call to load in R2HTML). Try this where iris is a data set built into R: library(R2HTML) HTML( iris, file(clipboard,w), append=FALSE ) Now paste the clipboard into Excel and from there into Word. (If you

Re: [R] main parameter in plot.default vs plot.formula

2006-02-10 Thread Gabor Grothendieck
On 2/9/06, Berton Gunter [EMAIL PROTECTED] wrote: Folks: R 2.2.0 on Windows. I find the following somewhat puzzling: a-1; x-0:1; y-x ## following works fine: plot(x,y ,main= bquote(n[1] == .(a) )) ## following produces an error: plot(y~x ,main= bquote(n[1] == .(a) )) Error in

Re: [R] Transferring R results to word prosessors

2006-02-10 Thread Gabor Grothendieck
On 10 Feb 2006 12:39:43 +0100, Peter Dalgaard [EMAIL PROTECTED] wrote: Gabor Grothendieck [EMAIL PROTECTED] writes: Yes, the R2HTML route is probably the quickest. Its just one line of code (plus the call to load in R2HTML). Try this where iris is a data set built into R: library

Re: [R] Transferring R results to word prosessors

2006-02-10 Thread Gabor Grothendieck
Given that this may very well be the most common use of the R2HTML package I wonder if the R2HTML package developer would be interested in providing an HTML2clip convenience wrapper as part of the R2HTML package like this: HTML2clip - function(x, file. = file(clipboard, w), append = FALSE,

Re: [R] Transferring R results to word prosessors

2006-02-10 Thread Gabor Grothendieck
On 2/10/06, Tom Backer Johnsen [EMAIL PROTECTED] wrote: At 17:10 09.02.2006 -0600, you wrote: Tom Backer Johnsen wrote: There has been an incredible number of responses in a short time, with a number of different suggestions. With hindsight, I must admit I have not been quite clear, so

Re: [R] Need frequency distribution for x,y coordinates

2006-02-11 Thread Gabor Grothendieck
Check out: http://addictedtor.free.fr/graphiques/graphcode.php?graph=116 On 2/11/06, mark shanks [EMAIL PROTECTED] wrote: Hi, I have a set of data in x,y coordinates across the range of -5 to 5 in each dimension. I would like to obtain the frequency distribution of the different points, and

Re: [R] srt --- slope text with function?

2006-02-11 Thread Gabor Grothendieck
On 2/11/06, Patricia J. Hawkins [EMAIL PROTECTED] wrote: iw == ivo welch [EMAIL PROTECTED] writes: iw * SUGGESTION: can we please offer the ?: operator ala C in iw addition to ifelse()? This would make R code prettier. R: if (condition) xxx else yyy if (condition) xxx else if (yyy) zzz

Re: [R] Plotting contour filled.contour in one graph

2006-02-12 Thread Gabor Grothendieck
Could you walk us through, in detail, what that graph is showing? On 2/12/06, Michael Prager [EMAIL PROTECTED] wrote: Besides the answers you already have, you might look at my 4D graph example (with code) on the R Graphics Gallery:

Re: [R] Fwd: Help scoring a matrix of item responses

2006-02-13 Thread Gabor Grothendieck
Assuming this test data: iris2 - round(iris[1:10, 1:4]) Try this: t(t(iris2) == c(iris2[1,])) + 0 On 2/13/06, Rick DeShon [EMAIL PROTECTED] wrote: Hi All. I'm new to R and trying to learn the data manipulation routines. At the moment, this is the one that has me stumped. Imagine n test

Re: [R] read.table

2006-02-13 Thread Gabor Grothendieck
You can do it manually by reading in the headers separately: headers - read.table(test, header = FALSE, nrow = 1, sep = ;, as.is = TRUE) read.table(test, header = FALSE, skip = 1, sep = ;, col.names = headers) On 2/13/06, Diethelm Wuertz [EMAIL PROTECTED] wrote: I have a file named test.csv

Re: [R] How to access values returned by R functions (to put into vectors)?

2006-02-13 Thread Gabor Grothendieck
Try this: coef(A) On 2/13/06, Quin Wills [EMAIL PROTECTED] wrote: The question is general for all functions, but here is a specific example - # For the logistic regression of the following correlated variables: C - c(457, 1371, 4113, 12339, 37017, 111051, 333153, 999459) E -

Re: [R] lattice: calling functions

2006-02-14 Thread Gabor Grothendieck
On 2/14/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 2/14/2006 8:56 AM, Wolfram Fischer wrote: I defined three functions: fun0 - function( x=1:5, y=1:5, ... ) xyplot( y ~ x, ... ) fun1 - function( x=1:5, y=1:5, ... ) fun2( y ~ x, ... ) fun2 - function( ... ) xyplot( ... ) The

Re: [R] Simple network diagram

2006-02-14 Thread Gabor Grothendieck
Check out ?stars On 2/14/06, Rainer Hahnekamp [EMAIL PROTECTED] wrote: Hello, I'm trying to create a simple network diagram like that on http://www.pauck.de/marco/photo/infrared/comparison_of_films/diagram3.gif. Unfortunately I've not yet found any function that could do this. I think

Re: [R] Setting intial path under windows to MyComputer in Interactive file browser

2006-02-15 Thread Gabor Grothendieck
On 2/15/06, Laetitia Marisa [EMAIL PROTECTED] wrote: Hello everyone, How can I specify in tcltk file browser the initial directory to MyComputer in Windows where Drives and Partition are accessible? And just a little question if anyone knows, is there a way to use the function choose.files

Re: [R] How to generate a report with graphics and tables?

2006-02-15 Thread Gabor Grothendieck
Read up about vignettes and Sweave which allows one to intersperse R code and latex. On 2/14/06, Edgar Urdas [EMAIL PROTECTED] wrote: how do i perform the stuff i just recorded?! __ R-help@stat.math.ethz.ch mailing list

Re: [R] Plotting two 3-dimensional time series in a 3 x 2 plot - alternatives to par(mfrow())

2006-02-15 Thread Gabor Grothendieck
plot.zoo takes the nc= argument which specifies the number of columns it uses, e.g. library(zoo) library(tseries) data(USeconomic) z - as.zoo(USeconomic) plot(z, nc = 2) On 2/15/06, Søren Højsgaard [EMAIL PROTECTED] wrote: I am trying to plot two 3-dimensional time series in one window (such

Re: [R] Group a dinamic number of vectors in a data.frame

2006-02-20 Thread Gabor Grothendieck
data.frame(OneVector, TwoVector, sapply(apropos(^N[0-9]*$), get, simplify = FALSE)) On 2/20/06, Daniele Medri [EMAIL PROTECTED] wrote: Hi all, I need to create a data.frame from a variable number of vectors. The number of these vectors could change so I need a dinamic way to group all in

Re: [R] Time on x-axis

2006-02-20 Thread Gabor Grothendieck
Try this: # test data tt - c(23:05:02, 23:10:02, 23:15:03, 23:20:03, 23:25:03, 23:30:03, 23:35:03, 23:40:03, 23:45:04, 23:50:04, 23:55:03, 23:55:03) x - c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) library(zoo)

Re: [R] glob2rx function not working

2006-02-20 Thread Gabor Grothendieck
Your expression is trying to sum a character vector containing the names of the variables that begin with ABC. Try this and try executing each portion of it to understand it better: ABC1 - ABC2 - 1 do.call(sum, lapply(apropos(glob2rx(ABC*)), get)) # 2 On 2/20/06, [EMAIL PROTECTED] [EMAIL

Re: [R] do.call, browser and traceback

2006-02-20 Thread Gabor Grothendieck
If f is long then you can get some savings like this: do.call(f, mtcars) # note: used f rather than f This does not solve the whole problem but its a step. On 2/20/06, hadley wickham [EMAIL PROTECTED] wrote: A problem that I've encountered when using do.call a lot is very large stack

Re: [R] How to sum values across multiple variables using a wildcard?

2006-02-20 Thread Gabor Grothendieck
See: ?rowSums On 2/20/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have a dataframe called data with 5 records (in rows) each of which has been scored on each of many variables (in columns). Five of the variables are named var1, var2, var3, var4, var5 using headers. The other

Re: [R] Number of Days Between Dates: Incorrect Results For Date Calucations.

2006-02-21 Thread Gabor Grothendieck
The results are actually correct if you consider daylight savings time. For example, try this and note that the difference is 23 hours, not 24 hours: as.POSIXct(2004-04-05) - as.POSIXct(2004-04-04) You can address this by either using Date or chron classes or adding the tz = GMT argument on

Re: [R] elements that appear only once

2006-02-22 Thread Gabor Grothendieck
I am not sure whether this is desirable but here is another way just in case: paste(setdiff(a, a[duplicated(a)])) You could replace paste with as.character if you prefer or could remove it entirely if you want the result as a factor. On 2/22/06, Robin Hankin [EMAIL PROTECTED] wrote: Hi. I

Re: [R] 2 barplots in the same graph

2006-02-22 Thread Gabor Grothendieck
The barplot solution already presented is probably what you want but just in case here is a zoo solution: library(zoo) z - merge(zoo(x2), zoo(x1, seq(x1)+.5)) plot(z, type = h, plot.type = single, col = 1:2, lwd = 5) Or a similar solution without zoo: plot(c(x1, x2) ~ c(seq(x1)+.5, seq(x2)),

Re: [R] converting character matrix to a dataframe

2006-02-23 Thread Gabor Grothendieck
You could do it directly like this: structure(split(ch.mat, col(ch.mat)), row.names = 1:nrow(ch.mat), .Names = 1:ncol(ch.mat), class = data.frame) On 2/23/06, John M. Miyamoto [EMAIL PROTECTED] wrote: Dear R-Help, Suppose I have a character matrix, e.g., (ch.mat -

Re: [R] importing data from BUGS format to R?

2006-02-23 Thread Gabor Grothendieck
Just source the file: source(mywinbugsfile.R) head(y) On 2/23/06, Jeffrey Moore [EMAIL PROTECTED] wrote: For those who use WinBUGS (or for those who are just familar with this format), I have a text file that looks like this (which is how R would export data if you used the structure

Re: [R] Summarize by two-column factor, retaining original factors

2006-02-24 Thread Gabor Grothendieck
Or even aggregate(DF[3:4], DF[1:2], sum) On 2/24/06, Marc Schwartz (via MN) [EMAIL PROTECTED] wrote: On Fri, 2006-02-24 at 08:18 -0800, Matt Crawford wrote: I am having trouble doing the following. I have a data.frame like this, where x and y are a variable that I want to do calculations

Re: [R] Sorting alphanumerically

2006-02-24 Thread Gabor Grothendieck
This was just discussed recently. Try: library(gtools) ?mixedorder On 2/24/06, mtb954 mtb954 [EMAIL PROTECTED] wrote: I'm trying to sort a DATAFRAME by a column ID that contains alphanumeric data. Specifically,ID contains integers all preceeded by the character g as in: g1, g6, g3, g19,

Re: [R] Time on x-axis

2006-02-24 Thread Gabor Grothendieck
the graph, without having to manually quote all the data items in the array? Thank you. Sangeetha = Original Message From Gabor Grothendieck [EMAIL PROTECTED] = Try this: # test data tt - c(23:05:02, 23:10:02, 23:15:03, 23:20:03, 23:25:03, 23:30:03, 23:35:03, 23:40:03, 23:45:04, 23:50

Re: [R] Time on x-axis

2006-02-24 Thread Gabor Grothendieck
And also, read 1. R News 4/1 help desk article on dates and times, 2. the zoo vignette: library(zoo) vignette(zoo) and 3. re-read the Introduction to R manual: http://cran.r-project.org/doc/manuals/R-intro.pdf On 2/24/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See: library(zoo

Re: [R] subtotal, submean, aggregate

2006-02-26 Thread Gabor Grothendieck
Create another variable that gives the run number and aggregate on both the habitat and run number removing the run number after aggregating: runno - cumsum(c(TRUE, diff(as.numeric(transect[,2])) !=0)) aggregate(transect[,1], list(obs = transect[,2], runno = runno), sum)[,-2] This does not give

Re: [R] subtotal, submean, aggregate

2006-02-26 Thread Gabor Grothendieck
was the key point... and then cumsum for polishing. Really great and also elegant (concise). I like it! Thanks a lot!!! Cheers, Patrick Gabor Grothendieck a écrit : Create another variable that gives the run number and aggregate on both the habitat and run number removing the run number

Re: [R] subtotal, submean, aggregate

2006-02-26 Thread Gabor Grothendieck
' observed come simply from the seed in rpois(length(habitats),2) It is unlikely it is the same on your and my computer... Cheers, Patrick Gabor Grothendieck a écrit : We are just comparing the difference to 0 so it does not matter if its positive or negative. All that matters is whether

Re: [R] Elegant way to express residual calculation in R?

2006-02-27 Thread Gabor Grothendieck
Try this: Xm - as.matrix(X) X.lm - lm(c(Xm) ~ factor(col(Xm)) + factor(row(Xm))) sum(resid(X.lm)^2) or if the idea was to do it without using lm try replacing your calculation of X.predicted with this: X.predicted - outer(operator.adjustment, machine.adjustment, +) + mean(mean(X)) On

Re: [R] Elegant way to express residual calculation in R?

2006-02-27 Thread Gabor Grothendieck
Here is one further idea: Xm - as.matrix(X) Xm. - scale(Xm, scale = FALSE) Xm.. - t(scale(t(tmp), scale = FALSE)) sum(Xm..^2) On 2/27/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: Xm - as.matrix(X) X.lm - lm(c(Xm) ~ factor(col(Xm)) + factor(row(Xm))) sum(resid(X.lm)^2

Re: [R] How to do it without for loops?

2006-02-28 Thread Gabor Grothendieck
Try: crossprod(x) or t(x) %*% x On 2/28/06, ronggui [EMAIL PROTECTED] wrote: This is the code: x-matrix(rnorm(20),5) y-list() for (i in seq(nrow(x))) y[[i]]-t(x[i,,drop=F])%*%x[i,,drop=F] y[[1]]+y[[2]]+y[[3]]+y[[4]]+y[[5]] How can I do it without using for loops? Thank you in advance!

Re: [R] Spearman correlation confidence interval

2006-02-28 Thread Gabor Grothendieck
You could use a bootstrapped confidence interval. You can find R code examples of using bootstrapped confidence intervals for correlation coefficients (and also an example of the alternative Fisher Transform) in the proto vignette: library(proto) vignette(proto) # see 3.2 On 2/28/06, McGehee,

Re: [R] vector math: calculating a rolling 12 row product?

2006-02-28 Thread Gabor Grothendieck
Use as.matrix to convert your data frame to a matrix and suppose we have this test data as a matrix: mat - matrix(seq(30*7), 30, 7) Then try this: library(zoo) mat2 - coredata(rapply(zoo(mat), 12, prod)) See: library(zoo) vignette(zoo) and the various zoo help files for more

Re: [R] subsetting a list of matrices

2006-02-28 Thread Gabor Grothendieck
Try this: lapply(z, [, 2:3, TRUE) On 2/28/06, Federico Calboli [EMAIL PROTECTED] wrote: Hi All, I have a list of matrices: x [,1] [,2] [1,]14 [2,]25 [3,]36 y [,1] [,2] [,3] [,4] [,5] [,6] [1,] 18 21 24 27 30 33 [2,] 19 22 25 28

Re: [R] relative referencing for filenames etc

2006-02-28 Thread Gabor Grothendieck
I think the idea of the prior respondents was that R_DATADIR would be set outside R and the application and just fetched from an environment variable inside the application so that the application is independent of it. If, in fact, your R code knows the data directory anyways, you could just do

Re: [R] repeated measures ANOVA

2006-02-28 Thread Gabor Grothendieck
Or use gl which directly forms a factor: group - gl(2, 5, 30) time - gl(3, 10) subject - gl(10, 1, 30) On 2/28/06, John Vokey [EMAIL PROTECTED] wrote: Christian, You need, first to factor() your factors in the data frame P.PA, and then denote the error-terms in aov correctly, as follows:

[R] Maximally independent variables

2006-02-28 Thread Gabor Grothendieck
Are there any R packages that relate to the following data reduction problem fo finding maximally independent variables? Currently what I am doing is solving the following minimax problem: Suppose we want to find the three maximally independent variables. From the full n by n correlation

Re: [R] Maximally independent variables

2006-02-28 Thread Gabor Grothendieck
(DF), 3) maxcor - function(x) max(as.vector(as.dist(cor(DF[,x] names(DF)[z[which.min(apply(z, 1, maxcor)),]] Gabor Grothendieck a écrit : Are there any R packages that relate to the following data reduction problem fo finding maximally independent variables? Currently what I am doing

Re: [R] linear lists, creation, insertion, deletion, traversal *someone?*

2006-03-01 Thread Gabor Grothendieck
Also check out ?append and the after= argument, in particular. On 3/1/06, Ben Bolker [EMAIL PROTECTED] wrote: Christian Hoffmann christian.hoffmann at wsl.ch writes: Hi, In a second try I will ask this list to give me some useful pointers. [There is a general problem with the list,

Re: [R] Maximally independent variables

2006-03-01 Thread Gabor Grothendieck
In case others are interested I did get a reply offlist regarding the escouf function in the pastecs package. See: library(pastecs) ?escouf Also see pages 47-52 of system.file(doc/pastecs.pdf, package = pastecs) (in French). On 3/1/06, Gabor Grothendieck [EMAIL PROTECTED] wrote

Re: [R] Selecting points

2006-03-01 Thread Gabor Grothendieck
I just asked a similar question yesterday except I was using correlation-based distances rather than Euclidean. Check out that thread: https://www.stat.math.ethz.ch/pipermail/r-help/2006-March/087782.html On 3/1/06, Matt Sakals [EMAIL PROTECTED] wrote: Dear all, I have point data from an

Re: [R] Optimization problem: selecting independent rows to maximize the mean

2006-03-01 Thread Gabor Grothendieck
Package lpSolve might help. On 3/1/06, Mark [EMAIL PROTECTED] wrote: Dear R community, I have a dataframe with 500,000 rows and 102 columns. The rows represent spatial polygons, some of which overlap others (i.e., not all rows are independent of each other). Given a particular row, the

Re: [R] Skip last NA's?

2006-03-02 Thread Gabor Grothendieck
Do you mean you wish to create a vector without the trailing NAs but with the others? If so, try: library(zoo) head(x, length(na.locf(x, rev = TRUE))) or library(zoo) head(x, length(na.locf(rev(x On 3/2/06, Robert Lundqvist [EMAIL PROTECTED] wrote: I wonder if anyone could help me find

Re: [R] Deparsing '...'

2006-03-02 Thread Gabor Grothendieck
Note that this still has the restriction that getdots must be used directly in the function which is to be deparsed so one could not, for example, put it in another utility function which deparses the function and extracts the first component. To do that you need to pass the frame: f -

Re: [R] Plotting FAQ?

2006-03-03 Thread Gabor Grothendieck
This might help: http://zoonek2.free.fr/UNIX/48_R/03.html On 3/3/06, Dan Bolser [EMAIL PROTECTED] wrote: Hi, Since I started to make some 'final' plots of my data I found that I have tons of questions related to 'the little things'. Rather than bother the list with all the questions (ahem),

Re: [R] what is scale function? Is it for variable transformation?

2006-03-05 Thread Gabor Grothendieck
It will change the coefficients from lm and therefore their t-values but it will not change the residuals, fitted values, R-squared, F statistic, etc. For example, try this: set.seed(1) x - 1:10 y - x + rnorm(10) lm0 - lm(y ~ x) # without scale lms - lm(y ~ scale(x)) # with scale

Re: [R] how to make plotmath expression work together with paste

2006-03-05 Thread Gabor Grothendieck
Try bquote (I may not have followed precisely what you want but hopefully this gives the idea). Note that you may need to use a few judiciously placed ~ and phantom(), as shown, in order to maintain syntax: plot(NA, xlim = c(0, 100), ylim = c(0, 100)) avar1 - 10 amath1 - bquote(slope ==

Re: [R] Interleaving elements of two vectors?

2006-03-05 Thread Gabor Grothendieck
Try this (note that your x and y do not have the same length and in this case the expression will recycle the shorter one and give a warning): z - c(rbind(x, y)) On 3/5/06, Ajay Narottam Shah [EMAIL PROTECTED] wrote: Suppose one has x - c(1, 2, 7, 9, 14) y - c(71, 72, 77)

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
If you make the levels the same does that give what you want: levs - c(LETTERS[1:6], 0) tmp1 - data.frame(col1 = factor(c(A, A, C, C, 0, 0), levs)) tmp2 - data.frame(col1 = factor(c(C, D, E, F), levs), col2 = 1:4) merge(tmp2, tmp1, all = TRUE, sort = FALSE) merge(tmp1, tmp2, all = TRUE, sort =

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
I think you will need to reorder it: out - merge( cbind(tmp1, seq = 1:nrow(tmp1)), tmp2, all.x = TRUE, sort = FALSE) out[out$seq, -2] On 3/6/06, Gregor Gorjanc [EMAIL PROTECTED] wrote: Gabor Grothendieck wrote: If you make the levels the same does that give what you want: levs - c

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
Actually we don't need sort = FALSE if we are reordering it anyways: out - merge( cbind(tmp1, seq = 1:nrow(tmp1)), tmp2, all.x = TRUE) out[out$seq, -2] On 3/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: I think you will need to reorder it: out - merge( cbind(tmp1, seq = 1:nrow(tmp1

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
On 3/6/06, Gregor Gorjanc [EMAIL PROTECTED] wrote: But I want to get out A NA A NA C 1 C 1 0 NA 0 NA That's what I get except for the rownames. Be sure to make the factor levels consistent. I have renamed the data frames tmp1a and tmp2a to distinguish them from the ones in your post

Re: [R] Length of a vector of POSIX objects reported incorrectly?

2006-03-06 Thread Gabor Grothendieck
POSIXlt stores its data in a 9 component structure so its length is always 9. See R News 4/1 help desk article for more info. To get what you are looking for try using POSIXct, not POSIXlt: length(as.POSIXct(times)) On 3/6/06, Jason Horn [EMAIL PROTECTED] wrote: I have a vector of POSIX

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
= TRUE) out - out[out$seq, -2] rownames(out) - rownames(tmp1a) out col1 col2 1A NA 2A NA 3C1 4C1 50 NA 60 NA On 3/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 3/6/06, Gregor Gorjanc [EMAIL PROTECTED] wrote: But I want to get out A NA A NA

Re: [R] Sort problem in merge()

2006-03-06 Thread Gabor Grothendieck
and reseting of rownames. Like the prior solution, it assumes that the elements of tmp2a$col1 are unique. On 3/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Sorry, I mixed up out and outa in the last post. Here it is correctly. levs - c(LETTERS[1:6], 0) tmp1a - data.frame(col1 = factor(c(A, A, C

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Gabor Grothendieck
The following are nearly identical to what others have already written but just in case: A - c(B) or A - B[,1] or if B were already a vector, b, in the first place, rather than a matrix: b - 1:2 A - b On 3/6/06, Michael [EMAIL PROTECTED] wrote: Hi all, I want to substract vector B from

Re: [R] Applying strptime() to a data set or array

2006-03-06 Thread Gabor Grothendieck
POSIXct, not POSIXlt, are used in data frame columns. See ?POSIXct where this is mentioned and try: A$date - as.POSIXct(A$date) Also be sure to read R News 4/1 for more about dates and times. On 3/6/06, Andrew Athan [EMAIL PROTECTED] wrote: I'm sure this is just the result of a basic

Re: [R] returning the largest element in an array/matrix?

2006-03-06 Thread Gabor Grothendieck
Try this: m - diag(4-abs(-4:4)) # test matrix wm - which.max(m) c(row(m)[wm], col(m)[wm]) # c(5,5) On 3/6/06, Michael [EMAIL PROTECTED] wrote: Hi all, I want to use which.max to identify the maximum in a 2D array/matrix and I want argmin and return the row and column indices. But

Re: [R] (newbie) Accessing the pieces of a 'by' object

2006-03-07 Thread Gabor Grothendieck
Try this: iris.by - do.call(rbind, by(iris[,-5], iris[,5,drop=FALSE],colSums)) do.call(rbind, iris.by) On 3/7/06, Vivek Satsangi [EMAIL PROTECTED] wrote: Folks, I know that I can do the following using a loop. That's been a lot easier for me to write and understand. But I am trying to force

Re: [R] (newbie) Accessing the pieces of a 'by' object

2006-03-07 Thread Gabor Grothendieck
Sorry, that should be: iris.by - by(iris[,-5], iris[,5,drop=FALSE],colSums) do.call(rbind, iris.by) On 3/7/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: iris.by - do.call(rbind, by(iris[,-5], iris[,5,drop=FALSE],colSums)) do.call(rbind, iris.by) On 3/7/06, Vivek Satsangi [EMAIL

Re: [R] POSIX time zone codes

2006-03-07 Thread Gabor Grothendieck
Only and GMT are really guaranteed to work on all systems since the time zones are system dependent but try: CDT6CST and see if that works on your system. On 3/7/06, Jason Horn [EMAIL PROTECTED] wrote: Whoops, [EDIT] as.POSIX(x, tz=UTC) ... works, gives UTC times as.POSIX(x, tz=EST) ...

Re: [R] POSIX time zone codes

2006-03-07 Thread Gabor Grothendieck
systems are. Thanks! On Mar 7, 2006, at 9:00 AM, Gabor Grothendieck wrote: Only and GMT are really guaranteed to work on all systems since the time zones are system dependent but try: CDT6CST and see if that works on your system. On 3/7/06, Jason Horn [EMAIL PROTECTED] wrote

Re: [R] (newbie) Accessing the pieces of a 'by' object

2006-03-07 Thread Gabor Grothendieck
Another solution (ex #3) is to return a data frame with at least two columns and then remove the dummy one using drop = FALSE: # ex #1. error iris.by - by(iris, iris[,5, drop = FALSE], length) do.call(rbind, iris.by) # ex #2. ok but no column heading iris.by - by(iris, iris[,5, drop=FALSE],

Re: [R] How to change time zones?

2006-03-07 Thread Gabor Grothendieck
POSIX objects are UTC internally but can be displayed with respect to other time zones. By the way, do you really need time zones in the first place? Read R News 4/1 help desk article which will help you determine which date/time class is suitable for your application and also has a table of

Re: [R] returning the largest element in an array/matrix?

2006-03-07 Thread Gabor Grothendieck
I agree that that is the best solution although not to the question as stated which said: I want to use which.max On 3/7/06, Michael [EMAIL PROTECTED] wrote: I think this is the best solution! Thank you! On 3/7/06, Petr Pikal [EMAIL PROTECTED] wrote: Hi If you do not insist on

Re: [R] Making an S3 object act like a data.frame

2006-03-07 Thread Gabor Grothendieck
If your class is a subclass of data.frame then I think it ought to be a special sort of data frame so all you need to do is the following in which case you get subscripting for free by inheritance: # constructor myobj - function(...) structure(data.frame(...), class = c(myobj,

Re: [R] Making an S3 object act like a data.frame

2006-03-07 Thread Gabor Grothendieck
Just to get something reproducible lets assume the objects of class myobj each consists of a one-element list that contains a data frame. Then try this: # constructor myobj - function(...) structure(list(value = data.frame(...)), class = myobj) $.myobj - function(obj, x) .subset2(obj,

Re: [R] Making an S3 object act like a data.frame

2006-03-07 Thread Gabor Grothendieck
On 3/7/06, hadley wickham [EMAIL PROTECTED] wrote: Just to get something reproducible lets assume the objects of class myobj each consists of a one-element list that contains a data frame. Then try this: Thanks for that - it makes sense. Every time I try to use inheritance in R, I

Re: [R] Making an S3 object act like a data.frame

2006-03-07 Thread Gabor Grothendieck
The problem is that x[[1]] in the definition of as.data.frame.myobj invokes [[.myobj whereas we want to extract the first element of the list in the internal representation of x -- which is not the same. Try this instead: as.data.frame.myobj - function(x) .subset2(x, 1) lm(y ~ x, z) Call:

Re: [R] info() function?

2006-03-08 Thread Gabor Grothendieck
Another possibility is eapply where I have used naCount from Henrik's solution: prop - function(x) list(class = data.class(x), dim = dim(x), size = object.size(x), NAs = naCount(x)) do.call(rbind, eapply(.GlobalEnv, prop)) On 3/8/06, Henrik Bengtsson [EMAIL PROTECTED] wrote: library(R.oo)

Re: [R] data import problem

2006-03-08 Thread Gabor Grothendieck
Check out: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/52957.html for a similar problem. On 3/8/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear All, I'm trying to read a text data file that contains several records separated by a blank line. Each record starts with a row that

Re: [R] How to do it without for loops?

2006-03-08 Thread Gabor Grothendieck
- matrix(unlist(matlis), 4, length(matlis)) S1 - matrix(rowSums(S), 2, 2) The code works ,but I want to ask if there is any other more better ways to do it? It seems that this kind of computation is quite common. 2006/2/28, Gabor Grothendieck [EMAIL PROTECTED]: Try: crossprod(x

Re: [R] How to do it without for loops?

2006-03-08 Thread Gabor Grothendieck
arguments one could have done this instead of the two lines involving result above: do.call(psum, mm) # if psum analog to pmax were available do.call(+, mm) # if + allowed 2 arguments On 3/8/06, Thomas Lumley [EMAIL PROTECTED] wrote: On Wed, 8 Mar 2006, Gabor Grothendieck wrote

Re: [R] Debugging a program written in the R language

2006-03-08 Thread Gabor Grothendieck
On 3/8/06, Thomas L Jones [EMAIL PROTECTED] wrote: From Tom: The subject is debugging a program written in the R language,under Windows. (Sorry, but I do not know either the Apple OS or *nix.) A computer program will usually not work on the first try, if only because of the risk of typos.

Re: [R] Making an S3 object act like a data.frame

2006-03-09 Thread Gabor Grothendieck
Can you create a small self contained reproducible example that does not work? The reproducible example I provided earlier on this thread worked fine. One idea is to check what the class is of the output of your .GGobiCall. If it were of class ggobiDataset then it would in turn be calling

Re: [R] Making an S3 object act like a data.frame

2006-03-09 Thread Gabor Grothendieck
I think the problem is that your ggobiDataset objects are also data.frame objects. They must NOT be. For example, note how the following example fails once we add data.frame to the class vector of x: The reason is that ordinary inheritance is not used by model.frame; rather, it uses

Re: [R] creating new vector

2006-03-10 Thread Gabor Grothendieck
Try this: x - 1:20 c(rowsum(x, gl(length(x), 5, length(x))) If the length of x is not a mulitple of 5 there will be a stub at the end containing the sum of less than 5 elements. On 3/10/06, Amir Safari [EMAIL PROTECTED] wrote: Hi R Users, I don't know how much is difficult my problem

Re: [R] Plot.date and legends

2006-03-10 Thread Gabor Grothendieck
The argument to legend should be of class date, not character. Also please post reproducible code including definitions of all variables used and library calls. On 3/10/06, Bryan Sykes [EMAIL PROTECTED] wrote: Hi: I'm trying to plot dates on the x-axis of a code, but the legend is not being

Re: [R] Linux editor like WinEdt?

2006-03-10 Thread Gabor Grothendieck
Check out: http://www.sciviews.org/_rgui/projects/Editors.html http://ess.r-project.org On 3/10/06, Ana Patricia Martins [EMAIL PROTECTED] wrote: Hi to all, I initiate in R - Linux and I've some problems to find an editor with R interface as like RWinEdt for WinEdt. Anyone know one?

Re: [R] Linux editor like WinEdt?

2006-03-10 Thread Gabor Grothendieck
Is anyone using vi for R? I use vim (actually gvim) on Windows XP. It has syntax highlighting for R, tex and many other formats. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!

Re: [R] difference between 2 dates: IN MONTHS the way Mothers compute it

2006-03-10 Thread Gabor Grothendieck
zoo has the yearmon class which will convert a date to a year + 0/12 to 11/12 to represent the month, disregarding the day, so: library(zoo) 12 * as.numeric((as.yearmon(2006-03-07) - as.yearmon(2006-02-06))) # 1 On 3/10/06, Smith, Phil [EMAIL PROTECTED] wrote: Hi R-people: I need a function

Re: [R] difference between 2 dates: IN MONTHS the way Motherscompute it

2006-03-10 Thread Gabor Grothendieck
to change the date string to a Date class before you call as.yearmon? i.e. 12* as.numeric(as.yearmon(as.Date(2006-03-07))-as.yearmon(as.Date(2006-02-07))) That returns 1 in Windows XP Regards Francisco From: Gabor Grothendieck [EMAIL PROTECTED] To: Smith, Phil [EMAIL PROTECTED] CC: r-help

Re: [R] A question on plot

2006-03-11 Thread Gabor Grothendieck
Try RSiteSearch(shade area under curve) On 3/11/06, Albert Sorribas [EMAIL PROTECTED] wrote: I'm trying to obtain a plot of given function, say the density of a normal, in which I could indicate the area under the curve between two points (a,b). I.e. the P(aXb). Could anyone indicate me

Re: [R] Conditional operation on columns in data frame

2006-03-11 Thread Gabor Grothendieck
y is of class matrix and $ is used for data frames, not matrices. Use y[,x1] or else create a data frame, data.frame(x1, x2, x3). On 3/11/06, Sander Oom [EMAIL PROTECTED] wrote: Dear R-users, I need to do an SQL like, conditional, operation on a data frame using an ifelse construction.

Re: [R] summary tables with tapply

2006-03-11 Thread Gabor Grothendieck
I am not sure I understand the question but is the situation that you have two vectors: x and y such that for each level of y x is constant so that for each level of y you want to find that value of x? In that case: x - c(A, A, A, B, B) y - c(1,1,2,3,3) unique(data.frame(x,y)) or tapply(x, y,

Re: [R] coloring leaves in a hclust or dendrogram plot [solved]

2006-03-11 Thread Gabor Grothendieck
Where does one find A2Rplot that is called in that example? A2R does not appear to be on CRAN. I did find this: http://addictedtor.free.fr/Download/A2R.zip which is a zip file containing some R code but it is not a package, which the line library(A2R) seems to need, and it does not include

<    9   10   11   12   13   14   15   16   17   18   >