[R] windows limits
Hello, Using the rgl package, I can set the device window to any dimension (that I have tested): par3d(windowRect=c(1,1,700,700)) With windows I can't get the window to span from the top to the bottom of the monitor. In the following, no matter how large the ypinch value gets it stops, leaving about 2 inches of space at the bottom of my screen: windows(record=TRUE, ypinch=1100, xpinch=10, xpos=1,ypos=1, rescale='fixed') ...I've read about some limits on windows. Is there any way around these limits? Any way I can get windows to perform like the rgl package 3d device? Thanks for your help! ben [[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] rgl device on web
Hello, I'm looking for help putting an interactive rgl package 3d device on the web so that it maintains full functionality. Where should I start? Is it possible? Is there an example I can see? (Note: I'm also looking at putting other normal plots on the web.) I'd like to stay within R as much as possible... I didn't find much online regarding rgl 3d plots. Thanks, Ben [[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.
Re: [R] rgl device on web
Thanks Duncan! I wish I had the time to work on something like that, but I have to stay focused on research. Thanks again for your extensive help! Have a good weekend everyone! Ben On Fri, Oct 21, 2011 at 4:24 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 11-10-21 3:38 PM, Ben qant wrote: Hello, I'm looking for help putting an interactive rgl package 3d device on the web so that it maintains full functionality. Where should I start? Is it possible? Is there an example I can see? (Note: I'm also looking at putting other normal plots on the web.) I'd like to stay within R as much as possible... I didn't find much online regarding rgl 3d plots. There are some 3d file formats that allow manipulation similar to what rgl does, but currently rgl can't write output to any of those formats. Last time I looked they were all proprietary, and it wasn't clear which one would be the winner, so I've never tried coding any of them. So if you pick one format, you'll need to code (in C++) what's necessary to write out the rgl scene to such a file. I'd be happy to include such code into rgl if you do it, but there's zero chance I'll look into this again in the next 4-6 months. Duncan Murdoch [[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.
Re: [R] high and lowest with names
Here is a more R'sh solution (speed unknown). Courtesy of Mark Leeds (I modified it a bit to generalize it for a cnt input and get min and max). Again, getting cnt highest and lowest values in the entire matrix and display the data point row and column names with each: x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 10 #=== print(dat) a b c d e z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 # MAKE IT A VECTOR FOR EASIER ORDERING datasvec - as.vector(dat) # ORDER IT datasvecordered- order(datasvec) # RECYCLE ROWS AND COLUMNS NAMES FOR EASIER MAPPING recycledcols - rep(colnames(dat),each=nrow(dat)) recycledrows - rep(rownames(dat),times=ncol(dat)) # GET THE VALUES, THE ROW NAMES AND THE COLUMN NAMES len = length(datasvecordered) rr_len = length(recycledrows) rbind(datasvec[datasvecordered][(len-cnt):len],recycledrows[datasvecordered][(rr_len-cnt):rr_len],recycledcols[datasvecordered][(rr_len-cnt):rr_len]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 9 9 10 12 12 12 12 13 15 20 28 [2,] y v z z y w x v v w x [3,] a d e a c c e b a d d rbind(datasvec[datasvecordered][1:cnt],recycledrows[datasvecordered][1:cnt],recycledcols[datasvecordered][1:cnt]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 2 3 5 5 6 6 7 7 7 [2,] v z y x v z w w z y [3,] e d e a c c e a b b enjoy ben On Wed, Oct 12, 2011 at 11:47 AM, Ben qant ccqu...@gmail.com wrote: Hello, This is my solution. This is pretty fast (tested with a larger data set)! If you have a more elegant way to do it (of similar speed), please reply. Thanks for the help! ## get highest and lowest values and names of a matrix # create sample data x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') #my solution nms = dimnames(dat) #get matrix row and col names cnt = 10 # number of max and mins to get tmp = dat mxs = list(list,cnt) mns = list(list,cnt) for(i in 1:cnt){ #get maxes mx_dims = arrayInd(which.max(tmp), dim(tmp)) # get max dims for entire matrix note: which.max also removes NA's mx_nm = c(nms[[1]][mx_dims[1]],nms[[2]][mx_dims[2]]) #get names mx = tmp[mx_dims] # get max value mxs[[i]] = c(mx,mx_nm) # add max and dim names to list of maxes tmp[mx_dims] = NA #removes last max so new one is found #get mins (basically same as above) mn_dims = arrayInd(which.min(tmp), dim(tmp)) mn_nm = c(nms[[1]][mn_dims[1]],nms[[2]][mn_dims[2]]) mn = tmp[mn_dims] mns[[i]] = c(mn,mn_nm) tmp[mn_dims] = NA } mxs mns # end Regards, Ben On Tue, Oct 11, 2011 at 5:32 PM, Dénes TÓTH tde...@cogpsyphy.hu wrote: which.max is even faster: dims - c(1000,1000) tt - array(rnorm(prod(dims)),dims) # which system.time( replicate(100, which(tt==max(tt), arr.ind=TRUE)) ) # which.max ( arrayInd) system.time( replicate(100, arrayInd(which.max(tt), dims)) ) Best, Denes But it's simpler and probably faster to use R's built-in capabilities. ?which ## note the arr.ind argument!) As an example: test - matrix(rnorm(24), nr = 4) which(test==max(test), arr.ind=TRUE) row col [1,] 2 6 So this gives the row and column indices of the max, from which row and column names can easily be obtained from the dimnames attribute of the matrix. Note: This assumes that the object in question is a matrix, NOT a data frame, for which it would be slightly more complicated. -- Bert On Tue, Oct 11, 2011 at 3:06 PM, Carlos Ortega c...@qualityexcellence.eswrote: Hi, With this code you can find row and col names for the largest value applied to your example: r.m.tmp-apply(dat,1,max) r.max-names(r.m.tmp)[r.m.tmp==max(r.m.tmp)] c.m.tmp-apply(dat,2,max) c.max-names(c.m.tmp)[c.m.tmp==max(c.m.tmp)] It's inmediate how to get the same for the smallest and build a function to calculate everything and return a list. Regards, Carlos Ortega www.qualityexcellence.es 2011/10/11 Ben qant ccqu...@gmail.com Hello, I'm looking to get the values, row names and column names of the largest and smallest values in a matrix. Example (except is does not include the names): x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','c') rownames(dat) = c('z','y','x','w','v') dat a b c d c z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 #top 10 sort(dat,partial=n-9:n)[(n-9):n] [1] 9 10 12 12 12 12 13 15 20 28 # bottom 10 sort(dat,partial=1:10)[1:10] [1] 1 2 3 5 5 6 6 7 7 7 ...except I need the rownames and colnames to go along for the ride
Re: [R] high and lowest with names
Besides being a much better solution, it displays ties (which I see as a benefit). For example, if I ask for 5 I get 8 for top values since 12 occurs 3 times. Here is the same thing David posted with slight mods to generalize it a bit for cnt: x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 5 #=== dattop - which(dat = c(dat)[rev(order(dat))][cnt], arr.ind=TRUE) rbind( top = dat[dattop], rows = rownames(dat)[ dattop[,1] ], cols = colnames(dat)[ dattop[,2] ]) datbot - which(dat = c(dat)[order(dat)][cnt], arr.ind=TRUE) rbind( bot = dat[datbot], rows = rownames(dat)[ datbot[,1] ], cols = colnames(dat)[ datbot[,2] ]) Thanks David! Ben On Thu, Oct 13, 2011 at 9:48 AM, David Winsemius dwinsem...@comcast.netwrote: On Oct 13, 2011, at 10:42 AM, Ben qant wrote: Here is a more R'sh solution (speed unknown). Really? The intermediate, potentially large, objects seem to be proliferating. Courtesy of Mark Leeds (I modified it a bit to generalize it for a cnt input and get min and max). Again, getting cnt highest and lowest values in the entire matrix and display the data point row and column names with each: 1) For max (or min) I would have thought that one could have much more easily gathered the maximum and minimum locations with: which(x == max(x), arr.ind=TRUE) # Bert Gunter's discarded suggestion ... and used the results as indices into x or rownames(x) or colnames(x). But I made no earlier comments because it did not appear that you had provided the swiss$Education object in a form that could be easily extracted for testing. I see now that setting up a similar object was fairly easy, but would encourage you to consider the `dput` function for such problem construction in the future; dat2 - matrix(sample(1:25, 25), 5,5) colnames(dat2) = c('a','b','c','d','e') rownames(dat2) = c('z','y','x','w','v') arrns - which(dat2 == max(dat2), arr.ind=TRUE) arrns row col v 5 1 colnames(dat2)[arrns[,2]] ; rownames(dat2)[arrns[,1]] [1] a [1] v 2) For display of all results with row/column labels : rbind(dat2, rownames(dat2)[row(dat2)], colnames(dat2)[row(dat2)]) 3) For display of values of bottom five and top five: dat2five - which(dat2 = c(dat2)[order(dat2)][5], arr.ind=TRUE) rbind( dat2LT5= dat2[dat2five], Rows = rownames(dat2)[ dat2five[,1] ], Cols = colnames(dat2)[ dat2five[,2] ]) #-- [,1] [,2] [,3] [,4] [,5] dat2LT5 2 3 5 1 4 Rowsx w y y x Colsa a c d d dat2topfive - which(dat2 = c(dat2)[rev(order(dat2))][5], arr.ind=TRUE) rbind( dat2top5= dat2[dat2topfive], Rows = rownames(dat2)[ dat2topfive[,1] ], Cols = colnames(dat2)[ dat2topfive[,2] ]) #--- [,1] [,2] [,3] [,4] [,5] dat2top5 24 25 23 22 21 Rows z v y w v Cols a a b e e x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 10 #=**== print(dat) a b c d e z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 # MAKE IT A VECTOR FOR EASIER ORDERING datasvec - as.vector(dat) # ORDER IT datasvecordered- order(datasvec) # RECYCLE ROWS AND COLUMNS NAMES FOR EASIER MAPPING recycledcols - rep(colnames(dat),each=nrow(**dat)) recycledrows - rep(rownames(dat),times=ncol(**dat)) # GET THE VALUES, THE ROW NAMES AND THE COLUMN NAMES len = length(datasvecordered) rr_len = length(recycledrows) rbind(datasvec[**datasvecordered][(len-cnt):**len],recycledrows[** datasvecordered][(rr_len-cnt):**rr_len],recycledcols[** datasvecordered][(rr_len-cnt):**rr_len]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 9 9 10 12 12 12 12 13 15 20 28 [2,] y v z z y w x v v w x [3,] a d e a c c e b a d d rbind(datasvec[**datasvecordered][1:cnt],** recycledrows[datasvecordered][**1:cnt],recycledcols[** datasvecordered][1:cnt]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 2 3 5 5 6 6 7 7 7 [2,] v z y x v z w w z y [3,] e d e a c c e a b b enjoy ben On Wed, Oct 12, 2011 at 11:47 AM, Ben qant ccqu...@gmail.com wrote: Hello, This is my solution. This is pretty fast (tested with a larger data set)! If you have a more elegant way to do it (of similar speed), please reply. Thanks for the help! ## get highest and lowest values and names of a matrix # create sample data x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') #my solution nms = dimnames(dat) #get matrix row and col names cnt = 10 # number of max and mins to get tmp = dat mxs = list(list,cnt) mns
Re: [R] high and lowest with names
Hello, This is my solution. This is pretty fast (tested with a larger data set)! If you have a more elegant way to do it (of similar speed), please reply. Thanks for the help! ## get highest and lowest values and names of a matrix # create sample data x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') #my solution nms = dimnames(dat) #get matrix row and col names cnt = 10 # number of max and mins to get tmp = dat mxs = list(list,cnt) mns = list(list,cnt) for(i in 1:cnt){ #get maxes mx_dims = arrayInd(which.max(tmp), dim(tmp)) # get max dims for entire matrix note: which.max also removes NA's mx_nm = c(nms[[1]][mx_dims[1]],nms[[2]][mx_dims[2]]) #get names mx = tmp[mx_dims] # get max value mxs[[i]] = c(mx,mx_nm) # add max and dim names to list of maxes tmp[mx_dims] = NA #removes last max so new one is found #get mins (basically same as above) mn_dims = arrayInd(which.min(tmp), dim(tmp)) mn_nm = c(nms[[1]][mn_dims[1]],nms[[2]][mn_dims[2]]) mn = tmp[mn_dims] mns[[i]] = c(mn,mn_nm) tmp[mn_dims] = NA } mxs mns # end Regards, Ben On Tue, Oct 11, 2011 at 5:32 PM, Dénes TÓTH tde...@cogpsyphy.hu wrote: which.max is even faster: dims - c(1000,1000) tt - array(rnorm(prod(dims)),dims) # which system.time( replicate(100, which(tt==max(tt), arr.ind=TRUE)) ) # which.max ( arrayInd) system.time( replicate(100, arrayInd(which.max(tt), dims)) ) Best, Denes But it's simpler and probably faster to use R's built-in capabilities. ?which ## note the arr.ind argument!) As an example: test - matrix(rnorm(24), nr = 4) which(test==max(test), arr.ind=TRUE) row col [1,] 2 6 So this gives the row and column indices of the max, from which row and column names can easily be obtained from the dimnames attribute of the matrix. Note: This assumes that the object in question is a matrix, NOT a data frame, for which it would be slightly more complicated. -- Bert On Tue, Oct 11, 2011 at 3:06 PM, Carlos Ortega c...@qualityexcellence.eswrote: Hi, With this code you can find row and col names for the largest value applied to your example: r.m.tmp-apply(dat,1,max) r.max-names(r.m.tmp)[r.m.tmp==max(r.m.tmp)] c.m.tmp-apply(dat,2,max) c.max-names(c.m.tmp)[c.m.tmp==max(c.m.tmp)] It's inmediate how to get the same for the smallest and build a function to calculate everything and return a list. Regards, Carlos Ortega www.qualityexcellence.es 2011/10/11 Ben qant ccqu...@gmail.com Hello, I'm looking to get the values, row names and column names of the largest and smallest values in a matrix. Example (except is does not include the names): x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','c') rownames(dat) = c('z','y','x','w','v') dat a b c d c z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 #top 10 sort(dat,partial=n-9:n)[(n-9):n] [1] 9 10 12 12 12 12 13 15 20 28 # bottom 10 sort(dat,partial=1:10)[1:10] [1] 1 2 3 5 5 6 6 7 7 7 ...except I need the rownames and colnames to go along for the ride with the values...because of this, I am guessing the return value will need to be a list since all of the values have different row and col names (which is fine). Regards, Ben [[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. [[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. [[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-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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read
[R] Tinn-R change editor background color
Hello, Does anyone know how to change the Tinn-R editor background color? White is rough on the eyes... Thanks, Ben [[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.
Re: [R] Tinn-R change editor background color
Never mind: option color preference Sorry...overlooked that 10 times I guess. regards On Wed, Oct 12, 2011 at 12:54 PM, Ben qant ccqu...@gmail.com wrote: Hello, Does anyone know how to change the Tinn-R editor background color? White is rough on the eyes... Thanks, Ben [[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] apply for each value
Hello, There has to be a more R'ish way to do this. I have two matrices, one has the values I want, but I want to NA some of them. The other matrix has binary values that tell me if I want to NA the values in the other matrix. I produce a third matrix based on this. I've also tried apply() passing in c(1,2) for rows and columns with no success yet. Example (this works, but I'm looking for a better/faster solution): a = matrix(1:6,2,3) colnames(a) = c('a','b','c') b = matrix(c(1,0,1,0,0,1),2,3) colnames(b) = colnames(a) c = matrix(0,nrow(a),ncol(a)) for(cl in 1:ncol(a)){ for(rw in 1:nrow(a)){ c[rw,cl] = ifelse(b[rw,cl]==1,a[rw,cl],NA) } } a a b c [1,] 1 3 5 [2,] 2 4 6 b a b c [1,] 1 1 0 [2,] 0 0 1 c [,1] [,2] [,3] [1,]13 NA [2,] NA NA6 Thanks! Ben [[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] high and lowest with names
Hello, I'm looking to get the values, row names and column names of the largest and smallest values in a matrix. Example (except is does not include the names): x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','c') rownames(dat) = c('z','y','x','w','v') dat a b c d c z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 #top 10 sort(dat,partial=n-9:n)[(n-9):n] [1] 9 10 12 12 12 12 13 15 20 28 # bottom 10 sort(dat,partial=1:10)[1:10] [1] 1 2 3 5 5 6 6 7 7 7 ...except I need the rownames and colnames to go along for the ride with the values...because of this, I am guessing the return value will need to be a list since all of the values have different row and col names (which is fine). Regards, Ben [[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.
Re: [R] axes3d/bbox3d - axis values not fixed
Excellent! Thank you! Ben On Sat, Oct 8, 2011 at 3:36 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 11-10-08 11:04 AM, Ben qant wrote: Thank you! Sorry, I have a couple more questions: 1) How to I turn off the box shading completely? I figured out how to lighten it up to a grey color with col=c(white... . I looked in the package pdf, but I didn't see anything. 2) I read about the zunit in the package pdf, but no matter what I change it to it doesn't seem to change anything. Here is where I am at right now: x- 1:10 y- 1:10 z- matrix(outer(x-5,y-5) + rnorm(100), 10, 10) open3d() persp3d(x, y, z, col=red, alpha=0.7,aspect=c(1,1,1),**xlab='',ylab='',zlab='z', axes=F) bbox3d(xat=c(5, 6), xlab=c(a, b), yat=c(2,4,6), zunit=10, col=c(white,black)) You need to play with the material properties of the bounding box. I think this gives what you want: bbox3d(xat=c(5, 6), xlab=c(a, b), yat=c(2,4,6), zunit=10, col=black, front=line, back=line, lit=FALSE) I see different axes for zunit=5, zunit=10, zunit=20. Not sure why you don't. Duncan Thank you for your help! Ben On Sat, Oct 8, 2011 at 5:09 AM, Duncan Murdochmurdoch.duncan@gmail.**commurdoch.dun...@gmail.com wrote: On 11-10-07 2:32 PM, Ben qant wrote: Hello, I'm using the rgl package and plotting a plot with it. I'd like to have all the axes values auto-hide, but I want to plot a series of characters instead of the values of the measurement for 2 of the axes. So in the end I will have one axis (z actually) behave per normal (auto-hide) and I'd like the other two axes to be custom character vectors that auto-hide. The axes in rgl are a little messy. It's been on my todo list for a long time to fix them, but there are a lot of details to handle, and only so much time. Essentially there are two separate systems for axes: the bbox3d system, and the axis3d system. The former is the ones that appear and disappear, the latter is really just lines and text added to the plot. Example: x- 1:10 y- 1:10 z- matrix(outer(x-5,y-5) + rnorm(100), 10, 10) open3d() persp3d(x, y, z, col=red, alpha=0.7, aspect=c(1,1,0.5),xlab='',ylab='',zlab='', axes=F) For the above, axes=F for demonstration purposes only. Now when I call: axes3d() ...the axis values hide/behave the way I want, but I want my own characters in there instead of the values that default. You want to use the bbox3d() call. For example, bbox3d(xat=c(5, 10), xlab=c(V, X), yat=c(2,4,6), zunit=10) for three different types of labels on the three axes. It would be nice if axis3d had the same options as bbox3d, but so far it doesn't. Duncan Murdoch Trying again: open3d() persp3d(x, y, z, col=red, alpha=0.7, aspect=c(1,1,0.5),xlab='',ylab='',zlab='', axes=F) axis3d('x',labels='test') ...puts in a custom character label 'test', but I loose the behavior/hiding. Also, then how do I get the values for the z axis to populate with the default values and auto-hide with the other two custom string axes auto-hiding? I'm pretty sure I need to use bbox3d(), but I'm not having any luck. I'm new'ish to R and very new to the rgl package. Hopefully that makes sense. Thanks for your help! ben [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help https://stat.**ethz.ch/mailman/listinfo/r-**helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.htmlhttp://www.**R-project.org/posting-guide.**htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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.
Re: [R] axes3d/bbox3d - axis values not fixed
Thank you! Sorry, I have a couple more questions: 1) How to I turn off the box shading completely? I figured out how to lighten it up to a grey color with col=c(white... . I looked in the package pdf, but I didn't see anything. 2) I read about the zunit in the package pdf, but no matter what I change it to it doesn't seem to change anything. Here is where I am at right now: x- 1:10 y- 1:10 z- matrix(outer(x-5,y-5) + rnorm(100), 10, 10) open3d() persp3d(x, y, z, col=red, alpha=0.7,aspect=c(1,1,1),xlab='',ylab='',zlab='z', axes=F) bbox3d(xat=c(5, 6), xlab=c(a, b), yat=c(2,4,6), zunit=10, col=c(white,black)) Thank you for your help! Ben On Sat, Oct 8, 2011 at 5:09 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 11-10-07 2:32 PM, Ben qant wrote: Hello, I'm using the rgl package and plotting a plot with it. I'd like to have all the axes values auto-hide, but I want to plot a series of characters instead of the values of the measurement for 2 of the axes. So in the end I will have one axis (z actually) behave per normal (auto-hide) and I'd like the other two axes to be custom character vectors that auto-hide. The axes in rgl are a little messy. It's been on my todo list for a long time to fix them, but there are a lot of details to handle, and only so much time. Essentially there are two separate systems for axes: the bbox3d system, and the axis3d system. The former is the ones that appear and disappear, the latter is really just lines and text added to the plot. Example: x- 1:10 y- 1:10 z- matrix(outer(x-5,y-5) + rnorm(100), 10, 10) open3d() persp3d(x, y, z, col=red, alpha=0.7, aspect=c(1,1,0.5),xlab='',**ylab='',zlab='', axes=F) For the above, axes=F for demonstration purposes only. Now when I call: axes3d() ...the axis values hide/behave the way I want, but I want my own characters in there instead of the values that default. You want to use the bbox3d() call. For example, bbox3d(xat=c(5, 10), xlab=c(V, X), yat=c(2,4,6), zunit=10) for three different types of labels on the three axes. It would be nice if axis3d had the same options as bbox3d, but so far it doesn't. Duncan Murdoch Trying again: open3d() persp3d(x, y, z, col=red, alpha=0.7, aspect=c(1,1,0.5),xlab='',**ylab='',zlab='', axes=F) axis3d('x',labels='test') ...puts in a custom character label 'test', but I loose the behavior/hiding. Also, then how do I get the values for the z axis to populate with the default values and auto-hide with the other two custom string axes auto-hiding? I'm pretty sure I need to use bbox3d(), but I'm not having any luck. I'm new'ish to R and very new to the rgl package. Hopefully that makes sense. Thanks for your help! ben [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] axes3d/bbox3d - axis values not fixed
Hello, I'm using the rgl package and plotting a plot with it. I'd like to have all the axes values auto-hide, but I want to plot a series of characters instead of the values of the measurement for 2 of the axes. So in the end I will have one axis (z actually) behave per normal (auto-hide) and I'd like the other two axes to be custom character vectors that auto-hide. Example: x - 1:10 y - 1:10 z - matrix(outer(x-5,y-5) + rnorm(100), 10, 10) open3d() persp3d(x, y, z, col=red, alpha=0.7, aspect=c(1,1,0.5),xlab='',ylab='',zlab='', axes=F) For the above, axes=F for demonstration purposes only. Now when I call: axes3d() ...the axis values hide/behave the way I want, but I want my own characters in there instead of the values that default. Trying again: open3d() persp3d(x, y, z, col=red, alpha=0.7, aspect=c(1,1,0.5),xlab='',ylab='',zlab='', axes=F) axis3d('x',labels='test') ...puts in a custom character label 'test', but I loose the behavior/hiding. Also, then how do I get the values for the z axis to populate with the default values and auto-hide with the other two custom string axes auto-hiding? I'm pretty sure I need to use bbox3d(), but I'm not having any luck. I'm new'ish to R and very new to the rgl package. Hopefully that makes sense. Thanks for your help! ben [[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.
Re: [R] counts in quantiles in and from a matrix
Excellent! Thank you! ben On Wed, Oct 5, 2011 at 9:18 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: Here's one way: m - matrix(rpois(100, 8), nrow = 5) f - function(x) { q - quantile(x, c(0.1, 0.9), na.rm = TRUE) c(sum(x q[1]), sum(x q[2])) } t(apply(m, 1, f)) HTH, Dennis On Wed, Oct 5, 2011 at 8:11 PM, Ben qant ccqu...@gmail.com wrote: Hello, I'm trying to get the count of values in each row that are above and below quantile thresholds. Thanks! Example: x = matrix(1:30,5,6) x [,1] [,2] [,3] [,4] [,5] [,6] [1,]16 11 16 21 26 [2,]27 12 17 22 27 [3,]38 13 18 23 28 [4,]49 14 19 24 29 [5,]5 10 15 20 25 30 qtl = t(apply(x, 1, quantile, probs = c(.1,.9),na.rm=T)) qtl 10% 90% [1,] 3.5 23.5 [2,] 4.5 24.5 [3,] 5.5 25.5 [4,] 6.5 26.5 [5,] 7.5 27.5 I would like counts like this for each row: cnts [,1] [,2] [1,] 11 [2,] 11 [3,] 11 [4,] 11 [5,] 11 ...because for the first row (x[1,]) only value 1 is less than 3.5 and only value 26 is greater 23.5 and so on for the other rows. I'm thinking its a apply(x,1,...some FUN here...), but still getting use to apply and I've been coding for too long... Also, if anyone knows how to change the background color of the r-Tinn editor my eyes would love you! Off to bed. I look forward to your answers! Thanks! Ben [[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. [[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] counts in quantiles in and from a matrix
Hello, I'm trying to get the count of values in each row that are above and below quantile thresholds. Thanks! Example: x = matrix(1:30,5,6) x [,1] [,2] [,3] [,4] [,5] [,6] [1,]16 11 16 21 26 [2,]27 12 17 22 27 [3,]38 13 18 23 28 [4,]49 14 19 24 29 [5,]5 10 15 20 25 30 qtl = t(apply(x, 1, quantile, probs = c(.1,.9),na.rm=T)) qtl 10% 90% [1,] 3.5 23.5 [2,] 4.5 24.5 [3,] 5.5 25.5 [4,] 6.5 26.5 [5,] 7.5 27.5 I would like counts like this for each row: cnts [,1] [,2] [1,] 11 [2,] 11 [3,] 11 [4,] 11 [5,] 11 ...because for the first row (x[1,]) only value 1 is less than 3.5 and only value 26 is greater 23.5 and so on for the other rows. I'm thinking its a apply(x,1,...some FUN here...), but still getting use to apply and I've been coding for too long... Also, if anyone knows how to change the background color of the r-Tinn editor my eyes would love you! Off to bed. I look forward to your answers! Thanks! Ben [[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] rm.outlier produces a list
Hello, Why does rm.outlier produce a list for me? I know its something about my data because I can't make a mock up that reproduces the issue. Any ideas? My data goes in as a matrix and comes out as a list: class(dat) [1] matrix dat = rm.outlier(dat) class(dat) [1] list Thanks, Ben [[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] removing outliers in non-normal distributions
Hello, I'm seeking ideas on how to remove outliers from a non-normal distribution predictor variable. We wish to reset points deemed outliers to a truncated value that is less extreme. (I've seen many posts requesting outlier removal systems. It seems like most of the replies center around why do you want to remove them, you shouldn't remove them, it depends, etc. so I've tried to add a lot of notes below in an attempt to answer these questions in advance.) Currently we Winsorize using the quantile function to get the new high and low values to set the outliers to on the high end and low end (this is summarized legacy code that I am revisiting): #Get the truncated values for resetting: lowq = quantile(dat,probs=perc_low,na.rm=TRUE) hiq = quantile(dat,probs=perc_hi,na.rm=TRUE) #resetting the highest and lowest values with the truncated values: dat[lowqdat] = lowq dat[hiqdat] = hiq What I don't like about this is that it always truncates values (whether they truly are outliers or not) and the perc_low and perc_hi settings are arbitrary. I'd like to be more intelligent about it. Notes: 1) Ranking has already been explored and is not an option at this time. 2) Reminder: these factors are almost always distributed non-normally. 3) For reason I won't get into here, I have to do this pragmatically. I can't manually inspect the data each time I remove outliers. 4) I will be removing outliers from candidate predictor variables. Predictors variable distributions all look very different from each other, so I can't make any generalizations about them. 5) As #4 above indicates, I am building and testing predictor variables for use in a regression model. 6) The predictor variable outliers are usually somewhat informative, but their extremeness is a result of the predictor variable calculation. I think extremeness takes away from the information that would otherwise be available (outlier effect). So I want to remove some, but not all, of their extremeness. For example, percent change of a small number: from say 0.001 to 500. Yes, we want to know that it changed a lot, but 49,999,900% is not helpful and masks otherwise useful information. I'd like to hear your ideas. Thanks in advance! Regards, Ben [[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] remove NaN from element in a vector in a list
Hello, What is the best way to turn a matrix into a list removing NaN's? I'm new to R... Start: mt = matrix(c(1,4,NaN,5,3,6),2,3) mt [,1] [,2] [,3] [1,]1 NaN3 [2,]456 Desired result: lst [[1]] [1] 1 3 [[2]] [1] 4 5 6 Thanks! Ben [[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.
Re: [R] remove NaN from element in a vector in a list
Excellent! Thank you! ben On Tue, Sep 27, 2011 at 2:07 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: alply is from the plyr package. You'll need to call that if its not already loaded. M On Tue, Sep 27, 2011 at 4:07 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Try this: alply(mt, 1, function(x) as.numeric(na.omit(x))) The as.numeric() addition may be necessary to strip the extra attributes na.omit() wants to add. Michael On Tue, Sep 27, 2011 at 4:02 PM, Ben qant ccqu...@gmail.com wrote: Hello, What is the best way to turn a matrix into a list removing NaN's? I'm new to R... Start: mt = matrix(c(1,4,NaN,5,3,6),2,3) mt [,1] [,2] [,3] [1,]1 NaN3 [2,]456 Desired result: lst [[1]] [1] 1 3 [[2]] [1] 4 5 6 Thanks! Ben [[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. [[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] R.oo: do work on data member at construction
Hello, I'd like to 'do work' on data members upon construction (i.e. without implementing it in a get method). Is this the best way to create data member 'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex I'll run into issues. setConstructorS3(MyClass, function(x=NA,y=NA,...) { this - extend(Object(), MyClass, .x=x, .y=y, .z=paste(x,y) ) }) setMethodS3(getX, MyClass, function(this, ...) { this$.x; }) setMethodS3(getY, MyClass, function(this, ...) { this$.y; }) setMethodS3(getZ, MyClass, function(this, ...) { this$.z; }) mc = MyClass('a','b') mc$x [1] a mc$y [1] b mc$z [1] a b Thanks, ben [[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.
Re: [R] R.oo: do work on data member at construction
Thank you very much! I'm using the first example. For others: there are two simple typos in Henrik's email below: pretty sure y - this$.; should be y - this$.y; Thanks again... Corrected below... Ben Hello, I'd like to 'do work' on data members upon construction (i.e. without implementing it in a get method). Is this the best way to create data member 'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex I'll run into issues. setConstructorS3(MyClass, function(x=NA,y=NA,...) { this - extend(Object(), MyClass, .x=x, .y=y, .z=paste(x,y) ) Looks good to me and is standard R procedure where you work with the *arguments*. You can also work on the object after it's been instantiated, e.g. setConstructorS3(MyClass, function(x=NA,y=NA,...) { this - extend(Object(), MyClass, .x=x, .y=y, .z=NULL ) # Assign z this$.z - paste(this$.x, this$.y); this; }) Note that if .z always a function of .x and .y it is redundant. Then an alternative is to create it on the fly, i.e. setMethodS3(getZ, MyClass, function(this, ...) { x - this$.x; y - this$.y; z - paste(x, y); z; }) You can then make it clever and cache the results so that it is only calculated once, e.g. setMethodS3(getZ, MyClass, function(this, ...) { z - this$.z; if (is.null(z)) { x - this$.x; y - this$.y; z - paste(x, y); this$.z - z; } z; }) However, you then have to make sure to reset z (this$.z - NULL) whenever .x or .y is changed. /Henrik On Thu, Sep 22, 2011 at 10:18 AM, Henrik Bengtsson h...@biostat.ucsf.eduwrote: On Thu, Sep 22, 2011 at 9:06 AM, Ben qant ccqu...@gmail.com wrote: Hello, I'd like to 'do work' on data members upon construction (i.e. without implementing it in a get method). Is this the best way to create data member 'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex I'll run into issues. setConstructorS3(MyClass, function(x=NA,y=NA,...) { this - extend(Object(), MyClass, .x=x, .y=y, .z=paste(x,y) ) Looks good to me and is standard R procedure where you work with the *arguments*. You can also work on the object after it's been instantiated, e.g. setConstructorS3(MyClass, function(x=NA,y=NA,...) { this - extend(Object(), MyClass, .x=x, .y=y, .z=NULL ) # Assign z this$.z - paste(this$.x, this$.y); this; }) Note that if .z always a function of .x and .y it is redundant. Then an alternative is to create it on the fly, i.e. setMethodS3(getZ, MyClass, function(this, ...) { x - this$.x; y - this$.; z - paste(x, y); z; }) You can then make it clever and cache the results so that it is only calculated once, e.g. setMethodS3(getZ, MyClass, function(this, ...) { z - this$.z; if (is.null(z)) { x - this$.x; y - this$.; z - paste(x, y); this$.z - z; } z; }) However, you then have to make sure to reset z (this$.z - NULL) whenever .x or .y is changed. /Henrik }) setMethodS3(getX, MyClass, function(this, ...) { this$.x; }) setMethodS3(getY, MyClass, function(this, ...) { this$.y; }) setMethodS3(getZ, MyClass, function(this, ...) { this$.z; }) mc = MyClass('a','b') mc$x [1] a mc$y [1] b mc$z [1] a b Thanks, ben [[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. [[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] rJython matrix message
Hello, I've posted something similar under a different subject and never received a solution. Trying again with (hopefully) a better description. Objective: Send a matrix of string data in an email message. The message must have authentication and be sent via an R script. I'm almost there! Here is where I am at: I collect long error message lines in 'errs', which is a matrix. Then I collapse them into a character vector via: errs = paste(errs, collapse = ) Then I send that in a email via rJython. The message is sent to an Microsoft Outlook address like this: mail = c( etc... paste(msg = MIMEText(',errs,'),sep=), ...etc) ...etc... [the rest of the rJython stuff to send a message omitted here] jython.exec(rJython,mail) The problem: The issue is that the message wraps the text in the body of the message so that the message just looks like one big line of text which makes it very difficult to read (aka is not acceptable). Notes: 1) The message must have authentication; therefore, I am using rJython. (My understanding is that there is no R way to send an email message with authentication.) 2) I have to receive the message in Outlook. 3) When I do errs = paste(errs, collapse = \n), and pass that as the message text, rJython gives me an error: Error in ls(envir = envir, all.names = private) : invalid 'envir' argument Thanks so much for your help! I'm new to R by the way... Ben [[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.
Re: [R] rJython matrix message
That fixed it!! Thank you very much! I should have thought of that. Thanks again, Ben On Wed, Sep 14, 2011 at 9:57 AM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: Hi, On Wed, Sep 14, 2011 at 11:44 AM, Ben qant ccqu...@gmail.com wrote: Hello, I've posted something similar under a different subject and never received a solution. Trying again with (hopefully) a better description. Objective: Send a matrix of string data in an email message. The message must have authentication and be sent via an R script. I'm almost there! Here is where I am at: I collect long error message lines in 'errs', which is a matrix. (I might collect this into a list, but that's just a matter of style) Then I collapse them into a character vector via: errs = paste(errs, collapse = ) Then I send that in a email via rJython. The message is sent to an Microsoft Outlook address like this: mail = c( etc... paste(msg = MIMEText(',errs,'),sep=), ...etc) ...etc... [the rest of the rJython stuff to send a message omitted here] jython.exec(rJython,mail) The problem: The issue is that the message wraps the text in the body of the message so that the message just looks like one big line of text which makes it very difficult to read (aka is not acceptable). Notes: 1) The message must have authentication; therefore, I am using rJython. (My understanding is that there is no R way to send an email message with authentication.) 2) I have to receive the message in Outlook. 3) When I do errs = paste(errs, collapse = \n), and pass that as the message text, rJython gives me an error: Error in ls(envir = envir, all.names = private) : invalid 'envir' argument It's hard to imagine why this would happen. using `paste(errs, collapse=)` vs. `paste(errs, collapse=\n)` will provide you with one character vector/string, so I've got to believe the problem is somewhere else. Just a stab in the dark, but does `paste(errs, collapse=\\n)` give you problems? What if you take your `errs = paste(errs, collapse=\n)` and call `writeLines` on `errs` to a tmp file that you provide the path for to rJython, which then reads the file and append into a message. Also -- if you want to be reading the file normally on windows, shouldn't you be using windows line endings (I think \r\n), or does outlook recognize \n as a new line (I'm imagining if you do get the whole thing to work, outlook might still just show you one long line since \n alone isn't recognized as a newline command on windows (last time I checked)). -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact [[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.
Re: [R] rJython matrix message
This fixed it: paste(errs, collapse=\\n) Since that fixed it, I did not try anything else. Thanks again, Ben On Wed, Sep 14, 2011 at 10:04 AM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: Hi, On Wed, Sep 14, 2011 at 12:01 PM, Ben qant ccqu...@gmail.com wrote: That fixed it!! Thank you very much! I should have thought of that. For the sake of others that might stumble on this thread -- what fixed it, exactly? Doing paste(errs, collapse=\\n), or the writing to a tmp file thing, or? -steve Thanks again, Ben On Wed, Sep 14, 2011 at 9:57 AM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: Hi, On Wed, Sep 14, 2011 at 11:44 AM, Ben qant ccqu...@gmail.com wrote: Hello, I've posted something similar under a different subject and never received a solution. Trying again with (hopefully) a better description. Objective: Send a matrix of string data in an email message. The message must have authentication and be sent via an R script. I'm almost there! Here is where I am at: I collect long error message lines in 'errs', which is a matrix. (I might collect this into a list, but that's just a matter of style) Then I collapse them into a character vector via: errs = paste(errs, collapse = ) Then I send that in a email via rJython. The message is sent to an Microsoft Outlook address like this: mail = c( etc... paste(msg = MIMEText(',errs,'),sep=), ...etc) ...etc... [the rest of the rJython stuff to send a message omitted here] jython.exec(rJython,mail) The problem: The issue is that the message wraps the text in the body of the message so that the message just looks like one big line of text which makes it very difficult to read (aka is not acceptable). Notes: 1) The message must have authentication; therefore, I am using rJython. (My understanding is that there is no R way to send an email message with authentication.) 2) I have to receive the message in Outlook. 3) When I do errs = paste(errs, collapse = \n), and pass that as the message text, rJython gives me an error: Error in ls(envir = envir, all.names = private) : invalid 'envir' argument It's hard to imagine why this would happen. using `paste(errs, collapse=)` vs. `paste(errs, collapse=\n)` will provide you with one character vector/string, so I've got to believe the problem is somewhere else. Just a stab in the dark, but does `paste(errs, collapse=\\n)` give you problems? What if you take your `errs = paste(errs, collapse=\n)` and call `writeLines` on `errs` to a tmp file that you provide the path for to rJython, which then reads the file and append into a message. Also -- if you want to be reading the file normally on windows, shouldn't you be using windows line endings (I think \r\n), or does outlook recognize \n as a new line (I'm imagining if you do get the whole thing to work, outlook might still just show you one long line since \n alone isn't recognized as a newline command on windows (last time I checked)). -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact [[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] DBS to R
Hello, I have a bunch of data files all with dbs file extensions. They are generated via a SQL query from another program and source. Does anyone know (or have ideas) how to get the data from a dbs file type into R (or into some other format that can imported to R)? I've searched online for 4 hours now... Thanks! Ben [[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.
Re: [R] DBS to R
Recap: trying to get a 'dbs' extension file into R. I tried most of the functions in the 'forgein' package. Nothing there worked. Scan seemed to do the best. See below... I've tired using readBin() for hours and I haven't extracted the value I want, price. This example is a tiny sample dbs file that should have ticker, fye month, company, split fact, and price, where ticker = 'IBM'; fye month='N/A'; Company='---'; split fact= '2.00' (5/27/99), '2.00' (5/28/97), and 'N/A'; Price='165.25' (9/02/11). As you might have guessed this is stock time series data on one stock (IBM). See the end of this email. I can see the ticker and Company, but nothing else seems reveal itself. to.read =scan(C:\\some_path\\one_test2.dbs,rb) to.read[1:600] [1] VER 3.7 \b \002\017\b\b *TICKER NZCIFYE FYE MONTH NZCICNAMECOMPANY NZCISPLITS SPLIT [14] FACTNZP 3PRICEXX XX XX XX XX XX XX XX XX XX [27] XX XX XX XX XX XX XX XX XX XX XX XX XX [40] XX XX XX XX XX XX XX XX XX XX XX XX XX to.read[600:length(to.read)] [1] XXXX XXXX XXXX [7] XXXX XXXX XXXX [13] XXXX XXXX XXXX ...cont'd.. [565] [571] [577] [583] [589] [595] [601] [607] IBM ñØ---Jq @qn @ À\035tÉ Any ideas or suggestions? I'm thinking readBin() is the way to go but all I get are meaningless numbers and the character strings you see above. However, I think scan() with the rb is doing a similar thing to readBin(). (If you are curious, when using readBin() I'm using integer(), n = 10, size = 8 (but I've tried many others), and endian='little.) Thank you so much for your help! Ben On Sat, Sep 10, 2011 at 1:50 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: No experience with dbs files, but the foreign package might be able to help you out. Michael On Sat, Sep 10, 2011 at 2:44 PM, Ben qant ccqu...@gmail.com wrote: Hello, I have a bunch of data files all with dbs file extensions. They are generated via a SQL query from another program and source. Does anyone know (or have ideas) how to get the data from a dbs file type into R (or into some other format that can imported to R)? I've searched online for 4 hours now... Thanks! Ben [[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. [[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.
Re: [R] DBS to R
The below is how scan() printed it in R...no obscured data here. I'm guessing that the 'XX's are place fillers because I read in only one ticker. The true 'source' is an SQL query. The other program isn't anything anyone would know about here. Thanks for any suggestions, ben On Sat, Sep 10, 2011 at 6:46 PM, Sarah Goslee sarah.gos...@gmail.comwrote: I'm assuming you don't have access to the original program and source, but do you know what it is, and what version? (If you do have access to the original, then just export it in a different format.) The identity of the program would definitely help in reverse-engineering the format or finding a way to convert it. In your example, are you really getting XX for all entries, or are you obfuscating the data? Sarah On Sat, Sep 10, 2011 at 7:54 PM, Ben qant ccqu...@gmail.com wrote: Recap: trying to get a 'dbs' extension file into R. I tried most of the functions in the 'forgein' package. Nothing there worked. Scan seemed to do the best. See below... I've tired using readBin() for hours and I haven't extracted the value I want, price. This example is a tiny sample dbs file that should have ticker, fye month, company, split fact, and price, where ticker = 'IBM'; fye month='N/A'; Company='---'; split fact= '2.00' (5/27/99), '2.00' (5/28/97), and 'N/A'; Price='165.25' (9/02/11). As you might have guessed this is stock time series data on one stock (IBM). See the end of this email. I can see the ticker and Company, but nothing else seems reveal itself. to.read =scan(C:\\some_path\\one_test2.dbs,rb) to.read[1:600] [1] VER 3.7 \b \002\017\b\b *TICKER NZCIFYE FYE MONTH NZCICNAMECOMPANY NZCISPLITS SPLIT [14] FACTNZP 3PRICEXX XX XX XX XX XX XX XX XX XX [27] XX XX XX XX XX XX XX XX XX XX XX XX XX [40] XX XX XX XX XX XX XX XX XX XX XX XX XX to.read[600:length(to.read)] [1] XXXX XXXX XXXX [7] XXXX XXXX XXXX [13] XXXX XXXX XXXX ...cont'd.. [565] [571] [577] [583] [589] [595] [601] [607] IBM ñØ---Jq @qn @ À\035tÉ Any ideas or suggestions? I'm thinking readBin() is the way to go but all I get are meaningless numbers and the character strings you see above. However, I think scan() with the rb is doing a similar thing to readBin(). (If you are curious, when using readBin() I'm using integer(), n = 10, size = 8 (but I've tried many others), and endian='little.) Thank you so much for your help! Ben On Sat, Sep 10, 2011 at 1:50 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: No experience with dbs files, but the foreign package might be able to help you out. Michael On Sat, Sep 10, 2011 at 2:44 PM, Ben qant ccqu...@gmail.com wrote: Hello, I have a bunch of data files all with dbs file extensions. They are generated via a SQL query from another program and source. Does anyone know (or have ideas) how to get the data from a dbs file type into R (or into some other format that can imported to R)? I've searched online for 4 hours now... Thanks! Ben -- Sarah Goslee http://www.functionaldiversity.org [[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] previous monday date
Hello, I'm attempting to return the date (in form '%Y-%m-%d') of the Monday previous to the current date. For example: since it is 2011-09-02 today, I would expect 2011-08-29 to be the return value. I found the following in: http://www.mail-archive.com/r-help@r-project.org/msg144184.html Start quote from link: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) For example, prevmonday(Sys.Date()) [1] 2011-08-15 prevmonday(prevmonday(Sys.Date())) [1] 2011-08-15 End quote from link. But when I do it I get: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) prevmonday(Sys.Date()) Error in as.Date.numeric(1 - 4) : 'origin' must be supplied I've tried setting the 'origin' argument in as.Date() in different ways, but it returns inaccurate results. Thanks, Ben [[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.
Re: [R] previous monday date
I didn't sort out the issue in my email below but here is a (not very R'ish) solution: pm = function(x) { + for(i in 1:7){ + if(format(as.Date(Sys.Date()-i),'%w') == 1){ + d = Sys.Date() - i; + } + } + d + } pm(Sys.Date()) [1] 2011-08-29 On Fri, Sep 2, 2011 at 9:35 AM, Ben qant ccqu...@gmail.com wrote: Hello, I'm attempting to return the date (in form '%Y-%m-%d') of the Monday previous to the current date. For example: since it is 2011-09-02 today, I would expect 2011-08-29 to be the return value. I found the following in: http://www.mail-archive.com/r-help@r-project.org/msg144184.html Start quote from link: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) For example, prevmonday(Sys.Date()) [1] 2011-08-15 prevmonday(prevmonday(Sys.Date())) [1] 2011-08-15 End quote from link. But when I do it I get: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) prevmonday(Sys.Date()) Error in as.Date.numeric(1 - 4) : 'origin' must be supplied I've tried setting the 'origin' argument in as.Date() in different ways, but it returns inaccurate results. Thanks, Ben [[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.
Re: [R] previous monday date
Oh OK, missed that. Here is a solution using base: (already posted) I didn't sort out the issue in my email below but here is a (not very R'ish) solution: pm = function(x) { + for(i in 1:7){ + if(format(as.Date(Sys.Date()- i),'%w') == 1){ + d = Sys.Date() - i; + } + } + d + } pm(Sys.Date()) [1] 2011-08-29 On Fri, Sep 2, 2011 at 9:59 AM, Marc Schwartz marc_schwa...@me.com wrote: On Sep 2, 2011, at 10:35 AM, Ben qant wrote: Hello, I'm attempting to return the date (in form '%Y-%m-%d') of the Monday previous to the current date. For example: since it is 2011-09-02 today, I would expect 2011-08-29 to be the return value. I found the following in: http://www.mail-archive.com/r-help@r-project.org/msg144184.html Start quote from link: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) For example, prevmonday(Sys.Date()) [1] 2011-08-15 prevmonday(prevmonday(Sys.Date())) [1] 2011-08-15 End quote from link. But when I do it I get: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) prevmonday(Sys.Date()) Error in as.Date.numeric(1 - 4) : 'origin' must be supplied I've tried setting the 'origin' argument in as.Date() in different ways, but it returns inaccurate results. Thanks, Ben If memory serves, this is because Gabor used the version of as.Date() from his 'zoo' package in that post, which does not require an origin to be specified, whereas the default as.Date() function in R's base package does: prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4) prevmonday(Sys.Date()) Error in as.Date.numeric(1 - 4) : 'origin' must be supplied require(zoo) Loading required package: zoo Attaching package: 'zoo' The following object(s) are masked from 'package:base': as.Date prevmonday(Sys.Date()) [1] 2011-08-29 # Remove 'zoo' to use the base function detach(package:zoo) prevmonday(Sys.Date()) Error in as.Date.numeric(1 - 4) : 'origin' must be supplied # Fix the function to use base::as.Date() prevmonday - function(x) 7 * floor(as.numeric(x-1+4) / 7) + as.Date(1-4, origin = 1970-01-01) prevmonday(Sys.Date()) [1] 2011-08-29 See ?as.Date HTH, Marc Schwartz [[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.
Re: [R] character vector to text with returns
Hello, I need to clarify, Henrique's suggestion worked great for getting the text that I needed via cat(), but I haven't sorted out how to get cat() like output into a variable so I can pass it into the message body variable I am using. Here is what I mean: x [1] a b c d paste(x,collapse='\n') [1] a\nb\nc\nd y = paste(x,collapse='\n') cat(y) a b c d This is the problem with 'y' has the msg body: paste(msg = MIMEText(',y,'),sep=) [1] msg = MIMEText('a\nb\nc\nd') This is what I am after (I think!): paste(msg = MIMEText(',y,'),sep=) [1] msg = MIMEText('a b c d') Here is how I am actually using it (with sensitive items generalized): require(rJython) rJython - rJython() rJython$exec( import smtplib ) rJython$exec(from email.MIMEText import MIMEText) rJython$exec(import email.utils) mail-c( #Email settings fromaddr = 'ccqu...@gmail.com', toaddrs = 'userna...@somethinghere.com', #msg = MIMEText('test message from R'), paste(msg = MIMEText(',y,'),sep=),# my message in this example is 'y' msg['From'] = email.utils.formataddr(('gmail acct', fromaddr)), msg['To'] = email.utils.formataddr(('cc email!', toaddrs)), msg['Subject'] = 'test with y', #SMTP server credentials username = 'ccqu...@gmail.com', password = 'a password here', #Set SMTP server and send email, e.g., google mail SMTP server server = smtplib.SMTP('smtp.gmail.com:587'), server.ehlo(), server.starttls(), server.ehlo(), server.login(username,password), server.sendmail(fromaddr, toaddrs, msg.as_string()), server.quit()) jython.exec(rJython,mail) # and here is the error I get. Error in ls(envir = envir, all.names = private) : invalid 'envir' argument Just in case someone asks, I can do this: y = a test ...and the above email sends fine with 'a test' as the msg body. Any ideas? PS - I received lots of suggestions. Thank you very much for your effort/input. Ben On Mon, Aug 29, 2011 at 9:29 PM, Bert Gunter gunter.ber...@gene.com wrote: Is something like this what you want? x - letters[1:4] x y -do.call(paste,c( paste('',x[1]), as.list(x[2:3]), paste(x[4],''),sep=\n)) y cat(y,\n) -- Bert On Mon, Aug 29, 2011 at 6:59 PM, Ben qant ccqu...@gmail.com wrote: Unfortunately that didn't work. I just says the text is an invalid argument. I also tried saving it in a variable name and passed that in, but that didn't work. I get: Error in ls(envir = envir, all.names = private) : invalid 'envir' argument ...when I try to send the message. Any other ideas? Thanks, Ben On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.com wrote: Try: paste(c(a, b, c), collapse = \n) On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote: Hello, Does anyone know how to convert this: msg [1] a [2] b [3] c To: msg a b c In other words, I need to convert a character vector to a single string with carriage returns for each row. Functionally, I'm attempting to send an email of a character vector in a way that is readable in the email body. I can only input one string as the message body parameter. I'm using rJython to send the email because I need authentication. Thanks! [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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. -- Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions. -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics [[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.
Re: [R] character vector to text with returns
Hello, (Sorry if this is a dup post...) I need to clarify, Henrique's suggestion worked great for getting the text that I needed via cat(), but I haven't sorted out how to get cat() like output into a variable so I can pass it into the message body variable I am using. Here is what I mean: x [1] a b c d paste(x,collapse='\n') [1] a\nb\nc\nd y = paste(x,collapse='\n') cat(y) a b c d This is the problem with 'y' has the msg body: paste(msg = MIMEText(',y,'),sep=) [1] msg = MIMEText('a\nb\nc\nd') This is what I am after (I think!): paste(msg = MIMEText(',y,'),sep=) [1] msg = MIMEText('a b c d') Here is how I am actually using it (with sensitive items generalized): require(rJython) rJython - rJython() rJython$exec( import smtplib ) rJython$exec(from email.MIMEText import MIMEText) rJython$exec(import email.utils) mail-c( #Email settings fromaddr = 'ccqu...@gmail.com', toaddrs = 'userna...@somethinghere.com' - Show quoted text - jython.exec(rJython,mail) # and here is the error I get. Error in ls(envir = envir, all.names = private) : invalid 'envir' argument Just in case someone asks, I can do this: y = a test ...and the above email sends fine with 'a test' as the msg body. Any ideas? PS - I received lots of suggestions. Thank you very much for your effort/input. Ben On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.comwrote: Try: paste(c(a, b, c), collapse = \n) On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote: Hello, Does anyone know how to convert this: msg [1] a [2] b [3] c To: msg a b c In other words, I need to convert a character vector to a single string with carriage returns for each row. Functionally, I'm attempting to send an email of a character vector in a way that is readable in the email body. I can only input one string as the message body parameter. I'm using rJython to send the email because I need authentication. Thanks! [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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.
Re: [R] character vector to text with returns
David, Yes, I understand that cat() won't do what I want, but that is the only way I can illustrate what I am after. Note the phrasing in my question: '...cat() like...' Regarding assigning the paste to a variable: it produces the same error. I've already tried that. Thanks for your suggestion! Ben On Tue, Aug 30, 2011 at 11:24 AM, David Winsemius dwinsem...@comcast.netwrote: On Aug 30, 2011, at 1:09 PM, Ben qant wrote: Hello, (Sorry if this is a dup post...) I need to clarify, Henrique's suggestion worked great for getting the text that I needed via cat(), but I haven't sorted out how to get cat() like output into a variable so I can pass it into the message body variable I am using. cat() is not the right function to get text assgned to an object. It's entire purpose is to have a side-effect and _not_ return anything into R's workspace. Why are you not assigning the result of that paste operation to the variable? Here is what I mean: x [1] a b c d paste(x,collapse='\n') [1] a\nb\nc\nd y = paste(x,collapse='\n') cat(y) a b c d This is the problem with 'y' has the msg body: paste(msg = MIMEText(',y,'),sep=) [1] msg = MIMEText('a\nb\nc\nd') This is what I am after (I think!): paste(msg = MIMEText(',y,'),sep=) [1] msg = MIMEText('a b c d') Here is how I am actually using it (with sensitive items generalized): require(rJython) rJython - rJython() rJython$exec( import smtplib ) rJython$exec(from email.MIMEText import MIMEText) rJython$exec(import email.utils) mail-c( #Email settings fromaddr = 'ccqu...@gmail.com', toaddrs = 'userna...@somethinghere.com' - Show quoted text - jython.exec(rJython,mail) # and here is the error I get. Error in ls(envir = envir, all.names = private) : invalid 'envir' argument Just in case someone asks, I can do this: y = a test ...and the above email sends fine with 'a test' as the msg body. Any ideas? PS - I received lots of suggestions. Thank you very much for your effort/input. Ben On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.com wrote: Try: paste(c(a, b, c), collapse = \n) On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote: Hello, Does anyone know how to convert this: msg [1] a [2] b [3] c To: msg a b c In other words, I need to convert a character vector to a single string with carriage returns for each row. Functionally, I'm attempting to send an email of a character vector in a way that is readable in the email body. I can only input one string as the message body parameter. I'm using rJython to send the email because I need authentication. Thanks! [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT [[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.
Re: [R] R.oo data members / inheritance
Henrik, Your last suggestion did not work for me. It seems like it does not allow me to create a ClassB object with 3 arguments: setConstructorS3(ClassA, function(A=15, x=NA) { + extend(Object(), ClassA, +.size = A, +.x=x + ) + }) setConstructorS3(ClassB, function(..., bData=NA) { + extend(ClassA(...), ClassB, + .bData = bData + ) + }) b = ClassB(1,2,3) Error in ClassA(...) : unused argument(s) (3) I got around it using your 'specific' suggestion: setConstructorS3(ClassA, function(A=15, x=NA) { + extend(Object(), ClassA, +.size = A, +.x=x + ) + }) setConstructorS3(ClassB, function(..., bData=NA) { + extend(ClassA(A=15,x=NA), ClassB, + .bData = bData + ) + }) b = ClassB(1,2,3) [[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.
Re: [R] R.oo data members / inheritance
Correction. My solution didn't work either Didn't return the correct values. Can you post an example that takes three arguments? I'm working on how to do this now. thanks...sorry. Im new to R and R.oo. Ben On Mon, Aug 29, 2011 at 8:35 AM, Ben qant ccqu...@gmail.com wrote: Henrik, Your last suggestion did not work for me. It seems like it does not allow me to create a ClassB object with 3 arguments: setConstructorS3(ClassA, function(A=15, x=NA) { + extend(Object(), ClassA, +.size = A, +.x=x + ) + }) setConstructorS3(ClassB, function(..., bData=NA) { + extend(ClassA(...), ClassB, + .bData = bData + ) + }) b = ClassB(1,2,3) Error in ClassA(...) : unused argument(s) (3) I got around it using your 'specific' suggestion: setConstructorS3(ClassA, function(A=15, x=NA) { + extend(Object(), ClassA, +.size = A, +.x=x + ) + }) setConstructorS3(ClassB, function(..., bData=NA) { + extend(ClassA(A=15,x=NA), ClassB, + .bData = bData + ) + }) b = ClassB(1,2,3) [[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] character vector to text with returns
Hello, Does anyone know how to convert this: msg [1] a [2] b [3] c To: msg a b c In other words, I need to convert a character vector to a single string with carriage returns for each row. Functionally, I'm attempting to send an email of a character vector in a way that is readable in the email body. I can only input one string as the message body parameter. I'm using rJython to send the email because I need authentication. Thanks! [[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.
Re: [R] character vector to text with returns
Unfortunately that didn't work. I just says the text is an invalid argument. I also tried saving it in a variable name and passed that in, but that didn't work. I get: Error in ls(envir = envir, all.names = private) : invalid 'envir' argument ...when I try to send the message. Any other ideas? Thanks, Ben On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.comwrote: Try: paste(c(a, b, c), collapse = \n) On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote: Hello, Does anyone know how to convert this: msg [1] a [2] b [3] c To: msg a b c In other words, I need to convert a character vector to a single string with carriage returns for each row. Functionally, I'm attempting to send an email of a character vector in a way that is readable in the email body. I can only input one string as the message body parameter. I'm using rJython to send the email because I need authentication. Thanks! [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] R.oo data members / inheritance
If someone is able, can you tell me if there is a better way to do this? More specifically, do I have to rewrite all of the data members stuff and extend stuff of parent class in the child class? See below. Thanks in advance! Example 1: setConstructorS3(ClassA, function(A,x) { if(missing(A))A=15; if(missing(x))x=NA; extend(Object(), ClassA, .size = A, .x=x ) }) setMethodS3(getSize, ClassA, function(this,...) { this$.size; }) setMethodS3(getX, ClassA, function(this,...) { this$.x; }) setConstructorS3(ClassB, function(A,x,bData) { if(missing(bData))bData = NA; extend(ClassA(), ClassB, .bData = bData ) }) setMethodS3(getBData, ClassB, function(this,...) { this$.bData; }) Usage: b = ClassB(13,100,6) b$getSize() # I expected to get 13. [1] 15 b$getBData() [1] 6 b$getX() [1] NA# Same thing here. I expected 100. I corrected it by rewriting the ClassA data member defaults and the ClassA extend() stuff within the ClassB class. Example 2: setConstructorS3(ClassA, function(A,x) { if(missing(A))A=15; if(missing(x))x=NA; extend(Object(), ClassA, .size = A, .x=x ) }) setMethodS3(getSize, ClassA, function(this,...) { this$.size; }) setMethodS3(getX, ClassA, function(this,...) { this$.x; }) setConstructorS3(ClassB, function(A,x,bData) { if(missing(bData))bData = NA; if(missing(A))A=15; #added if(missing(x))x=NA; #added extend(ClassA(), ClassB, .bData = bData, .x=x, #added .size=A #added ) }) setMethodS3(getBData, ClassB, function(this,...) { this$.bData; }) b = ClassB(13,100,6) b$getSize() [1] 13 b$getBData() [1] 6 b$getX() [1] 100 Thanks for your help! Ben [[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] R.oo inheritance with pass by reference
I thought I would post an example of using R.oo with inheritance and pass by reference for future searches. With PerMore I am inheriting Person. Then I am changing an object data memeber of an object of PerMore class using pass by reference ('mimiced' by R.oo) in an object of AgeMultiplier. I change a data member in the child class and the parent class for demonstration purposes. This is me giving back to the community...hope it helps. Moral of the story is use your sets and gets rather than obj$dataMember. I am new to R.oo so if you know how to do this better or have some tricks please email me at ccquant@g*m...@il.com. setConstructorS3(Person, function(age) { if (missing(age)) age - NA; extend(Object(), Person, .age=age ) }) setMethodS3(getAge, Person, function(this, ...) { this$.age; }) setMethodS3(setAge, Person, function(this,num, ...) { this$.age = num; }) #.. setConstructorS3(PerMore, function(age,wt) { if (missing(age)) age - NA; if (missing(wt)) wt - NA; extend(Person(), PerMore, .age=age, .wt=wt ) }) setMethodS3(getWeight, PerMore, function(this, ...) { this$.wt; }) setMethodS3(setWeight, PerMore, function(this,w, ...) { this$.wt = w; }) pc = PerMore(67,150) pc$getWeight() # pc$getAge() # 67 #... setConstructorS3(AgeMultiplier, function(m,perobj) { if(missing(m))m=NA; if(missing(perobj))perobj=NA; extend(Object(), AgeMultiplier, .m=m, .perobj=perobj, .AM=NA, .WM=NA ) }) setMethodS3(getPerObj, AgeMultiplier, function(this, ...) { this$.perobj }) setMethodS3(getAM, AgeMultiplier, function(this, ...) { this$.AM }) setMethodS3(getWM, AgeMultiplier, function(this, ...) { this$.WM }) setMethodS3(doMultiplyAge, AgeMultiplier, function(this, ...) { a = this$.perobj; this$.AM = a$getAge() * this$.m; a$setAge(this$.AM); }) setMethodS3(doMultiplyWeight, AgeMultiplier, function(this, ...) { a = this$.perobj; this$.WM = a$getWeight() * this$.m; a$setWeight(this$.WM); # a$wt = this$.WM; - that does not work on an object that inheritance involved }) p1 - PerMore(67,150) am1 = AgeMultiplier(5,p1) am1$doMultiplyAge() p1$age # 335 am1$AM # 335 am1$getAM() # 335 am1$doMultiplyWeight() p1$wt # doesn't work, I don't know why... p1$getWeight() # 750 am1$WM # 750 am1$getWM() # 750 am1$doMultiply() p1$age # 335 am1$AM # 335 am1$getAM() # 335 [[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.
Re: [R] R.oo modify an object inside another classes method
I didn't see an answer to this and I THINK I sorted it out myself so I thought I'd post it for anyone who is interested (in using it or correcting it): My original question: Can someone show me how to modify one (R.oo) class's object inside another (R.oo) class's method? Is that possible with the R.oo package? A quick example or reference to an example would be outstanding... Solution: setConstructorS3(Person, function(age) { if (missing(age)) age - NA; extend(Object(), Person, .age=age ) }) setMethodS3(getAge, Person, function(this, ...) { this$.age; }) setMethodS3(setAge, Person, function(this, newAge, ...) { if (!is.numeric(newAge)) throw(Age must be numeric: , newAge); if (newAge 0) throw(Trying to set a negative age: , newAge); this$.age - newAge; }) setConstructorS3(AgeMultiplier, function() { extend(Object(), AgeMultiplier, .age=NA, .age_multiplied=NA ) }) setMethodS3(doMultiply, AgeMultiplier, function(this,per_obj, ...) { this$.age_multiplied = per_obj$age * 2; per_obj$age = this$.age_multiplied; }) Use example: p1 - Person(67) am1 = AgeMultiplier() am1$doMultiply(p1) p1$age # 134 On Tue, Aug 23, 2011 at 8:22 AM, Ben qant ccqu...@gmail.com wrote: Can someone show me how to modify one (R.oo) class's object inside another (R.oo) class's method? Is that possible with the R.oo package? A quick example or reference to an example would be outstanding... Thanks, Ben [[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] R.oo modify an object inside another classes method
Can someone show me how to modify one (R.oo) class's object inside another (R.oo) class's method? Is that possible with the R.oo package? A quick example or reference to an example would be outstanding... Thanks, Ben [[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] email with authentication
Hello, I'd like to send an email from R using Windows Outlook. The sendmailR package doesn't allow for authentication (usernames and passwords). Is there any other way to do this? From the Windows command line? Right now I am using a .bat file to send an email via a program called Blat. I'd like to reduce our dependencies and run everything in R. Thanks! [[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] rank analysis - reinventing the wheel?
Hello, I have two data frames. One is my dependent variable and the other is my independent variable. For each row I'd like to split the independent variable into fractiles (25 or more) and calculate the average value of the dependent variable. Then I would like to plot the average of the averages for each row for each fractile. If possible, I'd like to have the option to 1) define the fractiles independently for each row, and 2) define the fractiles based off the independent variable data frame as a whole at the start and keep it fixed. Anyway, is there a pacakge/function in R that does something like this so I don't have to reinvent the wheel? If not, any help on how to do this efficiently in R would be great. Here is a super simple example using 3 fractiles: independent data frame: item1 item2 item3 1181516 2121217 3201318 dependent data frame: item1 item2 item3 1 3 1 6 2 2 2 7 3 1 3 8 fractiles by row by item: (done with independent data frame, redefining fractiles each row) fractiles: 12 3 row 1item2 item3 item1 (because 15 16 18) row 2item1,item2[none] item3 (because 12 17 ... or however ties are handled is fine) row 3item2 item3 item1 (because 13 18 20) Note: in the above fractiles there would almost always be more than one item in each fractile if this example wasn't so simple... dependent variable averages by row by fractile: fractiles: 12 3 row 1 1 63 row 2 2 [none] 7 row 3 3 8 1 Note: obviously this example is so simple there aren't actual averages because there aren't enough items for each fractile, but I hope you get the point. So then the averages of the fractiles would be: fractiles: 12 3 dependent data avg: 2 73.67 Then I would like to plot a histogram of the fractile averages directly above. Thanks! [[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] 2 matrix scatter x [a lot]
Hello, I'm pretty new to R. Basically, how do I speed up the for loop below. Or better yet, get rid of the for loop all together. objective: plot two data sets column against column by index. These data sets have alot NA's. Some columns are all NA's. I need the plots to overlay. I don't like the plots in matplot(). Needs to be much faster than the code below... #simple sample data.. my data sets have 61 rows and over 11k columns each. x = matrix(1:4,2,2) y = matrix(4:1,2,2) y[2,2] = NA y[1,1] = NA #calc'd here to save time on plotting xlim.v = c(min(x, na.rm = TRUE),max(x,na.rm = TRUE)) ylim.v = c(min(y, na.rm = TRUE),max(y,na.rm = TRUE)) for(i in 1:ncol(x)){ xy = na.omit(cbind(x[,i],y[,i])) if(length(dim(xy)[1]) 0){ plot(xy[,1],xy[,2],xlim = xlim.v,ylim= ylim.v); par(new=T); } } Thanks! [[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] R.oo error upon construction
Hello, Using the R.oo package, how do I throw an error if a field is not present when the user of the class creates the object? Using the example in the R.oo package: setConstructorS3(Person, function(name, age) { if (missing(name)) name - NA; if (missing(age)) age - NA; extend(Object(), Person, .name=name, .age=age ) }) [rest of class methods here...etc...] User types this with no issues because both age and name are there: p1 - Person(Dalai Lama, 67) User types this and I want it to throw an error because the age field is missing: p1 - Person(Dalai Lama) Link to the example I am drawing from: http://127.0.0.1:22346/library/R.oo/html/Object.html I know how to throw an error when a method is used. I want to throw an error when the object is created. I've tried print and cat statements in the Constructor section and after the extend statement. Thanks, Ben [[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.
Re: [R] R.oo error upon construction
Hey that helps! Wish we could also throw an error if both were missing... Thanks again! Ben On Mon, Aug 8, 2011 at 4:37 PM, Henrik Bengtsson h...@biostat.ucsf.eduwrote: Hi, you can do something like: setConstructorS3(Person, function(name, age) { # Check for missing arguments, but allow for empty # constructor calls, i.e. Person(). if (missing(name) missing(age)) { name - NA; age - NA; } else if (missing(name)) { throw(Argument 'name' is missing.); } else if (missing(age)) { throw(Argument 'age' is missing.); } extend(Object(), Person, .name=name, .age=age ) }) /Henrik On Tue, Aug 9, 2011 at 12:21 AM, Ben qant ccqu...@gmail.com wrote: Hello, Using the R.oo package, how do I throw an error if a field is not present when the user of the class creates the object? Using the example in the R.oo package: setConstructorS3(Person, function(name, age) { if (missing(name)) name - NA; if (missing(age)) age - NA; extend(Object(), Person, .name=name, .age=age ) }) [rest of class methods here...etc...] User types this with no issues because both age and name are there: p1 - Person(Dalai Lama, 67) User types this and I want it to throw an error because the age field is missing: p1 - Person(Dalai Lama) Link to the example I am drawing from: http://127.0.0.1:22346/library/R.oo/html/Object.html I know how to throw an error when a method is used. I want to throw an error when the object is created. I've tried print and cat statements in the Constructor section and after the extend statement. Thanks, Ben [[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. [[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] [?]apply functions or for loop
Hello, First time posting to this mail list. I'd like to use R in the most efficient way. I'm accomplishing what I want, but feel there is a more R'ish way to do it. Just learning R. *My goal: get ranks of value across rows with row names and column names intact.* I'm guessing one of the [?]apply functions will do what I need, but I couldn't sort out which one (after a lot of searching). Here is a simplified example of what I am doing. Again, I get the correct result, but I assume there is a better way to do it. x = data.frame(1:4,4) x X1.4 X4 11 4 22 4 33 4 44 4 ranks = matrix(0,nrow(x),ncol(x)) ranks [,1] [,2] [1,]00 [2,]00 [3,]00 [4,]00 for(i in 1:nrow(x)){ + ranks[i,] = rank(x[i,]) + } ranks[i,] [1] 1.5 1.5 ranks [,1] [,2] [1,] 1.0 2.0 [2,] 1.0 2.0 [3,] 1.0 2.0 [4,] 1.5 1.5 rownames(ranks) = rownames(x) ranks [,1] [,2] 1 1.0 2.0 2 1.0 2.0 3 1.0 2.0 4 1.5 1.5 rownames(ranks) = rownames(x) ranks [,1] [,2] 1 1.0 2.0 2 1.0 2.0 3 1.0 2.0 4 1.5 1.5 colnames(ranks) = colnames(x) ranks X1.4 X4 1 1.0 2.0 2 1.0 2.0 3 1.0 2.0 4 1.5 1.5 Thanks, Ben [[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.