Re: [R] change file name from file0.1_data.RData to file1_data.Rdata
use function system in R for (x in 1:100){ system (paste(rename file0.,x,_data.RData file,x,_data.Rdata,sep=)) } - Yasir Kaheil -- View this message in context: http://r.789695.n4.nabble.com/change-file-name-from-file0-1-data-RData-to-file1-data-Rdata-tp4637135p4637136.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] Entering Data Files
type ?read.table in R - Yasir Kaheil -- View this message in context: http://r.789695.n4.nabble.com/Entering-Data-Files-tp4636943p4636959.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] PCA
in biplot you could set the limits xlim, ylim of the axes to zoom in on the plot. - Yasir Kaheil -- View this message in context: http://r.789695.n4.nabble.com/PCA-tp4636840p4636961.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] Merging Data Frames in R
type ?merge in R - Yasir Kaheil -- View this message in context: http://r.789695.n4.nabble.com/Merging-Data-Frames-in-R-tp4636781p4636962.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] read.table with numeric row names
just do this: colnames(r)-substr(colnames(r),2,nchar(colnames(r))) This will remove the X. Later when you want to use the headed to plot something, cast it as numeric: plot(colMeans(r)~as.numeric(colnames(r))) - Yasir Kaheil -- View this message in context: http://r.789695.n4.nabble.com/read-table-with-numeric-row-names-tp4636342p4636354.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] Subset based on multiple values
yes just use %in% instead of == AllMax.. but also use table for count - Yasir Kaheil -- View this message in context: http://r.789695.n4.nabble.com/Subset-based-on-multiple-values-tp4636159p4636183.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] Spectral analysis with mtm-svd Multi-Taper Method Combined with Singular Value Decomposition
Hi list, Does anyone know if there is a library in R that does MTM-SVD method for spectral analysis? Thanks - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/Spectral-analysis-with-mtm-svd-Multi-Taper-Method-Combined-with-Singular-Value-Decomposition-tp21671934p21671934.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] create sequences from two from and to vectors
hi all, how can I create sequences that start from a known vector, say x1 and end with another say x2- also suppose all the sequences will be the same length. I don't want to use a for loop x1-c(1,2,3,4); x2-(3,4,5,6); what I want is 1 2 3 4 2 3 4 5 3 4 5 6 Thanks - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/create-sequences-from-two-%22from%22-and-%22to%22-vectors-tp21380194p21380194.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] create sequences from two from and to vectors
Great! thank you so much! Dimitris Rizopoulos-4 wrote: one way is using mapply(), e.g., mapply(:, 1:4, 3:6) I hope it helps. Best, Dimitris Yasir Kaheil wrote: hi all, how can I create sequences that start from a known vector, say x1 and end with another say x2- also suppose all the sequences will be the same length. I don't want to use a for loop x1-c(1,2,3,4); x2-(3,4,5,6); what I want is 1 2 3 4 2 3 4 5 3 4 5 6 Thanks - Yasir H. Kaheil Columbia University -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ 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. - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/create-sequences-from-two-%22from%22-and-%22to%22-vectors-tp21380194p21380311.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] generating a random signal with a known correlation
Hi, How can I generate a random signal that's correlated with a given signal at a given correlation (say 0.7)? I've been looking at rmvnorm etc but don't seem to figure it out. Thanks - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/generating-a-random-signal-with-a-known-correlation-tp18932541p18932541.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] generating a random signal with a known correlation
OK, here is the code for those who are interested: x-rnorm(1000, mean=20, sd=100); x.s-scale(x) xp-pnorm(x.s); xix- sort(xp,index.return=TRUE)$ix norm.cop - normalCopula(0.6) #correlation of 0.6, other libraries can be used instead of copula y - rcopula(norm.cop, length(x)) yp-pnorm(y) ypix- sort(yp[,1],index.return=TRUE)$ix yp-yp[ypix,]; yps-yp[,1];# dummy initialization yps[xix]-yp[,2]; #adjust mean and sd here. yqs-qnorm(yps,mean=mean(x),sd=sd(x)); cor(x,yqs) Yasir Kaheil wrote: Hi, How can I generate a random signal that's correlated with a given signal at a given correlation (say 0.7)? I've been looking at rmvnorm etc but don't seem to figure it out. Thanks - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/generating-a-random-signal-with-a-known-correlation-tp18932541p18937754.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] Is there way to multiple plots on gap.plot?
yeah, just use points twogrp-c(rnorm(5)+4,rnorm(5)+20,rnorm(5)+5,rnorm(5)+22) gpcol-c(2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5) gap.plot(twogrp,gap=c(8,12),xlab=Index,ylab=Group values, main=Plot gap on Y axis,col=gpcol) twogrp2-c(rnorm(5)+4,rnorm(5)+20,rnorm(5)+5,rnorm(5)+22) points(twogrp2, pch=20, cex=1.2, col=gpcol) Arthur Roberts wrote: Hi, all, Does anyone now of a way to put multiple plots on gap.plot? Much appreciated, Art __ 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. - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/Is-there-way-to-multiple-plots-on-gap.plot--tp18697486p18697604.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] Fill in NA values in vector with previous character/factor
maybe this is easiest way to do it: x-c(A,B,NA,NA,C,NA,NA,NA,NA,D,NA,NA); x[is.na(x)]- D; x thanks y Owen Jones-3 wrote: I have a vector of data (species names) interspersed with NA values and I want a function to fill in the blanks, replacing NA values with whatever the last species name was. For example the vector: A,B,NA,NA,C,NA,NA,NA,NA,D,NA,NA. should evaluate to: A B B B C C C C C D D D I tried to use rle() in a function to do this but have hit a brick wall. How would YOU do this? Many thanks, Owen __ 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. - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/Fill-in-NA-values-in-vector-with-previous-character-factor-tp18697427p18697756.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] Insurance review statistical methods
yes R has everything that TRICAST offers.. and much more Kenneth Cabrera-2 wrote: Hi R users: I will like to know if somebody works on insurance statistics (actuarial problems) and had use TRICAST, and can tell me if with all the R tools it can be build a solution like TRICAST or similar. In a word: Do you think that R has all the statistical tools (I mean modeling tools) to make a job similar to TRICAST? Does TRICAST has modeling tools that are not implemented on R yet? Thank you for your help. Kenneth -- Kenneth Roy Cabrera Torres [EMAIL PROTECTED] __ 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. - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/Insurance-review-statistical-methods-tp18454105p18462572.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] outlining symbol in legend with blackline
yes use plotting chars 22, 21 replace your legend statement with: legend(x=topright, legend=c(2006 mean, 2007 mean, 2008 mean, 1964-2005 mean \n max and min flows ), pch=c(22, 22, 22, 21), col=c(1,1,1,1), pt.bg=c(grey.colors(3, gamma=4),black), cex=1.5) box(which=plot, lty=solid) thnaks y stephen sefick wrote: # I would like to outline the squares in the legend with a black line. Does anyone know how to do this? x.t - structure(c(5987.387, 4354.516, 3685.789, 6478.592, 5924.315, NA, 8386, 5559.468, NA, 4651.273, 3967.5, NA, 4339.167, 5053.56, NA, 4631.978, 4808.694, NA, 5217.306, 4017.632, NA, 5846.903, 3969.883, NA, 3867.825, 3910.236, NA, 3886.434, 3782.094, NA, 3959.668, 3961.286, NA, 3848.853, 3711.262, NA), .Dim = c(3L, 12L), .Dimnames = list(c(Year.2006, Year.2007, Year.2008 ), c(January, February, March, April, May, June, July, August, September, October, November, December ))) library(IDPmisc) barplot(x.t, beside=T, ylim=c(0, 4), yaxt=n, ylab=Discharge(cfs), col=grey.colors(3, gamma=4)) axis(side=2, at=c(0,4000 ,7000, 1,15000, 2,25000,3,35000,4)) legend(x=topright, legend=c(2006 mean, 2007 mean, 2008 mean, 1964-2005 mean \n max and min flows ), pch=c(15, 15, 15, 19), col=c(grey.colors(3, gamma=4),black), cex=1.5) box(which=plot, lty=solid) points(2.5, 8313, pch=19, lwd=4) points(6, 9665, pch=19, lwd=4) points(10, 10675, pch=19, lwd=4) points(14, 10303, pch=19, lwd=4) points(18, 7926, pch=19, lwd=4) points(22, 7278, pch=19, lwd=4) points(26, 6472, pch=19, lwd=4) points(30, 6719, pch=19, lwd=4) points(34, 6123, pch=19, lwd=4) points(38, 6280, pch=19, lwd=4) points(42, 6334, pch=19, lwd=4) points(46, 7707, pch=19, lwd=4) #max thurmond flow bar Arrows(2.5, 8229, 2.5, 25580, size=0, sh.lwd=4) Arrows(6, 9555, 6, 28571, size=0, sh.lwd=4) Arrows(10, 10547, 10, 23153, size=0, sh.lwd=4) Arrows(14, 10182, 14, 37591, size=0, sh.lwd=4) Arrows(18, 7847, 18, 22521, size=0, sh.lwd=4) Arrows(22, 7206, 22, 18384, size=0, sh.lwd=4) Arrows(26, 6472, 26, 15489, size=0, sh.lwd=4) Arrows(30, 6719, 30, 16659, size=0, sh.lwd=4) Arrows(34, 6123, 34, 11841, size=0, sh.lwd=4) Arrows(38, 6280, 38, 14282, size=0, sh.lwd=4) Arrows(42, 6334, 42, 17364, size=0, sh.lwd=4) Arrows(46, 7707, 46, 25877, size=0, sh.lwd=4) #min thurmond flow bar Arrows(2.5, 8229, 2.5, 3602, size=0, sh.lwd=4) Arrows(6, 9555, 6, 3377, size=0, sh.lwd=4) Arrows(10, 10547, 10, 3490, size=0, sh.lwd=4) Arrows(14, 10182, 14, 3278, size=0, sh.lwd=4) Arrows(18, 7847, 18, 3579, size=0, sh.lwd=4) Arrows(22, 7206, 22, 3605, size=0, sh.lwd=4) Arrows(26, 6472, 26, 3579, size=0, sh.lwd=4) Arrows(30, 6719, 30, 3734, size=0, sh.lwd=4) Arrows(34, 6123, 34, 3694, size=0, sh.lwd=4) Arrows(38, 6280, 38, 3657, size=0, sh.lwd=4) Arrows(42, 6334, 42, 3287, size=0, sh.lwd=4) Arrows(46, 7707, 46, 3345, size=0, sh.lwd=4) -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/outlining-symbol-in-legend-with-blackline-tp18367274p18368074.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] netCDF to TIFF
the function is there in grDevices http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/png.html type ? png if tiff() is not listed, you need to update R to get the new base with new grDevices. thanks y Daniel Steinberg wrote: Greetings R users! I am working with the ENSEMBLE climate data (10 min resolution daily temperatures images for all of Europe 1950-2006). The data comes packaged in a single netCDF file. I would like to read the data in and export a subset (2002-2006) as geotiffs (one image per day). So far, I can successfully read in the data and view the images within an R display window. However, I have yet to figure out how to export the images as tiffs or geotiffs. Does anyone out there have experience converting netCDF grids to TIFFs? After reading the data into R, I have it stored in a dataframe with longitude values as the column names, latitude values as the row names, and temperatures as the actual values. Below is my code thus far that I adapted from an example on the UCAR website. Thanks in advance! -Dan -- # Set working directory and load library setwd('C:/Users/steinber/Documents/DATA/ENSEMBLES/') library(ncdf) library(rgdal) library(chron) library(fields) # Read netCDF file tg.ncdf = open.ncdf('tg_0.25deg_CRU_version1.0.nc') tg.ncdf lonmat = get.var.ncdf(nc=tg.ncdf,varid=longitude) # reads entire matrix latmat = get.var.ncdf(nc=tg.ncdf,varid=latitude)# ditto timearr = get.var.ncdf(nc=tg.ncdf,varid=time)# reads entire time array targettime = julian(x=1, d=1, y=2002, origin=c(month = 1, day = 1, year = 1950)) inds = (1:dim(timearr)) tind = inds[targettime == timearr] ndims= tg.ncdf$var[['data']]$ndims varsize = tg.ncdf$var[['data']]$varsize start = c(1, 1, tind) count = c(varsize[1], varsize[2],1) # Read in data slice: tg.data = get.var.ncdf(nc=tg.ncdf,varid=data,start,count) tg.data[tg.data == -] = NA tg.data = tg.data/100.0 x = 1:nrow(tg.data) # R plots rows along X axis! y = 1:ncol(tg.data) image.plot(x,y,tg.data,col=tim.colors()) test.data = data.frame(tg.data, row.names = lonmat) colnames(test.data) = latmat __ 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. - Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/netCDF-to-TIFF-tp18360688p18368372.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] array of arrays
Is it possible to have one array for bias and one for variance? such as.. biasAr= b1 b2 a1 biasbias a2 biasbias and varAr= b1 b2 a1 var var a2 var var then you can combine the two in a data frame? thanks y Michael Prince wrote: Dear R users, I want to calculate the bias and variance of an estimator for several values of two parameters a and b. For example : b1 b2 a1 bias bias variance variance a2 bias bias variance variance Can one do array of arrays ? I have tried and it did not work. Actually I would like to get this array for several values of the number of observations. That would be an array of arrays of arrays :-) Maybe there is a better way to do that... Is there also a way to export arrays to Latex ? Thank you very much [[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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/array-of-arrays-tp17655733p17658264.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] SVD on a matix
the variance is the eigen values of the correlation matrix of yoru matrix X.cor - cor(X) X.e - eigen(X.cor) X.e$values# Eigenvalues of cor(X) = variances you're asking about kayj wrote: Hi All, I performed an svd on a matrix X and saved the first three column of the left singular matrix U. ( I assume that they correspond to the projection of the matrix on the first three eigen vectors that corresponds to the first three largest eigenvalues). I would like to know how much variance is explained by the first eigenvectors? how can I find that. Thanks for your help - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/SVD-on-a-matix-tp17441337p17455129.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] R-Excel Macro Problem
hi Nate, could you please email me your excel workbook. thanks y nmarti wrote: I'm trying to write R functions into VBA code. I've done this many other times in other documents and everything has run great. But today I keep recieving an error message Run-time error '1004': Application-defined or object-defined error. Has anyone else encountered this same error message? I do not recieve this error in the document when running regular VBA code. But when I try to run, Call Rinterface.PutDataframe(Data, Range(Sheet1!A1:E2000)) I receive the error. I have the VBA References RExcelVBAlib checked. Any suggestions would be appreiciated, Nate - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/R-Excel-Macro-Problem-tp17450757p17455095.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] R-Excel Macro Problem
glad to hear things worked out. y nmarti wrote: Ok, so I'm embarrassed to admit I made a really dumb mistake. My VBA page was declared as Sheet1 code when it should have been Module1 code. I knew it was something stupid. Sorry for the inconvenience. Yasir Kaheil wrote: hi Nate, could you please email me your excel workbook. thanks y nmarti wrote: I'm trying to write R functions into VBA code. I've done this many other times in other documents and everything has run great. But today I keep recieving an error message Run-time error '1004': Application-defined or object-defined error. Has anyone else encountered this same error message? I do not recieve this error in the document when running regular VBA code. But when I try to run, Call Rinterface.PutDataframe(Data, Range(Sheet1!A1:E2000)) I receive the error. I have the VBA References RExcelVBAlib checked. Any suggestions would be appreiciated, Nate - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/R-Excel-Macro-Problem-tp17450757p17462407.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] Question about Runuran (Triangular Distribution)
Please refer to: qtriangle function in VGAM library thanks y Alberto Monteiro wrote: The Runuran package includes a simulation for the Triangular Distribution, urtriang. But I didn't find an analogue of the q* functions (rnorm - qnorm, runif - qunif), that would invert the CDF (?uqtriang). Are there any such functions? Alberto Monteiro __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Question-about-Runuran-%28Triangular-Distribution%29-tp17427688p17428151.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] question for Logic Regression
try: alltrees - predict(logicfit) coldeyes wrote: thanks for you response, i try predict command, it is doesn't work. i list a simulate code below: X - matrix(as.numeric(runif(400) 0.5), 50,8) colnames(X) - paste(X, 1:ncol(X), sep=) rownames(X) - paste(case, 1:nrow(X), sep=) # Define expected result: Y = (NOT X2) AND X6 Y - as.numeric(!X[,2] X[,6]) Z-cbin(X,Y) set.seed(12345) Annealing - logreg.anneal.control(start = 4, end = -4, iter = 1000, update = 50) logicfit - logreg(resp=Z[,9], bin=Z[,1:8], type = 3, select = 2, ntrees=2, nleaves=3, anneal.control=Annealing) new-data.frame(Z) new-NULL alltrees - predict(logicfit, new) names(logicfit) doesn't have coef class. thanks Yasir Kaheil wrote: try alltrees - predict(fit, model.dat2) # make sure response variable is not included in model.dat2 also to see the other attributes in fit, try: attributes(fit) thanks y coldeyes.Rhelp wrote: Hi All: how to get the coefficient for logic regression using selection=2 ( fit multiple models) and type=3 ( logistic regression) for example i have a fit like below : fit-logreg(resp = model.dat[,21], bin=model.dat[, 2:18],sep=model.dat[,1] ,type=3,select=2,ntrees=2,nleaves=6 ,anneal.control=Annealing,tree.control=TreeControl) i try to use fit$coef but i get nothing. and i try to use eval.logreg to evaluate a validate data model.dat2, but i cannot fit model class make below formula work alltrees - eval.logreg(fit$model , model.dat2) could anyone enlighten me a little. thanks leo __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/question-for-Logic-Regression-tp17310610p17328322.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] question for Logic Regression
try alltrees - predict(fit, model.dat2) # make sure response variable is not included in model.dat2 also to see the other attributes in fit, try: attributes(fit) thanks y coldeyes.Rhelp wrote: Hi All: how to get the coefficient for logic regression using selection=2 ( fit multiple models) and type=3 ( logistic regression) for example i have a fit like below : fit-logreg(resp = model.dat[,21], bin=model.dat[, 2:18],sep=model.dat[,1] ,type=3,select=2,ntrees=2,nleaves=6 ,anneal.control=Annealing,tree.control=TreeControl) i try to use fit$coef but i get nothing. and i try to use eval.logreg to evaluate a validate data model.dat2, but i cannot fit model class make below formula work alltrees - eval.logreg(fit$model , model.dat2) could anyone enlighten me a little. thanks leo __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/question-for-Logic-Regression-tp17310610p17311081.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] How to extract estimates, Std. Error, t Value and Pr(|t|) from summary
dat-array(runif(30),c(15,2)); dat-data.frame(x=dat[,1],y=dat[,2]); linm-lm(y~x,data=dat); linm.s-summary(linm); attributes(linm.s) #to see all attributes of the summary $names [1] call terms residuals coefficients [5] aliased sigma dfr.squared [9] adj.r.squared fstatisticcov.unscaled $class [1] summary.lm linm.s$coefficients # that's the variable you're looking for, right? Estimate Std. Error t valuePr(|t|) (Intercept) 0.6132455 0.1907463 3.214980 0.006769529 x -0.3648345 0.3134967 -1.163759 0.265436835 thanks y Daphne Renault wrote: __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/How-to-extract-estimates%2C-Std.-Error%2C-t-Value-and-Pr%28%3E%7Ct%7C%29-from-summary-tp17274673p17274850.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] re ading and analyzing a text file
use the parameter 'skip' in read.table dat-read.table(filename,skip=number of rows you want to skip) thanks y DAVID ARTETA GARCIA wrote: Dear list, I have a text file from a scanner that includes 20 lines of text (scanner settings) before it actually starts showing the readings in a tabular format (headings are ID, intensity, background and few others). I am a biologist with some experience using R and my question is if it is possible to read this file into an R workspace and store the actual readings in a dataframe, avoiding the text at the begining. It seems to me that this is not the actual purpose of R, but maybe someone can point me to a method for doing this. Do I need to parse the file with some other programming language? is it possible to link, say, Perl or C++ with R to automate the reading and the analysis of such files? The aim is to be able to automate this analysis since these files are our routine experimental output. Thanks for your help, D. __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/reading-and-analyzing-a-text-file-tp17276177p17276263.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] Lattice box percentile plot
it's a good question.. my guess is using panel.bpplot prevents filling in the shape the coffins- since the box is now two mirrored graphs. i hope i'm wrong. trellis.par.get() br = trellis.par.get(box.rectangle) br$col = black br$fill = lightblue #this is the parameter that fills in the box, but it doesn't work with panel.bpplot trellis.par.set(box.rectangle, br) bwplot(B~A,probs=seq(.01,.49,by=.01)) thanks y Mr Derik wrote: Dear Nabble. I am trying to draw a box percentile plot with trellis using the panel in Hmisc. I really want to colour the plots in. I can alter several of features of the plot by changing the trellis par settings but I just can’t fill the shape in. Here is some example code which alters line colour and dot symbol: require(lattice) require(Hmisc) A-c(rnorm(100,50,2),rnorm(100,60,5),rnorm(100,55,7)) B-rep(c(1,2,3),each=100) trellis.par.set(list(box.rectangle=list(col=black))) trellis.par.set(list(box.umbrella=list(col=black))) trellis.par.set(list(box.dot=list(pch=3,col=red))) bwplot(B~A,panel=panel.bpplot, probs=seq(.01,.49,by=.01)) I’d really appreciate it if someone could tell me how to change the fill colour as well as it is driving me mad. Chears. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Lattice-box-percentile-plot-tp17274559p17276179.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] merging data frames
DF1- data.frame(Name=as.factor(c(A,B,C)), Age= c(21,45,30)) DF2- data.frame(Name=as.factor(c(A,B,X)), Age= c(50,20,10)) DF3- data.frame(Name=as.factor(c(B,Y,K)), Age= c(40,21,30)) merge(merge(DF1,DF2, by.x= Name, by.y=Name, all=TRUE),DF3,by.x=Name,by.y=Name, all=TRUE); Name Age.x Age.y Age 1A2150 NA 2B4520 40 3C30NA NA 4XNA10 NA 5KNANA 30 6YNANA 21 thanks y Srinivas Iyyer wrote: Dear group, I have 3 different data frames. I want to merge all 3 data frames for which there is intersection. Say DF 1 and DF2 has 100 common elements in Column 1. DF3 does not have many intersection either with DF1 or with DF2. For names in column 1 not present in DF3 I want to introduce NA. DF1: Name Age A 21 B 45 C 30 DF2: Name Age A 50 B 20 X 10 DF3: Name Age B 40 Y 21 K 30 I want to merge all 3 into one: Df4: Name.1Age.1 Age.2 Age.3 A 21 50 NA B 45 20 40 C 30 NA NA K NA NA 30 X NA 10 NA Y NA NA 21 Could any one help me how can I merge 3 dataframes. appreciate your help. Thank you. srini __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/merging-data-frames-tp17286503p17287302.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] plot 2 bars
try: obs_data- c(26,43,20,14,18); pre_gam-c(26.284,61.101,29.016,11.160,11.439) (obs.hist - hist(obs_data, breaks = 10, plot = FALSE)); plot(obs.hist) plot(obs.hist, border = dark blue, col = light blue, xlab =whatever) (pre.hist - hist(pre_gam, breaks = 10, plot = FALSE)); lines(pre.hist, col = Midnight Blue) You can manipulate the number of breaks to reflect different bin widths. hth y Roslina Zakaria wrote: Hi r-expert, How do I plot this 2 histogram side by side so that it is easy to compare for bin range 0,5,10,15, 20 and more obs_data pre_gam [1,] 2695 2677.284 [2,] 43 61.101 [3,] 20 29.016 [4,] 14 11.160 [5,] 18 11.439 Thanks in advance. __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/plot-2-bars-tp17222387p17222757.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] Creating data.frames dynamically
Hi Worik: Is this what you want? Names - letters[1:5]; Dates- 1:20; d- data.frame(dates=Dates, a = vector(mode=numeric, length=length(Dates))); for(i in 2:5){d[,paste(sep=,Names[i])]-with(d,a)}; d dates a b c d e 1 1 0 0 0 0 0 2 2 0 0 0 0 0 3 3 0 0 0 0 0 4 4 0 0 0 0 0 5 5 0 0 0 0 0 6 6 0 0 0 0 0 7 7 0 0 0 0 0 8 8 0 0 0 0 0 9 9 0 0 0 0 0 1010 0 0 0 0 0 1111 0 0 0 0 0 1212 0 0 0 0 0 1313 0 0 0 0 0 1414 0 0 0 0 0 1515 0 0 0 0 0 1616 0 0 0 0 0 1717 0 0 0 0 0 1818 0 0 0 0 0 1919 0 0 0 0 0 2020 0 0 0 0 0 thanks y Worik R wrote: I have time series data in named vectors. They are all the same length for the same dates. The dates are in a separate vector. I want to create a vector of numeric data for every named series, associated with the dates in a data.frame. So if... Names - c(a, b, c) d - data.frame(dates=Dates, a=vector(mode=numeric, length=length(Dates), b=vector(mode=numeric, length=length(Dates), c=vector(mode=numeric, length=length(Dates)) Then I copy the processed data into d for(i in SomeVectorOfFactors){ for(N in Names){ d[[N]][i] - FunctionCallOfSomeSort(i) } } I want to create the data.frame, d, in the same style I access it. d - data.frame(dates=Dates, [[Names]]=vectors(.)) Then it is much simpler to add new columns. Worik ST [[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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Creating-data.frames-dynamically-tp17169662p17181259.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] applying cor.test to a (m, n) matrix
interesting request..I'm looking forward to the replies All I could come up with is putting it in two lines.. pr-array(0,c(dim(x)[2],dim(x)[2])); for (i in 1:dim(x)[2]) for (j in 1:dim(x)[2]) pr[i,j]-cor.test(x[,i],x[,j])$p.val; y Monica Pisica wrote: Hi everybody, I would like to apply cor.test to a matrix with m rows and n columns and get the results in a list of matrices , one matrix for p.val, one for the statistic, one for the correlation and 2 for upper and lower confidence intervals, something analog with cor() applied to a matrix. I have done my own function to get a matrix of p.values and i suppose i can build similar functions for all the others. But i have used for loops and i wonder if there is any way to actually use one of the functions from the apply family to do this in a quicker way. Here is my little function: cor.pval - function(x, method = c(pearson, kendal, spearman), digit=8) { n - dim(x)[2] pval - matrix(paste(rep(c, n*n), seq(1,n*n), sep = ), n, n, byrow = T) for (i in 1:n) { for (j in 1:n){ pval[i, j] - cor.test(x[,i], x[,j], method = method)$p.value } } pval - matrix(round(as.numeric(pval),digit), n, n, byrow = T) rownames(pval) - colnames(x) colnames(pval) - colnames(x) return(pval) } Thanks for any input, Monica _ esh_messenger_052008 __ 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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/applying-cor.test-to-a-%28m%2C-n%29-matrix-tp17134290p17142033.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] question about subseting a dataframe
you need to redefine the factor on ex1$id.. cast it again as.factor to redefine the levels. Dipankar Basu wrote: Hi! I am using R version 2.7.0 and am working on a panel dataset read into R as a dataframe; I call it ex. The variables in ex are: id year x id: a character string which identifies the unit year: identifies the time period x: the variable of interest (which might contain NAs). Here is an example: id - rep(c(A,B,C),2) year - c(rep(1970,3),rep(1980,3)) x - c(20,30,40,25,35,45) ex - data.frame(id=id,year=year,x=x) ex id year x 1 A 1970 20 2 B 1970 30 3 C 1970 40 4 A 1980 25 5 B 1980 35 6 C 1980 45 I want to draw a subset of ex by selecting only the A and B units: ex1 - subset(ex[which(ex$id==A|ex$id==B),]) Now I want to do some computations on x for each selected unit only: tapply(ex1$x, ex1$id, mean) ABC 22.5 32.5 NA But this gives me an NA value for the unit C, which I thought I had already left out. How do I ensure that the computation (in the last step) is limited to only the units I have selected in the first step? Dipankar [[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. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/question-about-subseting-a-dataframe-tp17159592p17159679.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] miniscule font size on R console output
from the upper menu, go to edit/gui preferences then you can increase the font size. i used windows so im not sure if this works on mac. thanks juanita choo wrote: Hi, I am having a situation where I cannot change the output size of the R console. I have played around with the font format menu but the changes are only reflected to the script that I type in but not to the output. Everytime I run a script, I have to go back to font format to increase the output script, which is currently showing up as small as the dust on my computer screen. I have mac by the way. Thanks for your suggestions. juanita [[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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/miniscule-font-size-on-R-console-output-tp17132821p17136574.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 regsubsets
is it possible that regsubsets divides the subset dataset into training and testing set.. so when it calculates R^2 it's not the same as what you'd get with lm. You probably need to look into the source code to know if this is true or not Edwards, David J wrote: Hi, I'm new to R and this mailing list, so I will attempt to state my question as appropriately as possible. I am running R version 2.7 with Windows XP and have recently been exploring the use of the function regsubsets in the leaps package in order to perform all-subsets regression. So, I'm calling the function as: sub=regsubsets(X,Y,nbest=5,nvmax=maxnv,method=exhaustive,really.big=F) I'm dealing with 14 observations and 23 variables and I'm aware of the linear dependencies that arise in these situations. I also know that regsubsets performs a branch-and-bound algorithm and that at times it is necessary to reorder the variables. However, anytime I get the message: Reordering variables and trying again the R^2 for a model chosen by regsubsets does not match the R^2 I get from fitting the same model using the usual linear model function (lm). If I don't get the Reordering variables and trying again message, I don't have any problems with R^2 (i.e. regubsets and lm match). Just for example, suppose the best 1-variable model chosen by regsubsets gives me an R^2 of 0.665. Fitting that same model using lm gives me an R^2 of 0.6317. Does anyone have any insight on why this may be happening? [[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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/help-with-regsubsets-tp17115128p17136650.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] pivoting - summing up factors
assuming what you have is a dataframe called x try: table(Plant=x$plant,Location=x$location) Location Plant x y z a 1 1 2 b 2 2 0 or simply: table(x$plant,x$location) x y z a 1 1 2 b 2 2 0 thanks juanita choo wrote: Hi I would like to know how to pivot a table that will sum the number of plants (a or b) for each location (x,y,z) I have read on the listserve similar questions but which involve summing up numbers rather than factors. I have also read about the R package reshape on the listserve but wanted to know if there's a way to do it easily without the package Thanks for the help! location plant x a x b x b y b y b y a z a z a into a table like this xy z a 11 2 b 22 0 [[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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/pivoting---summing-up-factors-tp17112158p17112407.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] Is there in R a function equivalent to the mround, as found in most spreadsheets?
Hi Ottorino, You could just use the modulus operator %% as follows: x-c(1803.02, 193.51, 3.47); x-x%%c(50,5,1) #just using the modulus operator [1] 1800 1903 thanks Dr. Ottorino-Luca Pantani wrote: Dear R-users, I have the following problem In a lab experiment I have to mix three solutions to get different concentrations of various molecules in a cuvette I've used R to calculate the necessary µliters for each of the level of the experiment and I must confess that it is more useful and easier to achieve the results than using spreadsheets. But there's a problem. Imagine that for a particular cuvette (I have 112 different cuvettes !!) you have to mix the following volumes of solution A, B, and C respectively. c(1803.02, 193.51, 3.47) Each solution is to be taken with 3 different pipettes (5000, 250 and 10 µL Volume max) and each of those delivers volumes in steps of 50 µL, 5 µL or 1µL, respectively Since the above values would eventually become c(1800, 195, 3) it is then necessary to recalculate all the final concentrations of A, B and C, because the volumes are changed. I know that in most spreadsheets (Calc in Open Office, Gnumeric, Excel and so on) there's a function such as mround(num; num) that give the results I need, but I want to learn more on R functions. I played a little with R functions such as round, signif, ceiling, trunc, and floor but without success. Any hint to solve this problem ? Thanks a lot http://www.openofficetips.com/blog/archives/2005/04/rounding_to_the.html http://www.gnome.org/projects/gnumeric/doc/gnumeric-MROUND.shtml -- Ottorino-Luca Pantani, Università di Firenze Dip. Scienza del Suolo e Nutrizione della Pianta P.zle Cascine 28 50144 Firenze Italia Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 [EMAIL PROTECTED] http://www4.unifi.it/dssnp/ __ 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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Is-there-in-R-a-function-equivalent-to-the-mround%2C-as-found-in-most-spreadsheets--tp17086856p17087399.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] General Plotting Question
cast the two vectors as.matrix-- see here: plot(as.matrix(f[2,4:26]), as.matrix(f[1,4:26])) y stephen sefick wrote: f - (structure(list(X = structure(96:97, .Label = c(119DAmm, 119DN, 119DNN, 119DO, 119DOC, 119Flow, 119Nit, 119ON, 119OPhos, 119OrgP, 119Phos, 119TKN, 119TOC, 148DAmm, 148DN, 148DNN, 148DO, 148DOC, 148Flow, 148Nit, 148ON, 148OPhos, 148OrgP, 148Phos, 148TKN, 148TOC, 179DAmm, 179DN, 179DNN, 179DO, 179DOC, 179Flow, 179Nit, 179ON, 179OPhos, 179OrgP, 179Phos, 179TKN, 179TOC, 185DAmm, 185DN, 185DNN, 185DO, 185DOC, 185Flow, 185Nit, 185ON, 185OPhos, 185OrgP, 185Phos, 185TKN, 185TOC, 190DAmm, 190DN, 190DNN, 190DO, 190DOC, 190Flow, 190Nit, 190ON, 190OPhos, 190OrgP, 190Phos, 190TKN, 190TOC, 198DAmm, 198DN, 198DNN, 198DO, 198DOC, 198Flow, 198Nit, 198ON, 198OPhos, 198OrgP, 198Phos, 198TKN, 198TOC, 202DAmm, 202DN, 202DNN, 202DO, 202DOC, 202Flow, 202Nit, 202ON, 202OPhos, 202OrgP, 202Phos, 202TKN, 202TOC, 215DAmm, 215DN, 215DNN, 215DO, 215DOC, 215Flow, 215Nit, 215ON, 215OPhos, 215OrgP, 215Phos, 215TKN, 215TOC, 61DAmm, 61DN, 61DNN, 61DO, 61DOC, 61Flow, 61Nit, 61ON, 61OPhos, 61OrgP, 61Phos, 61TKN, 61TOC, BCOPhos, BCOrgP, BCPhos, BCTKN, BCTOC, HCDAmm, HCDN, HCDNN, HCDO, HCDOC, HCFlow, HCNit, HCON, HCOPhos, HCOrgP, HCPhos, HCTKN, HCTOC, SCDAmm, SCDN, SCDNN, SCDO, SCDOC, SCFlow, SCNit, SCON, SCOPhos, SCOrgP, SCPhos, SCTKN, SCTOC), class = factor), RiverMile = structure(c(8L, 8L), .Label = c(119, 148, 179, 185, 190, 198, 202, 215, 61, BC, HC, SC), class = factor), Constituent = structure(5:6, .Label = c(DAmm, DN, DNN, DO, DOC, Flow, Nit, ON, OPhos, OrgP, Phos, TKN, TOC), class = factor), X2.1.06 = c(2.5, 2494), X4.1.06 = c(2.4, NA), X5.1.06 = c(2.3, NA), X6.1.06 = c(2.1, NA), X7.1.06 = c(2, NA), X8.1.06 = c(1.9, NA), X9.1.06 = c(2, NA), X10.1.06 = c(2.1, NA), X11.1.06 = c(2.9, NA), X12.1.06 = c(2.6, NA), X1.1.07 = c(2.1, 4229.55), X2.1.07 = c(2.1, 1823.5), X3.1.07 = c(2.8, 3617.5), X4.1.07 = c(2.3, NA), X5.1.07 = c(3.5, NA), X6.1.07 = c(2.8, 10974.5), X7.1.07 = c(2.5, 9652), X8.1.07 = c(2.4, 6700.5), X9.1.07 = c(2.2, 11438.5), X10.1.07 = structure(c(34L, 33L), .Label = c(-0.0214, -0.3660, #VALUE!, 0., 0.0010, 0.0040, 0.0060, 0.0080, 0.0086, 0.0090, 0.0100, 0.0110, 0.0120, 0.0140, 0.0220, 0.0230, 0.0240, 0.0280, 0.0300, 0.0720, 0.0890, 0.1000, 0.1200, 0.1280, 0.1400, 0.1500, 0.1880, 0.1910, 0.2000, 0.2080, 0.2200, 0.3900, 1141., 2.2000, 2.3000, 2.5000, 2.6000, 2606., 3., 3.4000, 4.5000, 4.6000, 4710., 4720., 4729., 6.9768, 7.7065, 7.7338, 8.0097), class = factor), X11.1.07 = c(2.2, 10968), X12.1.07 = c(2.2, 7361.5), X1.1.08 = c(2, 6797)), .Names = c(X, RiverMile, Constituent, X2.1.06, X4.1.06, X5.1.06, X6.1.06, X7.1.06, X8.1.06, X9.1.06, X10.1.06, X11.1.06, X12.1.06, X1.1.07, X2.1.07, X3.1.07, X4.1.07, X5.1.07, X6.1.07, X7.1.07, X8.1.07, X9.1.07, X10.1.07, X11.1.07, X12.1.07, X1.1.08), row.names = c(NA, -2L), class = data.frame)) plot(f[2,4:26], f[1,4:26]) #Error in plot.window(...) : need finite 'xlim' values #In addition: Warning messages: #1: In min(x) : no non-missing arguments to min; returning Inf #2: In max(x) : no non-missing arguments to max; returning -Inf #I want a scatterplot like what I thought would happen with the plot command and the rows and columns that contain the data. If there is a NA in either case there is no point . plotted. This is how plot works with the data in columns, I think. This is a small example of a much larger data set are there any suggestions. What am I missing? thanks stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/General-Plotting-Question-tp17087346p17087502.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] Plotting separate populations in scatterplot3d
#Install library rgl #here is the function which you need to run first: rgl.plot3d-function(z, x, y, cols=red,axes=T,new=T) {xr-range(x) x01-(x-xr[1])/(xr[2]-xr[1]) yr-range(y) y01-(y-yr[1])/(yr[2]-yr[1]) zr-range(z) z01-(z-zr[1])/(zr[2]-zr[1]) if(new) rgl.clear() if(axes) {xlab-pretty(x) ylab-pretty(y) zlab-pretty(z) xat-(xlab-xr[1])/(xr[2]-xr[1]) yat-(ylab-yr[1])/(yr[2]-yr[1]) zat-(zlab-zr[1])/(zr[2]-zr[1]) rgl.lines(c(0,1.1),0,0) rgl.lines(0,c(0,1.1),0) rgl.lines(0,0,c(0,1.1)) rgl.texts(xat,-.05,-.05,xlab) rgl.texts(-.05,yat,-.05,ylab) rgl.texts(-.05,-.05,zat,zlab) rgl.texts(c(0.5,-.15,-.15),c(-.15,.5,-.15),c(-.15,-.15,.5), c(deparse(substitute(x)),deparse(substitute(y)),deparse(substitute(z } rgl.spheres(x01,y01,z01,.01,color=cols) } #and here is how you call it library(rgl) data(iris) iris.pc-prcomp(iris[,1:4],scale=T) rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3]) # different colors rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3],col=unclass(iris[,5])+1) Refer to: http://www.nabble.com/interactive-rotatable-3d-scatterplot-td17030023.html#a17030164 thanks y Eleca Dunham wrote: Hi, I'm having trouble plotting populations as separate colors and points in the 3d scatterplot package. I have a column with 4 different population names and 3 columns with my data. I want to plot each population with a different color and pch. In addition, I want to use the type=h in my plotting so that I can see the points clearly in my graph( for publication purposes). I've also attached an example dataset. I simply want to show that each population clusters separately in space. I've attached a visual representation of what I want my data to look like. The scripts for this graph is as follows: data(trees) s3d - scatterplot3d(trees, type = h, color = blue, angle = 55, scale.y = 0.7, pch = 16, main = Adding elements) For some reason, R will not read my header, so I had to use the data.frame function to get R to read my data. This is a real pain because I have tons of data. I've tried the following to get R to recognize each population type separately: PopulationType.LK1-PopulationType[LK1] PopulationType.LK2-PopulationType[LK2] points((PopulationType.LK1, col=red, pch=19), (PopulationType.LK2, col=blue, pch=22), .) When I tweak the example tree code from above, R will plot all of my data no problem (with the rgl 3d graphs, not scatterplot3d), but only with one color and plotting character. It seems pretty straightforward, but I've spent 4 days on this already. Any help would be greatly appreciated. Regards, EJ __ 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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Plotting-separate-populations-in-scatterplot3d-tp17088785p17088937.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] General Plotting Question
the data frames work as follows: columns= variables and rows= records. when you plot with a data frame it's logical to plot one variable against another not one record against another. with casting into a matrix and rotating then casting back into a dataframe, you made your records variables.. this is why it worked. I hope this makes sense to you. Thanks stephen sefick wrote: Thanks for the help- It worked just fine: This will cast my ignorance across the table, but here it goes. Why do I need to make them a matrix? because they are in a row? if d - as.matrix(f) f.t - t(d) f.m - as.data.frame(f.t) now I could use just the following plot(f.m[c(rownumber), column], f.m[c(rownumber), column]) ? I am sure that I need to brush up on underlying data structures, but I am trying to analyze data as we speak and R along with all of your help is an invaluable tool. Am I missing something easy, do I not understand the logic/philosophy, or...? thanks Stephen On Tue, May 6, 2008 at 12:53 PM, Yasir Kaheil [EMAIL PROTECTED] wrote: cast the two vectors as.matrix-- see here: plot(as.matrix(f[2,4:26]), as.matrix(f[1,4:26])) y stephen sefick wrote: f - (structure(list(X = structure(96:97, .Label = c(119DAmm, 119DN, 119DNN, 119DO, 119DOC, 119Flow, 119Nit, 119ON, 119OPhos, 119OrgP, 119Phos, 119TKN, 119TOC, 148DAmm, 148DN, 148DNN, 148DO, 148DOC, 148Flow, 148Nit, 148ON, 148OPhos, 148OrgP, 148Phos, 148TKN, 148TOC, 179DAmm, 179DN, 179DNN, 179DO, 179DOC, 179Flow, 179Nit, 179ON, 179OPhos, 179OrgP, 179Phos, 179TKN, 179TOC, 185DAmm, 185DN, 185DNN, 185DO, 185DOC, 185Flow, 185Nit, 185ON, 185OPhos, 185OrgP, 185Phos, 185TKN, 185TOC, 190DAmm, 190DN, 190DNN, 190DO, 190DOC, 190Flow, 190Nit, 190ON, 190OPhos, 190OrgP, 190Phos, 190TKN, 190TOC, 198DAmm, 198DN, 198DNN, 198DO, 198DOC, 198Flow, 198Nit, 198ON, 198OPhos, 198OrgP, 198Phos, 198TKN, 198TOC, 202DAmm, 202DN, 202DNN, 202DO, 202DOC, 202Flow, 202Nit, 202ON, 202OPhos, 202OrgP, 202Phos, 202TKN, 202TOC, 215DAmm, 215DN, 215DNN, 215DO, 215DOC, 215Flow, 215Nit, 215ON, 215OPhos, 215OrgP, 215Phos, 215TKN, 215TOC, 61DAmm, 61DN, 61DNN, 61DO, 61DOC, 61Flow, 61Nit, 61ON, 61OPhos, 61OrgP, 61Phos, 61TKN, 61TOC, BCOPhos, BCOrgP, BCPhos, BCTKN, BCTOC, HCDAmm, HCDN, HCDNN, HCDO, HCDOC, HCFlow, HCNit, HCON, HCOPhos, HCOrgP, HCPhos, HCTKN, HCTOC, SCDAmm, SCDN, SCDNN, SCDO, SCDOC, SCFlow, SCNit, SCON, SCOPhos, SCOrgP, SCPhos, SCTKN, SCTOC), class = factor), RiverMile = structure(c(8L, 8L), .Label = c(119, 148, 179, 185, 190, 198, 202, 215, 61, BC, HC, SC), class = factor), Constituent = structure(5:6, .Label = c(DAmm, DN, DNN, DO, DOC, Flow, Nit, ON, OPhos, OrgP, Phos, TKN, TOC), class = factor), X2.1.06 = c(2.5, 2494), X4.1.06 = c(2.4, NA), X5.1.06 = c(2.3, NA), X6.1.06 = c(2.1, NA), X7.1.06 = c(2, NA), X8.1.06 = c(1.9, NA), X9.1.06 = c(2, NA), X10.1.06 = c(2.1, NA), X11.1.06 = c(2.9, NA), X12.1.06 = c(2.6, NA), X1.1.07 = c(2.1, 4229.55), X2.1.07 = c(2.1, 1823.5), X3.1.07 = c(2.8, 3617.5), X4.1.07 = c(2.3, NA), X5.1.07 = c(3.5, NA), X6.1.07 = c(2.8, 10974.5), X7.1.07 = c(2.5, 9652), X8.1.07 = c(2.4, 6700.5), X9.1.07 = c(2.2, 11438.5), X10.1.07 = structure(c(34L, 33L), .Label = c(-0.0214, -0.3660, #VALUE!, 0., 0.0010, 0.0040, 0.0060, 0.0080, 0.0086, 0.0090, 0.0100, 0.0110, 0.0120, 0.0140, 0.0220, 0.0230, 0.0240, 0.0280, 0.0300, 0.0720, 0.0890, 0.1000, 0.1200, 0.1280, 0.1400, 0.1500, 0.1880, 0.1910, 0.2000, 0.2080, 0.2200, 0.3900, 1141., 2.2000, 2.3000, 2.5000, 2.6000, 2606., 3., 3.4000, 4.5000, 4.6000, 4710., 4720., 4729., 6.9768, 7.7065, 7.7338, 8.0097), class = factor), X11.1.07 = c(2.2, 10968), X12.1.07 = c(2.2, 7361.5), X1.1.08 = c(2, 6797)), .Names = c(X, RiverMile, Constituent, X2.1.06, X4.1.06, X5.1.06, X6.1.06, X7.1.06, X8.1.06, X9.1.06, X10.1.06, X11.1.06, X12.1.06, X1.1.07, X2.1.07, X3.1.07, X4.1.07, X5.1.07, X6.1.07, X7.1.07, X8.1.07, X9.1.07, X10.1.07, X11.1.07, X12.1.07, X1.1.08), row.names = c(NA, -2L), class = data.frame)) plot(f[2,4:26], f[1,4:26]) #Error in plot.window(...) : need finite 'xlim' values #In addition: Warning messages: #1: In min(x) : no non-missing arguments to min; returning Inf #2: In max(x) : no non-missing arguments to max; returning -Inf #I want a scatterplot like what I thought would happen with the plot command and the rows and columns that contain the data. If there is a NA in either case there is no point . plotted. This is how plot works with the data in columns, I think. This is a small example of a much larger data set are there any suggestions. What am I missing? thanks stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel
Re: [R] Spatial join between two datasets using x and y co-ordinates
vector dat1.select is the selected records from dat1 by dat2. dat1.select- dat1$x1 %in% dat2$x2 dat1$y1 %in% dat2$y2 dat1[dat1.select,] x1 y1 descript 1 1824615 5980732 cat 2 1823650 5983220 dog Andrew McFadden wrote: Hi R users I am trying to create a spatial join between two datasets. The first data set is large and contains descriptive data including x and y co-ordinates. The second dataset is small and has been selected spatially. The only data contained within the second dataset is the x and y coordinates only i.e. no descriptive data. The aim of a join made between the two datasets is to select those points (and hence all the descriptive data) from dataset one that has the same x and y co-ordinates as dataset two. x1-c(1824615,1823650,1821910) y1-c(5980732,5983220,5990931) descript-c(cat, dog, horse) dat1-data.frame(x1,y1,descript) x2-c(1824615,1823650) y2-c(5980732,5983220) dat2-data.frame(x2,y2) dat1 dat2 The aim of the join is to produce: x1 y1 descript 1 1824615 5980732 cat 2 1823650 5983220 dog And therefore limit the data in dataset 1 to that which has the same x and y co-ordinates as dataset 2. Any suggestions? Regards Andy Andrew McFadden MVS BVSc Incursion Investigator Investigation Diagnostic Centres - Wallaceville Biosecurity New Zealand Ministry of Agriculture and Forestry Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St Upper Hutt This email message and any attachment(s) is intended solely for the addressee(s) named above. The information it contains is confidential and may be legally privileged. Unauthorised use of the message, or the information it contains, may be unlawful. If you have received this message by mistake please call the sender immediately on 64 4 8940100 or notify us by return email and erase the original message and attachments. Thank you. The Ministry of Agriculture and Forestry accepts no responsibility for changes made to this email or to any attachments after transmission from the office. [[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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Spatial-join-between-two-datasets-using-x-and-y-co-ordinates-tp17093486p17093656.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] bwplot
Hi Cedric, to change the names of different boxes, you could use levels on the dataframe factor variable you're plotting- see this example: library('lattice'); bwplot(voice.part ~ height, data=singer, xlab=Height (inches)) singer.m-singer levels(singer.m$voice.part)- c(a,f,g,j,k,o,y,t) bwplot(voice.part ~ height, data=singer.m, xlab=Height (inches)) I don't know how to change the order but I'm sure there is a way :) hope that helps c2dric wrote: Hi, I have 2 questions about bwplot in R : 1) How to change the order of my different boxes in the graph ? 2) How to rename the names of the differents boxes ? because I know how to do that with boxplot (using names) but I do not find the equivalent parameter in bwplot. thanks, Cédric __ 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. - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/bwplot-tp17062703p17065756.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] axis and tick widths decoupled (especially in rugs!)
Hi This is an ad-hoc fix.. d-rnorm(4) plot(1:4,d) g-3; rug((1:4),ticksize=-.03,lwd=g,side=1) rug((1:4),ticksize=0,lwd=(g-1),side=1,col=white) just drawing another white axis on top of the old one.. it looks ok :) y maiya wrote: Hi! (a complete newby, but will not give up easily!) I was wondering if there is any way to decouple the axis and tick mark widths? As I understand they are both controlled by the lwd setting, and cannot be controlled independently? For example I might want to create major and minor ticks, which I now know how to do by superimposing two axes with different at settings, but what if I also wanted the major ticks to be thicker? or a different colour? You might find this nitpicking, but I am particularly concerned about rug(), which passes to axis(), in that I cannot get a decent thick-lined rug, without the horizontal line also becoming equally thick. Is there any way to do this without having to resort to segments? Tnx! - Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/axis-and-tick-widths-decoupled-%28especially-in-rugs%21%29-tp17068508p17070684.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] barplot with log base 2 scale or shift the x-axis
user parameter offset barplot(d,offset = -2) #assuming that d is your data Summer Nitely wrote: Hi, I have data that is on a log base 2 scale. It goes from negative factors of 2 to positive ones. I am using barplot. However, I don't want the data centered at 0 - I want the min of the yaxis to be just below the lowest value in the data. The plots are kind of deceptive switching between positive and negative. I see that barplot has a log option, but that doesn't seem to be adjustable for a log base 2 scale. Does anyone know how to adjust the x-axis, so it's at y= -value rather than at y=0? I''d rather not add a factor to the data, unless I can have accurate labels on the y-axis. Any ideas? Thanks, Summer [[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. -- View this message in context: http://www.nabble.com/barplot-with-log-base-2-scale-or-shift-the-x-axis-tp17028736p17036612.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] re moving rows from matrix
you could do it using apply like the first two replies mentioned or you could just use the index way for example: (assuming your matrix name is ym and the values are greater than 25 and less than 50 and the column is column 3).. if you mean any column use the first two replies. ym-array(runif(10,20,100),c(6,5)); ym [,1] [,2] [,3] [,4] [,5] [1,] 97.57168 52.22471 41.23411 91.78960 22.57583 [2,] 41.17106 23.73572 55.77120 27.47041 37.94204 [3,] 41.23411 91.78960 22.57583 97.57168 52.22471 [4,] 55.77120 27.47041 37.94204 41.17106 23.73572 [5,] 22.57583 97.57168 52.22471 41.23411 91.78960 [6,] 37.94204 41.17106 23.73572 55.77120 27.47041 ym-ym[(ym[,3]25) (ym[,3] 50),]; ym [,1] [,2] [,3] [,4] [,5] [1,] 97.57168 52.22471 41.23411 91.78960 22.57583 [2,] 55.77120 27.47041 37.94204 41.17106 23.73572 thanks Monna Nygård wrote: Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. How would this be possible, I have tried to create a simple function for this, but I just don't seem to get it right.Thank you so much for your help, Monna _ [[elided Hotmail spam]] PLink [[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. -- View this message in context: http://www.nabble.com/removing-rows-from-matrix-tp17016646p17025836.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] Excluding/removing row and column names on text output files
try: write.table(x, file=/Users/Desktop/Data.txt, row.names= FALSE, col.names= FALSE, sep=, append=TRUE) this should do it. If you don't want to append, just turn that opion off. Stropharia wrote: Dear R users, I've had no joy finding a solution to this online or in any of my R books. Many thanks in advance for any help you can give. I'm seeking to output a data frame (or matrix - it doesn't matter which for my purposes) to a .txt file, but omit any row or column names. The data frame that I'm using doesn't actually have column or row names to start with as it has been coerced into its present form from a matrix. When I use: capture.output(x, file=/Users/Desktop/Data.txt, append=TRUE) I get the following (this is a small fraction of the actual data frame): 1 2 3 4 5 X1 0 0 0 0 2 X2 0 0 0 2 0 X3 1 1 2 0 0 If the data frame is transformed into a matrix, I still get row and column 'names' (or at least numbers like v1, etc.). Using the sink function also produces the exact same result. I've tried using row.names=FALSE (as you would when writing to a .csv file), in the capture.output function, but it doesn't work. I would also like the remove the horizontal spaces between numbers on the same row, to produce: 2 00020 11200 But, I want each row to remain a separate entity (not be concatenated with the others). I know I can remove the blank spaces by doing Find and Replace in a text editor, but is it possible to remove the row and column names, and the row spaces, directly in R so that it outputs like the above example? Thanks, Steve ~~ Steven Worthington Ph.D. Candidate New York Consortium in Evolutionary Primatology Department of Anthropology New York University 25 Waverly Place New York, NY 10003 U.S.A. ~~ -- View this message in context: http://www.nabble.com/Excluding-removing-row-and-column-names-on-text-output-files-tp17030424p17030476.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] interactive rotatable 3d scatterplot
#Install library rgl #here is the is the function: rgl.plot3d-function(z, x, y, cols=red,axes=T,new=T) {xr-range(x) x01-(x-xr[1])/(xr[2]-xr[1]) yr-range(y) y01-(y-yr[1])/(yr[2]-yr[1]) zr-range(z) z01-(z-zr[1])/(zr[2]-zr[1]) if(new) rgl.clear() if(axes) {xlab-pretty(x) ylab-pretty(y) zlab-pretty(z) xat-(xlab-xr[1])/(xr[2]-xr[1]) yat-(ylab-yr[1])/(yr[2]-yr[1]) zat-(zlab-zr[1])/(zr[2]-zr[1]) rgl.lines(c(0,1.1),0,0) rgl.lines(0,c(0,1.1),0) rgl.lines(0,0,c(0,1.1)) rgl.texts(xat,-.05,-.05,xlab) rgl.texts(-.05,yat,-.05,ylab) rgl.texts(-.05,-.05,zat,zlab) rgl.texts(c(0.5,-.15,-.15),c(-.15,.5,-.15),c(-.15,-.15,.5), c(deparse(substitute(x)),deparse(substitute(y)),deparse(substitute(z } rgl.spheres(x01,y01,z01,.01,color=cols) } #and here is how you call it library(rgl) data(iris) iris.pc-prcomp(iris[,1:4],scale=T) rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3]) # different colors rgl.plot3d(iris.pc$x[,1],iris.pc$x[,2],iris.pc$x[,3],col=unclass(iris[,5])+1) #you could also change the labels and everything else. Enjoy! Mark W Kimpel wrote: I would like to create a 3d scatterplot that is interactive in the sense that I can spin it on its axes to better visualize some PCA results I have. What are the options in R? I've looked at RGL and perhaps it will suffice but it wasn't apparent from the documentation I found. Any demo scripts available for a package that will work? Mark -- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail (317) 663-0513 Home (no voice mail please) ** [[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. -- View this message in context: http://www.nabble.com/interactive-rotatable-3d-scatterplot-tp17030023p17030164.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] predict.glm newdata
You could just say: yhat=predict(reg1,x2) the function predict will assing x2 to 'newdata' by default. thanks Daniel Malter wrote: Hi, could it be the newdata argument? When I run predict with the newdata argument, I get an error message - a different one though. The second reason might be that your dataset is named df, which is defined as a function an may produce problems. Try renaming the dataset. yhat=predict(reg1,newdata=x2) x1=seq(1:100) r.norm1=rnorm(100,0,20) x1=r.norm1+x1 x2=x1*2 r.norm2=rnorm(200,0,20) x2=r.norm2+x2 reg1=glm(y1~x1,binomial) yhat=predict(reg1) ##prediction works fine yhat=predict(reg1,newdata=x2) ##gives error message because of newdata Error in eval(predvars, data, env) : numeric 'envir' arg not of length one yhat=predict(reg1,data=x2) ##works fine ##using offset ofst=rep(0.5,100) reg1=glm(y1~x1,binomial,offset=ofst) yhat=predict(reg1) yhat1=predict(reg1,newdata=x2) ##gives error message yhat2=predict(reg1,data=x2) ##works fine - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Tom Guston Gesendet: Friday, April 04, 2008 1:29 PM An: r-help@r-project.org Betreff: [R] predict.glm newdata Hi all - I'm stumped by the following mdl - glm(resp ~ . , data = df, family=binomial, offset = ofst) WORKS yhat - predict(mdl) WORKS yhat - predict(mdl,newdata = df) FAILS Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) : subscript out of bounds I've tried without offset, quoting binomial. The offset variable ofst IS in df. Previous postings indicate possible names(df) problems (renaming factor levels?) but I'm using the same data.frame for the newdata option. Thank you in advance for any pointers. Tom. _ Going green? See the top 12 foods to eat organic. 1N1653A [[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. -- View this message in context: http://www.nabble.com/predict.glm---newdata-tp16501614p16986751.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.