[R] rgl: reproduce final state of interactive plot?
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/rgl-reproduce-final-state-of-interactive-plot-tp3667866p3667866.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl: reproduce final state of interactive plot?
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 to rotate/scale I discovered (by looking at the documentation of view3d) that I believe that all one needs are userMatrix, FOV, and zoom: ## create an rgl plot, interact with it, then: snap - par3d( c(userMatrix, FOV, zoom) ) ## create a new rgl plot, apply the same transformation: par3d( snap ) This can also be used to 'snap' the current view during an interactive session and restore it later during that same session, which could be quite useful. To save typing, a (trivial) pair of functions to encapsulate this: snap.view- function() par3d( c(userMatrix, FOV, zoom) ) restore.view - function( snap) par3d( snap ) -- View this message in context: http://r.789695.n4.nabble.com/rgl-reproduce-final-state-of-interactive-plot-tp3667866p3668272.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with assigning a value based on existing numbers
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 month etc. Also, to test for a NULL value do not compare to the string NULL, use the test operator is.null: names[ is.null( curvedata$Date.difference ) ] = missing -- View this message in context: http://n4.nabble.com/Help-with-assigning-a-value-based-on-existing-numbers-tp1692200p1692321.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rpad ?
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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpad ?
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 Web Interfaces section of the R FAQ I don't really see anything comparable -- does anyone have a suggestion for a similar web-based front-end to R? From the FAQ: Rpad, developed and actively maintained by Tom Short, provides a sophisticated environment which combines some of the features of the previous approaches with quite a bit of JavaScript, allowing for a GUI-like behavior (with sortable tables, clickable graphics, editable output), etc. -- View this message in context: http://n4.nabble.com/rpad-tp1679534p1679590.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpad ?
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 in context: http://n4.nabble.com/rpad-tp1679534p1679607.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [help] deleting rows which contain more than 2 NAs or zeros
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, na.rm=T ) = 2 ##true for rows with 2 or fewer 0's i1 i2 ##logical vector, true for rows satisfying both conditions d[ i1 i2, ] ##only those rows satisfying the condition, and all columns -- View this message in context: http://n4.nabble.com/help-deleting-rows-which-contain-more-than-2-NAs-or-zeros-tp1584613p1584641.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] quickest way convert 1-col df to vector?
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 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] counting the number of ones in a vector
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 the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tapply for function taking of 1 argument?
Thanks, Iâm actually more comfortable with vector-ish syntax than sql-ish but this is a good thing to keep in mind⦠I wonder how it compares in performance versus âbyâ or âtapplyâ From: Gabor Grothendieck [via R] [mailto:ml-node+1461531-1948782...@n4.nabble.com] Sent: Wednesday, February 03, 2010 1:19 PM To: Steve Jaffe Subject: Re: tapply for function taking of 1 argument? Also try this: library(sqldf) DF - data.frame(data = 1:10, groups = rep(1:2, 5), weights = 1) sqldf(select groups, sum(data * weights)/sum(weights) 'wtd mean' from DF group by groups) groups wtd mean 1 15 2 26 On Tue, Feb 2, 2010 at 5:06 PM, sjaffe [hidden email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1461531i=0 wrote: 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 weighted.mean will operate on a 2-column dataframe but not in the way one would expect. data = 1:10 weights = rep(1,10) groups = rep(c(1,2),5) by( data.frame(data,weights), groups, weighted.mean) groups: 1 [1] 15 groups: 2 [1] 17.5 But by( data.frame(data,weights), groups, function(d) { weighted.mean(d[,1], d[,2]) } ) does the right thing groups: 1 [1] 5 groups: 2 [1] 6 Bert Gunter wrote: ?by Bert Gunter Genentech Nonclinical Statistics -- View this message in context: http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1460489.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ [hidden email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1461531i=1 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1461531i=2 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. View message @ http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1461531.html To unsubscribe from Re: tapply for function taking of 1 argument?, click here (link removed) ==. -- View this message in context: http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1461541.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] tapply for function taking of 1 argument?
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 ) Thanks for your help. -- View this message in context: http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1460392.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing out csv files
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. I used write.table(maxr, fname, sep=,, col.names=TRUE, row.names=TRUE, quote=TRUE, na=0) which works, and yields something like 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14 Friday,4,3,2,2,2,2,1,2,2,2,1,2,1,1,1,1,1,2,3,4,5,6,9,8,8,5,8,1 etc The top row is the quarter hours of the day However, when Excel reads this, it will put the first 0 over Friday instead of over the 4. Is there a way to write this out with a quarter at the start of the first row? E.g., quarter, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14 Friday,4,3,2,2,2,2,1,2,2,2,1,2,1,1,1,1,1,2,3,4,5,6,9,8,8,5,8,1 etc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Writing-out-csv-files-tp1460357p1460407.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tapply for function taking of 1 argument?
'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 wrote: Hi sjaffem, You were almost there: tapply( yourdata, groups, weighted.mean, weights) See ?tapply for more information. HTH, Jorge -- View this message in context: http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1460419.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tapply for function taking of 1 argument?
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 weighted.mean will operate on a 2-column dataframe but not in the way one would expect. data = 1:10 weights = rep(1,10) groups = rep(c(1,2),5) by( data.frame(data,weights), groups, weighted.mean) groups: 1 [1] 15 groups: 2 [1] 17.5 But by( data.frame(data,weights), groups, function(d) { weighted.mean(d[,1], d[,2]) } ) does the right thing groups: 1 [1] 5 groups: 2 [1] 6 Bert Gunter wrote: ?by Bert Gunter Genentech Nonclinical Statistics -- View this message in context: http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1460489.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xmlToDataFrame drops me into browser
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 set any debug() on this function, and it doesn't complain about an error...but then it shouldn't since I've just copied the command from the documentation Any suggestions will be greatly appreciated. -- View this message in context: http://n4.nabble.com/xmlToDataFrame-drops-me-into-browser-tp1459119p1459119.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] regular expression submatch?
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-tp1459146p1459146.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regular expression submatch?
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; if the poster wants to point out my oversight, he is welcome to do so.) -- View this message in context: http://n4.nabble.com/regular-expression-submatch-tp1459146p1459215.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] omit empty cells in crosstab?
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 with 10 levels. The result of table() would exceed the memory space (on a 32bit machine). Is there any way to produce a table with empty cells omitted? (without first producing the whole table and then removing rows.) Thanks, Steve -- View this message in context: http://www.nabble.com/omit-empty-cells-in-crosstab--tp2363p2363.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] omit empty cells in crosstab?
small example: a-c(1.1, 2.1, 9.1) b-cut(a,0:10) c-data.frame(b,b) d-table(c) dim(d) ##result: c(10, 10) But only 9 of the 100 cells are non-zero. If there were 10 columns, the table have 10 dimensions each of length 10, so have 10^10 elements, too much even to fit in memory Dieter Menne wrote: sjaffe sjaffe at 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 sparse. Say we have 10 factors each with 10 levels. The result of table() would exceed the memory space (on a 32bit machine). Is there any way to produce a table with empty cells omitted? (without first producing the whole table and then removing rows.) It would be easier if you had a reproducible base example, but I suggest to create ONE new factor of the pasted levels using unique(), and creating a table of these. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/omit-empty-cells-in-crosstab--tp2363p23224071.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.