[R] reinstall all packages - easy way?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi is there an easy way of re-installing all packages in my user library? I am not referring to checkBuilt=TRUE, but re-install all packages, irrespective of the version. Reasoning: I installed Simons patched R for Mac to use the new C compiler, and I would like to re-install all packages to make sure that they are not compiled with the old compiler, as this can cause problems. I manually removed all Rcpp* packages and re-installed them, but this is not a real solution. I also have seen e.g. http://www.r-bloggers.com/automated-re-install-of-packages-for-r-3-0/ But I am wondering if there is an easier approach? Thanks, Rainer - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D):+49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSzmeTAAoJENvXNx4PUvmCv3oIANGufnd7kNW1/AEi5WisbmVl LEjmjUKSO8j/kTRRkHLz0Nkatev8gIbhWUA5ouEAXfVMVSa9B0Ap+ZOyHDHvo+El y5QBmguJdH+WOWdNtHhJ/aQgMQzeSVMUcaO9848vdDvZhIpsAA8ezYCEMUfXMLBd JXiUHuBxstANn9PwyJFOW6TMaIdhos53iGXzjSdPlyrJ8azvRJB79ncgEoxQxZTj kMduOAZ7D2Dq3oJQQ+zqNQlw7syrHfVua8zQQqZ5a8fzrLX+cRRdEoK8PbStzhSN 0uzBnYU1l9pw+zRr0Nzf5iNjMhyLmKl1H+XpgOhRPCjErf0etk7jtyfQsX+wbZI= =3ibl -END PGP SIGNATURE- __ 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] reinstall all packages - easy way?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/09/14, 10:35 , Berwin A Turlach wrote: G'day Rainer, Hi Berwin, On Thu, 09 Jan 2014 10:10:43 +0100 Rainer M Krug rai...@krugs.de wrote: is there an easy way of re-installing all packages in my user library? I am not referring to checkBuilt=TRUE, but re-install all packages, irrespective of the version. Something like: R ip - installed.packages() R colnames(ip) [1] Package LibPath [3] Version Priority [5] Depends Imports [7] LinkingTo Suggests [9] Enhances License [11] License_is_FOSS License_restricts_use [13] OS_type MD5sum [15] NeedsCompilation Built R unique(ip[,Priority]) [1] NArecommended base R install.packages(ip[is.na(ip[,Priority]), Package]) perhaps? The last command is, obviously, not tested. This supposes that you do not want to reinstall the recommended or base packages (probably best to just use update.packages() to update those). Yes - I only want to re-install the user installed packages, which are in .libPaths()[1] in my case, so I did: ip - installed.packages(lib.loc=.libPaths()[1]) install.packages(ip[Package], type=source) and off I go. Installing them at the moment. It just would be nice to have an argument in update.packages() like reinstallAll=FALSE which, if set to TRUE, would reinstall all installed packages in the lib.loc. Thanks, Rainer Best wishes, Berwin == Full address A/Prof Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019) +61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009 e-mail: berwin.turl...@gmail.com Australia http://www.maths.uwa.edu.au/~berwin http://www.researcherid.com/rid/A-4995-2008 - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D):+49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSznAeAAoJENvXNx4PUvmC2bYIAJOiKGvSZsvFL05/MewA/Xie mzcm0wcl7ZXMzNyzV2sUXFcI/V8CUly57dqaORYtgIO8L6wi0JdHP90vegPVUsn1 uRQ+eswWNnuQ5Dy/KVfylJg5vJV+6xW6ivSFlDX5XRmhn9RXfb1T6hwX5IuoeufV OdJW/h5b66QLgOZC28QWnx0UIxWbWYEg7BHT3wFFwViZ/lKQ3+S0JoXulULfxQZ0 4bTZcfI2IflrXJ7tN4dL/jISiJreaIxI4WUMgBoZ6cjvXhI/uQPVGXSfhTGs22TU UWXEtfVm0ZWYvF8BAsYqrPmffOUc64nFXFavHIaZAGoHvVfXBvB8wrEviQ5j3a8= =fD0/ -END PGP SIGNATURE- __ 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] Linear relative rate / excess relative risk models
Thanks for your suggestions! Here are links to simulated data and the Epicure syntax + reference fit: http://dwoll.de/err/dat.txt http://dwoll.de/err/epicure.log The model tested in Epicure is lambda = exp(alpha0 + alpha1*agePyr)*(1 + beta0*dosePyr*exp(beta1*agePyr)) with counts in variable event and offset pyears. Many thanks, D -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Thursday, January 09, 2014 4:33 AM To: Wollschlaeger, Daniel Cc: r-help@r-project.org Subject: Re: AW: [R] Linear relative rate / excess relative risk models On Jan 8, 2014, at 3:22 PM, Wollschlaeger, Daniel wrote: If I understand you correctly, that is exactly the approach taken by Atkinson Therneau: They get the baseline rates from published rate tables from the general population, multiply them by the appropriate person-time from their data to get expected counts, and use this as offset. Unfortunately, I won't have comparable baseline rate tables. And while I could fit a separate model only to the unexposed group for expected counts, I'd prefer to fit both factors (lambda0 and 1+ERR) simultaneously - as it is typically done in the existing literature. If you would describe your data situation more completely (ideally with a reproducible example) you might get a better answer. It's also considered polite on this mailing list to include the email chain, so appending original question: -- David Best, Daniel Von: David Winsemius [dwinsem...@comcast.net] Gesendet: Mittwoch, 8. Januar 2014 19:06 An: Wollschlaeger, Daniel Cc: r-help@r-project.org Betreff: Re: [R] Linear relative rate / excess relative risk models I would fit a Poisson model to the dose-response data with offsets for the baseline expecteds. David Winsemius, MD Alameda, CA, USA My question is how I can fit linear relative rate models (= excess relative risk models, ERR) using R. In radiation epidemiology, ERR models are used to analyze dose-response relationships for event rate data and have the following form [1]: lambda = lambda0(z, alpha) * (1 + ERR(x, beta)) * lambda is the event rate * lambda0 is the baseline rate function for non-exposed persons and depends on covariates z with parameters alpha * ERR is the excess relative risk function for exposed persons and depends on covariates x (among them dose) with parameters beta * lambda/lambda0 = 1 + ERR is the relative rate function Often, the covariates z are a subset of the covariates x (like sex and age). lambda is assumed to be log-linear in lambda0, and ERR typically has a linear (or lin-quadratic) dose term as well as a log-linear modifying term with other covariates: lambda0 = exp(alpha0 + alpha1*z1 + alpha2*z2 + ...) ERR = beta0*dose * exp(beta1*x1 + beta2*x2 + ...) The data is often grouped in form of life tables with the observed event counts and person-years (pyr) for each cell that results from categorizing and cross-classifying the covariates. The counts are assumed to have a Poisson-distribution with mean mu = lambda*pyr, and the usual Poisson-likelihood is used. The interest is less in lambda0, but in inference on the dose coefficient beta0 and on the modifier coefficients beta. In the literature, the specialized Epicure program is almost exclusively used. Last year, a similar question on R-sig-Epi [2] did not lead to a successful solution (I contacted the author). Atkinson Therneau in [3] discuss excess risk models but get lambda0 separately from external data instead of fitting lambda0 as a log-linear term. Some R packages sound promising to me (eg., gnm, timereg) but I currently don't see how to correctly specify the model. Any help on how to approach ERR models in R is highly appreciated! With many thanks and best regards __ 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] DanteR problems
Hi, Iam trying to run the DanteR package, but keep getting some problems. I installed the Gtk 2.24 version on my mac and was able than to install the RGtk2 package and load it. After installing the DantR package I tried to load it but I keep getting strange error massages. library(DanteR); dante() Loading required package: RGtk2Extras Loading required package: RGtk2 Loading required package: gWidgets Loading required package: gWidgetsRGtk2 Loading required package: RODBC Loading required package: e1071 Loading required package: class Loading required package: plotrix Loading required package: reshape Loading required package: plyr ... Loading required package: diagram Loading required package: shape Warning messages: 1: package âgWidgetsRGtk2â was built under R version 3.0.2 2: package âRODBCâ was built under R version 3.0.2 3: package âplotrixâ was built under R version 3.0.2 4: package ânlmeâ was built under R version 3.0.2 5: package âscatterplot3dâ was built under R version 3.0.2 *Options file does not exist* DanteR, v 0.2 R(19989,0x7fff7b69f960) malloc: *** error for object 0x4024: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap: 6 It seems that R is looking for a specific options files. In the Dante.R script there is also a function which looks for such a file and than gives the exact error massage if it is not there. But I am not even sure if R crashes because the file is not there, or if there is another reason for that. I would appreciate any help. Thanks Assa search() [1] .GlobalEnvpackage:DanteRpackage:diagram [4] package:shape package:pls package:MASS [7] package:ellipse package:colorspacepackage:scatterplot3d [10] package:RSQLite package:DBI package:outliers [13] package:car package:gplotspackage:rgl [16] package:nlme package:reshape package:plyr [19] package:plotrix package:e1071 package:class [22] package:RODBC package:gWidgetsRGtk2 package:gWidgets [25] package:RGtk2Extras package:RGtk2 package:stats [28] package:graphics package:grDevices package:utils [31] package:datasets package:methods Autoloads [34] package:base sessionInfo() R version 3.0.1 (2013-05-16) Platform: x86_64-apple-darwin10.8.0 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] DanteR_0.2 diagram_1.6.1shape_1.4.0 [4] pls_2.4-3MASS_7.3-29 ellipse_0.3-8 [7] colorspace_1.2-4 scatterplot3d_0.3-34 RSQLite_0.11.4 [10] DBI_0.2-7outliers_0.14car_2.0-19 [13] gplots_2.12.1rgl_0.93.963 nlme_3.1-113 [16] reshape_0.8.4plyr_1.8 plotrix_3.5-2 [19] e1071_1.6-1 class_7.3-9 RODBC_1.3-10 [22] gWidgetsRGtk2_0.0-82 gWidgets_0.0-52 RGtk2Extras_0.6.1 [25] RGtk2_2.20.25 loaded via a namespace (and not attached): [1] bitops_1.0-6 caTools_1.16 dichromat_2.0-0 digest_0.6.3 [5] gdata_2.13.2 ggplot2_0.9.3.1grid_3.0.1 gtable_0.1.2 [9] gtools_3.1.0 KernSmooth_2.23-10 labeling_0.2 lattice_0.20-23 [13] munsell_0.4.2 nnet_7.3-7 proto_0.3-10 RColorBrewer_1.0-5 [17] reshape2_1.2.2 scales_0.2.3 stringr_0.6.2 [[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] Call for papers: Geospatial Semantic Array Programming
** Apologies for any cross posting ** Earthzine http://www.earthzine.org/, an IEEE-sponsored online scientific journal, is soliciting articles of 800-3,000 words for its second quarter theme of 2014 on *Geospatial Semantic Array Programming *(GeoSemAP). We seek contributions from all regions of the globe, addressing environmental transdisciplinary research in which a concise integration of array-based semantics and array programming, geospatial tools and a modular composition of data-transformation models are exploited for geospatial problems within the paradigm of Semantic Array Programming. This theme specifically focuses on wide-scale transdisciplinary modelling for environment (WSTMe) as a scientific challenge with an increasingly important role in allowing strategic policy-making to be effectively discussed and programmed with the support of robust science. See the call for paper at http://www.earthzine.org/2013/12/18/call-for-papers-geospatial-semantic-array-programming/ and download it in PDF.http://www.earthzine.org/wp-content/uploads/2013/12/Call-For-Papers-GeoSemAP.pdf http://www.earthzine.org/wp-content/uploads/2013/12/Call-For-Papers-GeoSemAP.pdf -- Best regards, Dr. Margherita DI LEO Scientific / technical project officer European Commission - DG JRC Institute for Environment and Sustainability (IES) Via Fermi, 2749 I-21027 Ispra (VA) - Italy - TP 261 Tel. +39 0332 78 3600 margherita.di-...@jrc.ec.europa.eu Disclaimer: The views expressed are purely those of the writer and may not in any circumstance be regarded as stating an official position of the European Commission. [[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] DanteR problems
On 09/01/2014 10:41, Assa Yeroslaviz wrote: Hi, I am trying to run the DanteR package, but keep getting some problems. Isn't that the expected behavior? -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') __ 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] DanteR problems
What's that suppose to mean? Do you always expect problem when you do something? On Thu, Jan 9, 2014 at 12:11 PM, Patrick Burns pbu...@pburns.seanet.comwrote: On 09/01/2014 10:41, Assa Yeroslaviz wrote: Hi, I am trying to run the DanteR package, but keep getting some problems. Isn't that the expected behavior? -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') [[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] Levelplots with non-continuous x-axis breaks
Patrick, No error in your code, just two different ways of deriving a range of colors ... heat.colors() and color.scale(). I modified the code to just use color.scale(). You can tell it what two colors you want it to use for the extremes, and it will work out the shades in between. Jean # fake data fake - cbind(c(1,2,5,8,12,19), c(2,5,8,12,19,20), c(1,1,1,1,1,1), runif(6, 0, 2), runif(6, 0, 2)) mymatrix - fake dimnames(mymatrix)[[2]] - letters[1:dim(fake)[2]] # separate the first two columns from the remaining columns for simplicity mymatrix12 - mymatrix[, 1:2] mymatrix3plus - mymatrix[, -(1:2)] # create variables for the dimensions for easy reference later nrows - dim(mymatrix3plus)[1] ncols - dim(mymatrix3plus)[2] # to make sure that the min and max contain all of the data # use floor(100*...)/100 and ceiling(100*...)/100 instead of round(..., 2) datalim - c(floor(100*min(mymatrix3plus)), ceiling(100*max(mymatrix3plus)))/100 # choose two colors to be the end points colorlim - c(yellow, red) # create a sequence of 10 colors across the selected range for the legend lut - color.scale(seq(datalim[1], datalim[2], length=10), extremes=colorlim, xrange=datalim) # it's not clear from the help file, but the extremes= argument wants a range (a vector of length 2) mycolors - array(color.scale(mymatrix3plus, extremes=colorlim, xrange=datalim), dim=dim(mymatrix3plus)) ycenter - seq(from=0, to=1, length=(nrows + 2)) yheight - 1/(nrows + 2) # Plot the color key on the lower part ColorBar(lut=lut, min=datalim[1], max=datalim[2]) # Plot the actual heatmap par(new=TRUE) # can't use title for main= argument, because title only exists inside the ColorBar() function plot(c(mymatrix12[1, 1], mymatrix12[nrows, 2]), c(0, 1), col=White, xlab=, ylab=, main=SOMETHING, axes=F) for(i in 1:ncols){ RectPlotter(mymatrix12, ycenter[nrows - i + 2], yheight, mycolors[, i]) text(mymatrix12[1,1], ycenter[nrows - i + 2], colnames(mymatrix3plus)[i], pos=4) } On Wed, Jan 8, 2014 at 3:59 PM, Pachapep pacha...@gmail.com wrote: Hi Jean, Thanks for the great help. Indeed, it seems that that helps a bit. However, I included a control column made of ones. fake - cbind(c(1,2,5,8,12,19), c(2,5,8,12,19,20), c(1,1,1,1,1,1), runif(6, 0, 2), runif(6, 0, 2), runif(6, 0, 2)) However, the color doesnt correspond to that in the key (it is red-ish in the plot while the 1 corresponds to yellow-ish in the key), so Im not sure whether it is the key or the colors that are messed up. Sorry for all these questions.. and thanks (again) for the help provided. On Jan 8, 2014, at 16:15, Adams, Jean jvad...@usgs.gov wrote: Patrick, Thanks for providing reproducible code! I think the main problem was that the extremes= argument in the color.scale() function wants a range (a vector of length 2), and you were providing with more than that, length(lut) is 10. In the process of tracking this down, I made a bunch of minor changes to your code to help me see what was going on. This is what I ended up with. Jean # fake data fake - cbind(c(1,2,5,8,12,19), c(2,5,8,12,19,20), c(1,1,1,1,1,1), runif(6, 0, 2), runif(6, 0, 2), runif(6, 0, 2)) mymatrix - fake dimnames(mymatrix)[[2]] - letters[1:5] # separate the first two columns from the remaining columns for simplicity mymatrix12 - mymatrix[, 1:2] mymatrix3plus - mymatrix[, -(1:2)] # create variables for the dimensions for easy reference later nrows - dim(mymatrix3plus)[1] ncols - dim(mymatrix3plus)[2] # prepare plotting parameters lut - rev(heat.colors(10)) # to make sure that the min and max contain all of the data # use floor(100*...)/100 and ceiling(100*...)/100 instead of round(..., 2) minimum - floor(100*min(mymatrix3plus))/100 maximum - ceiling(100*max(mymatrix3plus))/100 # it's not clear from the help file, but the extremes= argument wants a range (a vector of length 2) mycolors - color.scale(mymatrix3plus, extremes=lut[c(1, length(lut))]) ycenter - seq(from=0, to=1, length=(nrows + 2)) yheight - 1/(nrows + 2) # Plot the color key on the lower part ColorBar(lut=lut, min=minimum, max=maximum) # Plot the actual heatmap par(new=TRUE) # can't use title for main= argument, because title only exists inside the ColorBar() function plot(c(mymatrix12[1, 1], mymatrix12[nrows, 2]), c(0, 1), col=White, xlab=, ylab=, main=SOMETHING, axes=F) for(i in 1:ncols){ RectPlotter(mymatrix12, ycenter[nrows - i + 2], yheight, mycolors[, i]) text(mymatrix12[1,1], ycenter[nrows - i + 2], colnames(mymatrix3plus)[i], pos=4) } On Wed, Jan 8, 2014 at 2:13 PM, Pachapep pacha...@gmail.com wrote: Hi Jean, Thanks a ton for the help. I think Im almost there, but there is still something weird about my stuff. I have been able to understand the color.scale() function. Now, I am trying to plot a key for the corresponding colors. The function is called ColorBar, which apparently works - the colors are indeed lut - rev(heat.colors(10)) and go from my
Re: [R] DanteR problems
On 09/01/2014 11:18, Assa Yeroslaviz wrote: What's that suppose to mean? Do you always expect problem when you do something? Actually, yes I do always expect problems, but more pertinently it is an oblique reference to 'The R Inferno'. http://www.burns-stat.com/documents/books/the-r-inferno/ Pat On Thu, Jan 9, 2014 at 12:11 PM, Patrick Burns pbu...@pburns.seanet.com mailto:pbu...@pburns.seanet.com wrote: On 09/01/2014 10:41, Assa Yeroslaviz wrote: Hi, I am trying to run the DanteR package, but keep getting some problems. Isn't that the expected behavior? -- Patrick Burns pbu...@pburns.seanet.com mailto:pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/__blog http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') __ 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] Standardised Pearson residuals
Dear all, I'm using the package pscl for adjusting a Zero-Inflated Negative Binomial Regression to my data set. I would like to know if it is possible to compute the standardised Pearson residuals from the output of this package. Thanks in advanced. Best regards, Helena. __ 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] Replace value in a matrix according to a list with a list of value .
Hi there !! I have a matrix like mm [,1] [,2] [,3] [1,] 1 11 21 [2,] 2 12 22 [3,] 3 13 23 I have a list of position index like pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values like gty $v1 9 3 $v2 4 8 $v3 7 4 1 Now i want to replace the value of each row in mm by pos list with value gty mm [,1] [,2] [,3] [1,] 9 11 3 [2,] 8 12 4 [3,] 7 1 4 Any suggestion regarding this problem will be very helpful . Thank you. Best regards ... Tanvir Ahamed Göteborg, Sweden [[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] Replace value in a matrix according to a list with a list of value .
On 09/01/2014 9:25 AM, Mohammad Tanvir Ahamed wrote: Hi there !! I have a matrix like mm [,1] [,2] [,3] [1,]1 11 21 [2,]2 12 22 [3,]3 13 23 I have a list of position index like pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values like gty $v1 9 3 $v2 4 8 $v3 7 4 1 Now i want to replace the value of each row in mm by pos list with value gty mm [,1] [,2] [,3] [1,]9 11 3 [2,]8 12 4 [3,]7 1 4 Any suggestion regarding this problem will be very helpful . Thank you. Use matrix indexing. You construct a two column matrix giving the indices, and then use it as an index to assign a vector of values. In your case, the matrix should be 1 1 1 3 2 3 2 2 3 1 3 3 3 2 (which you can create as indices - matrix(c(1,1,1,3, ... ), ncol=2, byrow = TRUE) and the vector should be 9 3 4 8 ... . Then mm[indices] - vals will do it. Duncan Murdoch __ 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] transmission of parameters to the glmmadmb function
Hi everybody, I wrote a function where several variables are created, and the used in a generalized mixed model, from the glmmADMB package. here is part of the function: deleted lines where ni, spx and spy are created print(length(spy)) uu-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, family=nbinom,zeroInflation=True)) when I run the function I get [1] 596 Error in eval(expr, envir, enclos) : object 'spy' not found (so spy is known to the function print but not to the function glmmadmb) now I modify my function: deleted lines where ni, spx and spy are created print(length(spy)) ni$spy-spy ni$spx-spx uu-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, family=nbinom,zeroInflation=True)) and that works. however, when I call glmmadmb interactively, it accepts in the formula variables which are in the dataframe specified by the 'data' argument, as well as variables which are not. and if in my function I replace glmmadmb by glm it works even if spy and spx are not in the 'ni' dataframe. that puzzles me. __ 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] recoding table dimensions interactively
Given a 3+ way table, I'd like a simple, elegant way to flatten the table to a two-way table, with some variables joined interactively to form the rows and others forming the columns. For example, starting with str(UCBAdmissions) table [1:2, 1:2, 1:6] 512 313 89 19 353 207 17 8 120 205 ... - attr(*, dimnames)=List of 3 ..$ Admit : chr [1:2] Admitted Rejected ..$ Gender: chr [1:2] Male Female ..$ Dept : chr [1:6] A B C D ... What I want is something similar to the result of ftable: ftable(UCBAdmissions) Dept A B C D E F AdmitGender Admitted Male512 353 120 138 53 22 Female 89 17 202 131 94 24 Rejected Male313 207 205 279 138 351 Female 19 8 391 244 299 317 One way to do this is to convert to a data.frame, paste the factors together and then convert back to a table: UCB.df - as.data.frame(UCBAdmissions) UCB.df$`Admit:Gender` - paste(UCB.df$Admit, UCB.df$Gender, sep=':') UCB.tab2 - xtabs(Freq ~ `Admit:Gender` + Dept, data=UCB.df) UCB.tab2 UCB.tab2 Dept Admit:GenderA B C D E F Admitted:Female 89 17 202 131 94 24 Admitted:Male 512 353 120 138 53 22 Rejected:Female 19 8 391 244 299 317 Rejected:Male 313 207 205 279 138 351 But maybe there is a simpler, more elegant and general way to do this. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb:http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ 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] Different colours for LatticeExtra graphs
Oh, thank you. Was this a mistaken reply from you? Because your link directs to yahoo mail. Al -- View this message in context: http://r.789695.n4.nabble.com/Different-colours-for-LatticeExtra-graphs-tp4683250p4683304.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] Replace value in a matrix according to a list with a list of value .
Hi, Try: res - do.call(rbind,lapply(seq_len(nrow(mm)),function(i) {x1 - mm[i,]; x1[pos[[i]]] - gty[[i]]; x1})) A.K. On Thursday, January 9, 2014 9:28 AM, Mohammad Tanvir Ahamed mashra...@yahoo.com wrote: Hi there !! I have a matrix like mm [,1] [,2] [,3] [1,] 1 11 21 [2,] 2 12 22 [3,] 3 13 23 I have a list of position index like pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values like gty $v1 9 3 $v2 4 8 $v3 7 4 1 Now i want to replace the value of each row in mm by pos list with value gty mm [,1] [,2] [,3] [1,] 9 11 3 [2,] 8 12 4 [3,] 7 1 4 Any suggestion regarding this problem will be very helpful . Thank you. Best regards ... Tanvir Ahamed Göteborg, Sweden [[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.
Re: [R] Replace value in a matrix according to a list with a list of value .
Hi, You may also try: vec1 - (seq(nrow(mm))-1)*ncol(mm) pos2 - unlist(mapply(+,pos,vec1)) mm1 - t(mm) mm1[pos2] - unlist(gty) identical(res,t(mm1)) #[1] TRUE A.K. On Thursday, January 9, 2014 9:40 AM, arun smartpink...@yahoo.com wrote: Hi, Try: res - do.call(rbind,lapply(seq_len(nrow(mm)),function(i) {x1 - mm[i,]; x1[pos[[i]]] - gty[[i]]; x1})) A.K. On Thursday, January 9, 2014 9:28 AM, Mohammad Tanvir Ahamed mashra...@yahoo.com wrote: Hi there !! I have a matrix like mm [,1] [,2] [,3] [1,] 1 11 21 [2,] 2 12 22 [3,] 3 13 23 I have a list of position index like pos $row1 [1] 1 3 $row2 [1] 3 2 $row3 [1] 1 3 2 I have a list of values like gty $v1 9 3 $v2 4 8 $v3 7 4 1 Now i want to replace the value of each row in mm by pos list with value gty mm [,1] [,2] [,3] [1,] 9 11 3 [2,] 8 12 4 [3,] 7 1 4 Any suggestion regarding this problem will be very helpful . Thank you. Best regards ... Tanvir Ahamed Göteborg, Sweden [[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.
Re: [R] Levelplots with non-continuous x-axis breaks
Great, it works perfectly! Thanks so much for the awesome help! (Happy) patrick On Jan 9, 2014, at 7:07, Adams, Jean jvad...@usgs.gov wrote: Patrick, No error in your code, just two different ways of deriving a range of colors ... heat.colors() and color.scale(). I modified the code to just use color.scale(). You can tell it what two colors you want it to use for the extremes, and it will work out the shades in between. Jean # fake data fake - cbind(c(1,2,5,8,12,19), c(2,5,8,12,19,20), c(1,1,1,1,1,1), runif(6, 0, 2), runif(6, 0, 2)) mymatrix - fake dimnames(mymatrix)[[2]] - letters[1:dim(fake)[2]] # separate the first two columns from the remaining columns for simplicity mymatrix12 - mymatrix[, 1:2] mymatrix3plus - mymatrix[, -(1:2)] # create variables for the dimensions for easy reference later nrows - dim(mymatrix3plus)[1] ncols - dim(mymatrix3plus)[2] # to make sure that the min and max contain all of the data # use floor(100*...)/100 and ceiling(100*...)/100 instead of round(..., 2) datalim - c(floor(100*min(mymatrix3plus)), ceiling(100*max(mymatrix3plus)))/100 # choose two colors to be the end points colorlim - c(yellow, red) # create a sequence of 10 colors across the selected range for the legend lut - color.scale(seq(datalim[1], datalim[2], length=10), extremes=colorlim, xrange=datalim) # it's not clear from the help file, but the extremes= argument wants a range (a vector of length 2) mycolors - array(color.scale(mymatrix3plus, extremes=colorlim, xrange=datalim), dim=dim(mymatrix3plus)) ycenter - seq(from=0, to=1, length=(nrows + 2)) yheight - 1/(nrows + 2) # Plot the color key on the lower part ColorBar(lut=lut, min=datalim[1], max=datalim[2]) # Plot the actual heatmap par(new=TRUE) # can't use title for main= argument, because title only exists inside the ColorBar() function plot(c(mymatrix12[1, 1], mymatrix12[nrows, 2]), c(0, 1), col=White, xlab=, ylab=, main=SOMETHING, axes=F) for(i in 1:ncols){ RectPlotter(mymatrix12, ycenter[nrows - i + 2], yheight, mycolors[, i]) text(mymatrix12[1,1], ycenter[nrows - i + 2], colnames(mymatrix3plus)[i], pos=4) } On Wed, Jan 8, 2014 at 3:59 PM, Pachapep pacha...@gmail.com wrote: Hi Jean, Thanks for the great help. Indeed, it seems that that helps a bit. However, I included a control column made of ones. fake - cbind(c(1,2,5,8,12,19), c(2,5,8,12,19,20), c(1,1,1,1,1,1), runif(6, 0, 2), runif(6, 0, 2), runif(6, 0, 2)) However, the color doesnt correspond to that in the key (it is red-ish in the plot while the 1 corresponds to yellow-ish in the key), so Im not sure whether it is the key or the colors that are messed up. Sorry for all these questions.. and thanks (again) for the help provided. On Jan 8, 2014, at 16:15, Adams, Jean jvad...@usgs.gov wrote: Patrick, Thanks for providing reproducible code! I think the main problem was that the extremes= argument in the color.scale() function wants a range (a vector of length 2), and you were providing with more than that, length(lut) is 10. In the process of tracking this down, I made a bunch of minor changes to your code to help me see what was going on. This is what I ended up with. Jean # fake data fake - cbind(c(1,2,5,8,12,19), c(2,5,8,12,19,20), c(1,1,1,1,1,1), runif(6, 0, 2), runif(6, 0, 2), runif(6, 0, 2)) mymatrix - fake dimnames(mymatrix)[[2]] - letters[1:5] # separate the first two columns from the remaining columns for simplicity mymatrix12 - mymatrix[, 1:2] mymatrix3plus - mymatrix[, -(1:2)] # create variables for the dimensions for easy reference later nrows - dim(mymatrix3plus)[1] ncols - dim(mymatrix3plus)[2] # prepare plotting parameters lut - rev(heat.colors(10)) # to make sure that the min and max contain all of the data # use floor(100*...)/100 and ceiling(100*...)/100 instead of round(..., 2) minimum - floor(100*min(mymatrix3plus))/100 maximum - ceiling(100*max(mymatrix3plus))/100 # it's not clear from the help file, but the extremes= argument wants a range (a vector of length 2) mycolors - color.scale(mymatrix3plus, extremes=lut[c(1, length(lut))]) ycenter - seq(from=0, to=1, length=(nrows + 2)) yheight - 1/(nrows + 2) # Plot the color key on the lower part ColorBar(lut=lut, min=minimum, max=maximum) # Plot the actual heatmap par(new=TRUE) # can't use title for main= argument, because title only exists inside the ColorBar() function plot(c(mymatrix12[1, 1], mymatrix12[nrows, 2]), c(0, 1), col=White, xlab=, ylab=, main=SOMETHING, axes=F) for(i in 1:ncols){ RectPlotter(mymatrix12, ycenter[nrows - i + 2], yheight, mycolors[, i]) text(mymatrix12[1,1], ycenter[nrows - i + 2], colnames(mymatrix3plus)[i], pos=4) } On Wed, Jan 8, 2014 at 2:13 PM, Pachapep pacha...@gmail.com wrote: Hi Jean, Thanks a ton for the help. I think Im almost there, but there is still
Re: [R] recoding table dimensions interactively
Do you just want to change how the rows and columns of ftable's output are labelled? If so, the following may do what you want: it produces a matrix with dimnames based on the row.vars and col.vars attributes of ftable's output. f - function(ftable) { makeDimNamesEl - function(x) { structure( list(do.call(paste, c(rev(expand.grid(rev(x))), list(sep=:, names = paste(collapse=:, names(x)) ) } structure( unclass(ftable), dimnames=c(makeDimNamesEl(attr(ftable, row.vars)), makeDimNamesEl(attr(ftable, col.vars))), row.vars=NULL, col.vars=NULL) } E.g., f(ftable(UCBAdmissions)) Dept Admit:GenderA B C D E F Admitted:Male 512 353 120 138 53 22 Admitted:Female 89 17 202 131 94 24 Rejected:Male 313 207 205 279 138 351 Rejected:Female 19 8 391 244 299 317 f(ftable(data=mtcars, am + gear ~ vs + carb)) am:gear vs:carb 0:3 0:4 0:5 1:3 1:4 1:5 0:1 0 0 0 0 0 0 0:2 4 0 0 0 0 1 0:3 3 0 0 0 0 0 0:4 5 0 0 0 2 1 0:6 0 0 0 0 0 1 0:8 0 0 0 0 0 1 1:1 3 0 0 0 4 0 1:2 0 2 0 0 2 1 1:3 0 0 0 0 0 0 1:4 0 2 0 0 0 0 1:6 0 0 0 0 0 0 1:8 0 0 0 0 0 0 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Friendly Sent: Thursday, January 09, 2014 7:14 AM To: R-help Subject: [R] recoding table dimensions interactively Given a 3+ way table, I'd like a simple, elegant way to flatten the table to a two-way table, with some variables joined interactively to form the rows and others forming the columns. For example, starting with str(UCBAdmissions) table [1:2, 1:2, 1:6] 512 313 89 19 353 207 17 8 120 205 ... - attr(*, dimnames)=List of 3 ..$ Admit : chr [1:2] Admitted Rejected ..$ Gender: chr [1:2] Male Female ..$ Dept : chr [1:6] A B C D ... What I want is something similar to the result of ftable: ftable(UCBAdmissions) Dept A B C D E F AdmitGender Admitted Male512 353 120 138 53 22 Female 89 17 202 131 94 24 Rejected Male313 207 205 279 138 351 Female 19 8 391 244 299 317 One way to do this is to convert to a data.frame, paste the factors together and then convert back to a table: UCB.df - as.data.frame(UCBAdmissions) UCB.df$`Admit:Gender` - paste(UCB.df$Admit, UCB.df$Gender, sep=':') UCB.tab2 - xtabs(Freq ~ `Admit:Gender` + Dept, data=UCB.df) UCB.tab2 UCB.tab2 Dept Admit:GenderA B C D E F Admitted:Female 89 17 202 131 94 24 Admitted:Male 512 353 120 138 53 22 Rejected:Female 19 8 391 244 299 317 Rejected:Male 313 207 205 279 138 351 But maybe there is a simpler, more elegant and general way to do this. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb:http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ 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.
Re: [R] recoding table dimensions interactively
Hi Michael, It's pretty easy with reshape: library(reshape2) ucbm - melt(UCBAdmissions) acast(ucbm, Admit + Gender ~ Dept) acast(ucbm, Admit ~ Dept + Gender) acast(ucbm, Admit + Dept + Gender ~ .) # You can also do aggregations acast(ucbm, Admit ~ Dept, fun = sum) Hadley On Thu, Jan 9, 2014 at 9:14 AM, Michael Friendly frien...@yorku.ca wrote: Given a 3+ way table, I'd like a simple, elegant way to flatten the table to a two-way table, with some variables joined interactively to form the rows and others forming the columns. For example, starting with str(UCBAdmissions) table [1:2, 1:2, 1:6] 512 313 89 19 353 207 17 8 120 205 ... - attr(*, dimnames)=List of 3 ..$ Admit : chr [1:2] Admitted Rejected ..$ Gender: chr [1:2] Male Female ..$ Dept : chr [1:6] A B C D ... What I want is something similar to the result of ftable: ftable(UCBAdmissions) Dept A B C D E F AdmitGender Admitted Male512 353 120 138 53 22 Female 89 17 202 131 94 24 Rejected Male313 207 205 279 138 351 Female 19 8 391 244 299 317 One way to do this is to convert to a data.frame, paste the factors together and then convert back to a table: UCB.df - as.data.frame(UCBAdmissions) UCB.df$`Admit:Gender` - paste(UCB.df$Admit, UCB.df$Gender, sep=':') UCB.tab2 - xtabs(Freq ~ `Admit:Gender` + Dept, data=UCB.df) UCB.tab2 UCB.tab2 Dept Admit:GenderA B C D E F Admitted:Female 89 17 202 131 94 24 Admitted:Male 512 353 120 138 53 22 Rejected:Female 19 8 391 244 299 317 Rejected:Male 313 207 205 279 138 351 But maybe there is a simpler, more elegant and general way to do this. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb:http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ 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. -- http://had.co.nz/ __ 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] Implementing A Formula
The phrase, need to go row by row plugging this formula in to only take data from that individual row suggests a spreadsheet-like concept. But R does not work the way a spreadsheet does. Given the example data and function that Frede provided (thank you!), a simple, and probably the most basic, way would be mydata$cool2 - myfun( mydata$a, mydata$b, mydata$c) This also works: mydata$cool3 - with(mydata, myfun(a,b,c)) mydata a b c d e cool cool2 cool3 1 1 11 21 31 41 323232 2 2 12 22 32 42 464646 3 3 13 23 33 43 626262 4 4 14 24 34 44 808080 5 5 15 25 35 45 100 100 100 6 6 16 26 36 46 122 122 122 7 7 17 27 37 47 146 146 146 8 8 18 28 38 48 172 172 172 9 9 19 29 39 49 200 200 200 10 10 20 30 40 50 230 230 230 If you're new to R, and for the purpose of learning R, I'd suggest understanding the simplest method before using the with() or do.call() methods. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/7/14 10:18 PM, Frede Aakmann Tøgersen fr...@vestas.com wrote: Hi Is is something like this that you want? mydata - data.frame(a=1:10, b=11:20, c=21:30, d=31:40, e=41:50) myfun - function(a,b,c)a*b+c mydata$cool - do.call(myfun, mydata[,c(a, b, c)]) mydata ## a b c d e cool ## 1 1 11 21 31 41 32 ## 2 2 12 22 32 42 46 ## 3 3 13 23 33 43 62 ## 4 4 14 24 34 44 80 ## 5 5 15 25 35 45 100 ## 6 6 16 26 36 46 122 ## 7 7 17 27 37 47 146 ## 8 8 18 28 38 48 172 ## 9 9 19 29 39 49 200 ## 10 10 20 30 40 50 230 Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance Modeling Technology Service Solutions T +45 9730 5135 M +45 2547 6050 fr...@vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Norman McBride Sent: 7. januar 2014 23:46 To: r-help@r-project.org Subject: [R] Implementing A Formula Hello R Mailing List Members, My name is Peter. I am a high school student who is doing a senior thesis in statistical analysis. As you can see that I have chosen R. So for the project I am working with a member of the US Navy and analyzing some data. So for this data I am using a formula to find a cooling coefficient. This formula gets it own column in the table/display frame. So I wanted to know if put this formula into the display frame would I need to go row by row plugging this formula in to only take data from that individual row or would it just do that for me? If I did have to do it row by row would there be anyway I could expedite the process because it is over 2000 rows. Thank you for any help you are able to give me. -Peter [[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. __ 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] tt() function (was Package dependencies in building R packages)
On 12/31/2013 05:00 AM, r-help-requ...@r-project.org wrote: Thanks for your kind response Duncan. To be more specific, I'm using the function mvrnorm from MASS. The issue is that MASS depends on survival and I have a function in my package named tt() which conflicts with a function in survival of the same name. I can think of 2 alternatives solutions to my problem, but I'm to an expert: 1) Copy mvrnorm into my package, which I thought was not a good idea 2) Rename my tt() function to something else in my package, but this is painful as I have it all over the place in other functions. Any suggestions would be much appreciated. Best, Axel. Version 2.37-5 of survival has just been submitted to CRAN. In this new release the tt() function was made externally invisible, so you should not have problems. This will take a few days to propogate out to the various mirrors (perhaps longer if the Windows build has issues). This question of how to best deal with functions that only have meaing within a coxph model statement came up on R-devel just over a year ago, and I'm just now implementing the workaround found there. In time the cluster(), pspline(), ridge() and frailty() functions are likely to receive the same treatment. Terry T __ 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] Best practices for loading large datasets into R
You have made a good first start by keeping your data in a database (it would be even slower if you read it in from a text file each time). The first suggestion is to not read in all the data, just bring in what you need. For early steps, exploring the data, getting a feel for what you want to do, basic plots, etc. you may want to work with just a sample of your data that will work quickly and easily, then later you can have a script load the full data and analyze it based on what you learned from the sample. You can also have the database calculate (often quicker) some of the summary statistics instead of bringing in the data to R. The ff package has tools for storing large datasets on the disk with just pointers in memory, then it will load in just those pieces that you need so just parts of the data are in memory at any given time. Also the biglm package has tools for working with just parts of the data at a time. Some of the tools for parallel processing can work well with large datasets, the High Performance Computing Task View would be good for you to skim through to see if any of those tools look useful to you. On Wed, Jan 8, 2014 at 2:23 PM, James Mahon james.maho...@gmail.com wrote: Hello, I'm working with a 22 GB datasets with ~100 million observations and ~40 variables. It's store in SQLite and I use the RSQLite package to load it into memory. Loading the full population, even for only a few variables, can be very slow and I was wondering if there are best practices for how to manage large datasets when doing analysis in R. Is there an alternative file format / relational datbase in which I should be storing the data? Best, James -- James F. Mahon III, Ph.D. Candidate Harvard University Tel: (857) 209-8438 Fax: (270) 813-3498 Web: http://www.people.fas.harvard.edu/~jmahon/ [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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] Numerical solution
?uniroot ?optim ?optimize and look at the Optimization and Mathematical Programming task view on CRAN. On Wed, Jan 8, 2014 at 8:55 PM, Aurélien Philippot aurelien.philip...@gmail.com wrote: Dear R experts, I want to use numerical methods to solve a complex problem. Here is a very simple example that gives an idea of what I would like to do. This example could be solved by hand, but I am interested in finding a numerical solution in R. Let's say that I have the following equation: Maxx (-2x^2+ Cx)=1 I want to numerically solve for C. Of course I could use the first order condition with respect to x on the left hand side, and find the value of x that maximizes the function x- -2x^2+ Cx, (as a function of C), and then solve for C. But, let's assume that my left hand side is much more complex and I want to avoid using the first order condition. So, I would need to use some numerical techniques directly. Is there a procedure that could be implemented in R? Thank you very much for any suggestion! Aurelien [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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] Unable to Install a package from source in Windows
Hi, I am using following R version: version _ platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport I was able to build the source of a package without any errors or warnings. However, when I try to install the package, I get the following error messages. Can someone point me to what I am doing wrong? Thanks in advance, Ravi install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, repos=NULL, type=source) Installing package into '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0' (as 'lib' is unspecified) '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. * installing *source* package 'BB' ... ** R ** demo ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded *** arch - i386 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted *** arch - x64 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted ERROR: loading failed for 'i386', 'x64' * removing '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' * restoring previous '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' Warning messages: 1: running command 'C:/PROGRA~1/R/R-30~1.1/bin/i386/R CMD INSTALL -l \\homer.win.ad.jhu.edu\users$\rvaradh1\Documents\R\win-library\3.0 H:/Documents/computations/BB_2014.01-1.tar.gz' had status 1 2: In install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, : installation of package 'H:/Documents/computations/BB_2014.01-1.tar.gz' had non-zero exit status [[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] Error in t.test
Hi Vivek, res1 - read.table(positve-res1.txt,header=TRUE) dim(res1) #[1] 5292 4 #You could simplify the first loop as: mean_Res2 - as.vector(rowMeans(res1)) identical(mean_Res1,mean_Res2) #[1] TRUE ##Regarding the second loop: pval_r2 - as.vector(apply(res1,1,function(x) as.numeric(try(t.test(x)$p.value length(pval_r2) #[1] 5292 sum(is.na(pval_r2)) #[1] 64 ##From running your second loop length(pval_r1) ##stopped at the first instance where data are essentially constant #[1] 63 res1[64,] # p118_diff p132_1_diff p132_2_diff mean #XLOC_000353 1 1 1 1 head(which(is.na(pval_r2))) #[1] 64 78 99 259 309 397 A.K. On Thursday, January 9, 2014 9:58 AM, Vivek Das vd4mm...@gmail.com wrote: I have some query. I would be glad if you can help me out. I am trying to calculate the p-value for a simple datafram, but am getting an error. The data in each column are relative differences.. The last column being the mean. I am giving the code snippet. I am not being able to figure out why this error is coming up. My matrix looks like: mean_Res1-c() for (i in 1:length(res1[,1])) { mean_Res1-c(mean_Res1,mean(as.numeric(res1[i,]))) } pval_r1-NULL for(i in 1:length(res1[,1])){ pval_r1-c(pval_r1,t.test(as.numeric(res1[i,]))$p.value) print(i) } Error in t.test.default(as.numeric(res1[i, ])) : data are essentially constant I am not being able to figure out why is the t-test failing? Here is my matrix in the attachment. Can you suggest me? -- Vivek Das __ 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] Having a problem with labels
Hi, I'm having a problem with my labels. I am reading in a data file: df - read.csv(file = 'batch1extract_100k_sample.csv') However, it's producing two sets of labels: labels(df) [[1]] [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [43] 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 [64] 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 [85] 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 [[2]] [1] PERSONPROFILE_POS PARTY_ID PERSON_FIRST_NAME [4] PERSON_LAST_NAME PERSON_MIDDLE_NAMEPARTY_NUMBER [7] ACCOUNT_NUMBERABILITEC_LINK ADDRESS1 [10] ADDRESS2 ADDRESS3 ADDRESS4 [13] CITY COUNTYSTATE [16] PROVINCE POSTAL_CODE COUNTRY [19] PRIMARY_PER_TYPE SELLTOADDR_LOSLOCATION_ID [22] SELLTOADDR_SOSPARTY_SITE_ID PRIMARYPHONE_CPOS [25] CONTACT_POINT_ID_PCP CONTACT_POINT_PURPOSE_PCP PHONE_LINE_TYPE [28] PRIMARY_FLAG_PCP PHONE_COUNTRY_CODE PHONE_AREA_CODE [31] PHONE_NUMBER EMAIL_CPOS CONTACT_POINT_ID_ECP [34] CONTACT_POINT_PURPOSE_ECP PRIMARY_FLAG_ECP EMAIL_ADDRESS [37] BB_PARTY_ID Notice I get 2 rows for the labels: the first row is a list of numbers (which does not appear in my dataset) and the second row which are my actual labels. I have no idea why it's returning all of the numbers in the labels command. They're definitely not there in the input file. Any suggestions? Thank you! [[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] Having a problem with labels
Hello, According to the help page for ?labels, for a data.frame it's simply the dimnames, meaning, the row names (your numbers) and the column names. Note that read.csv returns a data.frame, not a matrix, and data frames allways have row names, typically numbers. I wouldn't worry about it. Hope this helps, Rui Barradas Em 09-01-2014 18:29, Jeff Johnson escreveu: Hi, I'm having a problem with my labels. I am reading in a data file: df - read.csv(file = 'batch1extract_100k_sample.csv') However, it's producing two sets of labels: labels(df) [[1]] [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [43] 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 [64] 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 [85] 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 [[2]] [1] PERSONPROFILE_POS PARTY_ID PERSON_FIRST_NAME [4] PERSON_LAST_NAME PERSON_MIDDLE_NAMEPARTY_NUMBER [7] ACCOUNT_NUMBERABILITEC_LINK ADDRESS1 [10] ADDRESS2 ADDRESS3 ADDRESS4 [13] CITY COUNTYSTATE [16] PROVINCE POSTAL_CODE COUNTRY [19] PRIMARY_PER_TYPE SELLTOADDR_LOSLOCATION_ID [22] SELLTOADDR_SOSPARTY_SITE_ID PRIMARYPHONE_CPOS [25] CONTACT_POINT_ID_PCP CONTACT_POINT_PURPOSE_PCP PHONE_LINE_TYPE [28] PRIMARY_FLAG_PCP PHONE_COUNTRY_CODE PHONE_AREA_CODE [31] PHONE_NUMBER EMAIL_CPOS CONTACT_POINT_ID_ECP [34] CONTACT_POINT_PURPOSE_ECP PRIMARY_FLAG_ECP EMAIL_ADDRESS [37] BB_PARTY_ID Notice I get 2 rows for the labels: the first row is a list of numbers (which does not appear in my dataset) and the second row which are my actual labels. I have no idea why it's returning all of the numbers in the labels command. They're definitely not there in the input file. Any suggestions? Thank you! [[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.
Re: [R] Having a problem with labels
Hi Jeff, If you read the help for labels(), it says that for a dataframe it returns the dimnames: the first component is the row names, which by default are numbers, and the second component of the list is the column names. Since you appear to want just the latter, you could use colnames(df) instead. (But be careful: df is also the name of a function, and it's easy to confuse things.) Sarah On Thu, Jan 9, 2014 at 1:29 PM, Jeff Johnson mrjeffto...@gmail.com wrote: Hi, I'm having a problem with my labels. I am reading in a data file: df - read.csv(file = 'batch1extract_100k_sample.csv') However, it's producing two sets of labels: labels(df) [[1]] [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [43] 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 [64] 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 [85] 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 [[2]] [1] PERSONPROFILE_POS PARTY_ID PERSON_FIRST_NAME [4] PERSON_LAST_NAME PERSON_MIDDLE_NAMEPARTY_NUMBER [7] ACCOUNT_NUMBERABILITEC_LINK ADDRESS1 [10] ADDRESS2 ADDRESS3 ADDRESS4 [13] CITY COUNTYSTATE [16] PROVINCE POSTAL_CODE COUNTRY [19] PRIMARY_PER_TYPE SELLTOADDR_LOSLOCATION_ID [22] SELLTOADDR_SOSPARTY_SITE_ID PRIMARYPHONE_CPOS [25] CONTACT_POINT_ID_PCP CONTACT_POINT_PURPOSE_PCP PHONE_LINE_TYPE [28] PRIMARY_FLAG_PCP PHONE_COUNTRY_CODE PHONE_AREA_CODE [31] PHONE_NUMBER EMAIL_CPOS CONTACT_POINT_ID_ECP [34] CONTACT_POINT_PURPOSE_ECP PRIMARY_FLAG_ECP EMAIL_ADDRESS [37] BB_PARTY_ID Notice I get 2 rows for the labels: the first row is a list of numbers (which does not appear in my dataset) and the second row which are my actual labels. I have no idea why it's returning all of the numbers in the labels command. They're definitely not there in the input file. Any suggestions? Thank you! -- Sarah Goslee http://www.functionaldiversity.org __ 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] Unable to Install a package from source in Windows
The answer most likely is in the message: '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. That path starting with a \\ is a *UNC path* (a Windows thing), which I believe install.packages() cannot install to. If you look at the output of: .libPaths() you'll probably find that the first entry contains the above path (I think). I'm pretty sure there is a non-UNC path to your user home directory, e.g. C:\Users\rvaradh1 or just H:, but currently the system environment variable HOME points to '\\homer.win.ad.jhu.edu\users$\rvaradh1\, cf. Sys.getenv(HOME), which is used by default to set .libPaths(). However, you can control it by setting R_LIBS or R_LIBS_USER to avoid a UNC path, cf ?.libPaths. Also, you may want to tell your sysadm to change HOME to a non-UNC path (which is a bit odd). In the worst case scenario, you can try to map the UNC path to a drive letter and change .libPaths() accordingly, e.g. # Assuming the first lib path is the problematic one: path - .libPaths()[1] # Map to drive letter Z system2(net, args=c(use, Z:, path)) # Update so that packages are installed to that directory .libPaths(Z:/) Then retry to install... If you don't understand the above, talk to your sysadm. /Henrik On Thu, Jan 9, 2014 at 8:46 AM, Ravi Varadhan ravi.varad...@jhu.edu wrote: Hi, I am using following R version: version _ platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport I was able to build the source of a package without any errors or warnings. However, when I try to install the package, I get the following error messages. Can someone point me to what I am doing wrong? Thanks in advance, Ravi install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, repos=NULL, type=source) Installing package into '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0' (as 'lib' is unspecified) '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. * installing *source* package 'BB' ... ** R ** demo ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded *** arch - i386 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted *** arch - x64 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted ERROR: loading failed for 'i386', 'x64' * removing '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' * restoring previous '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' Warning messages: 1: running command 'C:/PROGRA~1/R/R-30~1.1/bin/i386/R CMD INSTALL -l \\homer.win.ad.jhu.edu\users$\rvaradh1\Documents\R\win-library\3.0 H:/Documents/computations/BB_2014.01-1.tar.gz' had status 1 2: In install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, : installation of package 'H:/Documents/computations/BB_2014.01-1.tar.gz' had non-zero exit status [[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.
Re: [R] recoding table dimensions interactively
Thanks for this, Bill Your solution does just what I want. In fact, it qualifies as the missing as.matrix() method for n-way tables arranged with ftable(), or vcd::structable(), which does provide an as.matrix() method, but omits the names and dimnames. Here it is, renamed and using _ as the default separator for names joined together, which is probably a better default. I'll propose this as an addition to the stats package on R-devel. # modified from Willaim Dunlop, wdun...@tibco.com, R-Help, 01-09-2014 as.matrix.ftable - function(x, sep=_) { makeDimNames - function(vars) { structure( list(do.call(paste, c(rev(expand.grid(rev(vars))), list(sep=sep, names = paste(collapse=sep, names(vars)) ) } structure( unclass(x), dimnames=c(makeDimNames(attr(x, row.vars)), makeDimNames(attr(x, col.vars))), row.vars=NULL, col.vars=NULL) } Tests: UCB - UCBAdmissions as.matrix(ftable(Dept ~ Admit + Gender, data=UCB)) Dept Admit_GenderA B C D E F Admitted_Male 512 353 120 138 53 22 Admitted_Female 89 17 202 131 94 24 Rejected_Male 313 207 205 279 138 351 Rejected_Female 19 8 391 244 299 317 as.matrix(ftable(Dept ~ ., data=UCB)) Dept Admit_GenderA B C D E F Admitted_Male 512 353 120 138 53 22 Admitted_Female 89 17 202 131 94 24 Rejected_Male 313 207 205 279 138 351 Rejected_Female 19 8 391 244 299 317 as.matrix(ftable(Admit + Gender ~ Dept, data=UCB)) Admit_Gender Dept Admitted_Male Admitted_Female Rejected_Male Rejected_Female A 512 89 313 19 B 353 17 207 8 C 120 202 205 391 D 138 131 279 244 E53 94 138 299 F22 24 351 317 as.matrix(ftable(Admit ~ ., data=UCB)) Admit Gender_Dept Admitted Rejected Male_A512 313 Male_B353 207 Male_C120 205 Male_D138 279 Male_E 53 138 Male_F 22 351 Female_A 89 19 Female_B 178 Female_C 202 391 Female_D 131 244 Female_E 94 299 Female_F 24 317 str(as.matrix(ftable(Admit + Gender ~ Dept, data=UCB))) num [1:6, 1:4] 512 353 120 138 53 22 89 17 202 131 ... - attr(*, dimnames)=List of 2 ..$ Dept: chr [1:6] A B C D ... ..$ Admit_Gender: chr [1:4] Admitted_Male Admitted_Female Rejected_Male Rejected_Female On 1/9/2014 11:32 AM, William Dunlap wrote: Do you just want to change how the rows and columns of ftable's output are labelled? If so, the following may do what you want: it produces a matrix with dimnames based on the row.vars and col.vars attributes of ftable's output. f - function(ftable) { makeDimNamesEl - function(x) { structure( list(do.call(paste, c(rev(expand.grid(rev(x))), list(sep=:, names = paste(collapse=:, names(x)) ) } structure( unclass(ftable), dimnames=c(makeDimNamesEl(attr(ftable, row.vars)), makeDimNamesEl(attr(ftable, col.vars))), row.vars=NULL, col.vars=NULL) } E.g., f(ftable(UCBAdmissions)) Dept Admit:GenderA B C D E F Admitted:Male 512 353 120 138 53 22 Admitted:Female 89 17 202 131 94 24 Rejected:Male 313 207 205 279 138 351 Rejected:Female 19 8 391 244 299 317 f(ftable(data=mtcars, am + gear ~ vs + carb)) am:gear vs:carb 0:3 0:4 0:5 1:3 1:4 1:5 0:1 0 0 0 0 0 0 0:2 4 0 0 0 0 1 0:3 3 0 0 0 0 0 0:4 5 0 0 0 2 1 0:6 0 0 0 0 0 1 0:8 0 0 0 0 0 1 1:1 3 0 0 0 4 0 1:2 0 2 0 0 2 1 1:3 0 0 0 0 0 0 1:4 0 2 0 0 0 0 1:6 0 0 0 0 0 0 1:8 0 0 0 0 0 0 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Friendly Sent: Thursday, January 09, 2014 7:14 AM To: R-help Subject: [R] recoding table dimensions interactively Given a 3+ way table, I'd like a simple, elegant way to flatten the table to a two-way table, with some variables joined interactively to form the rows and others forming the columns. For example, starting with str(UCBAdmissions) table [1:2, 1:2, 1:6] 512 313 89 19 353 207 17 8 120 205 ... - attr(*, dimnames)=List of 3 ..$ Admit : chr [1:2] Admitted Rejected ..$ Gender: chr [1:2] Male Female ..$ Dept : chr [1:6] A B C D ... What I want is something similar
Re: [R] Unable to Install a package from source in Windows
On Thu, Jan 9, 2014 at 11:04 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: The answer most likely is in the message: '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. That path starting with a \\ is a *UNC path* (a Windows thing), which I believe install.packages() cannot install to. Actually, that particular message appears because your *current working directory* (getwd()) is a UNC path. So, you must make sure to call install.packages() with a regular working directory. However, even if you still do this, I believe install.packages() will give another error related to the UNC path. My $.02+$.02 /H If you look at the output of: .libPaths() you'll probably find that the first entry contains the above path (I think). I'm pretty sure there is a non-UNC path to your user home directory, e.g. C:\Users\rvaradh1 or just H:, but currently the system environment variable HOME points to '\\homer.win.ad.jhu.edu\users$\rvaradh1\, cf. Sys.getenv(HOME), which is used by default to set .libPaths(). However, you can control it by setting R_LIBS or R_LIBS_USER to avoid a UNC path, cf ?.libPaths. Also, you may want to tell your sysadm to change HOME to a non-UNC path (which is a bit odd). In the worst case scenario, you can try to map the UNC path to a drive letter and change .libPaths() accordingly, e.g. # Assuming the first lib path is the problematic one: path - .libPaths()[1] # Map to drive letter Z system2(net, args=c(use, Z:, path)) # Update so that packages are installed to that directory .libPaths(Z:/) Then retry to install... If you don't understand the above, talk to your sysadm. /Henrik On Thu, Jan 9, 2014 at 8:46 AM, Ravi Varadhan ravi.varad...@jhu.edu wrote: Hi, I am using following R version: version _ platform i386-w64-mingw32 arch i386 os mingw32 system i386, mingw32 status major 3 minor 0.1 year 2013 month 05 day16 svn rev62743 language R version.string R version 3.0.1 (2013-05-16) nickname Good Sport I was able to build the source of a package without any errors or warnings. However, when I try to install the package, I get the following error messages. Can someone point me to what I am doing wrong? Thanks in advance, Ravi install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, repos=NULL, type=source) Installing package into '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0' (as 'lib' is unspecified) '\\homer.win.ad.jhu.edu\users$\rvaradh1\Documents' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. * installing *source* package 'BB' ... ** R ** demo ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded *** arch - i386 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted *** arch - x64 Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) : there is no package called 'BB' Error: loading failed Execution halted ERROR: loading failed for 'i386', 'x64' * removing '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' * restoring previous '\\homer.win.ad.jhu.edu/users$/rvaradh1/Documents/R/win-library/3.0/BB' Warning messages: 1: running command 'C:/PROGRA~1/R/R-30~1.1/bin/i386/R CMD INSTALL -l \\homer.win.ad.jhu.edu\users$\rvaradh1\Documents\R\win-library\3.0 H:/Documents/computations/BB_2014.01-1.tar.gz' had status 1 2: In install.packages(H:/Documents/computations/BB_2014.01-1.tar.gz, : installation of package 'H:/Documents/computations/BB_2014.01-1.tar.gz' had non-zero exit status [[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.
Re: [R] Numerical solution
On 10/01/14 07:00, Greg Snow wrote: ?uniroot ?optim ?optimize The OP will have to be careful and clever. Specifying the *intervals* over which uniroot() and optimise() search is going to be problematic, it seems to me. and look at the Optimization and Mathematical Programming task view on CRAN. There *may* be ways to avoid the problematic specification of search intervals to be found in this task view Good luck to the OP! cheers, Rolf Turner On Wed, Jan 8, 2014 at 8:55 PM, Aurélien Philippot aurelien.philip...@gmail.com wrote: Dear R experts, I want to use numerical methods to solve a complex problem. Here is a very simple example that gives an idea of what I would like to do. This example could be solved by hand, but I am interested in finding a numerical solution in R. Let's say that I have the following equation: Maxx (-2x^2+ Cx)=1 I want to numerically solve for C. Of course I could use the first order condition with respect to x on the left hand side, and find the value of x that maximizes the function x- -2x^2+ Cx, (as a function of C), and then solve for C. But, let's assume that my left hand side is much more complex and I want to avoid using the first order condition. So, I would need to use some numerical techniques directly. Is there a procedure that could be implemented in R? Thank you very much for any suggestion! __ 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] transmission of parameters to the glmmadmb function
On Jan 9, 2014, at 9:47 AM, Eric Elguero wrote: Hi everybody, I wrote a function where several variables are created, and the used in a generalized mixed model, from the glmmADMB package. here is part of the function: deleted lines where ni, spx and spy are created print(length(spy)) uu-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, family=nbinom,zeroInflation=True)) when I run the function I get [1] 596 Error in eval(expr, envir, enclos) : object 'spy' not found (so spy is known to the function print but not to the function glmmadmb) I would have thought you should ask: length(ni$spy) glmmadmb should be looking within the data object passed to it. -- David. now I modify my function: deleted lines where ni, spx and spy are created print(length(spy)) ni$spy-spy ni$spx-spx uu-summary(glmmadmb(spy~sex+poswing+spx+(1|host),data=ni, family=nbinom,zeroInflation=True)) and that works. however, when I call glmmadmb interactively, it accepts in the formula variables which are in the dataframe specified by the 'data' argument, as well as variables which are not. and if in my function I replace glmmadmb by glm it works even if spy and spx are not in the 'ni' dataframe. Those function must be different. Get over it. Learn to pass the data in a common object. that puzzles me. _ David Winsemius, MD Alameda, CA, USA __ 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] convert real valued matrix to binary matrix
Hi: I am trying to analyze an yeast gene expression data http://arep.med.harvard.edu/biclustering/yeast.matrix I need to convert the real-valued data matrix to a binary (0,1) matrix. Is there any package available? How can it be done? Thanks: John __ 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] looping through 3D array
Hi, Try: library(emdist) set.seed(435) results- array(sample(1:400,120,replace=TRUE),dim=c(10,3,4)) res - sapply(seq(dim(results)[1]),function(i) {x1 - results[i,,]; x2 - results; sapply(seq(dim(x2)[1]),function(i) emd2d(x1,x2[i,,]))}) dim(res) #[1] 10 10 A.K. On Thursday, January 9, 2014 3:25 PM, alex padron alexpadron1...@gmail.com wrote: I'll try to be clearer. in your example we have: results- array(1:120,dim=c(10,3,4)) I want to do the following: compare results[1,,] with every matrix inside results. I then want to jump to results[2,,] and compare it to all of the other 10 matrices inside results and so on. so emd2d from the emdist package outputs a single value when comparing matrices and since your example has 10 matrices who are all being compared, the output should be 100 values. Does that make sense? -Alex __ 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] looping through 3D array
Hi, No problem. You can use ?lower.tri() or ?upper.tri() res[lower.tri(res)] res[lower.tri(res,diag=TRUE)] #Other way would be to use: ?combn indx - combn(dim(results)[1],m=2) res2 - sapply(seq_len(ncol(indx)),function(i) {x1 - indx[,i]; emd2d(results[x1[1],,],results[x1[2],,]) }) identical(res[lower.tri(res)], res2) #[1] TRUE A.K. On Thursday, January 9, 2014 4:03 PM, alex padron alexpadron1...@gmail.com wrote: Thanks. This works. I just noticed that half of the matrix repeats. For example res[1,2] is the same as res[2,1]. any way to get half of the matrix output (notice the diagonal 0 across the output matrix)? -Alex On Thu, Jan 9, 2014 at 12:57 PM, arun smartpink...@yahoo.com wrote: #or you can use ?expand.grid() and then loop over: indx - expand.grid(rep(list(seq(dim(results)[1])),2)) res1 - matrix(sapply(seq_len(nrow(indx)),function(i) {x1 - indx[i,]; emd2d(results[x1[,1],,],results[x1[,2],,]) }),ncol=10) identical(res,res1) #[1] TRUE On Thursday, January 9, 2014 3:46 PM, arun smartpink...@yahoo.com wrote: Hi, Try: library(emdist) set.seed(435) results- array(sample(1:400,120,replace=TRUE),dim=c(10,3,4)) res - sapply(seq(dim(results)[1]),function(i) {x1 - results[i,,]; x2 - results; sapply(seq(dim(x2)[1]),function(i) emd2d(x1,x2[i,,]))}) dim(res) #[1] 10 10 A.K. On Thursday, January 9, 2014 3:25 PM, alex padron alexpadron1...@gmail.com wrote: I'll try to be clearer. in your example we have: results- array(1:120,dim=c(10,3,4)) I want to do the following: compare results[1,,] with every matrix inside results. I then want to jump to results[2,,] and compare it to all of the other 10 matrices inside results and so on. so emd2d from the emdist package outputs a single value when comparing matrices and since your example has 10 matrices who are all being compared, the output should be 100 values. Does that make sense? -Alex __ 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] convert real valued matrix to binary matrix
Why? You lose information in doing so, do you not? I also think you might do better posting to the Bioconductor list, as they are specifically concerned with such matters. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Thu, Jan 9, 2014 at 11:56 AM, email email8...@gmail.com wrote: Hi: I am trying to analyze an yeast gene expression data http://arep.med.harvard.edu/biclustering/yeast.matrix I need to convert the real-valued data matrix to a binary (0,1) matrix. Is there any package available? How can it be done? Thanks: John __ 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.
Re: [R] Function inside Sweave
Hi Silvano I am not sure exactly what you want as I am not sure of the structure and format going into xtable but the structure after you have formed the table is apparently the same structure. This is what I suggested before (modified) for(j in 1:25){ yourtable - ... xx - xtable(yourtable) caption(xx) - paste(Table, j) print(xx) if(j 25) cat(\n\n) } Pre xtable If you have different colums to tabulate I suggest you use a formula or bquote via a list to vary the columns in a loop and these are the variables to be tabulated. You can then use this for your column headers in xtable /latex. durin/Post xtable If single line header for table and formatting not needed to be changed everything OK otherwise inside chunk head, echo=FALSE, results=tex= for(j in 1:25){ yourtable - ... hdx = c(\\begin{table}[h]\n, \\caption{\\prevt{} and their equivalent \\dcode{}}%\n, \\label{tab:, j }%\n, \\begin{tabular}{l|r}\n) # adjust to suit cat(hdx) # header from col names or otherwise out - names(yourtable) out - c(, paste(\\multicolumn{1}{c}{, out, rep(c(} %\n, } ), c(length(out)-1, 1)), sep = ), \n ) cat(out, sep = ) # xtable xx - xtable(yourtable) xnd = c(\\end{tabular}\n, \\end{table}\n) cat(xnd) if(j 25) cat(\n\n) } @ %% end You can add booktabs functions within tabular by cat if needed If you have things that need to be changed they can be accessed by a vector/list If you have variable numbers of decimal points see an colour is black http://tex.stackexchange.com/questions/96982/coloring-text-in-a-dcolumn-alig ned-cell-of-a-table Henrik Bengtsson has a package to do this sort of thing but he discontinued it for ver 3 or 2.15 ca Regards Duncan -Original Message- From: silv...@uel.br [mailto:silv...@uel.br] Sent: Friday, 10 January 2014 04:48 To: Duncan Mackay Subject: Re: [R] Function inside Sweave Dear Duncan, I want relatioship two variables: DISCIPLINA and Questions. I have about 100 different disciplines (in same column) and 25 questions (25 differents columns). Head is: ALUNO DISCIPLINA FIELD1 DATA SERIE TURMA Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 PROFESSOR Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18 Q19 Q20 Q21 Q22 Q23 Q24 Q25 Something like this: DISCIPLINA:6PIV019 6VET017 6BIQ014 6ZOT058 6ZOT060 ... 6PIV018 Questions: Q1, Q2, Q3, ... Q25 I get what I want (form a one Question) with this commands: tab1 = table(DISCIPLINA, Q1) tab1.prop = round(100*prop.table(tab1, 1), 2) tab1.txt = xtable(tab1.prop, align=l|r, label='Q1', caption=c(Apresentação da proposta de programa a ser desenvolvida na disciplina, Q1)) print(tab1.txt, format.args=list(big.mark = ., decimal.mark = ,), caption.placement='top', table.placement='H') But, I need 25 commands like this, because I have 25 questions. I would like program a function to make this one time only. So, I try this general function: DISCIPLINA - rep(c(A, B, C, D, E), 5) for (i in 1:25){ aux - paste(Q, i, sep=) assign(aux, sample(rep(seq(1:5),5))) } cria.tabela - function(Questao){ Questao1 - get(Questao) tab1 - table(DISCIPLINA, Questao1) tab1.prop = round(100*prop.table(tab1, 1), 2) tab1.txt = xtable(tab1.prop, align=l|r, label=Questao, caption=paste(Questao)) print(tab1.txt, format.args=list(big.mark = ., decimal.mark = ,), caption.placement='top', table.placement='H') } geral - function(){ for (i in 1:25){ x-paste(Q, i, sep=) cria.tabela(x) } } geral() but I need change the created variable DISCIPLINA by DISCIPLINA in my dataset and I don't get this. If you want, I send you my dataset. Thanks a lot. Silvano. -Mensagem Original- From: Duncan Mackay Sent: Thursday, January 09, 2014 1:12 AM To: 'Silvano Cesar da Costa' Cc: R Subject: RE: [R] Function inside Sweave Hi Silvano I cannot use the data and function as the data is not available to me for the xtable part using data from xtable try as an example to see if it fits your needs data(tli) head(tli) for(j in 1:5){ xx - xtable(tli[1:6,]); caption(xx) - paste(Table, j); print(xx); if(j 5) cat(\n\n)} You can amend the xtable part to suit -- the cat command gives some spacing Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Silvano Cesar da Costa Sent: Thursday, 9 January 2014 04:24 To: r-help@r-project.org Subject: [R] Function inside Sweave Hi, I have a data set involving 25 Questions (Q1, Q2, ... , Q25), 100 Disciplina and 5 series. The variables are: ALUNO DISCIPLINA SERIE TURMA Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 ... Q25 I want to create tables associating each of the 25 questions to the Disciplina. Something like: tab1 = table(DISCIPLINA, Q1) tab1.prop = round(100*prop.table(tab1, 1), 2)
Re: [R] with() and within() functions inside lapply() not seeing outside of its environment?
Hi, I wouldn't call it a bug, but it's a documented limitation, if you know how to read it. As documented, the expression is evaluated with the caller's environment as the parent environment. But here the caller is some code in lapply, not your function f. x is not found there. Thanks! That explains it. I think this modification works, and is maybe the simplest way to get it to work: f - function(x){ y - list(y1=list()) mywithin - function(...) within(...) y - lapply(y, mywithin, {z-x}) y } The idea here is that the calling frame of f is the environment of mywithin(), so x is found there. It works. Best regards, Pavel __ 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] subsetting 3D array
Hi Alex, Try: set.seed(345) results- array(sample(-5:5,120,replace=TRUE),dim=c(10,3,4)) indx - !!apply(results,1,sum) library(plyr) results2 - laply(lapply(seq(dim(results)[1]),function(i) results[i,,])[indx],identity) attr(results2,dimnames) - NULL dim(results2) #[1] 9 3 4 A.K. I have a 3D array with 13,000 11x8 matrices. dim(results [1] 13000 11 8 Some matrices in the array add up to 0. For example sum(results[1,,])==0 [1] TRUE I would like to remove these. How can I do this? __ 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] subsetting 3D array
Just use apply() and indexing instead! results[,,apply(results,3,sum)TRUE] ## will do it. However, note that numerical error may make a hash of this. So safer would be something like: eps - 1e-15 ## i.e. something small results[,,abs(apply(results,3,sum))eps] Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Thu, Jan 9, 2014 at 7:23 PM, arun smartpink...@yahoo.com wrote: Hi Alex, Try: set.seed(345) results- array(sample(-5:5,120,replace=TRUE),dim=c(10,3,4)) indx - !!apply(results,1,sum) library(plyr) results2 - laply(lapply(seq(dim(results)[1]),function(i) results[i,,])[indx],identity) attr(results2,dimnames) - NULL dim(results2) #[1] 9 3 4 A.K. I have a 3D array with 13,000 11x8 matrices. dim(results [1] 1300011 8 Some matrices in the array add up to 0. For example sum(results[1,,])==0 [1] TRUE I would like to remove these. How can I do this? __ 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.
Re: [R] subsetting 3D array
I figured it out: dim(results[apply(results,1,sum)TRUE,,]) #[1] 9 3 4 A.K. On , arun smartpink...@yahoo.com wrote: dim(results[,,apply(results,3,sum)TRUE]) #[1] 10 3 4 dim(results[,,abs(apply(results,3,sum))eps]) #[1] 10 3 4 dim(results2) #[1] 9 3 4 A.K. On Friday, January 10, 2014 12:56 AM, Bert Gunter gunter.ber...@gene.com wrote: Just use apply() and indexing instead! results[,,apply(results,3,sum)TRUE] ## will do it. However, note that numerical error may make a hash of this. So safer would be something like: eps - 1e-15 ## i.e. something small results[,,abs(apply(results,3,sum))eps] Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Thu, Jan 9, 2014 at 7:23 PM, arun smartpink...@yahoo.com wrote: Hi Alex, Try: set.seed(345) results- array(sample(-5:5,120,replace=TRUE),dim=c(10,3,4)) indx - !!apply(results,1,sum) library(plyr) results2 - laply(lapply(seq(dim(results)[1]),function(i) results[i,,])[indx],identity) attr(results2,dimnames) - NULL dim(results2) #[1] 9 3 4 A.K. I have a 3D array with 13,000 11x8 matrices. dim(results [1] 13000 11 8 Some matrices in the array add up to 0. For example sum(results[1,,])==0 [1] TRUE I would like to remove these. How can I do this? __ 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.
[R] using lapply to get function values
Hi R users, I need to apply a function on a list of vectors. This is simple when I use functions that returns only one numerical value such as 'mean' or 'variance'. Things get complex when I use functions returning a list of value, such as 'acf'. In the following example I first create a list of vectors with equal length 10. Then I try to get the first order autocorrelation coefficient of each vector using lapply: # library(stats) X=rnorm(1:100) Y=split(X,as.numeric(gl(length(X),10,length(X# to divide X into 10 sub-vectors app=lapply(Y,FUN=acf,lag.max=1,plot=F) app # I need to know how to display other values of the function e.g. 'type', 'lag' not just 'acf'. Because using app=lapply(Y,FUN=acf$type,lag.max=1,plot=F) prompts the error object of type 'closure' is not subsettable Note that this is only an illustrative example. The function I am studying is not 'acf', but it also return a list of values and I need to call out specific values. Helps and comments are welcome. Long -- View this message in context: http://r.789695.n4.nabble.com/using-lapply-to-get-function-values-tp4683373.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] locate pattern in matrix
Dear all, I have a binary matrix 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 I want to find the location of all the square and rectangular 1 blocks, like First block in row=2, col=1 to row=3, col=3. Second block in row=5, col=4, to row=6, col=5. How can I find such blocks of 1? Thanks: John __ 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] GA optimization in two dimensions
Hi: I am trying to implement a bandwidth reduction algorithm for a (M x N) binary matrix using the GA package in R. I am using the folloging code to get the optimal permutation for rows and columns (optimization in two dimensions). M - matrix(c(0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1),nrow=5, ncol=4) BW - function(patt, origMatrix) { M1 - origMatrix[patt[1], patt[2]] temp2 - 0; temp3 - 0; for(i in 1:nrow(M1)) { for(j in 1:ncol(M1)) { if(M1[i,j] 0) { temp1 - abs(i - j) temp2 - append(temp2, temp1) } } temp3 - append(temp3, max(temp2)) temp2 - 0 } return(max(temp3)) } bwFit - function(patt, ...) 1/BW(patt[1], patt[2],...) GA - ga(type = permutation, fitness = bwFit, origMatrix = M, min = c(1,1), max = c(5,4), popSize = 100, maxiter = 5000, run = 500, pmutation = 0.2) I get this error message: Error in BW(patt[1], patt[2], ...) : unused argument (patt[2]) In summary, I am unable to implement the optimization in two dimensions. In the solution, I need two vectors containing the optimal row and column permutations. Can you suggest a solution? Regards: John __ 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.