Re: [R] understanding with
> On 10 Sep 2016, at 08:27 , Jeff Newmiller wrote: > > > The with function is just helpful syntactic sugar for reducing repetitious > typing of the name of the list/data frame that contains several objects you > want to refer to in a single expression. A little more than that, witness the difference between these two: > plot(airquality$Ozone) > with(airquality, plot(Ozone)) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Apply a multi-variable function to a vector
Thanks. I have gotten some replies. One problem was that I was not passing the names of the vectors to expand.grid. I didn't think I had to do that and that caused problems with do.call. I wanted to just define the vectors of variables values, the function, func, and then pass that to my.outer. I was using A <- c( ... ) Then, expand.grid(A, etc.) with do.call and as.list and without the names use in 'fund', there was an error. I didn't think it would matter what names I used in defining the function. Thanks very much. I think I have some good alternatives that all work. Steve On Sat, Sep 10, 2016 at 1:29 AM, Jeff Newmiller wrote: > Not sure I understand what you really want, if you have found ways to > accomplish what you want but are not satisfied with them. That is one > reason why keeping the mailing list involved (by reply-all) is good for > you. From my end, I don't do one-on-one support online, and may not be able > to carry on a thread to the end if I get busy. > > Your concept of a generalized outer function sounds to me like: > > myfunc <- function( A, B, C ) { > A * B + C > } > > gouter <- function( FUN, ... ) { > args <- list( ... ) > DF <- do.call( expand.grid, args ) > array( data = do.call( FUN, DF ) > , dim = sapply( args, FUN=length ) > , dimnames = args > ) > } > > gouter( myfunc, A = 1:3, B=2:6, C=3:4 ) > # , , C = 3 > # > #B > # A 2 3 4 5 6 > # 1 5 6 7 8 9 > # 2 7 9 11 13 15 > # 3 9 12 15 18 21 > # > # , , C = 4 > # > #B > # A2 3 4 5 6 > # 1 6 7 8 9 10 > # 2 8 10 12 14 16 > # 3 10 13 16 19 22 > > I generally just tack on columns to the expand.grid result... I almost > never have a need for multidimensional arrays. > > On Fri, 9 Sep 2016, Steve Kennedy wrote: > > Hello, >> >> Abstraction is what I want. I'm actually looking to do something more >> complicated. The functions do.call, and as.list get me most of the way >> there, but there is something I'm missing ... >> >> My eventual goal is to produce a multi-dimensional version of 'outer'. >> Like my.outer(func, a_vec, b_vec, c_vec, ..), where the function of the >> variables 'a', 'b', 'c', etc. would be applied to the vectors from the >> outer product of the vectors of values for each variable. >> >> I wanted to use expand.grid (does require reshaping the output). Using >> temps = c(40,50,60) and times = c(1:5), this doesn't quite seem to work: >> >> apply(expand.grid(temps,times), 1, function(a) do.call(func2, >> as.list(a))) >> >> although this does work: >> >> do.call(func2, as.list(c(10, 121))) >> >> And, this also works: >> >> apply(expand.grid(temps,times), 1, function(a) do.call("+", as.list(a))) >> >> There is some subtlety here I don't understand. >> >> Thanks, >> >> Steve >> >> -Original Message- >> From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] >> Sent: Friday, September 09, 2016 5:39 PM >> To: Steve Kennedy; r-help@r-project.org >> Subject: Re: [R] Apply a multi-variable function to a vector >> >> Your architecture has a bad smell to me. For one thing you are mixing >> different units in the same vector but should be putting multiple instances >> of the same variable into one vector. Lists of vectors (data frames) are >> typically used when multiple variables need to be grouped. >> >> Another problem is that you are constraining the names of the variables >> you pass to the function to be named the same as they are inside the >> function. This really limits your use of those functions. >> >> There really is too much abstraction going on here. >> -- >> Sent from my phone. Please excuse my brevity. >> >> On September 9, 2016 12:44:52 PM PDT, Steve Kennedy >> wrote: >> >>> Hello, >>> >>> I would like to define an arbitrary function of an arbitrary number of >>> variables, for example, for 2 variables: >>> >>> func2 <- function(time, temp) time + temp >>> >>> I'd like to keep variable names that have a meaning in the problem >>> (time and temperature above). >>> >>> If I have a vector of values for these variables, for example in the >>> 2-d case, c(10, 121), I'd like to apply my function (in this case >>> func2) and obtain the result. Conceptually, something like, >>> >>> func2(c(10,121)) >>> >>> becomes >>> >>> func2(10,121) >>> >>> Is there a simple way to accomplish this, for an arbitrary number of >>> variables? I'd like something that would simply work from the >>> definition of the function. If that is possible. >>> >>> Thanks, >>> >>> Steve Kennedy >>> >>> CONFIDENTIALITY NOTICE: This e-mail message, including >>> a...{{dropped:11}} >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> http://cp.mcafee.com/d/k-Kr6x0g6hASyMepov78FI6XCQXLK3AnCrFCQXLK3AnCnAPq >>> tTT1ObPdSjqaby8VMsUyYrEl-4fgb0HoiaXcDYtmZKsHkVsTI95tCj-eHuTelGsKrpYwCOw >>> evW_ccnpuKNRXBQQT1TfcFzCnTeEyCJtdmXP_axVZicHs3jq9JcTvANOoVcsCej76XCOsVH >>> kiPajSvvcCatoDwCHIcfBisEeRO9sDVWN
Re: [R] GGplot annotate by facet
Hi Saad, Please have a look at http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and/or http://adv-r.had.co.nz/Reproducibility.html for some suggestions on how to ask a question on R-help In particular it would be handy to have some sample data in dput() format. I always mess up geom_bar() calls and at the moment don't understand exactly what you are doing here qplot(factor(Value),data=dat1, geom="bar",fill=factor(Type)) John Kane Kingston ON Canada > -Original Message- > From: smk...@mail.missouri.edu > Sent: Sat, 10 Sep 2016 01:55:18 + > To: r-help@r-project.org > Subject: [R] GGplot annotate by facet > > Hi, > > I have a dataframe which I need to plot in ggplot2 it looks like this :- > > head(nodelta_firstexon) > Value Type Histone > 1 0.06 high H3K27ac > 2 0.12 low H3K27ac > 4 0.04 high H3K27me3 > 5 0.16 low H3K27me3 > 7 0.02 high H3K36me3 > 8 0.13 low H3K36me3 > > I have another data frame with p-v alues that looks like this :- > > > head(mypval_df) > > Histone count pvalues > > 1 H3K9ac 0 0.000 > > 2 H3K27me3 0 0.000 > > 3 H3K36me3 1000 1.000 > > 4 H3K4me3 583 0.583 > > 5 H3K4me1 882 0.882 > > 6 H3K27ac 970 0.970 > > This is how I plot the first dataframe using ggplot > p <- > qplot(factor(Value),data=nodelta_firstexon,geom="bar",fill=factor(Type))+facet_wrap(~Histone) > > Next I need to annotate p-values (p <= mypval_df$pvalues) to each facet > using the mypval_df. > > I can't seem to find an example on how to do it. Would appreciate any > help. > > Regards > Saad > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Architect from Open Analytics
Hello, i am new to R and try to use Architect from Open Analytics (0.9.8 on Debian 64bit). Is anybody on this list using this tool? I am asking because it seems to have lots of problems, like: * not possible to open the package manager * not possible to open details from the "About Architect" dialog * some commands not supported > a <- c(1:10) > a [1] 1 2 3 4 5 6 7 8 9 10 > data.entry(a) Error in dataentry(odata, as.list(Modes)) : X11 dataentry cannot be loaded In addition: Warning message: In dataentry(odata, as.list(Modes)) : unable to load shared object '/opt/architect/stable/20160518101101/plugins/eu.openanalytics.architec t.r.server.gtk.linux.x86_64_0.9.8.201511181238/R/modules//R_de.so': libpng12.so.0: cannot open shared object file: No such file or directory Problems with Eclipse UI: eclipse.buildId=unknown java.version=1.8.0_102 java.vendor=Oracle Corporation BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_GB Command-line arguments: -data file:/home/chris/.architect/workspace/ -os linux -ws gtk -arch x86_64 org.eclipse.ui Error Sat Sep 10 15:09:55 CEST 2016 Unhandled event loop exception java.lang.NullPointerException at org.eclipse.swt.widgets.TabFolder.gtk_switch_page(TabFolder.java:490) at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:2009) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4723) at org.eclipse.swt.internal.gtk.OS._gtk_widget_show(Native Method) at org.eclipse.swt.internal.gtk.OS.gtk_widget_show(OS.java:14727) at org.eclipse.swt.widgets.TabFolder.createItem(TabFolder.java:274) at org.eclipse.swt.widgets.TabItem.createWidget(TabItem.java:123) at org.eclipse.swt.widgets.TabItem.(TabItem.java:75) at de.walware.statet.r.internal.ui.pkgmanager.RPkgManagerDialog.createDial ogContent(RPkgManagerDialog.java:151) at de.walware.statet.nico.ui.util.ToolDialog.createDialogArea(ToolDialog.j ava:99) at org.eclipse.jface.dialogs.TitleAreaDialog.createContents(TitleAreaDialo g.java:161) at de.walware.statet.r.internal.ui.pkgmanager.RPkgManagerDialog.createCont ents(RPkgManagerDialog.java:113) at org.eclipse.jface.window.Window.create(Window.java:430) at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096) at org.eclipse.jface.window.Window.open(Window.java:792) Maybe somebody has some experience with Architect, any hint is appreciated :) BR Joysn __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to read a grib2 file
On Sat, 10 Sep 2016 at 07:12 Debasish Pai Mazumder wrote: > Hi > I am trying to read a grib2 file in R. > > Here is my script > > library(rgdal) > library(sp) > library(rNOMADS) > gribfile<-"tmax.01.2011040100.daily.grb2" > grib <- readGDAL(gribfile) > > I am getting following error : > > dec_jpeg2000: Unable to open JPEG2000 image within GRIB file. > Is the JPEG2000 driver available?tmax.01.2011040100.daily.grb2 has GDAL > driver GRIB > and has 190 rows and 384 columns > dec_jpeg2000: Unable to open JPEG2000 image within GRIB file. > Is the JPEG2000 driver available?dec_jpeg2000: Unable to open JPEG2000 > image within GRIB file. > > Hi there, please check if JPEG2000 is in the gdalDrivers() list, i.e. in rgdal::gdalDrivers()$name You are looking for one starting with "JP2" as per the list next to the "JPEG2000" rows here: http://gdal.org/formats_list.html I have JP2OpenJPEG on one system, but not (for example) on the Windows CRAN binary for rgdal, which is the only readily available Windows build for this package. I you don't have it, you might try on a system that has the JP2OpenJPEG driver, or ask someone to try on your behalf. You'd want to find out if that will enable this read for you before investing time in the Linux configuration. It's not too hard to set up a Linux system for this, but does assume a bit of experience on your part. Some of the docker images in the rockerverse have this all sorted I believe, but it's been a while since I used them. https://hub.docker.com/u/rocker/ Cheers, Mike. > Cheers > -Deb > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > -- Dr. Michael Sumner Software and Database Engineer Australian Antarctic Division 203 Channel Highway Kingston Tasmania 7050 Australia [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Matching/checking for occurence when values are double?
Actually, there was another reason for the function equal() but I wasn't remembering what. all.equal doesn't recycle its arguments, just see this example. equal <- function(x, y, eps = .Machine$double.eps^0.5) abs(x - y) < eps x <- seq(0, 1, by = 0.2) x == 0.6 all.equal(x, 0.6) equal(x, 0.6) Rui Barradas Citando ruipbarra...@sapo.pt: Not exactly, all.equal is much more complete. It accepts all kinds of objects, not just vectors. Rui Barradas Citando Ivan Calandra : Hi, Not sure, but it seems that your function equal() is exactly what all.equal() does, isn't it? Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-reims.fr -- https://www.researchgate.net/profile/Ivan_Calandra https://publons.com/author/705639/ Le 09/09/2016 à 14:47, ruipbarra...@sapo.pt a écrit : Hello, See FAQ 7.31. It's irrelevant if you write 100 or 100.0, the values are the same. The difference would be between 100 (double) and 100L (integer). To check for equality between floating-point numbers you can use, for instance, the following function. equal <- function(x, y, eps = .Machine$double.eps^0.5) abs(x - y) < eps equal(100, 100 + 2e-15) [1] TRUE Hope this helps, Rui Barradas Citando Matti Viljamaa : I need to pick from a dataset those rows that have a double value set to 100. However since the values in this column are like the following: [1] 121.11750 89.36188 115.44320 99.44964 92.74571 107.90180 [7] 138.89310 125.14510 81.61953 95.07307 88.57700 94.85971 [13] 88.96280 114.11430 100.53410 120.41910 114.42690 … Then can I match against 100 or 100.0? Or do I need to match against 100.0 or something else? E.g. does 100.0 %in% kidmomiq$mom_iq produce a truthful match result with this kind of data (I’m getting 0 occurrences, which might be correct, but I’m not sure)? __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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.