Re: [R] as.data.frame(cbind()) transforming numeric to factor?

2006-08-18 Thread Gabor Grothendieck
In R version 2.4.0 Under development (unstable) (2006-08-08 r38825) one can do this: as.data.frame(cbind(x.1,x.2),stringsAsFactors = FALSE) On 8/18/06, Tom Boonen [EMAIL PROTECTED] wrote: Dear List, why does as.data.frame(cbind()) transform numeric variables to factors, once one of the

Re: [R] Boxplot Help

2006-08-18 Thread Gabor Grothendieck
Try this: result - boxplot(Petal.Length ~ Species, iris) if (length(result$out)) text(result$group, result$out, match(result$out, iris$Petal.Length), pos = 4, col = red) If the outliers can be non-unique then match is not enough. In that case assume that the nth occurrence of any value in

Re: [R] Boxplot Help

2006-08-18 Thread Gabor Grothendieck
, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: result - boxplot(Petal.Length ~ Species, iris) if (length(result$out)) text(result$group, result$out, match(result$out, iris$Petal.Length), pos = 4, col = red) If the outliers can be non-unique then match is not enough. In that case

Re: [R] string-to-number SUMMARY

2006-08-19 Thread Gabor Grothendieck
On 8/19/06, Charles Annis, P.E. [EMAIL PROTECTED] wrote: Much gratitude to Professor Ripley, Peter Dalgaard, Marc Schwartz, and Roger Bivand. __ Roger Bivand wrote that ... strsplit() returns a list - one list component for each repeated.measures.columns element. Just pick

Re: [R] Query: how to modify the plot of acf

2006-08-19 Thread Gabor Grothendieck
Try this. It uses Matthias' trick for getting rid of lag 1. The it defines a new local plot.acf and then defines a new local plot.acf which # test data set.seed(1) x - rnorm(1000) # run acf x.acf - acf(x) # remove lag 0 -- see Matthias' post x.acf$acf[1] - NA # plot with custom x axis

Re: [R] question about cbind()

2006-08-19 Thread Gabor Grothendieck
First 4 colums of builtin data frame anscombe as a matrix: as.matrix(anscombe[1:4]) On 8/19/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear all, I have a question about how to get a matrix by combining a large number of columns from a data file. Suppose I read a file which have 1000

Re: [R] unquoting

2006-08-20 Thread Gabor Grothendieck
Try these get(names(AF)[2]) AF[Second] # this one different than the rest AF[[Second]] AF[, Second] AF$Second On 8/20/06, Murray Jorgensen [EMAIL PROTECTED] wrote: I would like a function to strip quotes off character strings. I should work like this: A - matrix(1:6, nrow =

Re: [R] Grid Points

2006-08-20 Thread Gabor Grothendieck
Try this. gl(2,50) is such that the first 50 points are series 1 and the second 50 points are series 2. The scales= argument defines the positions of the tick marks and the xlim= argument defines the x axis limits. The layout puts the panels on top of each other rather than side by side. strip

Re: [R] split a y-axis to show data on different scales

2006-08-20 Thread Gabor Grothendieck
Look at oma= and mar= parameters to par for controlling the space when using mfrow=. e.g. opar - par(oma = c(6, 0, 5, 0), mar = c(0, 5.1, 0, 2.1), mfrow = c(2,2)) for(i in 1:4) plot(1:10) par(opar) On 8/20/06, Anupam Tyagi [EMAIL PROTECTED] wrote: I think information can be enhanced by using

Re: [R] Grid Points

2006-08-20 Thread Gabor Grothendieck
the same scale of grid.points from one panel to next even if the scale of the data changes? For example: c(seq(601:700),seq(6510,7000, by=10)) ~ seq(601:700) | gl(2,50). --- Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this. gl(2,50) is such that the first 50 points are series 1

Re: [R] How to share variables

2006-08-21 Thread Gabor Grothendieck
On 8/21/06, Sergio Martino [EMAIL PROTECTED] wrote: Thanks for your fast replay and sorry for my late one (I was on holidays) The structure I would like to emulate (the fortran common statement) is a different from what you are describing. The examples scoping and the links to OO programming

Re: [R] How to share variables

2006-08-21 Thread Gabor Grothendieck
On 8/21/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 8/21/06, Sergio Martino [EMAIL PROTECTED] wrote: Thanks for your fast replay and sorry for my late one (I was on holidays) The structure I would like to emulate (the fortran common statement) is a different from what you

[R] R-packages posting guide (was: Re: [R-pkgs] New version of glmmML)

2006-08-21 Thread Gabor Grothendieck
Maybe an R-packages posting guide with an example and an automatic append of a one or two line summary at the end of each article posted - as already done on r-help. On 8/21/06, Martin Maechler [EMAIL PROTECTED] wrote: Hi Göran, GB == Göran Broström [EMAIL PROTECTED] on Mon, 21 Aug 2006

Re: [R] Dataframe modification

2006-08-21 Thread Gabor Grothendieck
Here are two solutions: A - 1:8 B - c(1,2,4,7,8) C - c(5,3,10,12,17) # solution 1 - assignment with subscripting DF - data.frame(A, B = A, C = 0) DF[A %in% B, C] - C # solution 2 - merge DF - with(merge(data.frame(A), data.frame(B, C), by = 1, all = TRUE), data.frame(A, B = A, C =

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread Gabor Grothendieck
Its not part of state.x77. Its a completely separate variable. Try ls(package:datasets) and notice its in the list or try ?state.region and note that its a variable in datasets. On 8/21/06, John Kane [EMAIL PROTECTED] wrote: I was looking ?aggregate and ran the first example

Re: [R] Dataframe modification

2006-08-21 Thread Gabor Grothendieck
this. Column A is something like this A - c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7,8,9,10,11,12) i.e it repeats. Rest all is same. How can I modify your solution to take care of this issue. Thanx in advance. Sachin Gabor Grothendieck [EMAIL PROTECTED] wrote: Here

Re: [R] question about 'coef' method and fitted_value calculation

2006-08-21 Thread Gabor Grothendieck
Try library(MASS) y.lmr - lm.ridge(y ~., longley) coefs - print(y.lmr) On 8/21/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear all, I am trying to calculate the fitted values using a ridge model (lm.ridge(), MASS library). Since the predict() does not work for lm.ridge object, I want

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread Gabor Grothendieck
, simplicity and comprehensiveness (there is no example of aggregate.data.frame). On 8/21/06, John Kane [EMAIL PROTECTED] wrote: --- Gabor Grothendieck [EMAIL PROTECTED] wrote: Its not part of state.x77. Its a completely separate variable. Try ls(package:datasets) and notice its in the list

Re: [R] How to share variables

2006-08-22 Thread Gabor Grothendieck
On 8/22/06, Sergio Martino [EMAIL PROTECTED] wrote: Hi Thanks again. I hope not to waste to much of your time. I delete some lines of your answer Each time myfun is run a new environment is created to hold its local variables. The parent of that environment is e in this example by

Re: [R] listing a sequence of vectors in a matrix

2006-08-22 Thread Gabor Grothendieck
Here are two solutions. seq(length = ...) instead of just seq(...) is so that v can possibly contain zeros. # data v - 3:5 # solution 1 - rbind/lapply f - function(n) { s = seq(length = n) replace(rep(NA, max(v)), s, s) } do.call(rbind, lapply(v, f)) # solution 2 - loop mat -

Re: [R] listing a sequence of vectors in a matrix

2006-08-22 Thread Gabor Grothendieck
,]123 NA NA [3,]1234 NA [4,]1234 NA [5,]1234 NA [6,]12345 [7,]12345 [8,] NA NA NA NA NA rksh On 22 Aug 2006, at 13:55, Gabor Grothendieck wrote: Here are two

Re: [R] Successive subsets from a vector?

2006-08-22 Thread Gabor Grothendieck
Here is a solution that uses gsub with a negative lookahead perl-style regexp to do it: VECTOR - c(1,4,2,6,5,0,11,10,4,3,6,8,6) e - ([[:digit:]]+),(?=([[:digit:]]+),([[:digit:]]+),([[:digit:]]+),([[:digit:]]+)) out - gsub(e, \\1\\2\\3\\4\\5 , paste(VECTOR, collapse = ,), perl = TRUE)

Re: [R] Selection on dataframe based on order of rows

2006-08-22 Thread Gabor Grothendieck
Try this: # data DF - structure(list(id = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4), date = structure(c(8, 9, 10, 11, 3, 7, 8, 10, 4, 1, 2, 3, 8, 9, 10, 11, 3, 5, 6), .Label = c(01/07/2006, 01/08/2006, 01/09/2006, 02/09/2006, 03/09/2006, 06/09/2006, 11/08/2006, 22/08/2006,

Re: [R] two density curves in one plot?

2006-08-23 Thread Gabor Grothendieck
With lattice graphics: library(lattice) d1 - rnorm(100) d2 - runif(100) densityplot(~ d1 + d2, auto.key = TRUE) On 8/23/06, Antje [EMAIL PROTECTED] wrote: Hello, I was wondering if I can plot two curves I get from density(data) into one plot. I want to compare both. With the following

Re: [R] editing .Internal functions

2006-08-23 Thread Gabor Grothendieck
You could also look at p.arrows in sfsmisc package which is entirely in R. On 8/23/06, B. Chasco [EMAIL PROTECTED] wrote: There is a function called arrows() which is an .Internal function. How difficult is it to modify that function to return the xy coordinates for the line segments that

Re: [R] help with pasting + expressions?

2006-08-23 Thread Gabor Grothendieck
Try bquote: y.hat - sigma.hat - 1.1 plot(1) lab - bquote(hat(y) == .(y.hat) * , ~ hat(sigma)^2 == .(sigma.hat)) text(1, 1, lab, pos = 4) On 8/23/06, Jeff D. Hamann [EMAIL PROTECTED] wrote: I can't believe I'm having such a hard time with this and I haven't been able to find out how to solve

Re: [R] Intro to Programming R Book

2006-08-24 Thread Gabor Grothendieck
There is some online material at: http://zoonek2.free.fr/UNIX/48_R/all.html http://pj.freefaculty.org/R/statsRus.html On 8/24/06, Raphael Fraser [EMAIL PROTECTED] wrote: I am new to R and am looking for a book that can help in learning to program in R. I have looked at the R website suggested

Re: [R] [Rd] reshape scaling with large numbers of times/rows

2006-08-24 Thread Gabor Grothendieck
On 8/24/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here is one more solution . It uses the reshape package. Its faster than using reshape but not as fast as xtabs; however, it is quite simple -- just one line and if that matters it might be useful: library(reshape) system.time(w4

Re: [R] Why are lagged correlations typically negative?

2006-08-24 Thread Gabor Grothendieck
The covariance has the same sign as the correlation so lets calculate the sample covariance of the vector T1 = (X,Y) with T2 = (Y,Z) where we ignored the third component in each case due to use=complete. cov(T1, T2) = XY + YZ - (X+Y)/2 * (Y+Z)/2 X, Y and Z are random variables so we take

Re: [R] xyplot tick marks and line thickness

2006-08-24 Thread Gabor Grothendieck
Look through the output of trellis.par.get() for the right parameters or when all else fails use grid (which we use below for the box around the panel since I could not locate the parameter): library(lattice) library(grid) x - 1:12 g - gl(3,4) lwd - 3 xyplot(x ~ x | g, type = l, lwd = lwd,

Re: [R] Lattice symbol size and legend margins

2006-08-24 Thread Gabor Grothendieck
Try par.settings= You can find examples via: RSiteSearch(par.settings) . On 8/24/06, Gattuso, Jean-Pierre [EMAIL PROTECTED] wrote: Hi: I am using the following command: xyplot(dat6$CO3*1e6 ~ dat6$irradiance, data=dat6, group=ref, xlab=list(label=expression(paste(Irradiance (, mu,

Re: [R] xyplot tick marks and line thickness

2006-08-24 Thread Gabor Grothendieck
Here is a way to automate finding the lwd= parameters. library(lattice) # test data x - 1:12 g - gl(3, 4) lwd - 3 # set parameters par - trellis.par.get() par - lapply(par, function(x) replace(x, names(x) == lwd, lwd)) xyplot(x ~ x | g, type = l, par.settings = par) On 8/24/06, Chuck Cleland

Re: [R] xyplot tick marks and line thickness

2006-08-24 Thread Gabor Grothendieck
That should read finding and setting. Chuck already showed how to find them. On 8/24/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here is a way to automate finding the lwd= parameters. library(lattice) # test data x - 1:12 g - gl(3, 4) lwd - 3 # set parameters par - trellis.par.get

Re: [R] extremely slow recursion in R?

2006-08-24 Thread Gabor Grothendieck
There was some discussion here: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/73646.html On 8/24/06, Jason Liao [EMAIL PROTECTED] wrote: I recently coded a recursion algorithm in R and ir ran a few days without returning any result. So I decided to try a simple case of computing binomial

Re: [R] generating an expression for a formula automatically

2006-08-24 Thread Gabor Grothendieck
Use as.formula to convert the character string to an object of class formula and note that we want to set the formula's environment appropriately: fit.main - function(resp, x, env = parent.frame()) { fo - as.formula(paste(y, ~, paste(x, collapse = +))) environment(fo) - env

Re: [R] Using a 'for' loop : there should be a better way in R

2006-08-24 Thread Gabor Grothendieck
Use cbind to create a two column matrix, mat, and multiply that by the appropriate inflation factors. Then use rowsum to sum the rows according to the id grouping factor. inf.fac - list(year1 = 1, year2 = 5, year3 = 10) mat - cbind(s1 = df1$cat1 + df1$cat2, s2 = df1$cat3 + df1$cat4) rowsum(mat *

Re: [R] Check values in colums matrix

2006-08-24 Thread Gabor Grothendieck
Try sd(obj.tr) which will give a vector of standard deviations, one per column. A column's entry will be zero if and only if all values in the column are the same. On 8/24/06, Muhammad Subianto [EMAIL PROTECTED] wrote: Dear all, I apologize if my question is quite simple. I have a dataset (20

Re: [R] Check values in colums matrix

2006-08-24 Thread Gabor Grothendieck
Non-Clinical Statistics South San Francisco, CA -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck Sent: Thursday, August 24, 2006 4:28 PM To: Muhammad Subianto Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Check values

Re: [R] generating an expression for a formula automatically

2006-08-25 Thread Gabor Grothendieck
Try this and note we must pay attention to which environment the expression is evaluated in. fit.sum - function(x, env = parent.frame()) eval(parse(text = paste(x, collapse = +)), env = env) # test x1 - x2 - 1 fit.sum(c(x1,x2)) On 8/25/06, Maria Montez [EMAIL PROTECTED] wrote: Thank you

Re: [R] Quickie : unload library

2006-08-25 Thread Gabor Grothendieck
You likely want the answer that Sarah has already given but in addition you might also want to look at the thread below, the point being that detaching a package still leaves portions: https://www.stat.math.ethz.ch/pipermail/r-help/2006-July/109056.html On 8/25/06, Sarah Goslee [EMAIL

Re: [R] Modifying the embed-results

2006-08-26 Thread Gabor Grothendieck
You can replace the for with lapply like this: VECTOR - c(0, 3, 6, 3, 11, 2, 11, 4, 3, 4, 7, 7, 6, 4, 8) f - function(i) unique(tail(VECTOR, length(VECTOR)-i+1))[1:5] out - do.call(rbind, lapply(seq(along = VECTOR), f)) na.omit(rbind(rep(NA, 5), out)) Note that a matrix with zero rows is

Re: [R] How to iteratively extract elements out of a list

2006-08-26 Thread Gabor Grothendieck
On 8/26/06, Patrick Connolly [EMAIL PROTECTED] wrote: On Sat, 26-Aug-2006 at 09:57AM +0100, Patrick Burns wrote: | sub.m - lapply(m, function(x)x[x2]) | sub.m | [[1]] | [1] 3 4 | | [[2]] | [1] 4 5 | | [[3]] | [1] 4 | | sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))] |

Re: [R] Modifying the embed-results

2006-08-27 Thread Gabor Grothendieck
On 8/27/06, Atte Tenkanen [EMAIL PROTECTED] wrote: Thanks! I see, that do.call-function is used often in R-algorithms... Looking over some extra do.call-examples seems useful. This tail-function is also new for me. Is there some reason to use seq(along = VECTOR) instead of

Re: [R] Can R compute the expected value of a random variable?

2006-08-27 Thread Gabor Grothendieck
On 8/27/06, Paul Smith [EMAIL PROTECTED] wrote: On 8/26/06, Mike Nielsen [EMAIL PROTECTED] wrote: Yes. Can R compute the expected value of a random variable? Mike: thank you very much indeed for your so insightful and complete answer. Answers are often in proportion to the questions

Re: [R] Merge list to list - as matrix

2006-08-28 Thread Gabor Grothendieck
Here are two ways: 1. use indexes: lapply(seq(along = x), function(i) cbind(x[[i]], y[[i]])) 2. use mapply: mapply(cbind, x, y, SIMPLIFY = FALSE) On 8/28/06, Muhammad Subianto [EMAIL PROTECTED] wrote: Dear all, I have dataset x - list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5,

Re: [R] How to change the color of Plot area.

2006-08-28 Thread Gabor Grothendieck
Try: x - 1:10 # test data plot(x ~ x, type = n) u - par(usr) rect(u[1], u[3], u[2], u[4], col = grey, border = red) points(x ~ x) On 8/28/06, Arun Kumar Saha [EMAIL PROTECTED] wrote: Dear all R users, Is there any effective way to change the body color of any plot? I am aware of the function

Re: [R] screen resolution effects on graphics

2006-08-28 Thread Gabor Grothendieck
1. Put the code from www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0721.mspx into, say, \bin\displayconfiguration.vbs, and then from R do this: as.numeric(gsub(.* , , grep(resolution, shell('cscript \\bin\\displayconfiguration.vbs', intern = TRUE), value = TRUE))) or we

Re: [R] Help on function adf.test

2006-08-28 Thread Gabor Grothendieck
Put your time series into a ts or zoo object. Now using EuStockMarkets which is builtin data set in R. (You might want to use align = right in rollapply.) library(tseries) library(zoo) eu91 - window(EuStockMarkets, end = 1992) # use portion for test data eu91.p.value - rollapply(eu91, 61,

Re: [R] Remove empty list from list

2006-08-28 Thread Gabor Grothendieck
example: x - list(matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4),matrix(1:20, 5, 4)) y - list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1),c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1),c(-1, -1, -1, -1, -1)) ## Thanks to Gabor Grothendieck for this trick. ## SIMPLIFY? SIMPLIFY

Re: [R] screen resolution effects on graphics

2006-08-28 Thread Gabor Grothendieck
patience. Charles Annis, P.E. [EMAIL PROTECTED] phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck Sent: Monday, August 28, 2006 11:39 AM To: [EMAIL

Re: [R] screen resolution effects on graphics

2006-08-28 Thread Gabor Grothendieck
Sorry, that still woudl not be good enough. Try this: as.numeric(sub(^[^:]*:, , grep(resolution, shell('cscript \\bin\\displayconfiguration.vbs', intern = TRUE), value = TRUE))) On 8/28/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: One other idea. Replace gsub with sub and see

Re: [R] screen resolution effects on graphics

2006-08-28 Thread Gabor Grothendieck
One other idea. Replace gsub with sub and see if that helps. Maybe the output from the video driver has spaces in it. On 8/28/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: This is what happens when I run it in R 2.3.1: as.numeric(gsub(.* , , grep(resolution, + shell('cscript \\bin

Re: [R] screen resolution effects on graphics

2006-08-28 Thread Gabor Grothendieck
- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck Sent: Monday, August 28, 2006 2:21 PM To: [EMAIL PROTECTED] Cc: r-help Subject: Re: [R] screen resolution effects on graphics This is what happens when I run it in R 2.3.1: as.numeric(gsub(.* , , grep

Re: [R] screen resolution effects on graphics

2006-08-28 Thread Gabor Grothendieck
I think there are problems with browseURL on Windows XP with IE. Put the file in screen.htm and then run: shell.exec(screen.htm) it will come up -- it will block it and you will have to click to unblock it; however, that will interfere with any automatic procedure. On 8/28/06, Charles Annis,

Re: [R] matrix Adjoint function

2006-08-28 Thread Gabor Grothendieck
Try: RSiteSearch(cofactor) On 8/28/06, Jessica M. Maia [EMAIL PROTECTED] wrote: Sorry but I wasn't very clear in my previous message. I want to compute the adjoint of a real matrix A, which is the transpose of the cofactor matrix of A. There is an example here:

Re: [R] Cannot get simple data.frame binding.

2006-08-28 Thread Gabor Grothendieck
The error message says that md1 and other have different number of rows. Please read the last line of every message to r-help. On 8/28/06, John Kane [EMAIL PROTECTED] wrote: I am stuck on a simple problem where an example works fine but the real one does not. I have a data.frame where I

Re: [R] Extracting column name in apply/lapply

2006-08-28 Thread Gabor Grothendieck
This can be done using a similar style but without a loop by using sapply over the indexes rather than over the columns: sapply(1:ncol(X), f) f - function(i) {...whatever...} ...whatever... can now refer to colnames(X)[i] and X[,i] On 8/28/06, Sundar Dorai-Raj [EMAIL PROTECTED] wrote: Nick

Re: [R] singular matrix

2006-08-28 Thread Gabor Grothendieck
b is nearly singular. Note that one of its eigenvalues is -2.935e-8 which is close to zero. We can use the generalized inverse from MASS to get one solution, x, but any multiple of the eigenvector corresponding to the near-zero eigenvalue when added to that will also give a solution as shown:

Re: [R] screen resolution effects on graphics

2006-08-29 Thread Gabor Grothendieck
]][[screen]][[width]] height - ie[[document]][[ParentWindow]][[screen]][[height]] ie$Quit() On 8/28/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: I think there are problems with browseURL on Windows XP with IE. Put the file in screen.htm and then run: shell.exec(screen.htm) it will come up

Re: [R] passing namees

2006-08-29 Thread Gabor Grothendieck
Put the data into a list, not into individual variables. Something like this (untested): L - sapply(symbols[-length(symbols)], get.hist.quote, start = 2005-01-09, quote = Close, simplify = FALSE) mat - do.call(cbind, L) cor.mat - cor(mat, use = complete) symnum(cor.mat) On 8/29/06,

Re: [R] lattice and several groups

2006-08-29 Thread Gabor Grothendieck
Try this: xyplot(val ~ x, data = df, type = p, col = as.numeric(df$f1), pch = as.numeric(df$f2)) key1 - list(border = TRUE, colums = 2, text = list(levels(df$f1)), points = list(pch = 1:nlevels(df$f1)) ) key2 - list(border = TRUE, colums = 2, text = list(levels(df$f2)),

Re: [R] Producing R demos

2006-08-29 Thread Gabor Grothendieck
I have not used this but wink is a free demo-maker for Windows available at: http://www.debugmode.com/wink/ Click the red on green arrow on that page to a (very short) demo. On 8/29/06, Gregor Gorjanc [EMAIL PROTECTED] wrote: Hello! I have found terrific demo or R package functionality at

Re: [R] Producing R demos

2006-08-29 Thread Gabor Grothendieck
Don't know. I would check whether the functionality is included in wink. On 8/29/06, Gregor Gorjanc [EMAIL PROTECTED] wrote: Gabor Grothendieck wrote: I have not used this but wink is a free demo-maker for Windows available at: http://www.debugmode.com/wink/ Click the red on green

Re: [R] lattice/xyplot: plotting 4 variables in two panels - can this be done?

2006-08-29 Thread Gabor Grothendieck
Try xyplot.zoo in the zoo package (be sure you have the latest zoo version). One caveat is that xyplot.zoo is under development and could change. Here we use the builtin data set anscombe as an example: # display the anscombe data set anscombe library(lattice) library(zoo) # create zoo object

Re: [R] lattice and several groups

2006-08-29 Thread Gabor Grothendieck
Note that before entering this you need: library(lattice) library(grid) # to access the viewport function On 8/29/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: xyplot(val ~ x, data = df, type = p, col = as.numeric(df$f1), pch = as.numeric(df$f2)) key1 - list(border

Re: [R] Barplot

2006-08-30 Thread Gabor Grothendieck
Try this. First we reduce the data to a frequency matrix and then plot it using classic and then lattice graphics: zm - as.matrix(rowsum(z1[-9], z1[,9])) barplot(zm, beside = TRUE, col = grey.colors(2)) legend(topleft, legend = levels(z1[,9]), fill = grey.colors(2)) library(lattice)

Re: [R] converting decimal - hexadecimal

2006-08-30 Thread Gabor Grothendieck
Try: sprintf(%x, 109) On 9/30/06, Romain Lorrilliere [EMAIL PROTECTED] wrote: Hi, do you know, a method to convert an decimal value (integer) to the corresponding hexadecimal value ? thinks for help. Romain -- Lorrillière Romain UMR 8079 Laboratoire Ecologie, Systématique et

Re: [R] working with summarized data

2006-08-30 Thread Gabor Grothendieck
In each case, look around (help.search, RSiteSearch) to see if you can find a function that handles weights. For the case you mention, medians, it can be done via quantile regression: x - w - 1:5 library(quantreg) coef(rq(x ~ 1, weight = w)) On 8/30/06, Rick Bischoff

Re: [R] lattice and several groups

2006-08-30 Thread Gabor Grothendieck
(key1, draw = TRUE, vp = viewport(.9, .9)) draw.key(key2, draw = TRUE, vp = viewport(.75, .9)) On 8/30/06, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : Note that before entering this you need: library(lattice) library(grid) # to access the viewport function On 8/29

Re: [R] lattice and several groups

2006-08-30 Thread Gabor Grothendieck
)) draw.key(key2, draw = TRUE, vp = viewport(.75, .9)) On 8/30/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: To handle conditioning on survey we provide a panel function that subsets col and pch: # define test data - df # note that your val2 and val3 lines had a syntax # so we have commented them

Re: [R] lattice and several groups

2006-08-30 Thread Gabor Grothendieck
(levels(df$f1)), points = list(pch = my.pch) ) key2 - list(border = TRUE, colums = 2, text = list(levels(df$f2)), lines = list(col = my.col) ) draw.key(key1, draw = TRUE, vp = viewport(.9, .9)) draw.key(key2, draw = TRUE, vp = viewport(.75, .9)) On 8/30/06, Gabor Grothendieck [EMAIL

Re: [R] Combine 'overlapping' dataframes, respecting row names

2006-08-30 Thread Gabor Grothendieck
If you are converting them to 'its' anyways then after the conversion to 'its' use the 'its' union command. On 8/31/06, James Howison [EMAIL PROTECTED] wrote: Hi, I've examined the archives and found quite a few questions on concatenating dataframes, but none that really addressed my issue,

Re: [R] grep question

2006-08-31 Thread Gabor Grothendieck
Or using the same x: setdiff(x, grep(Farrah|Common, x, value = TRUE)) [1] more last On 8/31/06, jim holtman [EMAIL PROTECTED] wrote: This finds the matching indices of Farrah and Common and then create a set that does not include them: x - c('Farrah', 'more', 'Common', 'last') got.F -

Re: [R] problems with plot.data.frame

2006-08-31 Thread Gabor Grothendieck
On 8/31/06, Monica Pisica [EMAIL PROTECTED] wrote: Hi again, OK i came up with this after i got few good sugegstions. First my data.frame actually looks like that (Thanks for clarifications to Prof. Brian Ripley) V1 V2 V3 V4 1 jan 3 1 7 2 mar 2 4 2 3 may 1 3 2 4 jul 3

Re: [R] How to get argument number

2006-08-31 Thread Gabor Grothendieck
Look at ?nargs On 8/31/06, Lord Tyranus [EMAIL PROTECTED] wrote: I create a function with R, I want to know how many argument number. Thanks in advance. -- Web Page http://geocities.com/lord_tyranus_96/ __ R-help@stat.math.ethz.ch mailing list

Re: [R] newbie question about index

2006-09-01 Thread Gabor Grothendieck
Try using outer: outer(1:3, a, ==)+0 On 8/31/06, z s [EMAIL PROTECTED] wrote: Hi, I am trying to convert a variable a = sample(1:3,100,rep = T) represents choices into a 3X100 dummy varible b with corresponding element set to 1 otherwise 0. eg. a: 1 3 2 1 2 3 1 1 b: 1 0 0 1 0 0 1

Re: [R] newbie question about index

2006-09-01 Thread Gabor Grothendieck
Here is an additional way: model.matrix(~ factor(a) - 1) On 9/1/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try using outer: outer(1:3, a, ==)+0 On 8/31/06, z s [EMAIL PROTECTED] wrote: Hi, I am trying to convert a variable a = sample(1:3,100,rep = T) represents choices

Re: [R] histograms

2006-09-01 Thread Gabor Grothendieck
Your data seems to have come through messed up but lets assume you have a data frame with one column per tumor. The convert your data to stacked form and call histogram: DF - data.frame(T1 = 1:10, T2 = 6:15) library(lattice) histogram(~ values | ind, stack(DF)) On 9/1/06, Nair, Murlidharan T

Re: [R] write a table to file with unequal length of lists

2006-09-01 Thread Gabor Grothendieck
A simple for loop would do it: x - 1:2; a - list(4:5, 8:10) # test data cat(x a\n, file = ) # only if you want a header for(i in seq(along = x)) cat(x[i], a[[i]], \n, file = ) On 9/1/06, Zhu Wang [EMAIL PROTECTED] wrote: Dear R helpers, To illustrate my problem, here is a simplified

Re: [R] Dividing objects in classes using function sample()

2006-09-02 Thread Gabor Grothendieck
If n and k are small try brute force. g - expand.grid(0:4, 0:4, 0:4) g[rowSums(g) == 4,] or more generally: n - 4; k - 3 g - do.call(expand.grid, rep(list(0:n), k)) g[rowSums(g) == n,] On 9/2/06, Maja Schröter [EMAIL PROTECTED] wrote: Hello everyone, I've a problem and dont know how to

Re: [R] simple matrix division.

2006-09-02 Thread Gabor Grothendieck
Try: prop.table(x, 2) On 9/2/06, Alexander Nervedi [EMAIL PROTECTED] wrote: Hi I have x-matrix(c(1,2,3,4), ncol = 2) x [,1] [,2] [1,]13 [2,]24 I'd like these two be divided by their column totals. so 1/3 and 2/3 and 3/7 and 4/7. The obvious x/colSums(x)

Re: [R] Merge list to list - as list

2006-09-03 Thread Gabor Grothendieck
] [5] [1,]16 11 16 1 [2,]27 12 17 1 [3,]38 13 18 -1 [4,]49 14 19 1 [5,]5 10 15 20 -1 Thanks you for any help. Best wishes, Muhammad Subianto #Gabor Grothendieck ggrothendieck at gmail.com #Mon Aug 28 13:53:52 CEST 2006

Re: [R] Merge list to list - as list

2006-09-03 Thread Gabor Grothendieck
))) cbind2(x,y) cbind2(x[[1]], y[[1]]) cbind2(x[[1]][[1]], y[[1]][[1]]) On 9/3/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: If z is the result then z[[i]] is formed from x[[i]] and y[[i]] using the previous solution, viz. z - list() z[[1]] - mapply(cbind, x[[1]], y[[1]], SIMPLIFY = FALSE) z

Re: [R] lattice and several groups

2006-09-03 Thread Gabor Grothendieck
) ) draw.key(key1, draw = TRUE, vp = viewport(.9, .9)) draw.key(key2, draw = TRUE, vp = viewport(.75, .9)) On 9/3/06, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : In thinking about this a bit more we can use panel.superpose/panel.groups to shorten it: # define data

Re: [R] How can I fit the secondary y axis legend on my graph?

2006-09-03 Thread Gabor Grothendieck
There is an example here: http://zoonek2.free.fr/UNIX/48_R/04.html#1.2 (Scroll down until you see the graphic with the two y axes. The code is in the box just above it.) On 9/3/06, Chris Grobler [EMAIL PROTECTED] wrote: Dear All, Having a bit of trouble with plotting two y variables on

Re: [R] Questions about sort data

2006-09-04 Thread Gabor Grothendieck
Regarding your other questions On 9/4/06, Xiao Zhao [EMAIL PROTECTED] wrote: Dear R users, I am doing my project which I want to plot a piecewise function, I knew that I can use the command segments to plot. But the problem is I want to use my real data which needs me to sort of my data by

Re: [R] opening files in directory

2006-09-04 Thread Gabor Grothendieck
On 9/4/06, Mike Nielsen [EMAIL PROTECTED] wrote: R won't do variable interpolation inside quotation marks as perl does. Just as an aside, gsubfn in package gsubfn will do perl-style (well, sort of) string interpolation: library(gsubfn) i - 1 gsubfn(x = data_files/file$i) [1] data_files/file1

Re: [R] abline and plot(augPred) help

2006-09-04 Thread Gabor Grothendieck
On 9/4/06, Paul Murrell [EMAIL PROTECTED] wrote: Hi Petr Pikal wrote: Dear all as I did not get any response on my post about abline and plot(augPred)) I try again. I hope I do not break some posting guide rules. I would try to contact package maintainer directly but there is

Re: [R] Help with plotmath

2006-09-04 Thread Gabor Grothendieck
Try: text(5,5,expression(x[i * , * j])) On 9/4/06, Kenneth Cabrera [EMAIL PROTECTED] wrote: Hi R users: How can I have several subscript number with a comma in a plot. I would like to have the LaTeX equivalent of x_{i,j}. I try: plot(1:10,1:10,type=n) text(5,5,expression(x[i,j]))

Re: [R] terms.inner

2006-09-05 Thread Gabor Grothendieck
Check out: http://tolstoy.newcastle.edu.au/R/help/01c/0340.html On 9/5/06, Terry Therneau [EMAIL PROTECTED] wrote: Question: I am trying to impliment a function in R that we use quite regularly in Splus, and it fails due to a lack of the terms.inner function in R. The substitute is? Part

Re: [R] biplot label size

2006-09-05 Thread Gabor Grothendieck
?biplot indicates cex= controls the size of the point labels. Is that what you want? I suspect not since you say you've tried it so if its something that ?biplot does not answer you may need to examine the source. Enter this into R to display the source: stats:::biplot.default On

Re: [R] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread Gabor Grothendieck
Here are a few possibilities: a - matrix(1:24, 4) # test data a / rep(a[1,], each = 4) a / outer(rep(1, nrow(a)), a[1,]) a %*% diag(1/a[1,]) sweep(a, 2, a[1,], /) On 9/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I am trying to divide the columns of a matrix by the first row in the

Re: [R] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread Gabor Grothendieck
And here is one more: t(apply(a, 1, function(x) x/a[1,])) On 9/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are a few possibilities: a - matrix(1:24, 4) # test data a / rep(a[1,], each = 4) a / outer(rep(1, nrow(a)), a[1,]) a %*% diag(1/a[1,]) sweep(a, 2, a[1,], /) On 9/6

Re: [R] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread Gabor Grothendieck
This last one could also be written slightly shorter as: t(apply(a, 1, /, a[1,])) On 9/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: And here is one more: t(apply(a, 1, function(x) x/a[1,])) On 9/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are a few possibilities

Re: [R] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread Gabor Grothendieck
Yet another one using the idempotent apply in reshape package that eliminates the transpose: library(reshape) iapply(a, 1, /, a[1,]) On 9/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: This last one could also be written slightly shorter as: t(apply(a, 1, /, a[1,])) On 9/6/06, Gabor

Re: [R] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread Gabor Grothendieck
In terms of speed Toby's original idea was actually the fastest. Here they are decreasing order of the largest timing in each row of system.time. I also tried it with a 100x10 matrix and got almost the same order: library(reshape) system.time(for(i in 1:1000) iapply(a, 1, /, a[1,])) [1] 11.51

Re: [R] deleting an arow added to a graphic

2006-09-06 Thread Gabor Grothendieck
This does not actually remove it but you could overwrite it with an arrow the same color as the background and then plot a new arrow: x - 1:10 plot(x ~ x) arrows(1, 1, 2, 2) # revise it arrows(1, 1, 2, 2, col = white) arrows(2, 2, 3, 3) On 9/6/06, Graham Smith [EMAIL PROTECTED] wrote: I know

Re: [R] graphics - joining repeated measures with a line

2006-09-06 Thread Gabor Grothendieck
Make each pair of points a separate group using group= and specify that both points and lines be used via type = b. Also set the symbols in par.settings= so that they are accessed by both the main plot and the legend: xyplot(var ~ visit, group = symbols[patient], type = b, auto.key =

Re: [R] graphics - joining repeated measures with a line

2006-09-06 Thread Gabor Grothendieck
Just one correction (although in this case it does not change the output) -- use group = patient rather than group = symbol[patient]: xyplot(var ~ visit, group = patient, type = b, auto.key = list(space = right), par.settings = list(superpose.symbol = list(pch = symbols))) On 9/6/06, Gabor

Re: [R] how to create time series object

2006-09-07 Thread Gabor Grothendieck
You can use the 'zoo' or 'its' packages. For 'zoo' see the documents listed at the end of: http://cran.r-project.org/src/contrib/Descriptions/zoo.html On 9/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi all i have date and the return series like below, but the dates are not in uniform

<    1   2   3   4   5   6   7   8   9   10   >