Re: [R] rgl: reproduce final state of interactive plot?

2011-07-14 Thread sjaffe
Terrific! This is great to know. I first tried saving and restoring the entire set from par3d but this produced some changes (eg bg) and also one must call par3d with no.readonly=TRUE. Clearly this is the way to go if one has changed a variety of rgl properties. But if one has only used the mouse

[R] rgl: reproduce final state of interactive plot?

2011-07-14 Thread sjaffe
After interacting with a 3d plot (eg plot3d, persp3d), is there a way to capture the final settings of view angles, etc, so that the final plot could be easily reproduced? The plot functions themselves just return a vector of 'ids'. -- View this message in context: http://r.789695.n4.nabble.com/r

Re: [R] Help with assigning a value based on existing numbers

2010-03-26 Thread sjaffe
An expression like "v >= 52", where v is a vector, will produce a vector resulting from comparing each entry -- that is why you see the message. What you want to do is logical subscripting. For example names <- character( nrow( curveData ) ) names[ curvedata$Date.difference <= 29 ] = "< 1 mon

Re: [R] rpad ?

2010-03-23 Thread sjaffe
Sharpie wrote: > > You could try Sage: > > http://www.sagemath.org > Yes, I've tried Sage (briefly) and it is very interesting. But what I'm looking for here is a client-server system that allows multiple users to access the results of R without exposing the details. -- View this message i

Re: [R] rpad ?

2010-03-23 Thread sjaffe
Based on a private response, it seems that rpad is no longer being maintained and in fact no longer works with the latest R release. I noticed that the web site listed in the FAQ no longer works, the code is being hosted by google code but it appears no one is working on it. Looking at the "R W

[R] rpad ?

2010-03-23 Thread sjaffe
Is anyone using rpad? Is there any documentation or examples beyond that in the 'man' directory of the source? -- View this message in context: http://n4.nabble.com/rpad-tp1679534p1679534.html Sent from the R help mailing list archive at Nabble.com.

[R] quickest way convert 1-col df to vector?

2010-03-08 Thread sjaffe
anything shorter than as.vector(as.matrix( df ) )? -- View this message in context: http://n4.nabble.com/quickest-way-convert-1-col-df-to-vector-tp1584646p1584646.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org ma

Re: [R] [help] deleting rows which contain more than 2 NAs or zeros

2010-03-08 Thread sjaffe
If the data is a dataframe or matrix 'd': d <- d[apply(d, 1, function(v) sum( is.na(v) ) <= 2 & sum(v==0, na.rm=T) <= 2 ), ] which can be deconstructed as follows: i1 <- apply(d, 1, function(v) sum(is.na(v)) <= 2 ) ## true for rows with 2 or fewer na's i2 <- apply(d, 1, function(v) sum( v == 0,

Re: [R] counting the number of ones in a vector

2010-03-04 Thread sjaffe
I got tired of writing length(which()) so I define a useful function which I source in my .Rprofile: count <- function( x ) length(which(x)) Then: count( x == 1 ) -- View this message in context: http://n4.nabble.com/counting-the-number-of-ones-in-a-vector-tp1570700p1578549.html Sent from t

Re: [R] tapply for function taking of >1 argument?

2010-02-03 Thread sjaffe
27; from DF > group by groups") groups wtd mean 1 15 2 2 6 On Tue, Feb 2, 2010 at 5:06 PM, sjaffe <[hidden email]<http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1461531&i=0>> wrote: > > Thanks! :-) > > I suppose it's obvi

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread sjaffe
Thanks! :-) I suppose it's obvious, but one will generally have to use a (anonymous) function to 'unpack' the data.frame into columns, unless the function already knows how to do this. I mention this because when I tested the solution on my example I got an unexpected result -- apparently weig

Re: [R] tapply for function taking of >1 argument?

2010-02-02 Thread sjaffe
'fraid not :-(( tapply( data, groups, weighted.mean, weights) won't work because the *entire* weights vector is passed as the 2nd arg to weighted.means. But weighted.mean needs 'weights' to be split in the same way as 'data' -- the first and 2nd args need to correspond. Jorge Ivan Velez wrot

Re: [R] Writing out csv files

2010-02-02 Thread sjaffe
write.table( rbind( quarter=names(maxr), maxr ), ..., col.names=FALSE, ... ) James Rome wrote: > > In my code, I calculate the maximum values with 2 factors using > maxr=with(arrdf, tapply(rate,list(weekday,quarter), max, na.rm=T)) > > and I want to write out the file so that Excel can read it

[R] tapply for function taking of >1 argument?

2010-02-02 Thread sjaffe
I'm sure I can put this together from the various 'apply's and split, but I wonder if anyone has a quick incantation: E.g. I can do tapply( data, groups, mean) but how can I do something like: tapply( list(data,weights), groups, weighted.mean ) ? (or: mapply is to sapply as ? is to tapply ) T

Re: [R] regular expression submatch?

2010-02-01 Thread sjaffe
Thanks for the suggestions. gsub("hello (.*)", "\\1", "hello world") seems simplest. Setting value=TRUE returns the whole match, not the subexpression. (I always read the man pages carefully before asking for help, gratuituous comments notwithstanding. I didn't see a solution using gregexpr;

[R] regular expression submatch?

2010-02-01 Thread sjaffe
What is the simplest way to extract a matched subexpression? Eg. in perl you can do "hello world" =~ m/hello (.*)/ which would return 1(true) and set $1 to the matched subexpression "world". -- View this message in context: http://n4.nabble.com/regular-expression-submatch-tp1459146p145914

[R] xmlToDataFrame drops me into browser

2010-02-01 Thread sjaffe
Even using the example from the documentation: > f = system.file("exampleData", "size.xml", package = "XML") > xmlToDataFrame(f, c("integer", "integer", "numeric")) Called from: xmlToDataFrame(doc, colClasses, homogeneous, collectNames, nodes = xmlChildren(xmlRoot(doc))) Browse[1]> I haven't se

Re: [R] omit empty cells in crosstab?

2009-04-24 Thread sjaffe
Dieter Menne wrote: > > sjaffe riskspan.com> writes: > >> >> I have data with many factors, each taking many values. However, only >> relatively few combinations appear in the data, ie have nonzero counts, >> in >> other words the resulting table is sp

[R] omit empty cells in crosstab?

2009-04-24 Thread sjaffe
Perhaps this is a common question but I haven't been able to find the answer. I have data with many factors, each taking many values. However, only relatively few combinations appear in the data, ie have nonzero counts, in other words the resulting table is sparse. Say we have 10 factors each wit