Re: [R] Problem Subsetting Rows that Have NA's

2017-10-24 Thread Ben Tupper
Hi,

It's related to how NAs are treated in comparison operations.  See the Details 
section of 
https://www.rdocumentation.org/packages/base/versions/3.4.1/topics/Comparison 
<https://www.rdocumentation.org/packages/base/versions/3.4.1/topics/Comparison>

You can try something like this...

x[which(x[,2] %in% 0),]
#  [,1] [,2]
# [1,]40
# [2,]50


... but I'm not sure if it is bullet proof.  Others may have more insight.

Cheers,
Ben



> On Oct 24, 2017, at 3:05 PM, BooBoo  wrote:
> 
> This has every appearance of being a bug. If it is not a bug, can someone 
> tell me what I am asking for when I ask for "x[x[,2]==0,]". Thanks.
> 
> > #here is the toy dataset
> > x <- rbind(c(1,1),c(2,2),c(3,3),c(4,0),c(5,0),c(6,NA),
> +   c(7,NA),c(8,NA),c(9,NA),c(10,NA)
> + )
> > x
>  [,1] [,2]
> [1,]11
> [2,]22
> [3,]33
> [4,]40
> [5,]50
> [6,]6   NA
> [7,]7   NA
> [8,]8   NA
> [9,]9   NA
> [10,]   10   NA
> >
> > #it contains rows that have NA's
> > x[is.na(x[,2]),]
> [,1] [,2]
> [1,]6   NA
> [2,]7   NA
> [3,]8   NA
> [4,]9   NA
> [5,]   10   NA
> >
> > #seems like an unreasonable answer to a reasonable question
> > x[x[,2]==0,]
> [,1] [,2]
> [1,]40
> [2,]50
> [3,]   NA   NA
> [4,]   NA   NA
> [5,]   NA   NA
> [6,]   NA   NA
> [7,]   NA   NA
> >
> > #this is more what I was expecting
> > x[which(x[,2]==0),]
> [,1] [,2]
> [1,]40
> [2,]50
> >
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




[[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] Generating help files for a function

2017-12-16 Thread Ben Tupper
Hi,

If you are using roxygen-style function documentation then why not use 
devtools::document()?  

Ben

  

> On Dec 16, 2017, at 9:00 AM, Erin Hodgess  wrote:
> 
> Hello everyone!
> 
> I'm in the process of writing a package, and I'm using the lovely "R
> Package" book as a guideline.
> 
> However, in the midst of my work,  I discovered that I had omitted a
> function and am now putting in it the package.  Not a problem.  But the
> problem is the help file.  What is the best way to generate a help file
> "after the fact" like that, please?
> 
> Thank you in advance.  Hope everyone is enjoying various holidays.
> 
> Sincerely,
> Erin
> 
> 
> -- 
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




[[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] httr::content without message

2018-01-02 Thread Ben Tupper
Ahoy!

That's a message generated by the readr::read_table() function (or it's 
friends).  You can suppress it a number of ways, but this should work as 
httr::content() will pass through arguments, like col_types = cols(), to the 
file reader.

junk <- httr::content(r1, col_types = cols())

See more here...

https://blog.rstudio.com/2016/08/05/readr-1-0-0/ 
<https://blog.rstudio.com/2016/08/05/readr-1-0-0/>


Cheers,
Ben



> On Jan 2, 2018, at 12:30 PM, Roy Mendelssohn - NOAA Federal 
>  wrote:
> 
> Hi All:
> 
> I am using httr to download files form a service, in this case a .csv file.  
> When I use httr::content on the result,  I get a message.  Since this will be 
> in a package.  I want to suppress the message,  but haven't figured out how 
> to do so.
> 
> The following should reproduce the result:
> 
> myURL <- 
> 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
> r1 <- httr::GET(myURL)
> junk <- httr::content(r1)
> 
> when the last command is run, you get:
> 
> Parsed with column specification:
> cols(
>  `time (UTC)` = col_datetime(format = "")
> )
> 
> I want to suppress that output.
> 
> Thanks,
> 
> -Roy
> 
> **
> "The contents of this message do not reflect any position of the U.S. 
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
> 
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected" 
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




[[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] httr::content without message

2018-01-02 Thread Ben Tupper
That's good to know about when to auto-parse and when not to.  There is quite a 
big stable of tools to check the response before you try to read...

> httr::http_error(r1)
[1] FALSE

> httr::http_status(r1)
$category
[1] "Success"

$reason
[1] "OK"

$message
[1] "Success: (200) OK"

and

> httr::http_type(r1)
[1] "text/csv"


> On Jan 2, 2018, at 12:53 PM, Roy Mendelssohn - NOAA Federal 
>  wrote:
> 
> Thanks to all that replied.  I had just looked through the httr code and sure 
> enough for a .csv mime time it calls readr::read_csv().  The httr::content 
> docs suggest not using automatic parsing in a package,  rather to determine 
> mime type and parse yourself and Ben's suggestion also works if I do:
> 
> junk <- readr::read_csv(r1$content, col_types = cols())
> 
> Perfect.  Using httr rather than putting the url in any of the read.csv or 
> read_csv type code allows me greater control if the request fails.
> 
> Thanks again,
> 
> -Roy
> 
>> On Jan 2, 2018, at 9:44 AM, Ben Tupper  wrote:
>> 
>> Ahoy!
>> 
>> That's a message generated by the readr::read_table() function (or it's 
>> friends).  You can suppress it a number of ways, but this should work as 
>> httr::content() will pass through arguments, like col_types = cols(), to the 
>> file reader.
>> 
>> junk <- httr::content(r1, col_types = cols())
>> 
>> See more here...
>> 
>> https://blog.rstudio.com/2016/08/05/readr-1-0-0/
>> 
>> 
>> Cheers,
>> Ben
>> 
>> 
>> 
>>> On Jan 2, 2018, at 12:30 PM, Roy Mendelssohn - NOAA Federal 
>>>  wrote:
>>> 
>>> Hi All:
>>> 
>>> I am using httr to download files form a service, in this case a .csv file. 
>>>  When I use httr::content on the result,  I get a message.  Since this will 
>>> be in a package.  I want to suppress the message,  but haven't figured out 
>>> how to do so.
>>> 
>>> The following should reproduce the result:
>>> 
>>> myURL <- 
>>> 'https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1sstdmday.csvp?time[0:1:last]'
>>> r1 <- httr::GET(myURL)
>>> junk <- httr::content(r1)
>>> 
>>> when the last command is run, you get:
>>> 
>>> Parsed with column specification:
>>> cols(
>>> `time (UTC)` = col_datetime(format = "")
>>> )
>>> 
>>> I want to suppress that output.
>>> 
>>> Thanks,
>>> 
>>> -Roy
>>> 
>>> **
>>> "The contents of this message do not reflect any position of the U.S. 
>>> Government or NOAA."
>>> **
>>> Roy Mendelssohn
>>> Supervisory Operations Research Analyst
>>> NOAA/NMFS
>>> Environmental Research Division
>>> Southwest Fisheries Science Center
>>> ***Note new street address***
>>> 110 McAllister Way
>>> Santa Cruz, CA 95060
>>> Phone: (831)-420-3666
>>> Fax: (831) 420-3980
>>> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>>> 
>>> "Old age and treachery will overcome youth and skill."
>>> "From those who have been given much, much will be expected" 
>>> "the arc of the moral universe is long, but it bends toward justice" -MLK 
>>> Jr.
>>> 
>>> __
>>> 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.
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>> Ecocast Reports: http://seascapemodeling.org/ecocast.html
>> Tick Reports: https://report.bigelow.org/tick/
>> Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/
>> 
>> 
>> 
> 
> **
> "The contents of this message do not reflect any position of the U.S. 
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
> 
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected" 
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




[[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] roxygen2 error - x$tag operator is invalid for atomic vectors

2018-01-17 Thread Ben Tupper
Hi,

It's not really a roxygen thing but a subsetting thing.

> x = c(foo = 7, tag = 8)
> x$tag
Error in x$tag : $ operator is invalid for atomic vectors

For simple vectors you want ...

> x['tag']
tag 
  8 

... or ...

> x[['tag']]
[1] 8


See more at 

> ?`$`


Cheers,
Ben
> On Jan 17, 2018, at 8:16 AM, Martin Møller Skarbiniks Pedersen 
>  wrote:
> 
> Hi,
> 
>  I am trying to create my first R package.
>  I will later today put the files on Github.
> 
>  However I gets this error and I can't find any reason for it:
> 
> R> roxygen2::roxygenise()
> First time using roxygen2. Upgrading automatically...
> Error in x$tag : $ operator is invalid for atomic vectors
> R>
> 
>  Any ideas?
> 
> Regards
> Martin M. S. Pedersen
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




[[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] how to add a child to a child in XML

2018-03-21 Thread Ben Tupper
Hi,

XML doesn't use the `$` to access child nodes.  Instead use either `[name]` to 
get a list of children of that name or `[[name]]` to get the just the first 
child of that name encountered in the genealogy.  Thus for your example...

> root$child1
NULL

> root[['child1']]



On the other hand, you might consider using newXMLNode() instead of xmlNode() 
as it accepts a "parent = " argument.  The alternative using newXMLNode() would 
look like...

atts_root <- c("val1","val2","val3")
names(atts_root) <- c("att1","att2","att3")
root <- newXMLNode("root", attrs = atts_root)

atts_child <- LETTERS[1:3]
names(atts_child) <- paste("name",1:3,sep="")
child <- newXMLNode("child",attrs = atts_child, parent = root)

atts_grandchild <- letters[1:3]
names(atts_grandchild) <- paste("name",4:6,sep="")
grandchild <- newXMLNode("grandchild",attrs = atts_grandchild, parent = child)

root
#
#  
#
#  
# 


Cheers,
Ben
 
> On Mar 21, 2018, at 4:25 PM, Bond, Stephen  wrote:
> 
> I am trying to add a child to a child using XML package in R. the following 
> fails
> 
> library(XML)
> 
> node1 <- c("val1","val2","val3")
> 
> names(node1) <- c("att1","att2","att3")
> 
> root <- xmlNode("root", attrs=node1)
> 
> node2 <- LETTERS[1:3]
> 
> names(node2) <- paste("name",1:3,sep="")
> 
> root <- addChildren(root,xmlNode("child1",attrs=node2))
> 
> node3 <- letters[1:3]
> 
> names(node3) <- paste("name",4:6,sep="")
> 
> root <- addChildren(root$child1,xmlNode("child2",attrs=node3))
> 
> 
> 
> Error in UseMethod("addChildren") : no applicable method for 'addChildren' 
> applied to an object of class "NULL"
> 
> 
> Stephen B
> 
> 
>   [[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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/





[[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] how to add a child to a child in XML

2018-03-22 Thread Ben Tupper
Hi,

It's a reasonable question. The answer is that it actually is included, but 
there are many instances across packages where multiple functions are 
documented on a single help page.  The following brings up such a page... (for 
XML_3.98-1.9)

> library(XML)
> ?newXMLNode

You can see the same on line...

https://www.rdocumentation.org/packages/XML/versions/3.98-1.9/topics/newXMLDoc

You have dig in to find it.  

If you are just starting out with XML, you might want to spend some time 
comparison shopping with the xml2 package. 
https://www.rdocumentation.org/packages/xml2/versions/1.2.0 
<https://www.rdocumentation.org/packages/xml2/versions/1.2.0>  I like each one, 
and I use both XML and xml2 (not at the same time). I have been slowly 
migrating toward xml2 as I use more of the tidyverse stuff.

Cheers,
Ben

> On Mar 22, 2018, at 9:19 AM, Bond, Stephen  wrote:
> 
> Big thanks. newXMLNode works great. Wonder why it is not included in the 
> documentation.
> There is newXMLDoc and newXMLNamespace, but no mention of newXMLNode.
>  
> Stephen
>  
> From: Ben Tupper [mailto:btup...@bigelow.org] 
> Sent: Wednesday, March 21, 2018 6:18 PM
> To: Bond, Stephen
> Cc: r-help
> Subject: Re: [R] how to add a child to a child in XML
>  
> Hi,
>  
> XML doesn't use the `$` to access child nodes.  Instead use either `[name]` 
> to get a list of children of that name or `[[name]]` to get the just the 
> first child of that name encountered in the genealogy.  Thus for your 
> example...
>  
> > root$child1
> NULL
>  
> > root[['child1']]
> 
>  
>  
> On the other hand, you might consider using newXMLNode() instead of xmlNode() 
> as it accepts a "parent = " argument.  The alternative using newXMLNode() 
> would look like...
>  
> atts_root <- c("val1","val2","val3")
> names(atts_root) <- c("att1","att2","att3")
> root <- newXMLNode("root", attrs = atts_root)
>  
> atts_child <- LETTERS[1:3]
> names(atts_child) <- paste("name",1:3,sep="")
> child <- newXMLNode("child",attrs = atts_child, parent = root)
>  
> atts_grandchild <- letters[1:3]
> names(atts_grandchild) <- paste("name",4:6,sep="")
> grandchild <- newXMLNode("grandchild",attrs = atts_grandchild, parent = child)
>  
> root
> #
> #  
> #
> #  
> # 
>  
>  
> Cheers,
> Ben
>  
> On Mar 21, 2018, at 4:25 PM, Bond, Stephen  <mailto:stephen.b...@cibc.com>> wrote:
>  
> I am trying to add a child to a child using XML package in R. the following 
> fails
> 
> library(XML)
> 
> node1 <- c("val1","val2","val3")
> 
> names(node1) <- c("att1","att2","att3")
> 
> root <- xmlNode("root", attrs=node1)
> 
> node2 <- LETTERS[1:3]
> 
> names(node2) <- paste("name",1:3,sep="")
> 
> root <- addChildren(root,xmlNode("child1",attrs=node2))
> 
> node3 <- letters[1:3]
> 
> names(node3) <- paste("name",4:6,sep="")
> 
> root <- addChildren(root$child1,xmlNode("child2",attrs=node3))
> 
> 
> 
> Error in UseMethod("addChildren") : no applicable method for 'addChildren' 
> applied to an object of class "NULL"
> 
> 
> Stephen B
> 
> 
> [[alternative HTML version deleted]]
> 
> __________
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
> 
>  
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org <http://www.bigelow.org/>
>  
> Tick Forecasting: https://eco.bigelow.org/ <https://eco.bigelow.org/>
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/





[[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] netCDF to GeoTIFF by layer in r

2018-03-28 Thread Ben Tupper
Hi Ahmed,

When reading from a ncdf file you can use the 'varname', 'lvar' and 'level' 
arguments - see the 'Details' section in the docs

https://www.rdocumentation.org/packages/raster/versions/2.6-7/topics/raster 
<https://www.rdocumentation.org/packages/raster/versions/2.6-7/topics/raster>

We can't tell what is in the ncdf file from what you report other than it has 4 
bands (layers) and that the first is called 
'Volumetric.water.content.at..33.kPa' If you want to know more about the what 
is in the file, then I suggest you use the ncdf4 package to open the file and 
explore it's contents - you should get a clear picture of it's contents from 
that.  Something like this (untested)...

library(ncdf4)
x <- nc_open(file.nc)
x
nc_close(x)

While print lots of info about the file.

Ben

> On Mar 28, 2018, at 10:37 AM, Ahmed Attia  wrote:
> 
> Hi
> 
> I have a netCDF file of volumetric soil water content at four
> different soil layers and want to convert each soil layer in the
> netCDF file to a GeoTIFF layer. This code converts the netCDF file to
> one GeoTIFF layer, i.e. unclear which soil depth.
> 
> file.nc <- "C:/Soil_Weather_data/Agro/VMC21/VMC21.nc"
> 
> file.tiff <- "C:/Soil_Weather_data/Agro /VMC21/VMC21"
> 
> importnetcdf <- raster(file.nc)
> 
>> importnetcdf
> class   : RasterLayer
> band: 1  (of  4  bands)
> #the bands here are the four soil layers
> dimensions  : 16800, 43200, 72576  (nrow, ncol, ncell)
> resolution  : 0.0083, 0.0083  (x, y)
> extent  : -180, 179.9998, -56, 83.5  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source :
> C:\FAPSEP_Eucalyptus\FAPSEP\Soil_Weather_data\Agro_IBIS_Eucalipto\VMC21\VMC21.nc
> names   : Volumetric.water.content.at..33.kPa
> z-value : 4.5
> zvar: VMC2
> 
> 
> 
> VMC1<-writeRaster(importnetcdf,filename="file.tiff",format="GTiff",overwrite=TRUE,bylayer=TRUE,suffix="1:4")
>   #bylayer=TRUE, did not work.
> 
>> VMC1
> class   : RasterLayer
> dimensions  : 16800, 43200, 72576  (nrow, ncol, ncell)
> resolution  : 0.0083, 0.0083  (x, y)
> extent  : -180, 179.9998, -56, 83.5  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
> +towgs84=0,0,0
> data source : C:\Users\Ahmed\Documents\file.tif
> names   : file
> values  : 2, 80  (min, max)
> 
> Any help!
> 
> 
> Ahmed Attia, Ph.D.
> Agronomist & Soil Scientist
> 
>   [[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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/





[[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] Histogram of character elements

2018-06-07 Thread Ben Tupper
Hi,

Is this what you are after? 

group <- c("a", "b", "c", "d", "e")
freq <-c(1, 2, 2, 5, 3)
x = rep(group, freq)
barplot(table(x))

Cheers,
Ben



> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
> 
> Dear all,
> I have a dataframe with a column representing the names of the
> elements (a, b, etc) and one with their frequencies.
> How can I plot the frequencies so that each element has an associated
> frequency value?
> I have been thinking of a histogram, but I have found it difficult to
> implement. I have tried the following:
> 
> group <- c("a", "b", "c", "d", "e")
> freq <-c(1, 2, 2, 5, 3)
> df <- data.frame(group, freq, stringsAsFactors = FALSE)
> hist(df$freq)
> library(lattice)
> histogram( ~ df$group)
> histogram( ~ as.factor(df$group))
> histogram(df$freq ~ as.factor(df$group))
> 
> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
> times, the values 3 and 5 appear once and 4 never. This is not what I
> wanted; I want instead a graph telling me that a appears once, b twice
> etc.
> 
> histogram( ~ df$group) gives the error:
> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
> include.lowest = include.lowest,  :
>  negative length vectors are not allowed
> 
> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
> as.factor(df$group)) report all groups on the x axis (that is good)
> but all at 20% level.
> 
> What am I missing?
> Thank you.
> 
> -- 
> Best regards,
> Luigi
> 
> __
> 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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] Histogram of character elements

2018-06-07 Thread Ben Tupper
Hi again,

I'm sort of pre-coffee still, but does this do it?  The data frame only has one 
variable, a factor where the order of the levels is specified.

library(lattice)
group   <- c("a", "b", "c", "d", "e")
freq<- c(1, 2, 2, 5, 3)
x   <- rep(group, freq)
df  <- data.frame(group = factor(x, levels = c("d", "a", "b", "c", "e")) )
histogram(~ group, data = df)

As far as super-grouping the answer is likely yes, but without details and an 
example (and coffee) I'm at a loss.   I suggest getting a your hands on a copy 
of https://www.r-project.org/doc/bib/R-books_bib.html#R:Sarkar:2008 
<https://www.r-project.org/doc/bib/R-books_bib.html#R:Sarkar:2008> It's really 
worth it if you plan to spend time with lattice.

Cheers,
Ben 


> On Jun 7, 2018, at 7:02 AM, Luigi Marongiu  wrote:
> 
> also, with this approach, I need to re-arrange the data. Is it
> possible to work directly on a dataframe?
> On Thu, Jun 7, 2018 at 12:48 PM Ben Tupper  wrote:
>> 
>> Hi,
>> 
>> Is this what you are after?
>> 
>> group <- c("a", "b", "c", "d", "e")
>> freq <-c(1, 2, 2, 5, 3)
>> x = rep(group, freq)
>> barplot(table(x))
>> 
>> Cheers,
>> Ben
>> 
>> 
>> 
>> On Jun 7, 2018, at 6:00 AM, Luigi Marongiu  wrote:
>> 
>> Dear all,
>> I have a dataframe with a column representing the names of the
>> elements (a, b, etc) and one with their frequencies.
>> How can I plot the frequencies so that each element has an associated
>> frequency value?
>> I have been thinking of a histogram, but I have found it difficult to
>> implement. I have tried the following:
>> 
>> group <- c("a", "b", "c", "d", "e")
>> freq <-c(1, 2, 2, 5, 3)
>> df <- data.frame(group, freq, stringsAsFactors = FALSE)
>> hist(df$freq)
>> library(lattice)
>> histogram( ~ df$group)
>> histogram( ~ as.factor(df$group))
>> histogram(df$freq ~ as.factor(df$group))
>> 
>> hist(df$freq) returns a histogram in which the values 1 and 2 appear 3
>> times, the values 3 and 5 appear once and 4 never. This is not what I
>> wanted; I want instead a graph telling me that a appears once, b twice
>> etc.
>> 
>> histogram( ~ df$group) gives the error:
>> Error in hist.default(as.numeric(x), breaks = breaks, plot = FALSE,
>> include.lowest = include.lowest,  :
>> negative length vectors are not allowed
>> 
>> histogram( ~ as.factor(df$group)) and histogram(df$freq ~
>> as.factor(df$group)) report all groups on the x axis (that is good)
>> but all at 20% level.
>> 
>> What am I missing?
>> Thank you.
>> 
>> --
>> Best regards,
>> Luigi
>> 
>> __
>> 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.
>> 
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>> Ecological Forecasting: https://eco.bigelow.org/
>> 
>> 
>> 
>> 
>> 
> 
> 
> -- 
> Best regards,
> Luigi
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] aggregate and list elements of variables in data.frame

2018-06-07 Thread Ben Tupper
Hi,

Does this do what you want?  I had to change the id values to something more 
obvious.  It uses tibbles which allow each variable to be a list.

library(tibble)
library(dplyr)
x   <- tibble(id=LETTERS[1:10],
A=c(123,345,123,678,345,123,789,345,123,789))
uA  <- unique(x$A)
idx <- lapply(uA, function(v) which(x$A %in% v))
vals<- lapply(idx, function(index) x$id[index])

r <- tibble(unique_A = uA, list_idx = idx, list_vals = vals)


> r
# A tibble: 4 x 3
  unique_A list_idx  list_vals
 
1 123.  
2 345.  
3 678.  
4 789.  
> r$list_idx[1]
[[1]]
[1] 1 3 6 9

> r$list_vals[1]
[[1]]
[1] "A" "C" "F" "I"


Cheers,
ben



> On Jun 7, 2018, at 8:21 AM, Massimo Bressan  
> wrote:
> 
> sorry, but by further looking at the example I just realised that the posted 
> solution it's not completely what I need because in fact I do not need to get 
> back the 'indices' but instead the corrisponding values of column A 
> 
> #please consider this new example 
> 
> t<-data.frame(id=c(18,91,20,68,54,27,26,15,4,97),A=c(123,345,123,678,345,123,789,345,123,789))
>  
> t 
> 
> # I need to get this result 
> r<-data.frame(unique_A=c(123, 345, 678, 
> 789),list_id=c('18,20,27,4','91,54,15','68','26,97')) 
> r 
> 
> # any help for this, please? 
> 
> 
> 
> 
> 
> Da: "Massimo Bressan"  
> A: "r-help"  
> Inviato: Giovedì, 7 giugno 2018 10:09:55 
> Oggetto: Re: aggregate and list elements of variables in data.frame 
> 
> thanks for the help 
> 
> I'm posting here the complete solution 
> 
> t<-data.frame(id=1:10,A=c(123,345,123,678,345,123,789,345,123,789)) 
> t$A <- factor(t$A) 
> l<-sapply(levels(t$A), function(x) which(t$A==x)) 
> r<-data.frame(list_id=unlist(lapply(l, paste, collapse = ", "))) 
> r<-cbind(unique_A=row.names(r),r) 
> row.names(r)<-NULL 
> r 
> 
> best 
> 
> 
> 
> Da: "Massimo Bressan"  
> A: "r-help"  
> Inviato: Mercoledì, 6 giugno 2018 10:13:10 
> Oggetto: aggregate and list elements of variables in data.frame 
> 
> #given the following reproducible and simplified example 
> 
> t<-data.frame(id=1:10,A=c(123,345,123,678,345,123,789,345,123,789)) 
> t 
> 
> #I need to get the following result 
> 
> r<-data.frame(unique_A=c(123, 345, 678, 
> 789),list_id=c('1,3,6,9','2,5,8','4','7,10')) 
> r 
> 
> # i.e. aggregate over the variable "A" and list all elements of the variable 
> "id" satisfying the criteria of having the same corrisponding value of "A" 
> #any help for that? 
> 
> #so far I've just managed to "aggregate" and "count", like: 
> 
> library(sqldf) 
> sqldf('select count(*) as count_id, A as unique_A from t group by A') 
> 
> library(dplyr) 
> t%>%group_by(unique_A=A) %>% summarise(count_id = n()) 
> 
> # thank you 
> 
> 
> -- 
> 
>  
> Massimo Bressan 
> 
> ARPAV 
> Agenzia Regionale per la Prevenzione e 
> Protezione Ambientale del Veneto 
> 
> Dipartimento Provinciale di Treviso 
> Via Santa Barbara, 5/a 
> 31100 Treviso, Italy 
> 
> tel: +39 0422 558545 
> fax: +39 0422 558516 
> e-mail: massimo.bres...@arpa.veneto.it 
>  
> 
> 
> -- 
> 
>  
> Massimo Bressan 
> 
> ARPAV 
> Agenzia Regionale per la Prevenzione e 
> Protezione Ambientale del Veneto 
> 
> Dipartimento Provinciale di Treviso 
> Via Santa Barbara, 5/a 
> 31100 Treviso, Italy 
> 
> tel: +39 0422 558545 
> fax: +39 0422 558516 
> e-mail: massimo.bres...@arpa.veneto.it 
>  
> 
>   [[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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] Generate random Bernoulli draws

2018-07-06 Thread Ben Tupper
Hi,

I haven't any idea about what you ask, but I do know that Rseek.org 
<http://rseek.org/> is a gold mine!  Check out...

https://rseek.org/?q=Bernoulli+random+variable 
<https://rseek.org/?q=Bernoulli+random+variable>

Cheers,
Ben

> On Jul 6, 2018, at 1:35 AM, Marino David  wrote:
> 
> Dear Bert,
> 
> I know it is a simple question. But for me, at current, I fail to implement
> it. So, I ask for help here.
> 
> It is not homework.
> 
> Best,
> 
> David
> 
> 2018-07-06 13:32 GMT+08:00 Bert Gunter :
> 
>> Is this homework?
>> 
>> (There is an informal no-homework policy on this list).
>> 
>> Cheers,
>> Bert
>> 
>> 
>> 
>> Bert Gunter
>> 
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> 
>> On Thu, Jul 5, 2018 at 10:23 PM, Marino David 
>> wrote:
>> 
>>> Dear All,
>>> 
>>> I would like to generate N random Bernoulli draws given a probability
>>> function F(x)=1-exp(-2.5*x) in which x follows  uniform distribution, say
>>> x~U(0,2).
>>> 
>>> Can some one leave me some code lines for implementing this?
>>> 
>>> Thanks in advance.
>>> 
>>> David
>>> 
>>>[[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/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>> 
>> 
> 
>   [[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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] inconsistency in display of character vector....

2018-07-08 Thread Ben Tupper
Hi,

You will be hard pressed to get helpful answers as you have not provided any 
way for list readers to replicate your data and code.  Check out this 
https://rseek.org/?q=reproducible+example

On the other hand, ...

(1)  I have a hunch that one place you are getting tripped up by your effort to 
treat IDT as a regular data.frame.  In fact, read_excel(), I'm guessing from 
the readxl package, returns a tibble.  When you subset a tibble like you have 
with...

leq <- IDT[,1]

... you get a 1-column tibble...

> leq
# A tibble: 208 x 1
   SymbolSeries
  
 1 ACCEQ   
 2 ADANIENTEQ  
 3 ADANIPORTSEQ
 4 ADANIPOWEREQ
 5 AJANTPHARMEQ
 6 ALBKEQ  
 7 AMARAJABATEQ
 8 AMBUJACEMEQ 
 9 ANDHRABANKEQ
10 APOLLOHOSPEQ
# ... with 198 more rows

So, that may be part of the issue (but I'm not really sure if it causes the 
problem you identify).

(2) Also another possible tripping point, when you prepend 'NSE/' to whatever 
lneq is supposed to be, you are using paste() without specifying the sep 
argument which defaults to a single space " ".  If you want it to be something 
else then you have to explicitly set the value of sep.

(3) Finally, you will have much better luck getting help if you configure your 
email client to send plain text to this list.  Fancily formatted text is made 
un-fancy by the list-server software - which will mess up your posted code.  
That's why you keep getting ...

[[alternative HTML version deleted]]

... at the tail end of your emails.


Good luck!
Ben

> On Jul 8, 2018, at 8:37 AM, akshay kulkarni  wrote:
> 
> dear members,
> The mail is not showing the spaces between [192] 
> "NSE/YESBANK" and  [193] "NSE/ZEEL" ...Actually there is a lot of empty 
> spaces between the two.!!
> 
> 
> From: R-help  on behalf of akshay kulkarni 
> 
> Sent: Sunday, July 8, 2018 5:58 PM
> To: R help Mailing  list
> Subject: [R] inconsistency in display of character vector
> 
> dear members,
>I have the following code to update the list of 
> stocks:
> 
> function (snlcqn)
> {
>  lneq <- c()
>  URL <- "https://canmoney.in/Intraday%20scrip.xls";
>  file.string <- tempfile()
> 
>  download.file(URL,file.string)
> 
>  IDT <- read_excel(file.string)
> 
>  leq <- IDT[,1]
> 
>  for(i in 1:length(leq)){
>  lneq[i] <- substr(leq[i],1,(nchar(leq[i])-2))}
> 
>  for(j in 1:length(lneq)){
>  snlcqna[j] <- paste("NSE/",lneq[j])}
> 
>  if(identical(snlcqn,snlcqna) == "FALSE"){
>  return(snlcqna) }
> 
>  else{
>  return(snlcqn)  }
> 
> }
> snlcqn is the list of present stocks and snlcqna is the list of updated 
> stocks.
> The problem is the return object, instead of getting displayed in contiguous 
> list, is getting displayed with lots of spaces...( I am using R on a LINUX 
> RHEL AWS instance):
> 
> [192] "NSE/YESBANK"
> [193] "NSE/ZEEL"
> 
> Why is this happening? How can I get the return object as a contiguous list?
> Very many thanks for your time and effort...
> yours sincerely,
> AKSHAY M KULKARNI
> 
>[[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.
> 
>   [[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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] taking a small piece of large tiff

2017-04-05 Thread Ben Tupper
Hi,

You'll get a lot of help if you take this question to the R-sig-geo list 

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

In the meantime, you might want to try reading this using raster::raster() and 
then cropping to your desired region. Here's a discussion that may help you...

https://stat.ethz.ch/pipermail/r-sig-geo/2010-July/008838.html

You will find many other useful bits using Rseek.org - try 
http://rseek.org/?q=subset+large+geotif

Cheers,
Ben

> On Apr 5, 2017, at 3:23 AM, Louisa Reynolds via R-help  
> wrote:
> 
> Ok. I have a tiff of size over 2GB. It covers a sixth of the Earth's surface 
> and I'm trying to cut a UK piece out of it. The tiff I start with seems to be 
> too large for R to handle. 
> 
> 
> Sent from my iPhone
> 
>> On 4 Apr 2017, at 18:37, jim holtman  wrote:
>> 
>> How big is 'large'?
>> 
>> Jim Holtman
>> Data Munger Guru
>> 
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>> 
>> 
>> On Tue, Apr 4, 2017 at 7:47 AM, Louisa Reynolds via R-help
>>  wrote:
>>> Dear Forum
>>> I am trying to cut out a small section of a very large 2-dimensional 
>>> grayscale image as a tiff in R, but it is having difficulty handling such 
>>> large files.  I have looked at bigmemory and ff packages but it is unclear 
>>> how I can use these packages with tiffs. Can anyone please suggest 
>>> something? I have tried tiff and rtiff libraries.
>>> Thanks in advance.
>>>   [[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.
> 
> ______
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] as.POSIXct character string is not in a standard unambiguous format

2017-04-05 Thread Ben Tupper
Hi,

I can't answer the question about R 3.3.3, but I don't see anything in the 
update notes. 

http://mirror.its.dal.ca/cran/doc/manuals/r-release/NEWS.html

In the meantime, would it skirt your issue if you explicitly stated the format?

x <- as.POSIXct("2002-02-02 02:02", format = "%Y-%m-%d %H:%M")

Ben



> On Apr 5, 2017, at 11:21 AM, Sebastien Moretti  
> wrote:
> 
> Hi
> 
> I have lots of issues when I try to install R 3.3.3 during the "make check" 
> step.
> 
> Every time a call to as.POSIXct is done in test scripts, I got the same error 
> message:
> e.g. x <- as.POSIXct("2002-02-02 02:02")
> Error in as.POSIXlt.character(x, tz, ...) :
>  character string is not in a standard unambiguous format
> 
> 
> It looks to be linked to localtime but when I compiled R 3.3.2  6 months ago, 
> the same test scripts were there and succeeded.
> 
> 
> Is there an environmental variable to use to change the as.POSIXct behavior?
> 
> Regards
> 
> --
> Sébastien
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] readr to generate tibble from a character matrix

2017-04-06 Thread Ben Tupper
Hello,

I have a workflow yields a character matrix that I convert to a tibble. Here is 
a simple example.

library(tibble)
library(readr)

m <- matrix(c(letters[1:12], 1:4, (11:14 + 0.2)), ncol = 5)
colnames(m) <- LETTERS[1:5]

x <- as_tibble(m)

# # A tibble: 4 × 5
#   A B C D E
#   
# 1 a e i 1  11.2
# 2 b f j 2  12.2
# 3 c g k 3  13.2
# 4 d h l 4  14.2

The workflow output columns can be a mix of a known set column outputs.  Some 
of the columns really should be converted to non-character types before I 
proceed.  Right now I explictly set the column classes with something like 
this...

mode(x[['D']]) <- 'integer'
mode(x[['E']]) <- 'numeric'

# # A tibble: 4 × 5
#   A B C D E
#   
# 1 a e i 1  11.2
# 2 b f j 2  12.2
# 3 c g k 3  13.2
# 4 d h l 4  14.2


I wonder if there is a way to use the read_* functions in the readr package to 
read the character matrix into a tibble directly which would leverage readr's 
excellent column class guessing. I can see in the vignette ( 
https://cran.r-project.org/web/packages/readr/vignettes/readr.html ) that I'm 
not too far off in thinking this could be done (step 1 tantalizingly says 'The 
flat file is parsed into a rectangular matrix of strings.')  

I know that I could either write the matrix to a file or paste it all into a 
character vector and then use read_* functions, but I confess I am looking for 
a straighter path by simply passing the matrix to a function like 
readr::read_matrix() or the like.

Thanks!
Ben

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] readr to generate tibble from a character matrix

2017-04-06 Thread Ben Tupper
Hi,

Thanks for this solution!  Very slick! 

I see what you mean about the two calls to as_tibble(). I suppose I could do 
the following, but I doubt it is a gain...

mm <- lapply(colnames(m), function(nm, m) type.convert(m[,nm], as.is = TRUE), 
m=m)
names(mm) <- colnames(m)
as_tibble(mm)

# # A tibble: 4 × 5
#   A B C D E
#   
# 1 a e i 1  11.2
# 2 b f j 2  12.2
# 3 c g k 3  13.2
# 4 d h l 4  14.2

I'll benchmark these with writing to a temporary file and pasting together a 
string.

Cheers and thanks,
Ben

On Apr 6, 2017, at 11:15 AM, Ulrik Stervbo  wrote:
> 
> Hi Ben,
> 
> type.convert should do the trick:
> 
> m %>%
>   as_tibble() %>% 
>   lapply(type.convert) %>% 
>   as_tibble()
> 
> I am not too happy about to double 'as_tibble' but it get the job done.
> 
> HTH
> Ulrik
> 
> On Thu, 6 Apr 2017 at 16:41 Ben Tupper  <mailto:btup...@bigelow.org>> wrote:
> Hello,
> 
> I have a workflow yields a character matrix that I convert to a tibble. Here 
> is a simple example.
> 
> library(tibble)
> library(readr)
> 
> m <- matrix(c(letters[1:12], 1:4, (11:14 + 0.2)), ncol = 5)
> colnames(m) <- LETTERS[1:5]
> 
> x <- as_tibble(m)
> 
> # # A tibble: 4 × 5
> #   A B C D E
> #   
> # 1 a e i 1  11.2
> # 2 b f j 2  12.2
> # 3 c g k 3  13.2
> # 4 d h l 4  14.2
> 
> The workflow output columns can be a mix of a known set column outputs.  Some 
> of the columns really should be converted to non-character types before I 
> proceed.  Right now I explictly set the column classes with something like 
> this...
> 
> mode(x[['D']]) <- 'integer'
> mode(x[['E']]) <- 'numeric'
> 
> # # A tibble: 4 × 5
> #   A B C D E
> #   
> # 1 a e i 1  11.2
> # 2 b f j 2  12.2
> # 3 c g k 3  13.2
> # 4 d h l 4  14.2
> 
> 
> I wonder if there is a way to use the read_* functions in the readr package 
> to read the character matrix into a tibble directly which would leverage 
> readr's excellent column class guessing. I can see in the vignette ( 
> https://cran.r-project.org/web/packages/readr/vignettes/readr.html 
> <https://cran.r-project.org/web/packages/readr/vignettes/readr.html> ) that 
> I'm not too far off in thinking this could be done (step 1 tantalizingly says 
> 'The flat file is parsed into a rectangular matrix of strings.')
> 
> I know that I could either write the matrix to a file or paste it all into a 
> character vector and then use read_* functions, but I confess I am looking 
> for a straighter path by simply passing the matrix to a function like 
> readr::read_matrix() or the like.
> 
> Thanks!
> Ben
> 
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org <http://www.bigelow.org/>
> 
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org




[[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] readr to generate tibble from a character matrix

2017-04-07 Thread Ben Tupper
Thanks!

I made up a little test for converting from character matrix to tibble: dumping 
to file and reading back, pasting up a big string, using pipes, using 
as.data.frame and using a pipeless version.  By far and away it is worth using 
Ulrik's or your solution compared to dumping the matrix to a file and then 
reading back OR pasting the matrix into one honking big string.

There is a difference in how the various methods interpret date-time inputs, 
but otherwise the results are all identical.

Cheers,
Ben

 START
library(nycflights13)
library(tibble)
library(magrittr)
library(readr)
library(microbenchmark)


m <- as.matrix(flights)

via_file <- function(m){
filename = tempfile(fileext = '.csv')
write.csv(m, file = filename, row.names = FALSE, quote = FALSE)
readr::read_csv(filename)
}

via_paste <- function(m){
s <- paste(
c(paste(colnames(m), collapse = ","), apply(m, 1, paste, collapse = 
",")), 
collapse = "\n")
readr::read_csv(s)
}

via_pipes <- function(m){
m %>%
tibble::as_tibble() %>% 
lapply(type.convert, as.is = TRUE) %>% 
tibble::as_tibble()
}

via_dataframe <- function(m){
mm <- lapply(data.frame(m, stringsAsFactors=FALSE), type.convert, 
as.is=TRUE)
tibble::as_tibble(mm)
}

via_pipeless <- function(m){
tibble::as_tibble(lapply(tibble::as_tibble(m), type.convert, as.is=TRUE))
}

X <- list(
file=via_file(m),
paste=via_paste(m),
pipes=via_pipes(m),
dataframe=via_dataframe(m),
pipeless=via_pipeless(m))

sapply(names(X), function(n) all.equal(X[[n]], X[[1]]))

# $file
# [1] TRUE

# $paste
# [1] TRUE

# $pipes
# [1] "Incompatible type for column time_hour1: x character, y POSIXct" 
"Incompatible type for column time_hour2: x character, y POSIXt" 

# $dataframe
# [1] "Incompatible type for column time_hour1: x character, y POSIXct" 
"Incompatible type for column time_hour2: x character, y POSIXt" 

# $pipeless
# [1] "Incompatible type for column time_hour1: x character, y POSIXct" 
"Incompatible type for column time_hour2: x character, y POSIXt" 

microbenchmark(
via_file(m),
via_paste(m),
via_pipes(m),
via_dataframe(m),
via_pipeless(m),
times = 5
)

#Unit: milliseconds
# expr   minlq  meanmedianuq   max 
neval
#  via_file(m) 2362.7778 2396.2277 2415.9207 2413.0772 2439.5752 2467.9457  
   5
# via_paste(m) 5287.8176 5305.6228 5622.1432 5666.0165 5919.3568 5931.9023  
   5
# via_pipes(m)  461.4782  464.5656  506.4157  509.5532  542.1091  554.3726  
   5
# via_dataframe(m)  507.4674  514.2550  553.1791  515.9132  518.0807  710.1794  
   5
#  via_pipeless(m)  448.9529  470.1074  499.4392  470.6874  500.6027  606.8459  
   5

sessionInfo()
# R version 3.3.1 (2016-06-21)
# Platform: x86_64-apple-darwin13.4.0 (64-bit)
# Running under: OS X 10.11.6 (El Capitan)

# 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] microbenchmark_1.4-2.1 readr_1.0.0magrittr_1.5   
tibble_1.2 nycflights13_0.2.0

# loaded via a namespace (and not attached):
 # [1] colorspace_1.2-6 scales_0.4.1 plyr_1.8.4   assertthat_0.1   
tools_3.3.1  gtable_0.2.0 Rcpp_0.12.9  ggplot2_2.1.0grid_3.3.1  
 munsell_0.4.3  


### END
 



> On Apr 6, 2017, at 3:34 PM, David L Carlson  wrote:
> 
> Ulrik's solution gives you factors. To get them as characters, add as.is=TRUE:
> 
>> m %>%
> +as_tibble() %>% 
> +lapply(type.convert, as.is=TRUE) %>% 
> +as_tibble()
> # A tibble: 4 × 5
>  A B C D E
>  
> 1 a e i 1  11.2
> 2 b f j 2  12.2
> 3 c g k 3  13.2
> 4 d h l 4  14.2
> 
> Other possibilities:
> 
>> mm <- lapply(data.frame(m, stringsAsFactors=FALSE), type.convert, as.is=TRUE)
>> as_tibble(mm)
> # Your solution simplified by converting to a data.frame
> 
>> as_tibble(lapply(as_tibble(m), type.convert, as.is=TRUE))
> # Ulrik's solution but without the pipes. Shows why you need 2 as_tibbles()
> 
> -
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ben Tupper
> Sent: Thursday, April 6, 2017 11:42 AM
> To: Ulrik Stervbo 
> Cc: R-help Mailing List 
> Subject: Re: [R] readr to generate tibble from a character matrix
> 
> Hi,
> 
> Thanks for this solution

Re: [R] Maximum length for a -e argument to Rscript?

2017-04-21 Thread Ben Tupper
e script to a file and then execute 
> that file with Rscript, since that seems to work; but I was really hoping to 
> avoid that extra complication and overhead.  Is there a better way?
> 
>  Thanks for any help you can provide!  :->
> 
> Cheers,
> -B.
> 
> Benjamin C. Haller
> Messer Lab
> Cornell University
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Reading XML attriutes in R

2017-04-27 Thread Ben Tupper
Hi,

There might be an easy solution out there already, but I suspect that you will 
need to parse the XML yourself.  The example below uses package xml2 not XML 
but you could do this with either.  The example simply shows how to get values 
out of the XML hierarchy.  Once you have the attributes you want in hand you 
can assemble the elements into a data frame (or a tibble from package tibble.)
 
By the way, I had to prepend your example with ''

Cheers,
Ben

### START

library(tidyverse)
library(xml2)

txt <- "GB"

x <- read_xml(txt)

windspeed <- x %>% 
xml_find_first("wind/speed") %>% 
xml_attrs()

winddir <- x %>% 
xml_find_first("wind/direction") %>% 
xml_attrs()

windspeed
#  valuename 
#  "4.6" "Gentle Breeze" 

winddir
#  value   code   name 
#  "90""E" "East" 

### END



> On Apr 27, 2017, at 6:08 AM, Archit Soni  wrote:
> 
> Hi All,
> 
> I have a XML file like :
> 
> 
> 
> GB
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> I want to create a data frame out of this XML but
> obviously xmlToDataFrame() is not working.
> 
> It has dynamic attributes like for node precipitation , it could have
> attributes like value and mode both if there is ppt in some city.
> 
> My basic issue now id to read XML attributes of different nodes and convert
> it into a data frame, I have scraped many forums but could not find any
> help in this.
> 
> For starters, please suggest a solution to parse the value of city node and
> corresponding id, name, lat, long etc.
> 
> I know I am asking a lot, thanks for reading and cheers! :)
> 
> -- 
> Regards
> Archit
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Reading XML attriutes in R

2017-04-28 Thread Ben Tupper
Hi again,

It would be super easy if xml2::xml_attrs() accepted a list of attribute names 
and defaults values like xml2::xml_attr() does, but it doesn't.  Once you have 
a list of character vectors like that returned by your ...

ppt <- x %>% xml_find_all("precipitation") %>% xml_attrs()

..then you need only try to extract the fields you want.  Perhaps something 
like the following untested steps...

precip <-  tibble::as_tibble(do.call(rbind, lapply(ppt, '[', c('unit', 'value', 
'type')) ))

colnames(precip) <- c('unit', 'value', 'type')

Bon chance!
Ben

P.S.  Don't forget to change your email client to send plain text messages to 
this list.  Typically rich text and html emails get turned into hash by the 
R-help list services.

> On Apr 28, 2017, at 4:25 AM, Archit Soni  wrote:
> 
> Thanks Ben, got it working, just want one more help on this,
> 
> If i have a node like:  and in some other city it 
> came like:  
> 
> How can i make my code to handle this dynamically? I am sorry to ask such 
> novice questions but it would be extremely helpful if you could help me with 
> this.
> 
> So, i would want my resulting data set from this code:- ppt <- (x %>% 
> xml_find_all("precipitation") %>% xml_attrs())
>  if mode is no, then the three columns should come and values should be NA 
> and if values are populated then as is.
> 
> Unit Value  Type
> NANA NA
> 3h0.0925 rain
> 
> Thanks again and in advance ! 
> 
> Archit
> 
> On Thu, Apr 27, 2017 at 6:27 PM, Ben Tupper  wrote:
> Hi,
> 
> There might be an easy solution out there already, but I suspect that you 
> will need to parse the XML yourself.  The example below uses package xml2 not 
> XML but you could do this with either.  The example simply shows how to get 
> values out of the XML hierarchy.  Once you have the attributes you want in 
> hand you can assemble the elements into a data frame (or a tibble from 
> package tibble.)
> 
> By the way, I had to prepend your example with ''
> 
> Cheers,
> Ben
> 
> ### START
> 
> library(tidyverse)
> library(xml2)
> 
> txt <- " lat=\"51.51\"/>GB set=\"2017-01-30T16:47:56\"/> min=\"278.15\" max=\"281.15\" unit=\"kelvin\"/> unit=\"%\"/> name=\"Gentle Breeze\"/> name=\"East\"/> clouds\"/> number=\"701\" value=\"mist\" icon=\"50d\"/> value=\"2017-01-30T15:50:00\"/>"
> 
> x <- read_xml(txt)
> 
> windspeed <- x %>%
> xml_find_first("wind/speed") %>%
> xml_attrs()
> 
> winddir <- x %>%
> xml_find_first("wind/direction") %>%
> xml_attrs()
> 
> windspeed
> #  valuename
> #  "4.6" "Gentle Breeze"
> 
> winddir
> #  value   code   name
> #  "90""E" "East"
> 
> ### END
> 
> 
> 
> > On Apr 27, 2017, at 6:08 AM, Archit Soni  wrote:
> >
> > Hi All,
> >
> > I have a XML file like :
> >
> > 
> > 
> > GB
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >
> > I want to create a data frame out of this XML but
> > obviously xmlToDataFrame() is not working.
> >
> > It has dynamic attributes like for node precipitation , it could have
> > attributes like value and mode both if there is ppt in some city.
> >
> > My basic issue now id to read XML attributes of different nodes and convert
> > it into a data frame, I have scraped many forums but could not find any
> > help in this.
> >
> > For starters, please suggest a solution to parse the value of city node and
> > corresponding id, name, lat, long etc.
> >
> > I know I am asking a lot, thanks for reading and cheers! :)
> >
> > --
> > Regards
> > Archit
> >
> >   [[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.
> 
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
> 
> 
> 
> 
> 
> 
> -- 
> Regards
> Archit

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Copy and Rename Folder in same directory

2017-05-08 Thread Ben Tupper
Hi,

Checkout all of the functions for file/directory management under ?files  (note 
the plural).

Cheers,
Ben


> On May 8, 2017, at 6:30 AM, Archit Soni  wrote:
> 
> Hello,
> 
> Forgive me to ask this kind of naive question.
> 
> But it would be of immense help if you could help me suggesting a way to
> copy a folder in the same directory and paste it in the same directory with
> different name.
> 
> Ex:
> 
> C:/Folder A -- C:/Folder A_B
> 
> Contents should be copied as is.
> 
> Thanks for reading and thanks in advance!
> 
> Archit
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Copy and Rename Folder in same directory

2017-05-08 Thread Ben Tupper
My eye gets drawn immediately to file.rename() - did you give that a shake?



> On May 8, 2017, at 6:59 AM, Archit Soni  wrote:
> 
> Hey Ben,
> 
> I tried this,
> 
> # identify the folders
> current.folder <- "C:/Where my files currently live"
> new.folder <- "H:/Where I want my files to be copied to"
>  
> # find the files that you want
> list.of.files <- list.files(current.folder, "SDM\\.tif$",full.names=T)
>  
> # copy the files to the new folder
> file.copy(list.of.files, new.folder)
> 
> But i am still getting FALSE and files are not getting copied from the 
> folder. However,if I give a single file name it copies that file to new 
> folder.
> 
> Any thoughts ?
> 
> On Mon, May 8, 2017 at 4:07 PM, Archit Soni  <mailto:soni.archit1...@gmail.com>> wrote:
> Thanks Ben. :)
> 
> On May 8, 2017 16:06, "Ben Tupper"  <mailto:btup...@bigelow.org>> wrote:
> Hi,
> 
> Checkout all of the functions for file/directory management under ?files  
> (note the plural).
> 
> Cheers,
> Ben
> 
> 
> > On May 8, 2017, at 6:30 AM, Archit Soni  > <mailto:soni.archit1...@gmail.com>> wrote:
> >
> > Hello,
> >
> > Forgive me to ask this kind of naive question.
> >
> > But it would be of immense help if you could help me suggesting a way to
> > copy a folder in the same directory and paste it in the same directory with
> > different name.
> >
> > Ex:
> >
> > C:/Folder A -- C:/Folder A_B
> >
> > Contents should be copied as is.
> >
> > Thanks for reading and thanks in advance!
> >
> > Archit
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> > UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help 
> > <https://stat.ethz.ch/mailman/listinfo/r-help>
> > PLEASE do read the posting guide 
> > http://www.R-project.org/posting-guide.html 
> > <http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> 
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org <http://www.bigelow.org/>
> 
> 
> 
> 
> 
> 
> -- 
> Regards
> Archit

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org




[[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] Nested for loop

2017-08-06 Thread Ben Tupper
umerator of schnabel formula
> schnabel.comp$numerator <- with(schnabel.comp,
>n.sampled * cum.sampled)
> 
> ## denominator of schnable formula is n.prev.sampled
> 
> ## pop.estimate -- after each sample (starting with 2nd -- need at least
> two samples)
> schnabel.comp$pop.estimate <- NA
> 
> for(i in 1:length(schnabel.comp$pop.estimate)) {
>  schnabel.comp$pop.estimate[i] <- sum(schnabel.comp$numerator[1:i]) /
> sum(schnabel.comp$n.prev.sampled[1:i])
> }
> 
> 
> ## Plot population estimate after each sample
> if (!require("ggplot2")) {install.packages("ggplot2"); require("ggplot2")}
> if (!require("scales")) {install.packages("scales"); require("scales")}
> 
> 
> small.sample.dat <- schnabel.comp
> 
> small.sample <- ggplot(data = small.sample.dat,
>   mapping = aes(x = sample, y = pop.estimate)) +
>  geom_point(size = 2) +
>  geom_line() +
>  geom_hline(yintercept = N, col = "red", lwd = 1) +
>  coord_cartesian(xlim = c(0:100), ylim = c(300:500)) +
>  scale_x_continuous(breaks = pretty_breaks(11)) +
>  scale_y_continuous(breaks = pretty_breaks(11)) +
>  labs(x = "\nSample", y = "Population estimate\n",
>   title = "Sample sizes are between 5% and 15%\nof the population") +
>  theme_bw(base_size = 12) +
>  theme(aspect.ratio = 1)
> 
> small.sample
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/

__
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] Nested for loop

2017-08-07 Thread Ben Tupper
Hmmm.

If I understand you correctly, your question has to do with adding lines to 
your graph?  If so, my ggplot2 skills are sort of floppy, but you could append 
your sampling results to your data frame (one for each sample set) and then 
simply add layers.  Sort of like this.

N <- 10
x <- 1:N
df <- data.frame(
x = x,
y1 = sample(x, N, replace = TRUE),
y2 = sample(x, N, replace = TRUE),
y3 = sample(x, N, replace = TRUE))

ggplot(df, mapping = aes(x = x, y = y1)) +
geom_point(aes(y = y1), col = 'orange') + geom_line(aes(y = y1),col = 
'orange') +
geom_point(aes(y = y2), col = 'blue') + geom_line(aes(y = y2), col = 
'blue') +
geom_point(aes(y = y3), col = 'gray') + geom_line(aes(y = y3), col = 
'gray')

If plotting is not the issue then I don't understand what your question is.

Cheers,
Ben


> On Aug 6, 2017, at 3:44 PM, Kirsten Morehouse  wrote:
> 
> Hi Ben,
> 
> That's exactly right! Except for each set it's the sample population that is 
> 400, 800 or 300. I want to take 3 samples, each of 100, where only the 
> population differs. I can do this separately, but I'm having trouble putting 
> them all on the same graph. 
> 
> I'd like to have sample on the x axis (1-300) and estimate on the y axis. I 
> want to show how population affects the estimates. 
> 
> Does this make more sense?
> 
> Thanks for your time!
> 
> Kirsten 
> On Sun, Aug 6, 2017 at 3:21 PM Ben Tupper  <mailto:btup...@bigelow.org>> wrote:
> Hi Kirsten,
> 
> 
> 
> I can run your example code but I can't quite follow your division of 
> sampling.  Can you restate the the task?  Below is what I think you are 
> asking for, but I have the feeling I may be off the mark.
> 
> 
> 
> 
> 
> Set A: 400 samples, draw 100 in range of 5 to 15
> 
> 
> 
> Set B: 800 samples, draw 100 in range of 5 to 15
> 
> 
> 
> Set C: 300 samples, draw 100 in range of 5 to 15
> 
> 
> 
> Ben
> 
> 
> 
> > On Aug 5, 2017, at 9:21 AM, Kirsten Morehouse  > <mailto:kmore...@swarthmore.edu>> wrote:
> 
> >
> 
> > Hi! Thanks for taking the time to read this.
> 
> >
> 
> > The code below creates a graph that takes 100 samples that are between 5%
> 
> > and 15% of the population (400).
> 
> >
> 
> > What I'd like to do, however, is add two other sections to the graph. It
> 
> > would look something like this:
> 
> >
> 
> > from 1-100 samples take 100 samples that are between 5% and 15% of the
> 
> > population (400). From 101-200 take 100 samples that are between 5% and 15%
> 
> > of the population (800). From 201-300 take 100 samples that are between 5%
> 
> > and 15% of the population (300).
> 
> >
> 
> > I assume this would require a nested for loop. Does anyone have advice as
> 
> > to how to do this?
> 
> >
> 
> > Thanks for your time. Kirsten
> 
> >
> 
> > ## Mark-Recapture
> 
> > ## Estimate popoulation from repeated sampling
> 
> >
> 
> > ## Population size
> 
> > N <- 400
> 
> > N
> 
> >
> 
> > ## Vector labeling each item in the population
> 
> > pop <- c(1:N)
> 
> > pop
> 
> >
> 
> > ## Lower and upper bounds of sample size
> 
> > lower.bound <- round(x = .05 * N, digits = 0)
> 
> > lower.bound ## Smallest possible sample size
> 
> >
> 
> > upper.bound <- round(x = .15 * N, digits = 0)
> 
> > upper.bound ## Largest possible sample size
> 
> >
> 
> > ## Length of sample size interval
> 
> > length.ss.interval <- length(c(lower.bound:upper.bound))
> 
> > length.ss.interval ## total possible sample sizes, ranging form lower.bound
> 
> > to upper.bound
> 
> >
> 
> > ## Determine a sample size randomly (not a global variable...simply for
> 
> > test purposes)
> 
> > ## Between lower and upper bounds set previously
> 
> > ## Give equal weight to each possible sample size in this interval
> 
> > sample(x = c(lower.bound:upper.bound),
> 
> >   size = 1,
> 
> >   prob = c(rep(1/length.ss.interval, length.ss.interval)))
> 
> >
> 
> > ## Specify number of samples to take
> 
> > n.samples <- 100
> 
> >
> 
> > ## Initiate empty matrix
> 
> > ## 1st column is population (item 1 thorugh item 400)
> 
> > ## 2nd through nth column are all rounds of sampling
> 
> > dat <- matrix(data = NA,
> 
> >  nro

Re: [R] really dumb question with building/creating a new package.

2017-08-17 Thread Ben Tupper
Hi,

Below is the help from a terminal session.  Note that you provide the directory 
name (where your package files are located).  I think in your case that would 
be '/Users/emhodgess/RcmdrPlugin.gstats'

ben@gale ~ $ R CMD build --help
Usage: R CMD build [options] pkgdirs

Build R packages from package sources in the directories specified by
‘pkgdirs’

Options:
  -h, --helpprint short help message and exit
  -v, --version print version info and exit

  --force   force removal of INDEX file
  --keep-empty-dirs do not remove empty dirs
  --no-build-vignettes  do not (re)build package vignettes
  --no-manual   do not build the PDF manual even if \Sexprs are present
  --resave-data=re-save data files as compactly as possible:
"no", "best", "gzip" (default)
  --resave-data same as --resave-data=best
  --no-resave-data  same as --resave-data=no
  --compact-vignettes=  try to compact PDF files under inst/doc:
"no" (default), "qpdf", "gs", "gs+qpdf", "both"
  --compact-vignettes   same as --compact-vignettes=qpdf
  --md5 add MD5 sums
### end


You want to explore Hadley Wickham's devtools package which makes package 
development a breeze.  More here... 

https://cran.r-project.org/web/packages/devtools/index.html

Cheers,
Ben


> On Aug 17, 2017, at 5:46 PM, Erin Hodgess  wrote:
> 
> Hello.
> 
> I am creating a new RcmdrPlugin package.  However, I am getting some very
> odd messages.
> 
> R CMD build RcmdrPlugin.gstats_1.0.0
> 
> ERROR
> 
> cannot change to directory ‘RcmdrPlugin.gstats_1.0.0’
> 
> es-macbook-air:~ emhodgess$ R CMD check RcmdrPlugin.gstats_1.0.0
> 
> Warning: ‘RcmdrPlugin.gstats_1.0.0’ is neither a file nor directory,
> skipping
> 
> 
> es-macbook-air:~ emhodgess$ cd RcmdrPlugin.gstats/
> 
> es-macbook-air:RcmdrPlugin.gstats emhodgess$ pwd
> 
> /Users/emhodgess/RcmdrPlugin.gstats
> 
> es-macbook-air:RcmdrPlugin.gstats emhodgess$
> 
> 
> I can neither run R CMD build nor check.  Any help truly appreciated.  It's
> been ages since I've put together a package.
> 
> Thanks,
> Erin
> 
> 
> -- 
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/

__
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] rgdal error when trying to import raster

2017-09-06 Thread Ben Tupper
Hi,

The message "there is no package called 'rgdal'" means that you don't have 
rgdal installed.

https://cran.r-project.org/web/packages/rgdal/index.html

Also, you will get very good patial-centric help if you subscribed to r-sig-geo 
here

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Cheers,
Ben



> On Sep 6, 2017, at 2:52 PM, john polo  wrote:
> 
> Dear useRs,
> 
> I am trying to import a raster with the line:
> 
> nlcd <- raster("/home/jpolo/NRI/nlcd_nri5000.tif")
> 
> And I keep getting an error like this:
> 
> "Warning message:
> In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return 
> = TRUE,  :
>   there is no package called 'rgdal'
> Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  :
>   Cannot create RasterLayer object from this file; perhaps you need to 
> install rgdal first
> Calls: raster -> raster -> .local -> .rasterObjectFromFile
> Execution halted"
> 
> This is the session info:
> 
> "R version 3.2.5 (2016-04-14)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: CentOS release 6.3 (Final)
> 
> locale:
> [1] C
> 
> attached base packages:
> [1] methods   stats graphics  grDevices utils datasets  base
> 
> other attached packages:
> [1] raster_2.5-8 sp_1.2-4 rgeos_0.3-23
> 
> loaded via a namespace (and not attached):
> [1] Rcpp_0.12.10grid_3.2.5  lattice_0.20-35 "
> 
> I know the R version is old, but this is a system that I can not update, I 
> have no control over it. Because the version of R is old, the admin told me 
> that they cannot install rgdal. I am not using library(rgdal) and none of the 
> other libraries that are loaded require rgdal. The package raster does 
> suggest it though. Is that causing the problem? Is there a way to avoid this? 
> Any help is welcome.
> 
> best,
> 
> John
> 
> 
> -- 
> "Ask a man to be quiet,
> and he'll be silent for a moment.
> Feed a man to a red dragon
> and he'll be silent for a lifetime."
> -Anne Isabella Thackeray Ritchie
> 
> __________
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/

__
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] rgdal error when trying to import raster

2017-09-06 Thread Ben Tupper
Ah, I didn't read the entire message.  Sorry about that!


> On Sep 6, 2017, at 7:20 PM, Jeff Newmiller  wrote:
> 
> Indeed, Ben, but the question was something more like it is not a Dependency, 
> just Suggested, so why the error...
> 
> John:
> 
> If you read the Introduction to the 'raster' package vignette, it indicates 
> that some input formats are supported within the raster package and some rely 
> on other packages. Clearly the attempt to read a TIFF was an example of the 
> latter. Had you used a different input file format the issue of rgdal might 
> never have appeared... ergo, Suggests rather than Depends. 
> 
> Note that someone may feel pity for your plight, John, and give you a 
> convenient alternative way to import the data to raster (there are other 
> packages that read TIFF but you would probably have to roll the geolocation 
> yourself... an avenue for which help would be better pursued on R-sig-geo), 
> but the premise of your email (cannot upgrade) does put it squarely in the 
> off-topic category according to the Posting Guide. Fortunately R is 
> open-source so if you are diligent you can write/borrow R code as needed or 
> even recompile R and necessary packages entirely within your personal 
> development directories with no system installation to bother your sysadmin 
> about... but you might also just go find another computer to do your work on.
> -- 
> Sent from my phone. Please excuse my brevity.
> 
> On September 6, 2017 3:29:41 PM PDT, Ben Tupper  wrote:
>> Hi,
>> 
>> The message "there is no package called 'rgdal'" means that you don't
>> have rgdal installed.
>> 
>> https://cran.r-project.org/web/packages/rgdal/index.html
>> 
>> Also, you will get very good patial-centric help if you subscribed to
>> r-sig-geo here
>> 
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> 
>> Cheers,
>> Ben
>> 
>> 
>> 
>>> On Sep 6, 2017, at 2:52 PM, john polo  wrote:
>>> 
>>> Dear useRs,
>>> 
>>> I am trying to import a raster with the line:
>>> 
>>> nlcd <- raster("/home/jpolo/NRI/nlcd_nri5000.tif")
>>> 
>>> And I keep getting an error like this:
>>> 
>>> "Warning message:
>>> In library(package, lib.loc = lib.loc, character.only = TRUE,
>> logical.return = TRUE,  :
>>>  there is no package called 'rgdal'
>>> Error in .rasterObjectFromFile(x, band = band, objecttype =
>> "RasterLayer",  :
>>>  Cannot create RasterLayer object from this file; perhaps you need
>> to install rgdal first
>>> Calls: raster -> raster -> .local -> .rasterObjectFromFile
>>> Execution halted"
>>> 
>>> This is the session info:
>>> 
>>> "R version 3.2.5 (2016-04-14)
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>> Running under: CentOS release 6.3 (Final)
>>> 
>>> locale:
>>> [1] C
>>> 
>>> attached base packages:
>>> [1] methods   stats graphics  grDevices utils datasets  base
>>> 
>>> other attached packages:
>>> [1] raster_2.5-8 sp_1.2-4 rgeos_0.3-23
>>> 
>>> loaded via a namespace (and not attached):
>>> [1] Rcpp_0.12.10grid_3.2.5  lattice_0.20-35 "
>>> 
>>> I know the R version is old, but this is a system that I can not
>> update, I have no control over it. Because the version of R is old, the
>> admin told me that they cannot install rgdal. I am not using
>> library(rgdal) and none of the other libraries that are loaded require
>> rgdal. The package raster does suggest it though. Is that causing the
>> problem? Is there a way to avoid this? Any help is welcome.
>>> 
>>> best,
>>> 
>>> John
>>> 
>>> 
>>> -- 
>>> "Ask a man to be quiet,
>>> and he'll be silent for a moment.
>>> Feed a man to a red dragon
>>> and he'll be silent for a lifetime."
>>> -Anne Isabella Thackeray Ritchie
>>> 
>>> __
>>> 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.
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 045

Re: [R] UUIDgenerate() withn a s4 class produces the same uuid at each instance

2016-06-08 Thread Ben Tupper
Hi,

I think your issue is that in the absence of an explicit 'initialize' method 
the value of id is assigned when you define the class prototype.  All 
subsequent new instances will use that very same prototype value defined when 
you first defined the class.  That's in the help for ?new, "The function new 
begins by copying the prototype object from the class definition."  Read on in 
the details section to learn more about 'initialize'.

To get a new id for each new object instance you can define an 'initialize' 
method.

setMethod("initialize",
  "C",
  function(.Object){
  .Object@id = UUIDgenerate(use.time = TRUE)
  .Object
  })

> new("C")
An object of class "C"
Slot "id":
[1] "f5e87504-2d83-11e6-9dcb-685b35bcefe9"

> new("C")
An object of class "C"
Slot "id":
[1] "f73cf010-2d83-11e6-9dcb-685b35bcefe9"

> new("C")
An object of class "C"
Slot "id":
[1] "f8321f22-2d83-11e6-9dcb-685b35bcefe9"

> new("C")
An object of class "C"
Slot "id":
[1] "f96e3c90-2d83-11e6-9dcb-685b35bcefe9"


There may be other ways to achieve the same outcome.   Caveat... I handy with 
Reference Classes (see ?setRefClass) but have only recently exploring S4 
classes.

Cheers,
Ben

> On Jun 8, 2016, at 8:24 AM, Servet Ahmet Çizmeli 
>  wrote:
> 
> 
> 
> Hello 
> 
> When I create a new instance of an S4 class in R, I would like the newly
> created object to have a unique id field. I try to achieve it through
> UUIDgenerate() from the uuid package. The problem is that I obtain the
> same UUID at every new object instance : 
> 
> library(uuid)
> setClass("C",
> representation=representation(
> id = "character"
> ),
> prototype = prototype(
> id = UUIDgenerate(use.time = TRUE))
> )
> 
> new("C")
> 
> An object of class "C" Slot "id": [1]
> "1e07d7c2-2d71-11e6-b5e1-e1f59d8ccf09" 
> 
> new("C")
> 
> An object of class "C" Slot "id": [1]
> "1e07d7c2-2d71-11e6-b5e1-e1f59d8ccf09" 
> 
> new("C")
> 
> An object of class "C" Slot "id": [1]
> "1e07d7c2-2d71-11e6-b5e1-e1f59d8ccf09" 
> 
> Calling UUIDgenerate() successively at the R command line produces
> different UUIDS each time. 
> 
> Where do I go wrong? 
> 
> Thanks 
> 
> Servet 
> 
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Report Gulf of Maine jellyfish sightings to jellyf...@bigelow.org or tweet them 
to #MaineJellies -- include date, time, and location, as well as any 
descriptive information such as size or type.  Learn more at 
https://www.bigelow.org/research/srs/nick-record/nick-record-laboratory/mainejellies/

__
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] documenting R reference class methods with roxygen2

2016-07-20 Thread Ben Tupper
Hi,

Yes, it takes a lot of searching for find out how to use roxygen with Ref 
Classes.  Thank goodness for Hadley Wickham's book ( http://r-pkgs.had.co.nz/ ).

For a Ref Class methods are actually documenting NULL, and you need to add the 
"@name Classname_Methodname" tag.  Otherwise, documentation is similar to that 
for functions.

#' Title
#'
#' Other stuff
#'
#' @name MyClass_fooey
#' @param foo_value numeric blah blah blah
#' @return numeric
#' @examples{
#'  \dontrun{
#'  blah blah blah
#'  }
#' }
NULL
MyClass$methods(
fooey = function(foo_value = 3){
cat("in the fooey method\n")
return(foo_value)
})

You could scout out some of the examples here ... 
https://github.com/BigelowLab/flowcamr 


Cheers,
Ben


> On Jul 20, 2016, at 4:26 AM, Witold E Wolski  wrote:
> 
> I would like to document function arguments in R reference classes and
> I do not know how.
> 
> I know that methods description can be provided by adding
> a string below the function declaration. But how to document the
> function arguments in similar fashion like the arguments of R
> functions (which can be documented with @param).
> 
> Thank you.
> 
> PS. Sorry if for some this question is off topic but I did not found a
> mailing list dedicated to roxygen2.
> 
> 
> 
> -- 
> Witold Eryk Wolski
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Report Gulf of Maine jellyfish sightings to jellyf...@bigelow.org or tweet them 
to #MaineJellies -- include date, time, and location, as well as any 
descriptive information such as size or type.  Learn more at 
https://www.bigelow.org/research/srs/nick-record/nick-record-laboratory/mainejellies/

__
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] splitting a vector of strings

2016-07-21 Thread Ben Tupper
Hi,

I'm not sure about the more generalized solution, but how about this for a 
start.


x <- c("a;b;c", "d;e", "foo;g;h;i")
x
#[1] "a;b;c" "d;e"   "foo;g;h;i"

sapply(strsplit(x, ";",fixed = TRUE), '[',1)
#[1] "a"   "d"   "foo"

If you want elegance then I suggest you take a look at the stringr package. 

https://cran.r-project.org/web/packages/stringr/index.html

Cheers,
Ben


> On Jul 21, 2016, at 7:54 AM, Eric Elguero  wrote:
> 
> Hi everybody,
> 
> I have a vector of character strings.
> Each string has the same pattern and I want
> to split them in pieces and get a vector made
> of the first pieces of each string.
> 
> The problem is that strsplit returns a list.
> 
> All I found is
> 
> uu<- matrix(unlist(strsplit(x,";")),ncol=3,byrow=T)[,1]
> 
> where x is the vector ";" is the delimiting character
> and I know that each string will be cut in 3 pieces.
> 
> That works for my problem but I would prefer a
> more elegant solution. Besides, it would not
> work if all the string didn't have the same
> number of pieces.
> 
> does someone have a better solution?
> 
> sorry if that topic was discussed recently.
> There is too much traffic on the r-help list,
> I cannot catch up.
> 
> -- 
> Eric Elguero
> 
> MIVEGEC. - UMR (CNRS/IRD/UM) 5290
> Maladies Infectieuses et Vecteurs, Génétique, Evolution et Contrôle
> Institut de Recherche pour le Développement (IRD)
> 911, Avenue Agropolis
> BP 64501
> 34394 Montpellier Cedex 5, France
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Report Gulf of Maine jellyfish sightings to jellyf...@bigelow.org or tweet them 
to #MaineJellies -- include date, time, and location, as well as any 
descriptive information such as size or type.  Learn more at 
https://www.bigelow.org/research/srs/nick-record/nick-record-laboratory/mainejellies/

__
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 add overall xlabel and ylabel?

2016-09-25 Thread Ben Tupper
Hi,

Here's a place to start...

https://www.r-bloggers.com/two-tips-adding-title-for-graph-with-multiple-plots-add-significance-asterix-onto-a-boxplot/

You might also want to checkout the text() function and the xpd argument to par.

Ben

> On Sep 25, 2016, at 7:51 AM, Matti Viljamaa  wrote:
> 
> I have created a 2x2 plot using par(mfrow = c(2, 2)).
> 
> I can add x- and ylabels to individual plots, but what I want is to add 
> overall xlabel and ylabel for the entire 2x2 plot.
> 
> How to do this?
> __
> 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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Efficient means to link two data frames

2016-09-29 Thread Ben Tupper
Hi,

I have a solution based upon findInterval() which depends upon the ordered 
nature of the 'Day' column.  I can't speak to whether or not it is efficient 
but it is handy.  I love the findInterval() function but have often wished it 
works with look up tables in descending order.  This function, find_interval(), 
is my first reasonable pass at working with descending order.

https://gist.github.com/btupper/5fc6cc4e7d86f39f9e4f

## start
source("find_interval.R")

x <- structure(list(Day = c(1L, 2L, 3L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
13L, 14L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
27L, 28L, 29L, 30L), Value = c(76, 116, 111, 103, 114, 99, 128, 
96, 81, 84, 81, 108, 109, 106, 125, 128, 92, 90, 83, 89, 76, 
89, 101, 93, 98, 77, 92)), .Names = c("Day", "Value"), row.names = c(NA, 
-27L), class = "data.frame")

TESTDAYS <- data.frame(TestDay = c(4, 11, 15))

x <- x[rev(1:nrow(x)),]

ix <- find_interval(TESTDAYS[,'TestDay'], x[,'Day'])

TESTDAYS[,'TestValue'] <- x[ix,'Value']

TESTDAYS
#   TestDay TestValue
# 1   4   103
# 2  1184
# 3  15   109

### end

Will that do the trick with your large dataset?

Ben


> On Sep 29, 2016, at 9:38 AM, Dennis Fisher  wrote:
> 
> R 3.3.1 
> OS X
> 
> Colleagues,
> 
> I have two large data frames that I am trying to link efficiently.   A small 
> example is as follows:
> 
> structure(list(Day = c(1L, 2L, 3L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
> 13L, 14L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
> 27L, 28L, 29L, 30L), Value = c(76, 116, 111, 103, 114, 99, 128, 
> 96, 81, 84, 81, 108, 109, 106, 125, 128, 92, 90, 83, 89, 76, 
> 89, 101, 93, 98, 77, 92)), .Names = c("Day", "Value"), row.names = c(NA, 
> -27L), class = "data.frame")
> 
> which becomes:
>  Day Value
> 1176
> 22   116
> 33   111
> 45   103
> 56   114
> 6799
> 78   128
> 8996
> 9   1081
> 10  1184
> 11  1381
> 12  14   108
> 13  16   109
> 14  17   106
> 15  18   125
> 16  19   128
> 17  2092
> 18  2190
> 19  2283
> 20  2389
> 21  2476
> 22  2589
> 23  26   101
> 24  2793
> 25  2898
> 26  2977
> 27  3092
> 
> The second dataframe is merely:
> TESTDAYS  <- data.frame(TestDay = c(4, 11, 15))
> 
> For each row in the second dataframe, I would like to identify the first row 
> in the first dataframe in which Day is >= TestDay.
> For example, for TestDay == 4, Day would equal 5.  I would then append the 
> corresponding “Value” in the TestValue column
> The result would be:
> TestDay TestValue
> 1   4   103
> 2  1184
> 3  15   109
> 
> I can accomplish this with brute force but I suspect that there is some 
> clever day to vectorize this.  Any help would be appreciated.
> 
> Dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com <http://www.plessthan.com/>
> 
> 
> 
> 
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Ben Tupper

On Apr 19, 2015, at 9:44 AM, John Sorkin  wrote:

> Windows 7 64-bit
> R 3.1.3
> RStudio 0.98.1103
> 
> 
> I am trying to generate a list of  length 4n which consists of the integers 1 
> to n repeated in groups of four, i.e.
> 
> 1,1,1,1,  2,2,2,2,  3,3,3,3, . . . . , n,n,n,n
> 

Hi,

Like this?

> x <- 1:4
> xx <- rep(x, each = 4)
> xx
 [1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4

Cheers,
Ben



> (The spaces in the list are added only for clarity.)
> 
> I can generate the list as follows, but the code must be modified for any 
> value n, and the code is UGLY!
> 
> c(rep(1,4), rep(2,4), rep(3,4), . . . ,c(n,4))
> 
> Can anyone help me?
> 
> Thank you,
> John
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> 
> Call
> Send SMS
> Add to Skype
> You'll need Skype CreditFree via Skype
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> 
> 
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:25}}

__
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] Interactive maps

2015-04-27 Thread Ben Tupper
 
>>> 
>>> 
> Antonio Serrano
>>> 
>> aasde...@aim.com
>>> ن
>>> 
>>> 
>>> -Original
> Message-
>>> From: Jim Lemon
>> 
>>> To: Antonio
> Serrano 
>>> Cc: r-help
>> mailing list
> 
>>> Sent: Sat, Apr 25, 2015 5:47 am
>>> 
>> Subject: Re:
> [R] Interactive maps
>>> 
>>> Hi Antonio,
>>> If you do create the map
>> in R,
> you can use
>>> locator().
>>> 
>>> Jim
>>> 
>>> 
>>> On Sat, Apr 25, 2015 at
> 8:37
>> AM, Antonio Serrano via
>>> R-help
>>> 
> wrote:
>>>> 
>>>> 
>> Hello, all:
>>>> 
>>>>   I am new here,
>>> and have a
> challenge to present some
>> graphical data to the user in a
>>> convenient
>>> 
> way.
>>>> 
>>>>   The challenge
>> is to present a map to the user which is
> coloured
>>> with the value of a
>> variable. Say for example, temperature. This
> is a
>>> preexisting graph that I
>> can generate in any format, including svg.
> I don't
>>> have
>>> to produce it
>> using R.
>>>> 
>>>>   When the user clicks
> anywhere in the map, the
>>> coordinates
>> (longitude and latitude) have to be
> passed to R so that this, R,
>>> can
>>> look
>> for the values of other
> variables in that location and make another
>>> graph
>>> 
>> with
> them.
>>>> 
>>>>   Does anyubody know how could I accomplish
>> 
> this?.
>>>> 
>>>> 
>>> Thanks in advance.
>>>> 
>>>> 
>>>> 
>>>> Antonio
> Serrano
>>>> 
>> aasde...@aim.com
>>>> ن
>>>> 
>>>> 
>>>> 
>>> [[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.
> 
> 
> 
> 
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Comparing 2 different files in R

2015-05-17 Thread Ben Tupper
Hi,

On May 17, 2015, at 6:56 AM, Lyle Warren  wrote:

> Thanks and sorry for being light on detail.
> 
> I have multiple files of raw human genome SNP data. Very large - the
> compressed zip files are about 8mb large.
> 

You'll have better luck asking on the Bioconductor help list ( 
http://www.bioconductor.org/ ) You may want to start here...

http://www.bioconductor.org/help/support/posting-guide/

and here...

http://www.bioconductor.org/help/search/index.html?q=SNP


Cheers,
Ben




> On 17 May 2015 at 20:53, John Kane  wrote:
> 
>> Probably but since you  have not told us anything about what you are doing
>> it is difficult to say.
>> 
>> You might find these links helpful
>> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>> and http://adv-r.had.co.nz/Reproducibility.html
>> 
>> 
>> John Kane
>> Kingston ON Canada
>> 
>> 
>>> -Original Message-
>>> From: lyl...@gmail.com
>>> Sent: Sun, 17 May 2015 08:32:45 +1000
>>> To: r-help@r-project.org
>>> Subject: [R] Comparing 2 different files in R
>>> 
>>> Hi,
>>> 
>>> I have multiple files that I want to compare in R. They contain SNP data
>>> with genotype in the 4th column, which is what I want to compare.
>>> 
>>> Is there any easy way to do this?
>>> 
>>>  [[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.
>> 
>> 
>> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
>> your desktop!
>> Check it out at http://www.inbox.com/marineaquarium
>> 
>> 
>> 
> 
>   [[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.

__
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] Basic editing of XML file

2015-08-13 Thread Ben Tupper
Hi,

Your email client is set to send in HTML format which has mangled your message. 
 Please set your client to send plain text to R-help.

You could use the XML package to modify the attributes of a given node.

> library(XML)

# make an reproducible example
> z <- newXMLNode("BLABLA",
+ attrs = c(version = "XXX"),
+ .children = list(
+ newXMLNode("A1", 
+ attrs = c(X1=2, X2="0", X3 = "100")),
+ newXMLNode("A2", 
+ attrs = c(X1=133.708, X2=36.28558)),
+ newXMLNode("A3",
+ attrs = c(X1=1, X2 = 2, X3 = 3, X4 = 4))
+ ))
> z

  
  
  
 

# XML child nodes can be access using like a list 
# z[['A1']] will extract the first node with that name
# then use the XML::xmlAttrs() function to get and set the attributes 
> a1_atts <- xmlAttrs(z[["A1"]])
> a1_atts
   X1X2X3 
  "2"   "0" "100" 
> a1_atts[['X3']] <- "boo"
> xmlAttrs(z[["A1"]]) <- a1_atts
> z

  
  
  
 

Is that what you want to do?


Cheers,
Ben


On Aug 13, 2015, at 8:51 AM, Robert U  wrote:

> Dear RUser,I’m tryingto operate some very slight editing to the values of an 
> XML file. I looked abit everywhere and it appears that dealing with XML files 
> is not that easy… besidemy XML files might be a bit weirdly structured. 
> Anyway, let me give you an exampleof it :
> Root(xmlfile)   X1="133.708" X2="36.28558"/>   mode="0"/>…  ………   I’d like to modify the value of 
> say,X1 in A1 line, or X1 in A2 line. Unfortunately the structure of this 
> datasetdoes not really look like the examples I’ve seen on the internet, 
> where youhave something that look like that :  something to change  
> In my case as you noticed, thevalues I want to edit are inside de <>, which 
> is pretty odd… Any tips?  Regards
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] backslash quirk in paste

2014-12-06 Thread Ben Tupper
Hi,

When you call paste without assigning the value it returns to anything it runs 
through the print command.  So, while your string may contain escapes, using 
print will not present escapes as you are expecting them.  In this case you 
could wrap cat() around your paste command.  

> cat(paste(fname, '\\', lname), "\n")
John \ Smith 

See FAQ 7.37 

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-does-backslash-behave-strangely-inside-strings_003f

Cheers,
Ben

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.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 

loaded via a namespace (and not attached):
[1] tools_3.1.0


On Dec 6, 2014, at 2:00 PM, Prof J C Nash (U30A)  wrote:

> This is NOT critical. It arose due to a fumble fingers when developing
> an R example, but slightly intriguing.
> 
> How could one build a string from substrings with a single backslash (\)
> as separator. Here's the reproducible example:
> 
> fname = "John"; lname = "Smith"
> paste(fname, lname)
> paste(fname, lname, sep=" / ")
> # BUT there's a glitch with backslash
> paste(fname, lname, sep=" \ ") # because of escaping character
> paste(fname, lname, sep=' \ ')
> paste(fname, lname, sep=' \\ ') # because of escaping character
> bslash <- "\\"
> print(bslash)
> paste(fname, lname, sep=bslash)
> 
> Possibly the answer is that R never allows a single backslash in its
> strings, but I can imagine possible cases where I might want to output
> such lines, for example, in documenting this.
> 
> Best, JN
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Checking if a logical variable exists

2014-12-14 Thread Ben Tupper
Hi,

Does this work for you?  It simply tests if the name Fisher is found among the 
names of the elements of spec.

obj = list(spec = list)
Fisher <- ifelse(!("Fisher" %in% names(obj$spec)), FALSE, obj$spec$Fisher)

Cheers,
Ben

On Dec 14, 2014, at 8:07 AM, Steven Yen  wrote:

> My obj does not always come with a logical variable defined. So I do
> 
> my.foo <- function(obj,df,digits=5){
> if (!is.na("obj$spec$Fisher")) Fisher<-obj$spec$Fisher
> ...
> }
> 
> This works when "Fisher" is defined in/passed from obj. When it is not, I get 
> error:
> 
> Error in (!is.na("obj$spec$Fisher")) & Fisher :
>  operations are possible only for numeric, logical or complex types
> 
> I tried exist(Fisher), missing(Fisher)... to no vail. Any idea? Thanks.
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] list of lists, is this element empty

2014-12-20 Thread Ben Tupper
Hi,


On Dec 20, 2014, at 10:58 AM, Ragia Ibrahim  wrote:

> Hello,
> Kindly I have a list of lists as follow
> x
> [[1]]
> [1] 7
> 
> [[2]]
> [1] 3 4 5
> 
> as showen x[[3]] does not have a value and it has NULL, how can I check on 
> this 
> how to test if x[[3]] is empty.
> 

In general you can us is.null()

x <- list(7, 3:5, NULL, "A")

> is.null(x[[3]])
[1] TRUE

but be aware that trying access an element by index that is greater than the 
length of the list will cause you issues.

> is.null(x[[10]])
Error in x[[10]] : subscript out of bounds

You can make your own function to test for the existence of an element and if 
it is NULL.  Note that the function isn't complete in the sense that it doesn't 
test if you provide an negative index, that x is not a list, etc.  You can add 
all of those tests in.

is_null <- function(x, index){
( index[1] > length(x) ) || is.null(x[[index[1]]])
}

> is_null(x, 1)
[1] FALSE
> is_null(x, 3)
[1] TRUE
> is_null(x, 10)
[1] TRUE


There a lot of info on index at 

> ?`[`

Does that answer your question?

Cheers,
Ben

> thanks in advance
> Ragia
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Do NOT use ifelse() if you can use if(.) else . [was "Checking .."]

2014-12-23 Thread Ben Tupper

On Dec 23, 2014, at 4:05 AM, Martin Maechler  wrote:

>>>>>> Steven Yen 
>>>>>>on Sun, 14 Dec 2014 09:30:56 -0500 writes:
>>>>>> Steven Yen 
>>>>>>on Sun, 14 Dec 2014 09:30:56 -0500 writes:
> 
>> Thanks. This worked!! :)
>> Fisher <- ifelse(!("Fisher" %in% names(obj$spec)), FALSE, obj$spec$Fisher)
> 
> "worked",  yes.
> 
> But please --- for the mailing list archives ---
> do use better code.
> 
> Unfortunately, ifelse() is used and has been advertized much too
> often in cases where it is very sub-optimal efficiency wise. 
> ifelse(Cond, A, B)  should only be used  when the condition
> 'Cond', a logical vector can be (and typically is) of length > 1
> {and even then, it maybe a nice short cut, but often still suboptimal
> efficiency wise ... but let's not get there}
> 
> In cases like this one when the condition 'Cond' is a
> simple TRUE or FALSE (i.e. of length 1), using
> 
>   if(Cond) A else B
> 
> instead of
> 
>   ifelse(Cond, A, B)
> 
> is
> 
>  1. much more R - like  [[ "everything you do is a function call" ]]
> hence much more elegant
> 
>  2. considerably more efficient.
> 
>  3. :-) less typing: uses two "," less ;-)
> 
>> require(microbenchmark)
>  Loading required package: microbenchmark
>> x <- setNames(,LETTERS)
>> y <- setNames(letters, runif(letters))
>> z <- pi
>> microbenchmark(r1 <- ifelse(z > 3, x, y), r2 <- if(z > 3) x else y, 
>> times=1000)
>  Unit: nanoseconds
>   expr  min lq mean median uq   max neval cld
>   r1 <- ifelse(z > 3, x, y) 4466 4971.5 5498.928   5244 5673.5 31705  1000   b
>   r2 <- if (z > 3) x else y  171  212.0  265.241264  291.0  3130  1000  a 
>> 
> 
> i.e., roughly a factor of 20 times more efficient
> 

Wow! This is great, and I had no idea I was misusing ifelse. 

Thanks!
Ben



> 
> Martin Maechler,
> ETH Zurich and R Core Team.
> 
> 
>> At 08:43 AM 12/14/2014, Ben Tupper wrote:
>>> Hi,
>>> 
>>> Does this work for you?  It simply tests if the name Fisher is found 
>>> among the names of the elements of spec.
>>> 
>>> obj = list(spec = list)
>>> Fisher <- ifelse(!("Fisher" %in% names(obj$spec)), FALSE, obj$spec$Fisher)
>>> 
>>> Cheers,
>>> Ben
>>> 
>>> On Dec 14, 2014, at 8:07 AM, Steven Yen  wrote:
>>> 
>>>> My obj does not always come with a logical variable defined. So I do
>>>> 
>>>> my.foo <- function(obj,df,digits=5){
>>>> if (!is.na("obj$spec$Fisher")) Fisher<-obj$spec$Fisher
>>>> ...
>>>> }
>>>> 
>>>> This works when "Fisher" is defined in/passed from obj. When it 
>>> is not, I get error:
>>>> 
>>>> Error in (!is.na("obj$spec$Fisher")) & Fisher :
>>>> operations are possible only for numeric, logical or complex types
>>>> 
>>>> I tried exist(Fisher), missing(Fisher)... to no vail. Any idea? Thanks.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Interesting article on R

2014-12-30 Thread Ben Tupper
Hi,

In case you missed it...

http://www.nature.com/news/programming-tools-adventures-with-r-1.16609

Cheers,
Ben

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Cube of Matrices or list of Matrices

2015-01-19 Thread Ben Tupper
Hi,

On Jan 18, 2015, at 4:36 PM, Karim Mezhoud  wrote:

> Dear All,
> I am trying to get correlation between  Diseases (80) in columns and
> samples in rows (UNEQUAL) using gene expression (at less 1000,numeric). For
> this I can use CORREP package with cor.unbalanced function.
> 
> But before to get this final matrix I need to load and to store the
> expression of 1000 genes for every Disease (80). Every disease has
> different number of samples (between 50 - 500).
> 
> It is possible to get a cube of matrices with equal columns but unequal
> rows? I think NO and I can't use array function.
> 
> I am trying to get à list of matrices having the same number of columns but
> different number of rows. as
> 
> Cubist <- vector("list", 1)
> Cubist$Expression <- vector("list", 1)
> 
> 
> for (i in 1:80){
> 
> matrix <- function(getGeneExpression[i])
> Cubist$Expression[[Disease[i]]] <- matrix
> 
> }
> 
> At this step I have:
> length(Cubist$Expression)
> #80
> dim(Cubist$Expression$Disease1)
> #526 1000
> dim(Cubist$Expression$Disease2)
> #106  1000
> 
> names(Cubist$Expression$Disease1[4])
> #ABD
> 
> names(Cubist$Expression$Disease2[4])
> #ABD
> 
> Now I need to built the final matrices for every genes (1000) that I will
> use for CORREP function.
> 
> Is there a way to extract directly the first column (first gene) for all
> Diseases (80)  from Cubist$Expression? or
> 

I don't understand most your question, but the above seems to be straight 
forward.  Here's a toy example:

# make a list of matrices, each with nCol columns and differing
# number of rows, nRow
nCol <- 3
nRow <- sample(3:10, 5)
x <- lapply(nRow, function(x, nc) {matrix(x:(x + nc*x - 1), ncol = nc, nrow = 
x)}, nCol)
x

# make a simple function to get a single column from a matrix
getColumn <- function(x, colNum) {
   return(x[,colNum])
}

# use the function to get the column from each matrix
col1 <- lapply(x, getColumn, 1)
col1

Does that help answer this part of your question?  If not, you may need to 
create a very small example of your data and post it here using the head() and 
dput() functions.

Ben



> I need to built 1000 matrices with 80 columns and unequal rows?
> 
> Cublist$Diseases <- vector("list", 1)
> 
> for (k in 1:1000){
> for (i in 1:80){
> 
> Cublist$Diseases[[gene[k] ]] <- Cubist$Expression[[Diseases[i] ]][k]
> }
> 
> }
> 
> This double loops is time consuming...Is there a way to do this faster?
> 
> Thanks,
> karim
>  Ô__
> c/ /'_;kmezhoud
> (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> http://bioinformatics.tn/
> 
>   [[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.

__
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] Cube of Matrices or list of Matrices

2015-01-19 Thread Ben Tupper
Hi again,

On Jan 19, 2015, at 1:53 PM, Karim Mezhoud  wrote:

> Yes Many thanks.
> That is my request using lapply.
> 
> do.call(cbind,col1)
> 
>  converts col1 to matrix but does not fill empty value with NA.
> 
> Even for
> 
> matrix(unlist(col1), ncol=5,byrow = FALSE)
> 
> 
> How can get Matrix class of col1? And fill empty values with NA?
> 

Perhaps best is to determine the maximum number of rows required first, then 
force each subset to have that length.

# make a list of matrices, each with nCol columns and differing
# number of rows
nCol <- 3
nRow <- sample(3:10, 5)
x <- lapply(nRow, function(x, nc) {matrix(x:(x + nc*x - 1), ncol = nc, nrow = 
x)}, nCol)
x

# make a simple function to get a single column from a matrix
getColumn <- function(x, colNum, len = nrow(x)) {
   y <- x[,colNum]
   length(y) <- len
   y
}

# what is the maximum number of rows
n <- max(sapply(x, nrow))

# use the function to get the column from each matrix
col1 <- lapply(x, getColumn, 1, len = n)
col1

do.call(cbind, col1)
  [,1] [,2] [,3] [,4] [,5]
 [1,]38579
 [2,]4968   10
 [3,]5   1079   11
 [4,]   NA   118   10   12
 [5,]   NA   129   11   13
 [6,]   NA   13   NA   12   14
 [7,]   NA   14   NA   13   15
 [8,]   NA   15   NA   NA   16
 [9,]   NA   NA   NA   NA   17

Ben

> Thanks
> Karim
> 
> 
>   Ô__
>  c/ /'_;kmezhoud
> (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> http://bioinformatics.tn/
> 
> 
> 
> On Mon, Jan 19, 2015 at 4:36 PM, Ben Tupper  wrote:
> Hi,
> 
> On Jan 18, 2015, at 4:36 PM, Karim Mezhoud  wrote:
> 
> > Dear All,
> > I am trying to get correlation between  Diseases (80) in columns and
> > samples in rows (UNEQUAL) using gene expression (at less 1000,numeric). For
> > this I can use CORREP package with cor.unbalanced function.
> >
> > But before to get this final matrix I need to load and to store the
> > expression of 1000 genes for every Disease (80). Every disease has
> > different number of samples (between 50 - 500).
> >
> > It is possible to get a cube of matrices with equal columns but unequal
> > rows? I think NO and I can't use array function.
> >
> > I am trying to get à list of matrices having the same number of columns but
> > different number of rows. as
> >
> > Cubist <- vector("list", 1)
> > Cubist$Expression <- vector("list", 1)
> >
> >
> > for (i in 1:80){
> >
> > matrix <- function(getGeneExpression[i])
> > Cubist$Expression[[Disease[i]]] <- matrix
> >
> > }
> >
> > At this step I have:
> > length(Cubist$Expression)
> > #80
> > dim(Cubist$Expression$Disease1)
> > #526 1000
> > dim(Cubist$Expression$Disease2)
> > #106  1000
> >
> > names(Cubist$Expression$Disease1[4])
> > #ABD
> >
> > names(Cubist$Expression$Disease2[4])
> > #ABD
> >
> > Now I need to built the final matrices for every genes (1000) that I will
> > use for CORREP function.
> >
> > Is there a way to extract directly the first column (first gene) for all
> > Diseases (80)  from Cubist$Expression? or
> >
> 
> I don't understand most your question, but the above seems to be straight 
> forward.  Here's a toy example:
> 
> # make a list of matrices, each with nCol columns and differing
> # number of rows, nRow
> nCol <- 3
> nRow <- sample(3:10, 5)
> x <- lapply(nRow, function(x, nc) {matrix(x:(x + nc*x - 1), ncol = nc, nrow = 
> x)}, nCol)
> x
> 
> # make a simple function to get a single column from a matrix
> getColumn <- function(x, colNum) {
>return(x[,colNum])
> }
> 
> # use the function to get the column from each matrix
> col1 <- lapply(x, getColumn, 1)
> col1
> 
> Does that help answer this part of your question?  If not, you may need to 
> create a very small example of your data and post it here using the head() 
> and dput() functions.
> 
> Ben
> 
> 
> 
> > I need to built 1000 matrices with 80 columns and unequal rows?
> >
> > Cublist$Diseases <- vector("list", 1)
> >
> > for (k in 1:1000){
> > for (i in 1:80){
> >
> > Cublist$Diseases[[gene[k] ]] <- Cubist$Expression[[Diseases[i] ]][k]
> > }
> >
> > }
> >
> > This double loops is time consuming...Is there a way to do this faster?
> >
> > Thanks,
> > karim
> >  Ô__
> > c/ /'_;kmezhoud
> > (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> > http://bioinformatics.tn/
> >
> >   [[alternative HTML version deleted]]
> >
> > 

Re: [R] Cube of Matrices or list of Matrices

2015-01-19 Thread Ben Tupper
Hi,

On Jan 19, 2015, at 5:17 PM, Karim Mezhoud  wrote:

> Thanks Ben.
> I need to learn more about apply. Have you a link or tutorial about apply. R 
> documentation is very short.
> 
> How can obtain:
> z <- list (Col1, Col2, Col3, Col4..)?
> 

This may not be the most efficient way and there certainly is no error 
checking, but you can wrap one lapply within another as shown below.  The 
innermost iterates over your list of input matrices, extracting one column 
specified per list element.  The outer lapply iterates over the various column 
numbers you want to extract.


getMatrices <- function(colNums, dataList = x){
   # the number of rows required
   n <- max(sapply(dataList, nrow))
   lapply(colNums, function(x, dat, n) { # iterate along requested columns
  do.call(cbind, lapply(dat, getColumn,x, len=n)) # iterate along input 
data list
   }, dataList, n)
}
   
getMatrices(c(1,3), dataList = x)  

If we are lucky, one of the plyr package users might show us how to do the same 
with a one-liner. 


There are endless resources online, here are some gems. 
 
http://www.r-project.org/doc/bib/R-books.html 
http://www.rseek.org/
http://www.burns-stat.com/documents/
http://www.r-bloggers.com/

Also, I found "Data Manipulation with R" ( 
http://www.r-project.org/doc/bib/R-books_bib.html#R:Spector:2008 ) helpful.  

Ben

> Thanks
> 
>   Ô__
>  c/ /'_;kmezhoud
> (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
> http://bioinformatics.tn/
> 
> 
> 
> On Mon, Jan 19, 2015 at 8:22 PM, Ben Tupper  wrote:
> Hi again,
> 
> On Jan 19, 2015, at 1:53 PM, Karim Mezhoud  wrote:
> 
>> Yes Many thanks.
>> That is my request using lapply.
>> 
>> do.call(cbind,col1)
>> 
>>  converts col1 to matrix but does not fill empty value with NA.
>> 
>> Even for
>> 
>> matrix(unlist(col1), ncol=5,byrow = FALSE)
>> 
>> 
>> How can get Matrix class of col1? And fill empty values with NA?
>> 
> 
> Perhaps best is to determine the maximum number of rows required first, then 
> force each subset to have that length.
> 
> # make a list of matrices, each with nCol columns and differing
> # number of rows
> nCol <- 3
> nRow <- sample(3:10, 5)
> x <- lapply(nRow, function(x, nc) {matrix(x:(x + nc*x - 1), ncol = nc, nrow = 
> x)}, nCol)
> x
> 
> # make a simple function to get a single column from a matrix
> getColumn <- function(x, colNum, len = nrow(x)) {
>y <- x[,colNum]
>length(y) <- len
>y
> }
> 
> # what is the maximum number of rows
> n <- max(sapply(x, nrow))
> 
> # use the function to get the column from each matrix
> col1 <- lapply(x, getColumn, 1, len = n)
> col1
> 
> do.call(cbind, col1)
>   [,1] [,2] [,3] [,4] [,5]
>  [1,]38579
>  [2,]4968   10
>  [3,]5   1079   11
>  [4,]   NA   118   10   12
>  [5,]   NA   129   11   13
>  [6,]   NA   13   NA   12   14
>  [7,]   NA   14   NA   13   15
>  [8,]   NA   15   NA   NA   16
>  [9,]   NA   NA   NA   NA   17
> 
> Ben
> 
>> Thanks
>> Karim
>> 
>> 
>>   Ô__
>>  c/ /'_;kmezhoud
>> (*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
>> http://bioinformatics.tn/
>> 
>> 
>> 
>> On Mon, Jan 19, 2015 at 4:36 PM, Ben Tupper  wrote:
>> Hi,
>> 
>> On Jan 18, 2015, at 4:36 PM, Karim Mezhoud  wrote:
>> 
>> > Dear All,
>> > I am trying to get correlation between  Diseases (80) in columns and
>> > samples in rows (UNEQUAL) using gene expression (at less 1000,numeric). For
>> > this I can use CORREP package with cor.unbalanced function.
>> >
>> > But before to get this final matrix I need to load and to store the
>> > expression of 1000 genes for every Disease (80). Every disease has
>> > different number of samples (between 50 - 500).
>> >
>> > It is possible to get a cube of matrices with equal columns but unequal
>> > rows? I think NO and I can't use array function.
>> >
>> > I am trying to get à list of matrices having the same number of columns but
>> > different number of rows. as
>> >
>> > Cubist <- vector("list", 1)
>> > Cubist$Expression <- vector("list", 1)
>> >
>> >
>> > for (i in 1:80){
>> >
>> > matrix <- function(getGeneExpression[i])
>> > Cubist$Expression[[Disease[i]]] <- matrix
>> >
>> > }
>> >
>> > At this step I have:
>> > length(Cubist$Expression)
>> > #80
>> > dim(Cubist$Expression$Disease1)
>> > #526 1000
>> > di

Re: [R] How to use curve() function without using x as the variable name inside expression?

2015-01-31 Thread Ben Tupper
Hi Philippe,

Ah!  Thanks for pointing out the pesky ifelse() issue.  I have only recently 
been learning (the hard way) that ifelse() is not a tool for the uninformed 
like me, but it is ever so tempting!

I would like to offer another way to speed things up. findInterval() can be 
quite fast, and the speed up is most noticeable when the size of the input 
grows (note I made input x <- 1:3000).

func <- function (x, mn, mx) 1/(mx-mn) * (x >= mn & x <= mx)

funcIfElse <- function (x, mn, mx) ifelse(x < mn | x > mx, 0, 1/(mx - mn))

funcFindInterval <- function(x, mn, mx)  1/(mx - mn) * (findInterval(x, c(mn, 
mx), rightmost.closed = TRUE) == 1)

mn<- 100; mx <- 200; x <- 1:3000
microbenchmark::microbenchmark(func(x, mn, mx), funcIfElse(x, mn, mx), 
funcFindInterval(x, mn, mx))

#Unit: microseconds
#expr min  lq  mean   median   uq  
max neval
# func(x, mn, mx)  74.920  76.006  88.57119  76.5635  78.7065  
897.333   100
#   funcIfElse(x, mn, mx) 728.388 733.206 832.02225 735.4280 796.1910 
1645.804   100
# funcFindInterval(x, mn, mx)  33.954  35.334  56.57323  36.5010  38.3340  
993.193   100

r1 <- func(x, mn, mx)
r2 <- funcIfElse(x, mn, mx)
r3 <- funcFindInterval(x, mn, mx)

identical(r1, r2)
#[1] TRUE
identical(r2, r3)
#[1] TRUE

Cheers,
Ben


On Jan 31, 2015, at 4:03 AM, Philippe Grosjean  wrote:

> Also note that ifelse() should be avoided as much as possible. To define a 
> piecewise function you can use this trick:
> 
> func <- function (x, min, max) 1/(max-min) * (x >= min & x <= max)
> 
> The performances are much better. This has no impact here, but it is a good 
> habit to take in case you manipulate such kind of functions in a more 
> computing-intensive context (numerical integration, nls(), etc.).
> 
> funcIfElse <- function (x, min, max) ifelse(x < min | x > max, 0, 1/(max - 
> min))
> min <- 100; max <- 200; x <- 1:300
> microbenchmark::microbenchmark(func(x, min, max), funcIfElse(x, min, max))
> ## Unit: microseconds
> ## exprmin   lq  mean  median 
>   uq  max neval
> ## func(x, min, max) 10.242  16.0175  18.43348  18.446  19.8680   
> 47.266   100
> ##  funcIfElse(x, min, max) 90.386 125.1605 148.18555 143.455 148.6695 
> 1203.292   100
> 
> Best,
> 
> Philippe Grosjean
> 
>> On 31 Jan 2015, at 09:39, Rolf Turner  wrote:
>> 
>> On 31/01/15 21:10, C W wrote:
>>> Hi Bill,
>>> 
>>> One quick question.  What if I wanted to use curve() for a uniform
>>> distribution?
>>> 
>>> Say, unif(0.5, 1.3), 0 elsewhere.
>>> 
>>> My R code:
>>> func <- function(min, max){
>>>  1 / (max - min)
>>> }
>>> 
>>> curve(func(min = 0.5, max = 1.3), from = 0, to = 2)
>>> 
>>> curve() wants an expression, but I have a constant.   And I want zero
>>> everywhere else.
>> 
>> Well if that's what you want, then say so!!!
>> 
>> func <- function(x,min,max) {
>>  ifelse(x < min | x > max, 0, 1/(max - min))
>> }
>> 
>> curve(func(u,0.5,1.3),0,2,xname="u")
>> 
>> Or, better (?) curve(func(u,0.5,1.3),0,2,xname="u",type="s")
>> 
>> which avoids the slight slope in the "vertical" lines.
>> 
>> cheers,
>> 
>> Rolf Turner
>> 
>> -- 
>> Rolf Turner
>> Technical Editor ANZJS
>> Department of Statistics
>> University of Auckland
>> Phone: +64-9-373-7599 ext. 88276
>> Home phone: +64-9-480-4619
>> 
>> __
>> 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.


Re: [R] Categorizing by month

2015-03-27 Thread Ben Tupper
Hi,

On Mar 27, 2015, at 12:06 PM, lychang  wrote:

> Hi everyone,
> 
> I'm trying to categorize by month in R. How can I do this if my dates are in
> date/month/year form?
> 

I'm not sure about the date form you describe, but if you have the dates as 
POSIXct you can extract the month as character and categorize with that.

x <- seq(from = as.POSIXct("2000/1/1", format="%Y/%m/%d"), to = 
as.POSIXct("2009/12/1", format="%Y/%m/%d"), by = 'month')
mon <- format(x, '%m')
xx <- split(x, mon)
str(xx)
List of 12
 $ 01: POSIXct[1:10], format: "2000-01-01" "2001-01-01" "2002-01-01" 
"2003-01-01" ...
 $ 02: POSIXct[1:10], format: "2000-02-01" "2001-02-01" "2002-02-01" 
"2003-02-01" ...
 $ 03: POSIXct[1:10], format: "2000-03-01" "2001-03-01" "2002-03-01" 
"2003-03-01" ...
 $ 04: POSIXct[1:10], format: "2000-04-01" "2001-04-01" "2002-04-01" 
"2003-04-01" ...
 $ 05: POSIXct[1:10], format: "2000-05-01" "2001-05-01" "2002-05-01" 
"2003-05-01" ...
 $ 06: POSIXct[1:10], format: "2000-06-01" "2001-06-01" "2002-06-01" 
"2003-06-01" ...
 $ 07: POSIXct[1:10], format: "2000-07-01" "2001-07-01" "2002-07-01" 
"2003-07-01" ...
 $ 08: POSIXct[1:10], format: "2000-08-01" "2001-08-01" "2002-08-01" 
"2003-08-01" ...
 $ 09: POSIXct[1:10], format: "2000-09-01" "2001-09-01" "2002-09-01" 
"2003-09-01" ...
 $ 10: POSIXct[1:10], format: "2000-10-01" "2001-10-01" "2002-10-01" 
"2003-10-01" ...
 $ 11: POSIXct[1:10], format: "2000-11-01" "2001-11-01" "2002-11-01" 
"2003-11-01" ...
 $ 12: POSIXct[1:10], format: "2000-12-01" "2001-12-01" "2002-12-01" 
"2003-12-01" ...

Does that help?

Ben

> Thanks,
> Lois
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Categorizing-by-month-tp4705173.html
> Sent from the R help mailing list archive at Nabble.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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Help with POSIX

2015-03-30 Thread Ben Tupper
Hi,


On Mar 30, 2015, at 9:15 PM, Doran, Harold  wrote:

> I�m struggling a bit with learning about POSIX objects to do some basic 
> things with objects of this class. Suppose I have the following simple example
> 
> times <- c("03:20", "29:56", "03:30", "21:03", "56:26")
> 
> aa <- strptime(times, "%M:%S�)
> 
> I can do means, and some other basic things, but I cannot correlate the 
> objects with some other variable
> 
> cor(aa, rnorm(5))
> 


You can cast your POSIXlt values to numeric

cor(as.numeric(aa), rnorm(5))


> Also, for purposes of a user-interface I have built with shiny, I need for 
> the time to be viewed as simply as minutes:seconds, such as this
> 
> format(aa, '%M:%S�)
> 
> But of course after doing this I lose the ability to work with this object as 
> a time variable.
> 

You may need to keep a copy of your times in a POSIX or numeric format in 
addition to converting to character.  It's hard to tell without more 
information.

Cheers,
Ben

> Thank you
> Harold
> 
>   [[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.

__
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] error with the expand.grid command

2018-08-09 Thread Ben Tupper
MODIS
> from a combination of NASA's l2gen (for basic sensor geometry corrections,
> etc) and HYGEOS Polymer v3.5 (for atmospheric correction).  The Rrs were
> binned to a sinusoidal 4km level-3 grid, and later to 4km geographic
> projection, by Brockmann Consult's BEAM.  Derived products were generally
> computed with the standard SeaDAS algorithms.  QAA IOPs were derived using
> the standard SeaDAS algorithm but with a modified backscattering table to
> match that used in the bandshifting.  The final chlorophyll is a combination
> of OC4, Hu's CI and OC5, depending on the water class memberships.
> Uncertainty estimates were added using the fuzzy water classifier and
> uncertainty estimation algorithm of Tim Moore as documented in Jackson et al
> (2017).
>tracking_id: 659b397a-953c-4814-a3e2-460d6218fcfa
>id:
> ESACCI-OC-L3S-CHLOR_A-MERGED-1M_MONTHLY_4km_GEO_PML_OCx-199709-fv3.1.nc
> <http://esacci-oc-l3s-chlor_a-merged-1m_monthly_4km_geo_pml_ocx-199709-fv3.1.nc/>
> 
>   [[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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] Understanding read.csv error message

2018-08-18 Thread Ben Tupper
Hi,

I would be tempted, as a start, to read the entire file in as rows of text, 
split each line by the expected delimiter, and then count the number of 
elements each split line yields.  Once you know each row splits into the 
expected number of 

txt <- "name,easting,northing,elev,sampdate,prcp
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-01,0.59
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-02,0.08
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-03,0.1
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-04,0
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-05,0
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-06,0.02
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-07,0.05
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-08,0.1
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-09,0
Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-10,0.02"

txtCon <- textConnection(txt)
x <- readLines(txtCon)
close(txtCon)

n <- sapply(strsplit(x, ",", fixed = TRUE), length)
table(n)

If any have a different length then investigate that/those line(s).  If they 
all have the same length then it likely isn't about the delimiter.

Cheers,
Ben


 
> On Aug 18, 2018, at 5:05 AM, peter dalgaard  wrote:
> 
> What Don said, and also notice that the error is not about anything having 
> value 0, it is about replacing something with something of _length_ 0. It is 
> not obvious where that happens, sometimes a traceback() can give a clue, but 
> probably Don is right that the issue is that there is something not quite CSV 
> in the file. 
> 
> One further idea is to read using colClasses="character" and see if that 
> actually gives you 6 columns and then afterwards try and convert each column 
> to the appropriate type.
> 
> -pd
> 
>> On 18 Aug 2018, at 00:08 , Rich Shepard  wrote:
>> 
>> I have a data file, 'precip_projected.csv,' that starts like this:
>> 
>> name,easting,northing,elev,sampdate,prcp
>> Headworks Portland 
>> Water,2370575.38427211,199337.634652112,228,2005-01-01,0.59
>> Headworks Portland 
>> Water,2370575.38427211,199337.634652112,228,2005-01-02,0.08
>> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-03,0.1
>> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-04,0
>> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-05,0
>> Headworks Portland 
>> Water,2370575.38427211,199337.634652112,228,2005-01-06,0.02
>> Headworks Portland 
>> Water,2370575.38427211,199337.634652112,228,2005-01-07,0.05
>> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-08,0.1
>> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-09,0
>> Headworks Portland 
>> Water,2370575.38427211,199337.634652112,228,2005-01-10,0.02
>> 
>> There are a bunch of NAs in the data file.
>> 
>> The command to read it produces an error:
>> 
>> rainfall <- read.csv('../data/precipitation/precip_projected.csv', header = 
>> T, sep = ',', as.is = T)
>> 
>> Error in `$<-.data.frame`(`*tmp*`, date, value = numeric(0)) :
>> replacement has 0 rows, data has 113569
>> 
>> Is the error generated by finding a date that looks like the number zero
>> or by a prcp value of zero?
>> 
>> BTW, I get the same error if I specify stringsAsFactors = F.
>> 
>> TIA,
>> 
>> Rich
>> 
>> __
>> 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.
> 
> -- 
> 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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] Casting Date to char

2018-09-05 Thread Ben Tupper
Hi,

Perhaps you wanted to convert dp$rainfall.sampdate and not dp$sampdate like 
this...

dp$sampdate <- as.character(dp$rainfall.sampdate)

... or even better, take charge of the conversion with format() ...

dp$sampdate <- format(dp$rainfall.sampdate, format = '%Y-%m-%d')

Cheers,
Ben

> On Sep 5, 2018, at 4:17 PM, Rich Shepard  wrote:
> 
>  I've read the help for as.Date: "Date Conversion Functions to and from
> Character" but the method as.character(x ...) isn't working for me:
> 
>> str(dp)
> 'data.frame': 113569 obs. of  2 variables:
> $ rainfall.sampdate: Date, format: "2005-01-01" "2005-01-02" ...
> $ rainfall.prcp: num  0.59 0.08 0.1 0 0 0.02 0.05 0.1 0 0.02 ...
>> dp$sampdate <- as.Character(dp$sampdate)
> Error in `$<-.data.frame`(`*tmp*`, sampdata, value = character(0)) :
>  replacement has 0 rows, data has 113569
> 
>  I don't understand the error message and want to learn what I've done
> incorrectly.
> 
> Regards,
> 
> Rich
> 
> __
> 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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] Sp-package overlay

2018-10-02 Thread Ben Tupper
Hi,

I'm pretty sure that what you ask is likely not too hard to do.  On the other 
hand, I think you will do well to consider the following...

1. Join the mailing list; the folks there will know better what you are trying 
to do - see

https://stat.ethz.ch/mailman/listinfo/r-sig-geo 
<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>


2. Switch from the sf package to the sf package if you can - see  

https://cran.r-project.org/web/packages/sf/


3. Come up to speed with geospatial data handling in R starting here 

https://geocompr.robinlovelace.net/index.html


Cheers,
Ben


> On Oct 2, 2018, at 10:33 AM, Ivy Pieters  wrote:
> 
> Hey there, 
> 
> For my internship I have to work with R. I am working with R for the first
> time and I don't know much. 
> Somehow I don't manage to find the answer to my question in google. I think
> I don't search with the right words, or maybe I just don't understand
> enough. Anyways, I hope someone here can help me out. 
> 
> I have 2 datasets: 
> 
> a SpatialPolygonDataFrame, this dataset is called "field" (these are
> different fields of arable land) 
> and a SpatialPointsDataFrame, this dataset is called "odk" (these are
> different soil samples taken in each field) 
> 
> The field data set consists of 8 polygons and they have a slot with coords 
> 
> The odk data set consists of 537 features (soil samples), these features
> belong to the polygons but they are all mixed. This dataset also has a slot
> with coords 
> 
> They are both projected in the same coordinate system. 
> 
> Now I would like to create a new dataset with a table with the features of
> odk that belong to polygon 1 and a separate table for the features that
> belong to polygon 2 etc. The best is if they also get into the
> spatialpointsdataframe format. 
> 
> I really don't know how to do this. I hope someone here can help me out. I
> hope that I gave enough information for anyone to help me else let me know
> if I have to tell something more about my datasets. 
> 
> Thank you already a lot in advance, 
> 
> Hope to hear from anyone soon, 
> 
> Kind regards, 
> 
> Ivy
> 
> __
> 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.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] gemo_text issue

2018-11-27 Thread Ben Tupper
Hi,

I had to include 

library(reshape2) 

to get things working as you use melt(). Explicitly setting the x and y values 
in geom_text() is needed since you are providing new data.

zp1 <- zp1 + geom_text(data=test2, x=test2$con, y=test2$Prob, label = 
test2$Project, size = 6, color = "white")


Cheers,
Ben

> On Nov 27, 2018, at 3:04 PM, Reith, William [USA]  
> wrote:
> 
> I am experiencing issues with trying to label points added to a ggplot via 
> geom_point. I think an underlying issue is the fact that I already used 
> ggplot function to create a 5x5 risk matrix "background", but I am not 
> certain. I have tried multiple solutions online but cannot find one that has 
> a similar the background plotting I am attempting.
> 
> I have attached the .R file and a picture of what I am creating minus the 
> buggy text labels. Code is also pasted below.
> 
> Thanks,
> 
> William
> 
> 
> library(ggplot2)
> 
> Project<-c("C","C","C","C","C","B","B","B","D","E","E","F","F","F","F")
> Prob<-c(3,3,3,2,2,2,2,2,3,4,3,5,4,3,3)
> con<-c(3.675941831,2.354582402,2.354582402,2.354582402,1.95075378,3.0602443,3.0602443,3.283695274,1.904452395,3.579022044,3.579022044,2.58190428,1.76065948,2.365243619,1.354491286)
> test2<-data.frame(Project,Prob,con)
> 
> ### build risk coloring matrix ###
> myData <- matrix(c(1,2,3,3,3,1,2,2,3,3,1,1,2,2,3,1,1,2,2,2,1,1,1,1,2), nrow = 
> 5, ncol = 5, byrow = TRUE)
> rownames(myData) <- c("5", "4", "3", "2","1")
> colnames(myData) <- c("1", "2", "3", "4","5")
> 
> ### convert to data frame ###
> longData <- melt(myData)
> colnames(longData) <- c("Probability", "Consequence", "value")
> longData$value<-as.factor(longData$value)
> 
> ### define color tiles ###
> color<-c("green" ,"green" ,"green","green"  ,"green",
>"yellow","yellow","green","green"  ,"green",
>"red"   ,"yellow","yellow","yellow","green",
>"red"   ,"red"   ,"yellow","yellow","green",
>"red"   ,"red"   ,"red"   ,"yellow","yellow")
> 
> ### create color background 5x5 ###
> zp1 <- ggplot(longData,aes(x = Consequence, y = Probability)) #, fill = 
> value))
> zp1 <- zp1 + geom_tile(fill = color)
> zp1 <- zp1 + scale_x_continuous(breaks = 0:6, expand = c(0, 0))
> zp1 <- zp1 + scale_y_continuous(breaks = 0:6, expand = c(0, 0))
> zp1 <- zp1 + coord_fixed()
> zp1 <- zp1 + theme_bw()
> print(zp1)
> 
> ### Add title and lines ###
> zp1 <- zp1 + ggtitle("5x5 Plot")+theme(plot.title = element_text(hjust = 0.5))
> zp1 <- zp1 + geom_vline(xintercept=c(1.5:5.5))
> zp1 <- zp1 + geom_hline(yintercept=c(1.5:5.5))
> print(zp1)
> 
> ### Plot points ###
> zp1 <- zp1 + geom_point(data=test2, x=test2$con, y=test2$Prob, alpha = 1, 
> size = 9, color = "blue")
> print(zp1)
> 
> ### This is the line I cannot get working; tried multiple approaches ###
> ### intent is to add white labels to plotted points ###
> zp1 <- zp1 + geom_text(data=test2, label = test2$Project, size = 6, color = 
> "white")
> print(zp1)
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] POSIXct format

2018-12-04 Thread Ben Tupper
Hi,

It is because the print method for POSIXct likely tries to simplify.  To see it 
in the format you desire, you need to be explicit when calling it.

x = as.POSIXct('2018-11-2700:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
format(x, "%Y-%m-%d %H:%M:%S %Z")
[1] "2018-11-27 00:00:00 UTC"

Cheers,
Ben

> On Dec 4, 2018, at 7:51 AM, Christofer Bogaso  
> wrote:
> 
> Hi,
> 
> I am trying to format my Character strings to POSIXct as below :
> 
>> as.POSIXct('2018-11-2700:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
> [1] "2018-11-27 UTC"
>> as.POSIXct('2018-11-2701:00:00', format = "%Y-%m-%d%H:%M:%S", tz = 'UTC')
> [1] "2018-11-27 01:00:00 UTC"
> 
> For the first case, I wanted to see "2018-11-27 00:00:00 UTC", but the
> Hour/Min/Sec part was missing in R output. Is it possible to get consistent
> formatting in both cases?
> 
> Thanks for your help. Regards
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/

__
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] Width of a text

2018-12-12 Thread Ben Tupper
Hi,

Does strwidth() do the trick?

https://www.rdocumentation.org/packages/graphics/versions/3.5.1/topics/strwidth 
<https://www.rdocumentation.org/packages/graphics/versions/3.5.1/topics/strwidth>

Ben

> On Dec 12, 2018, at 6:55 AM, Christofer Bogaso  
> wrote:
> 
> Hi,
> 
> In HTML there is a way to measure the width of a Text before printing it on
> screen as in https://www.w3schools.com/tags/canvas_measuretext.asp
> 
> In R we have nchar() function which just measures the number of letters in
> a Text, but I wonder if we can measure the width of text as well.
> 
> I have a shiny app where I need to print a text in an Area onto the screen
> which has a specific width, so some the texts are not showing within that
> area (overflowing), where some are though all of them have the equal number
> of letters.
> 
> Thanks for any input.
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] I can't get seq to behave how I think it should

2019-01-17 Thread Ben Tupper
Hi,

This looks like a floating point reality bump - see 

https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
 


You can use other methods to finding your row - I would opt for findInterval()

> lut = seq(1.4, 2.1, by=0.001)
> findInterval(1.8, lut)
[1] 401

findInterval() uses a rapid search to find the index in the look up table (lut) 
that is just less than  or equal to the search value (in your example 1.8).

Cheers,
Ben

> On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS 
> FOUNDATION TRUST) via R-help  wrote:
> 
> I am using seq with the expression seq(1.4, 2.1, by=0.001) to create a 
> sequence of references from 1.4 to 2.1 in 0.001 increments.  They appear to 
> be created correctly.  They have a related pair of data which for the 
> purposes of this we will call val.  I'm interested in the content on the row 
> with seq = 1.8. But I can't seem to get it returned.  I can get other values 
> but not 1.8!  yet looking at row 401 there is nothing to indicate an issue
> 
>> a = 1.4
>> b = 2.1
>> seq = seq(a, b, by=0.001)
>> val = ceiling(seq * 50)
>> s=data.frame(seq, val)
>> s$val[seq==1.799]
> [1] 90
>> s$val[s$seq==1.8]
> numeric(0)
>> s$val[seq==1.8]
> numeric(0)
>> s$val[s$seq==1.800]
> numeric(0)
>> s$val[s$seq==1.801]
> [1] 91
>> head(s[s$seq>1.798,])
>  seq val
> 400 1.799  90
> 401 1.800  90
> 402 1.801  91
> 403 1.802  91
> 404 1.803  91
> 405 1.804  91
> 
> 
> Can anyone explain what's going on here and how I would correctly find the 
> content of row 401 by using an expression to equal the seq column?
> 
> 
> 
> 
> 
> 
> 
> This message may contain confidential information. If ...{{dropped:25}}

__
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] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Ben Tupper
Hi,

You might try your hand at the tidyverse collection of tools which are veddy 
nice for this kind of wrangling. https://www.tidyverse.org/

Does this do the trick?

## START
library(readr)
library(dplyr)

txt <- "row plot lai leaf
1 104 82 1
2 104 167 2
3 104 248 3
4 104 343 4
5 104 377 5
6 105 64 1
7 105 139 2
8 105 211 3
9 105 296 4
10 105 348 5
11 106 94 1
12 106 167 2
13 106 243 3
14 106 281 4
15 106 332 5
16 108 83 1
17 108 382 2
18 108 320 3
19 108 146 4
20 108 129 5"

x <- readr::read_delim(txt, delim = " ") %>%
dplyr::group_by(plot) %>%
dplyr::summarize(mean_lai = mean(lai))

x
# A tibble: 4 x 2
   # plot mean_lai
  # 
# 1   104 243.
# 2   105 212.
# 3   106 223.
# 4   108 212 

## END
 
Cheers,
Ben

>   [[alternative HTML version deleted]]


P.S.  Don't forget that HTML formatted emails get stripped of formatting on 
this list - so be sure to change your email client to send plain text.


> On Feb 14, 2019, at 9:31 AM, Isaac Barnhart  wrote:
> 
> I am having trouble finding the mean of a specific part of my dataset. Here 
> is a sample of it:
> 
> plot lai leaf
> 1 104 82 1
> 2 104 167 2
> 3 104 248 3
> 4 104 343 4
> 5 104 377 5
> 6 105 64 1
> 7 105 139 2
> 8 105 211 3
> 9 105 296 4
> 10 105 348 5
> 11 106 94 1
> 12 106 167 2
> 13 106 243 3
> 14 106 281 4
> 15 106 332 5
> 16 108 83 1
> 17 108 382 2
> 18 108 320 3
> 19 108 146 4
> 20 108 129 5
> 
> I have many different plot numbers, none of which follow any kind of specific 
> numeric sequence (even though I have sorted them from smallest to largest). I 
> need to take the average (mean) of the LAI for each plot, and was wondering 
> if there was a way to specify the code to do this. For example: I need the 
> average of all the LAI measurements for each leaf of plot 104, 105, etc. Any 
> help would be appreciated. Thanks!
> 
> Get Outlook for iOS<https://aka.ms/o0ukef>
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/

__
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] Randomization Test

2019-02-27 Thread Ben Tupper
 9495
> 10 9531
> -5 9491
> -4 9441
> -3 9388
> -2 9380
> -1 9369
> 0 9354
> 1 9367
> 2 9369
> 3 9341
> 4 9305
> 5 9308
> 6 9324
> 7 9385
> 8 9451
> 9 9496
> 10 9527
> -5 9369
> -4 9354
> -3 9367
> -2 9369
> -1 9341
> 0 9305
> 1 9308
> 2 9324
> 3 9385
> 4 9451
> 5 9496
> 6 9527
> 7 9544
> 8 9543
> 9 9535
> 10 9536
> -5 9586
> -4 9583
> -3 9572
> -2 9533
> -1 9454
> 0 9392
> 1 9420
> 2 9451
> 3 9475
> 4 9514
> 5 9561
> 6 9542
> 7 9502
> 8 9461
> 9 9468
> 10 9463
> -5 9587
> -4 9562
> -3 9530
> -2 9445
> -1 9404
> 0 9395
> 1 9417
> 2 9449
> 3 9467
> 4 9470
> 5 9524
> 6 9512
> 7 9448
> 8 9398
> 9 9431
> 10 9467
> -5 9467
> -4 9470
> -3 9524
> -2 9512
> -1 9448
> 0 9398
> 1 9431
> 2 9467
> 3 9490
> 4 9517
> 5 9526
> 6 9574
> 7 9573
> 8 9562
> 9 9563
> 10 9566
> ",header=TRUE)
> 
> data<-matrix(c(dta$CR),ncol=71)
> A<-matrix(rep(-5:10,71))
> B<-matrix(data)
> 
> oodf<-data.frame(A,B)
> a<--5:10
> oodf<-data.frame(A,B)
> library(plotrix)
> std.error<-function(x) return(sd(x)/(sum(!is.na(x
> oomean<-as.vector(by(oodf$B,oodf$A,mean))
> oose<-as.vector(by(oodf$B,oodf$A,std.error))
> plot(-5:10,oomean,type="l",ylim=c(8890,9100),
> )
> A<-oomean-1.96*oose
> B<-oomean+1.96*oose
> lines(a,A,col="red")
> lines(a,B,col="red")
> 
> My Question:
> I wish to conduct a randomization test of significance (90 and 99
> percentile) of the reductions/decreases as displayed by the signal.
> 
> I am attempting using:
> x<-sample(8890:9500,1136,replace=T )
> 
> to generate the random numbers, where 8890, 9500 and 1136 are the
> minimum  and maximum of the signal and 1136 the length of sample data.
> Q1: Please how do I generate many samples as x above, say up to 5000
> or 10,000? I manually generated and stored as x1,x2, x3 up to x100.
> 
> Q2: Please how do I use this randomly generated numbers to test the
> statistical significance level of the signal generated by
> plot(-5:10,oomean,type="l",ylim=c(8890,9100),  )?
> 
> I wish to test for 90% and 99% percentile.
> 
> I am sorry that this is too long.
> 
> Many thanks for your kind contributions
> 
> Best
> Ogbos
> 
> 
> 
> 
> 
> 
> 
> On Sun, Feb 10, 2019 at 3:55 PM Ogbos Okike  wrote:
>> 
>> Dear Michael,
>> This is great! Thank you.
>> 
>> I have not really got any response other than yours.
>> 
>> I have long before now included what I have in a paper submitted to a 
>> journal.
>> 
>> I am awaiting the feedback of the reviewer. I will compare the
>> comments with your input here and determine the corrections to make
>> and probably return to the list for additional help.
>> 
>> Best wishes
>> Ogbos
>> 
>> On Fri, Feb 8, 2019 at 4:31 PM Meyners, Michael  wrote:
>>> 
>>> Ogbos,
>>> 
>>> You do not seem to have received a reply over the list yet, which might be 
>>> due to the fact that this seems rather a stats than an R question. Neither 
>>> got your attachment (Figure) through - see posting guide.
>>> 
>>> I'm not familiar with epoch analysis, so not sure what exactly you are 
>>> doing / trying to achieve, but some general thoughts:
>>> 
>>> * You do NOT want to restrict your re-randomizations in a way that "none of 
>>> the dates corresponds with the ones in the real event" - actually, as a 
>>> general principle, the true data must be an admissible re-randomization as 
>>> well. You seem to have excluded that (and a lot of other randomizations at 
>>> the same time which might have occurred, i.e. dates 1 and 2 reversed but 
>>> all others the same), thereby rendering the test invalid. Any restrictions 
>>> you have on your re-randomizations must've applied to the original 
>>> randomization as well.
>>> * If you have rather observational data (which I suspect, but not sure), 
>>> Edgington & Onghena (2007) would rather refer to this as a permutation test 
>>> - the difference being that you have to make strong assumptions (similar to 
>>> parametric tests) on the nature of the data, which are designed-in to be 
>>> true for randomization tests. It might be a merely linguistic 
>>> discrimination, but it is important to note which assumptions have to be 
>>> (implicitly) made.
>>> * I'm not sure what you mean by "mean differences" of the ev

Re: [R] looking for 'tied rows' in dataframe

2019-03-18 Thread Ben Tupper
Hi,

Might you replaced 'T' with a numeric value that signals the TRUE case without 
rumpling your matrix?  0 might be a good choice as it is never an index for a 
1-based indexing system.

hold=apply(test,1,which.max)
hold[apply(test,1,isUnique)==FALSE] <- 0
hold
[1] 1 2 0
 


> On Mar 17, 2019, at 8:17 PM, Evan Cooch  wrote:
> 
> Solved --
> 
> hold=apply(test,1,which.max)
> hold[apply(test,1,isUnique)==FALSE] <- 'T'
> 
> Now, all I need to do is figure out how to get <- 'T' from turning everything 
> in the matrix to a string.
> 
> 
> On 3/17/2019 8:00 PM, Evan Cooch wrote:
>> Got relatively close - below:
>> 
>> On 3/17/2019 7:39 PM, Evan Cooch wrote:
>>> Suppose I have the following sort of structure:
>>> 
>>> test <- matrix(c(2,1,1,2,2,2),3,2,byrow=T)
>>> 
>>> What I need to be able to do is (i) find the maximum value for each row, 
>>> (ii) find the column containing the max, but (iii) if the maximum value is 
>>> a tie (in this case, all numbers of the row are the same value), then I 
>>> want which.max (presumably, a tweaked version of what which.max does) to 
>>> reurn a T for the row where all values are the same.
>>> 
>>> Parts (i) and (ii) seem easy enough:
>>> 
>>> apply(test,1,max)  --- gives me the maximum values
>>> apply(test,1,which.max) --- gives me the column
>>> 
>>> But, standard which.max doesn't handles ties/duplicates in a way that 
>>> serves my need. It defaults to returning the first column containing the 
>>> maximum value.
>>> 
>>> What I'd like to end up with is, ultimately, something where 
>>> apply(test,1,which.max) yields 1,2,T  (rather than 1,2,1).
>>> 
>>> So, a function which does what which.max currently does if the elements of 
>>> the row differ, but which returns a T (or some such) if in fact the row 
>>> values are all the same.
>>> 
>>> I've tried a bunch of things, to know avail. Closest I got was to use a 
>>> function to test for whether or not a vector
>>> 
>>> isUnique <- function(vector){
>>>  return(!any(duplicated(vector)))
>>> }
>>> 
>>> which returns TRUE if values of vector all unique. So
>>> 
>>> apply(test,1,isUnique)
>>> 
>>> returns
>>> 
>>> [1]  TRUE  TRUE FALSE
>>> 
>>> but I'm stuck beyond this. 
>> 
>> The following gets me pretty close,
>> 
>> test_new <- test
>> test_new[which(apply(test,1,isUnique)==FALSE),] <- 'T'
>> 
>> but is clunky.
>> 
>> 
>> 
>> 
>> 
>> 
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/

__
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 overlay a vector map (polygon) on raster maps?

2019-04-11 Thread Ben Tupper
Hi,

I think you want to build a levelplot object with polygon overlaid for each 
layer.  Like the link below shows but with the added layer per your example.  

https://oscarperpinan.github.io/rastervis/FAQ.html#several_rasters

Also, you will get bucket loads of spatial-centric help using the r-sig-geo 
mailing list; check it out here https://stat.ethz.ch/mailman/listinfo/r-sig-geo.

Cheers,
Ben

### START
library(sp)
library(raster)
library(rasterVis)
library(RColorBrewer)

S <- raster::stack(system.file("external/rlogo.grd", package="raster"))

# make a polygon by shrinking the extent and casting object type
Poly <- as(raster::extent(S) + c(15, -32, 25, -10), "SpatialPolygons")

# build the layers in a list, adding the polygon to each layer
themes <- c("Reds", "Greens", "Blues")
PP <- lapply(seq_len(nlayers(S)),
function(i) {
levelplot(S[[i]], 
par.settings = rasterVis::rasterTheme(region = 
RColorBrewer::brewer.pal(9, themes[i])), 
margin=FALSE) + 
layer(sp.polygons(Poly, col = "orange", lwd = 2))
}
)

# print each layer, but specify the location within a layout scheme
print(PP[[1]], split=c(1, 1, 1, 3), more = TRUE)
print(PP[[2]], split=c(1, 2, 1, 3), more = TRUE)
print(PP[[3]], split=c(1, 3, 1, 3), more = FALSE)
### END



> On Apr 11, 2019, at 7:28 AM, Kristi Glover  wrote:
> 
> He R users,
> I have been struggling to plot a boundary map over the raster maps. I tried 
> using the following example, but the boundary map could not be displayed over 
> the three raster maps.
> It works if we plot for a single raster. However when I want to plot the 
> three maps using "levelplot" and add the boundary map it did not work.  I 
> wanted to plot three raster same time because the "levelplot" so that we can 
> compare the maps as they have only one legend.
> 
> My example code is given below, do you have any suggestions?
> 
> 
> library(gridExtra)
> 
> library(raster)
> 
> library(sp)
> 
> library(rasterVis)
> 
> library(rgdal)
> 
> library(maptools)
> 
> 
> boundary<- readShapeSpatial("boundrymap.shp")
> 
> 
> minTemp<-raster("minTemp.tif")
> 
> maxTemp<-raster("maxTemp.tif")
> 
> averageTemp<-raster("averageTemp.tif")
> 
> Temp<-stack(minTemp,maxTemp,averageTemp)
> 
> 
> levelplot(Temp, layout=c(1,3))+ layer(sp.polygons(boundary, col = "yellow"))
> 
> thanks
> 
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/

__
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 overlay a vector map (polygon) on raster maps?

2019-04-11 Thread Ben Tupper
Hi,

That's great topic to search on RSeek.org <http://rseek.org/>

https://rseek.org/?q=plot+multiple+rasters+with+one+legend 
<https://rseek.org/?q=plot+multiple+rasters+with+one+legend>

or to pose a question about on r-sig-geo

Cheers,
Ben

> On Apr 11, 2019, at 11:32 AM, Kristi Glover  wrote:
> 
> Dear Ben, 
> Thank you very much for the message. I run it and it produced three separate 
> images with X and y Axis  and a legend for each image. I was thinking to plot 
> all of these three images with a single legend and only X axis value at the 
> bottom's image and y values for each image.  
> 
> I added the following code on your code
> grid.arrange(PP[[1]],PP[[2]],PP[[3]])
>  
> But, as I mentioned above, I can get three separate images with its own 
> legend and X and Y axix
> Thanks,
> 
> From: Ben Tupper 
> Sent: April 11, 2019 7:13 AM
> To: Kristi Glover
> Cc: r-help@r-project.org
> Subject: Re: [R] How to overlay a vector map (polygon) on raster maps?
>  
> Hi,
> 
> I think you want to build a levelplot object with polygon overlaid for each 
> layer.  Like the link below shows but with the added layer per your example.  
> 
> https://oscarperpinan.github.io/rastervis/FAQ.html#several_rasters 
> <https://oscarperpinan.github.io/rastervis/FAQ.html#several_rasters>
> 
> Also, you will get bucket loads of spatial-centric help using the r-sig-geo 
> mailing list; check it out 
> herehttps://stat.ethz.ch/mailman/listinfo/r-sig-geo 
> <https://stat.ethz.ch/mailman/listinfo/r-sig-geo>.
> 
> Cheers,
> Ben
> 
> ### START
> library(sp)
> library(raster)
> library(rasterVis)
> library(RColorBrewer)
> 
> S <- raster::stack(system.file("external/rlogo.grd", package="raster"))
> 
> # make a polygon by shrinking the extent and casting object type
> Poly <- as(raster::extent(S) + c(15, -32, 25, -10), "SpatialPolygons")
> 
> # build the layers in a list, adding the polygon to each layer
> themes <- c("Reds", "Greens", "Blues")
> PP <- lapply(seq_len(nlayers(S)),
> function(i) {
> levelplot(S[[i]], 
> par.settings = rasterVis::rasterTheme(region = 
> RColorBrewer::brewer.pal(9, themes[i])),  
> margin=FALSE) + 
> layer(sp.polygons(Poly, col = "orange", lwd = 2))
> }
> )
> 
> # print each layer, but specify the location within a layout scheme
> print(PP[[1]], split=c(1, 1, 1, 3), more = TRUE)
> print(PP[[2]], split=c(1, 2, 1, 3), more = TRUE)
> print(PP[[3]], split=c(1, 3, 1, 3), more = FALSE)
> ### END
> 
> 
> 
> > On Apr 11, 2019, at 7:28 AM, Kristi Glover  
> > wrote:
> > 
> > He R users,
> > I have been struggling to plot a boundary map over the raster maps. I tried 
> > using the following example, but the boundary map could not be displayed 
> > over the three raster maps.
> > It works if we plot for a single raster. However when I want to plot the 
> > three maps using "levelplot" and add the boundary map it did not work.  I 
> > wanted to plot three raster same time because the "levelplot" so that we 
> > can compare the maps as they have only one legend.
> > 
> > My example code is given below, do you have any suggestions?
> > 
> > 
> > library(gridExtra)
> > 
> > library(raster)
> > 
> > library(sp)
> > 
> > library(rasterVis)
> > 
> > library(rgdal)
> > 
> > library(maptools)
> > 
> > 
> > boundary<- readShapeSpatial("boundrymap.shp")
> > 
> > 
> > minTemp<-raster("minTemp.tif")
> > 
> > maxTemp<-raster("maxTemp.tif")
> > 
> > averageTemp<-raster("averageTemp.tif")
> > 
> > Temp<-stack(minTemp,maxTemp,averageTemp)
> > 
> > 
> > levelplot(Temp, layout=c(1,3))+ layer(sp.polygons(boundary, col = "yellow"))
> > 
> > thanks
> > 
> > 
> >[[alternative HTML version deleted]]
> > 
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help 
> > <https://stat.ethz.ch/mailman/listinfo/r-help>
> > PLEASE do read the posting guide 
> > http://www.R-project.org/posting-guide.html 
> > <http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> 
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org <http://www.bigelow.org/>
> 
> Ecological Forecasting: https://eco.bigelow.org/ <https://eco.bigelow.org/>
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






[[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] How to overlay a vector map (polygon) on raster maps?

2019-04-11 Thread Ben Tupper
Hi,

It's best to keep all of the replies on the list - you will get better answers 
and leave a trail for others with similar questions to follow.  If you need 
more help, I strongly suggest that you start a fresh question on r-sig-geo.

I suppose you could try the panel argument to levelplot().  Using the panel 
argument will modify each raster - that is each rendering of elements of your 
raster stack - by performing what ever task you put in the panel function.  
It's all a bit mysterious to me how it really works which is why I often 
gravitate toward the more obvious-to-me layering that the latticeExtra package 
provides with `levelplot(something) + layer(more stuff)`. 

library(rasterVis)
library(sp)

set.seed(10)
x = runif(200, -0.0005, .9875)
y = runif(200, -0.0008, .99)
xmat = matrix(x, nrow = 500)
ymat = matrix(x, nrow = 500)
xras = raster(xmat)
yras = raster(ymat)
min_ = min(minValue(xras), minValue(yras))
max_ = max(maxValue(xras), maxValue(yras))
r.range = c(min_, max_)
Poly <- as(raster::extent(xras) + c(.15, -.32, .25, -.10), "SpatialPolygons")
levelplot(stack(xras, yras), 
col.regions = rev(rainbow(99, start=0, end=1)), 
colorkey = list(space = "bottom"),
panel = function(...){
panel.levelplot(...)
sp.polygons(Poly, col = 'black', lwd = 3)
}
)

Cheers,
Ben



> On Apr 11, 2019, at 11:50 AM, Kristi Glover  wrote:
> 
> Thank you Ben for the link. It has lots of the information. One of the 
> example bellow, here how can we overlay a polygon (let's say river map) on 
> the two raster images? The two raster images are of Maximum and Minimum 
> temperature of a specific area. 
> library(rasterVis)
> 
> set.seed
> (10)
> 
> x 
> = runif(200, -0.0005, .9875)
> 
> y 
> = runif(200, -0.0008, .99)
> 
> xmat 
> = matrix(x, nrow = 500)
> 
> ymat 
> = matrix(x, nrow = 500)
> 
> xras 
> = raster(xmat)
> 
> yras 
> = raster(ymat)
> 
> min_ 
> = min(minValue(xras), minValue(yras))
> 
> max_ 
> = max(maxValue(xras), maxValue(yras))
> 
> r.range 
> = c(min_, max_)
> 
> 
> levelplot
> (stack(xras, yras), col.regions = rev(rainbow(99, start=0, end=1)), colorkey 
> = list(space = "bottom"))
> thank you so much for your help.
> 
> 
> 
> From: Ben Tupper 
> Sent: April 11, 2019 9:43 AM
> To: Kristi Glover
> Cc: r-help@r-project.org
> Subject: Re: [R] How to overlay a vector map (polygon) on raster maps?
>  
> Hi,
> 
> That's great topic to search on RSeek.org
> 
> https://rseek.org/?q=plot+multiple+rasters+with+one+legend
> 
> or to pose a question about on r-sig-geo
> 
> Cheers,
> Ben
> 
>> On Apr 11, 2019, at 11:32 AM, Kristi Glover  
>> wrote:
>> 
>> Dear Ben, 
>> Thank you very much for the message. I run it and it produced three separate 
>> images with X and y Axis  and a legend for each image. I was thinking to 
>> plot all of these three images with a single legend and only X axis value at 
>> the bottom's image and y values for each image.  
>> 
>> I added the following code on your code
>> grid.arrange(PP[[1]],PP[[2]],PP[[3]])
>>  
>> But, as I mentioned above, I can get three separate images with its own 
>> legend and X and Y axix
>> Thanks,
>> 
>> From: Ben Tupper 
>> Sent: April 11, 2019 7:13 AM
>> To: Kristi Glover
>> Cc: r-help@r-project.org
>> Subject: Re: [R] How to overlay a vector map (polygon) on raster maps?
>>  
>> Hi,
>> 
>> I think you want to build a levelplot object with polygon overlaid for each 
>> layer.  Like the link below shows but with the added layer per your example. 
>>  
>> 
>> https://oscarperpinan.github.io/rastervis/FAQ.html#several_rasters
>> 
>> Also, you will get bucket loads of spatial-centric help using the r-sig-geo 
>> mailing list; check it out 
>> herehttps://stat.ethz.ch/mailman/listinfo/r-sig-geo.
>> 
>> Cheers,
>> Ben
>> 
>> ### START
>> library(sp)
>> library(raster)
>> library(rasterVis)
>> library(RColorBrewer)
>> 
>> S <- raster::stack(system.file("external/rlogo.grd", package="raster"))
>> 
>> # make a polygon by shrinking the extent and casting object type
>> Poly <- as(raster::extent(S) + c(15, -32, 25, -10), "SpatialPolygons")
>> 
>> # build the layers in a list, adding the polygon to each layer
>> themes <- c("Reds", "Greens", "Blues")
>> PP <- lapply(seq_len(nlayers(S)),
>> function(i) {
>> leve

Re: [R] Depth vs Temp graph for different transects

2014-09-01 Thread Ben Tupper

On Sep 1, 2014, at 12:32 PM, David Winsemius  wrote:

> 
> On Sep 1, 2014, at 3:52 AM, Tinus Sonnekus wrote:
> 
>> Hi All,
>> 
>> Have the following code. The graph works well plotting the 15 transect for
>> me however the legend shows a total of 22 transects. The original data has
>> 22 transects numbered from 1 to 22. New data set got only 15. How can I get
>> the legend to show only the transects plotted.
>> 
>> 
>> # Create Line Chart
>> 
>> 
>> TAll <- read.csv("TAll Data.csv")
> 
> You have set up a situation where we can only guess.


If this data is generated by a CTD or similar instrument then I highly 
recommend you use Dan Kelley's oce package.  It will help you manage, analyze 
and display the cast data.

http://cran.r-project.org/web/packages/oce/index.html

Cheers,
Ben


> 
>> 
>> 
>> # convert factor to numeric for convenience
>> TAll$Tran <- as.numeric(TAll$Trans)
>> nTrans <- max(TAll$Trans)
>> 
>> # get the range for the x and y axis
>> xrange <- range(TAll$Temp)
>> yrange <- range(TAll$Depth)
>> 
>> # set up the plot
>> plot(xrange, yrange, ylim = rev(yrange), type="n", xlab="Temp (deg C)",
>> ylab="Depth (m)" )
>> colors <- rainbow(nTrans)
>> linetype <- c(1:nTrans)
>> plotchar <- seq(1,1+nTrans,1)
>> 
>> # add lines
>> for (i in 1:nTrans) {
>> tree <- subset(TAll, Trans==i)
>> lines(tree$Temp, tree$Depth, type="b", lwd=1.5,
>>   lty=linetype[i], col=colors[i], pch=plotchar[i])
>> }
>> 
>> # add a legend
>> legend(xrange[-2], yrange[-2], 1:nTrans, cex=0.8, col=colors,
>> pch=plotchar, lty=linetype, title="Transect")
>> 
> If nTrans is 22 then you are getting what you ask for. If you subsetted a 
> dataset where TAll$Trans was a factor then it's perfecty possible that the 
> legend would have more items than the subset. Perhaps you should use `length` 
> or length(unique(.))` rather than `max`.
> 
> -- 
> David.
> 
> 
>> 
>> 
>> Thanks for the help,
>> Tinus
>> 
>> -- 
>> M.J. Sonnekus
>> PhD Candidate (The Phytoplankton of the southern Agulhas Current Large
>> Marine Ecosystem (ACLME))
>> Department of Botany
>> South Campus
>> Nelson Mandela Metropolitan University
>> PO Box 77000
>> Port Elizabeth
>> South Africa
>> 6031
>> 
>> Cell: 082 080 9638
>> E-mail: tsonne...@gmail.com
>> 
>>  [[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> 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-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] "missings=function(x) x[x==998|x==999]<-NA" doesn't work...

2014-09-18 Thread Ben Tupper
Hi,

On Sep 18, 2014, at 10:13 AM, Doreen Mueller  wrote:

> Hi!
> 
> I want to have a function that assigns NAs to certain values of my 
> variable "var" in the dataset "d". This doesn't work:
> 
>> missings=function(x) x[x==998|x==999]<-NA
>> missings(d$var)
>> table(d$var, useNA="always")
> 
>0  1  999  
> 220  752  321 5264 
> 
> I don't get any error messages, but "d$var" remains unchanged. The 
> function:
>> missings=function(x) x[x==90|x==99]<<-NA
> doesn't work either, and I read that "<<-" is "dangerous" anyway?
> 

You are so close.  R returns the value of the last thing evaluated in your 
function.  In this case, the *copy* of your input argument was modified within 
the function, but you didn't return the value of the copy to the calling 
environment.  You need to explicitly return the modified value.

> missings <- function(x) { x[ (x==998) | (x==999) ] <- NA ; return(x) }
> missings(990:1010)
 [1]  990  991  992  993  994  995  996  997   NA   NA 1000 1001 1002 1003 1004 
1005 1006 1007
[19] 1008 1009 1010

By the way, don't forget to switch your email client to use text instead of 
html when sending a message to the list.

Cheers,
Ben





> It is important for me to work with variable names (and therefore with 
> functions instead loops) because the number and order of variables in my 
> dataset changes regularly.
> 
> Thank you,
> Doreen
>   [[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] Injecting a column of characters to a matrix of numerics

2014-10-29 Thread Ben Tupper
Hi,

On Oct 29, 2014, at 11:41 AM, Steven Yen  wrote:

> Hello
> I am designing a regression printout, which works out nicely. Then, I try to 
> inject a column of characters to indicate a discrete regressor with a dot 
> (.). Then, all numbers seem to turn into characters, in quotations. Is there 
> a way to do this right? Below, I show the lines of codes before and after. 
> Thanks.
> Steven Yen
> 
> ---
> out<-round(cbind(me,se,t,p),digits)
> colnames(out)<-c("estimates","s.e.","|t-value|","p-value")
> rownames(out)<-rownames(me)
> out
>estimates s.e. |t-value|  p-value
> (Intercept)  0.223263 0.146167  1.527459 0.127173
> sex  0.049830 0.039612  1.257973 0.208890
> age -0.070423 0.029539  2.384035 0.017433
> yrmarry  0.015567 0.005298  2.938126 0.003429
> children 0.060525 0.044778  1.351659 0.176993
> religius-0.053128 0.014413  3.686260 0.000248
> educ 0.003226 0.008453  0.381636 0.702866
> occu 0.003915 0.011860  0.330147 0.741404
> rating  -0.077856 0.014466  5.381925 0.00
> 
> out<-round(cbind(me,se,t,p),digits); out<-cbind(out,disc)
> colnames(out)<-c("estimates","s.e.","|t-value|","p-value","disc")
> rownames(out)<-rownames(me)
> 
> (Intercept) "0.223263"  "0.146167" "1.527459" "0.127173" ""
> sex "0.04983"   "0.039612" "1.257973" "0.20889"  "."
> age "-0.070423" "0.029539" "2.384035" "0.017433" ""
> yrmarry "0.015567"  "0.005298" "2.938126" "0.003429" ""
> children"0.060525"  "0.044778" "1.351659" "0.176993" "."
> religius"-0.053128" "0.014413" "3.68626"  "0.000248" ""
> educ"0.003226"  "0.008453" "0.381636" "0.702866" ""
> occu"0.003915"  "0.01186"  "0.330147" "0.741404" ""
> rating  "-0.077856" "0.014466" "5.381925" "0"""
> 


It appears the 'out' is originally a numeric matrix, thus adding column of 
characters demotes the entire matrix to character.  Convert 'out' to data.frame 
to allow mixed data types.

> out<-round(cbind(me,se,t,p),digits); out <- as.data.frame(out) ; 
> out<-cbind(out,disc)


Cheers,
Ben

> __
> 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] Why would something work in R but not Rscript?

2014-11-19 Thread Ben Tupper
Hi,

On Nov 19, 2014, at 11:48 AM, Jeff Hansen  wrote:

> I have a script that uses RWeka (and consequently rJava).  When I run
> it in Rstudio everything works fine. When I run it with `R CMD BATCH`,
> everything also works fine. However, when I run it with Rscript, I get
> the following error:
> 
> Error in FUN(X[[1L]], ...) :
>  object is not a Java object reference (jobjRef/jarrayRef).
> Calls: evaluate_Weka_classifier -> t -> sapply -> lapply -> FUN
> Execution halted
> 
> The following is a very simple toy script that you can run to produce
> the results:
> 
> library("RWeka")
> result <- c(TRUE,FALSE,TRUE,FALSE,TRUE)
> observation <- c(TRUE,FALSE,TRUE,FALSE,TRUE)
> df <- data.frame(result,observation)
> j48 <- J48(result ~ .,data=df)
> evaluate_Weka_classifier(j48)
> 
> Save that to a file called help.R and run
> 
> R CMD BATCH help.R
> 
> Check the output file help.Rout and you should see no errors. Now try
> running it from:
> 
> Rscript help.R
> 

You might try using the the --vanilla option for each.  At least then you can 
rule out that something is being restored in the session of one but not the 
other. 

R --vanilla CMD BATCH help.R
Rscript --vanilla help.R

Cheers,
Ben


> And you should see the error I've pasted above.
> 
> I have consulted (and will continue to consult) the literature, but
> the manuals tend to answer how usage differs between the two commands
> rather than going into implementation details. I imagine there's a
> difference in how environments get loaded and I just need to adjust
> something on the Rscript side.
> 
> I'm working on a Mac (OSX) running R 3.1.0, but I get the same results
> when I run everything from a Centos 6.4 virtual machine (headless)
> with R 3.1.1 installed.
> 
> Thanks for any help!
> 
> __
> 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] Extracting XML value

2015-09-03 Thread Ben Tupper
Hi,

You are very close and your understanding is correct - you need to extract the 
root node from the XMLDocument returned from xmlTreeParse.

library(XML)

txt <-  "\n\n  \n\n\n\n\n"

# parse the text tree and extract the root node
obs <- xmlRoot(xmlTreeParse(txt, useInternalNodes = TRUE, asText = TRUE))

# get the first child node of 'observation' name.  Yes, there is just one.
obs1 <- obs['observation'][[1]]

# it has no value, just attributes of which 'value' is one
xmlAttrs(obs1)[['value']]


Cheers,
Ben



On Sep 3, 2015, at 11:23 AM, Glenn Schultz  wrote:

> All,
> 
> I have made it as far as generating an api call which returns the following 
> xml
> [1] "\n realtime_start=\"2015-09-03\" realtime_end=\"2015-09-03\" 
> observation_start=\"2015-09-01\" observation_end=\"2015-09-01\" units=\"lin\" 
> output_type=\"1\" file_type=\"xml\" order_by=\"observation_date\" 
> sort_order=\"asc\" count=\"1\" offset=\"0\" limit=\"10\">\n   realtime_start=\"2015-09-03\" realtime_end=\"2015-09-03\" date=\"2015-09-01\" 
> value=\"0.46\"/>\n\n\n\n\n"
> attr(,"Content-Type")
>   charset 
> "text/xml""UTF-8" 
> 
> following DTL's presentation on the Berkley site and the package help I 
> parsed the xml
> 
> doc = xmlTreeParse(USSW10, asText = TRUE, useInternal = TRUE)
> 
> which gives
> 
>  observation_start="2015-09-01" observation_end="2015-09-01" units="lin" 
> output_type="1" file_type="xml" order_by="observation_date" sort_order="asc" 
> count="1" offset="0" limit="10">
>date="2015-09-01" value="0.46"/>
> 
> 
> finally I try to extract the value 0.46 using the xmlValue function.  I have 
> lost something in translation and I am unable to extract the value.  my 
> understanding is I have one node with no children, correct?
> 
> -Glenn
> 
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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 plot shades between curves?

2015-10-18 Thread Ben Tupper
Hi,

Thanks for the reproducible example!  (Don't forget to make your email client 
send text-only messages, not html, when sending to this list).

Would log scale work for you?


Capa.diss<-c(0.7261102, 0.6655960, 0.5638357,0.8585834,0.6964527,0.8434504, 
0.7106749,0.5981460,0.5747585,0.7347864,0.8012803,0.6826862,0.4949845, 
0.5466870,0.5417343,0.4774860,0.4814479,0.5254794,0.6236299,0.6575862,0.7047694,0.5550153,0.4499349,0.5939971,0.4138955,0.3659061,0.3126497,0.2476329,0.2503446,0.2686042,0.3036808,0.2747602,0.4221727,0.3935815,0.3942621,0.5821026,0.2251284,0.2670861,0.3580937,0.4239509,0.4010682,0.4104427,0.3666264,0.2555372,0.2995469,0.3985690,0.4304724,0.4136308,0.3525836,0.3898816,0.3517483,0.2924678,0.4807643,0.4471870,0.3694882,0.3970183,0.4827425,0.4766994,0.3391238,0.4153885,0.5502231,0.5330776,0.5867776,0.5195776,0.4882179,0.5298611,0.4626142)

Capa.diss.age<-c(2,152,302,452,602,752,902,1052,1202,1352,1502,1652,1802,1952,2102,2252,2402,2552,2702,2852,3002,3152,3302,3452,3602,3752,3902,4052,4202,4352,4502,4652,4802,4952,5102,5252,5402,5552,5702,5852,6002,6152,6302,6452,6602,6752,6902,7052,7202,7352,7502,7652,7802,7952,8102,8252,8402,8552,8702,8852,9002,9152,9302,9452,9602,9752,9902)

plot(Capa.diss,Capa.diss.age,
ylim = c(0,10500),
xlim = pmax(range(Capa.diss), c(0.1, 30)),
type="l",
log = 'x')

Note that pmax() is selecting the maximum of each element in the two input 
vectors - you might want something different


Cheers,
Ben


On Oct 18, 2015, at 10:15 AM, Jackson Rodrigues  
wrote:

> Dear all,
> 
> I have to compare several curves that range through different scales (x
> axis) along the same time, so to make them comparable I brought all of them
> to the same scale (x axis) and obviously kept the age axis (y axis) for all
> of them.
> As result, some variations (wiggles) simply disappeared (Figure on link
> below, line Capa.diss) making impossible any interpretation. To deal with
> such of problem, I plot the curve as it has to be in large scale (line
> Capa.diss) and added a the same curve again on a secondary axis, but
> exaggerating its values by a subjective factor of 0.7 (Capa.diss2).
> Further, I want to fill the gap between both curves with some color.
> 
> Figure available on:
> https://www.dropbox.com/s/dtcgk167mh9xykj/12120156_533366843482278_6929357065463452649_o.jpg?dl=0
> 
> My idea in doing it is: I have a plot in which the wiggles are "invisible",
> to highlight these wiggles I projected a shadded curve of exaggerated data.
> 
> My question is: How to plot shades between curves?
> 
> 
> Thank you all
> 
> Jackson Rodrigues
> 
> My codes are:
> 
> plot(Capa.diss,Capa.diss.age,ylim =
> rev((range)(Capa.diss.age=c(min(Capa.diss.age),
> 10500))),xlim=(c(0,30)),type="l")
> Capa.diss2<-Capa.diss*0.7
> par(new=TRUE)
> plot(Capa.diss2, Capa.diss.age, col='black',type="l",ylim =
> rev((range)(Capa.diss.age=c(min(Capa.diss.age), 10500))),
> xlim=(c(0,1)),xaxt="n",yaxt="n",xlab="",ylab="")
> 
> The following lline is the one I trying to use to fill the gap, but it is
> not working.
> polygon(c(Capa.diss.age,rev(Capa.diss.age)),c(Capa.diss2,rev(Capa.diss)),col="grey")
> 
> 
> Date used:
> 
> Capa.diss<-c(0.7261102, 0.6655960, 0.5638357,0.8585834,0.6964527,0.8434504,
> 0.7106749,0.5981460,0.5747585,0.7347864,0.8012803,0.6826862,0.4949845,
> 0.5466870,0.5417343
> ,0.4774860,0.4814479,0.5254794,0.6236299,0.6575862,0.7047694,0.5550153,0.4499349,0.5939971,0.4138955,0.3659061,0.3126497,0.2476329,0.2503446,0.2686042,0.3036808,0.2747602,0.4221727,0.3935815,0.3942621,0.5821026,0.2251284,0.2670861,0.3580937,0.4239509,0.4010682,0.4104427,0.3666264,0.2555372,0.2995469,0.3985690,0.4304724,0.4136308,0.3525836,0.3898816,0.3517483,0.2924678,0.4807643,0.4471870,0.3694882,0.3970183,0.4827425,0.4766994,0.3391238,0.4153885,0.5502231,0.5330776,0.5867776,0.5195776,0.4882179,0.5298611,0.4626142)
> 
> Capa.diss.age<-c(2,152,302,452,602,752,902,1052,1202,1352,1502,1652,1802,1952,2102,2252,2402,2552,2702,2852,3002,3152,3302,3452,3602,3752,3902,4052,4202,4352,4502,4652,4802,4952,5102,5252,5402,5552,5702,5852,6002,6152,6302,6452,6602,6752,6902,7052,7202,7352,7502,7652,7802,7952,8102,8252,8402,8552,8702,8852,9002,9152,9302,9452,9602,9752,9902)
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Mai

Re: [R] Graphing the Area of Definite Integral

2015-11-27 Thread Ben Tupper
Hi Steve,

Give RSeek.org a try ...

http://rseek.org/?q=show+area+under+curve

There a loads of examples and blogs on this topic at RSeek.org.  Under the 
'Support' tab there is an exchange between two USM folk on this very topic.

Cheers,
Ben


On Nov 27, 2015, at 7:52 AM, Steven Stoline  wrote:

> Dear All:
> 
> I am trying to explain to my students how to calculate the definite
> integral using the Riemann sum. Can someone help me to graph the area under
> the curve of the function, showing the curve as well as the rectangles
> between 0 and 4..
> 
> *f(x) = x^3 - 2*x *
> 
> over the interval [0 , 4]
> 
> 
> 
> with many thanks
> steve
> 
> -- 
> Steven M. Stoline
> 1123 Forest Avenue
> Portland, ME 04112
> sstol...@gmail.com
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] "par(tcl=0.5,las=1)" doesn't work

2016-01-07 Thread Ben Tupper
Hi,

I think it may be the order in which your par() configuration occurs relative 
to png().  When you open a new device, as you have with png(), the default 
par() values for that device are exposed. If you move your par() statement to 
*after* your call to png() you get the result you desire.

S=read.table("Sarrazin-2.5",as.is = default.stringsAsFactors())
#par(tcl=0.5,las=1)   # - move to after you open the device
png(file="partest-1.png",width=580,height=580)
par(tcl=0.5,las=1)# - configure the device after opening it
dev.control("enable") 
plot(V3,V2,xlab=" ",ylab="BIP, rel. zu Deutschland", 
pch=16,xlim=c(630,930),ylim=c(95,135))
dev.off()

See the 'details' section of ?par  - "Each device has its own set of graphical 
parameters."  I take that to mean a new set of parameters are exposed.

Cheers,
Ben

P.S.  I wonder if that sentence might have more value if it read like this, 
"Configure each device after opening as each device has its own set of 
graphical parameters."

> On Jan 7, 2016, at 3:30 AM, Hans Haußmann  wrote:
> 
> Hi Bert Gunter and David Winsemius,
> 
> sorry for sending my first post to R-help in German and thank you David for 
> your efforts to translate.
> 
> Here are two scripts now. In the first one the graphics parameters "tcl" and 
> "las" are not recognized, in the second one they are. Why not in the first 
> one?
> 
> I am not sure whether I may attach the outputs of the two scripts, I just try.
> 
> Kind regards,
> 
> Hans Haußmann (Haussmann)
> __
> 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.

Re: [R] Extracting point data using longitude and latitude from netcdf file using R

2016-01-09 Thread Ben Tupper
Hi,

This post gives more details on how to transform your lat/lon values to 
row/column indices. The question and answer are specifically about the ncdf 
package, but the workflow is identical when using the ncfd4 package.

https://stat.ethz.ch/pipermail/r-help/2011-March/272641.html

Cheers,
Ben

> On Jan 9, 2016, at 7:14 AM, Anthoni, Peter (IMK)  
> wrote:
> 
> Hi Peter,
> 
> the start in nc_varget requires a latitude and longitude index, not the 
> latitude and longitude in double format.
> So you need to figure out what index your latitude and longitude correspond 
> to, which will depends on what data are in your netCDF.
> 
> it might have looked like that it worked for a positive latitude, but you got 
> the data from the latitude index 6 or 7, depends on how the double was 
> transformed into an integer.
> 
> best regards
> Peter
> 
>> On 09 Jan 2016, at 12:28, Peter Tuju via R-help  wrote:
>> 
>> I have data file in netcdf with three dimensions (x, y, t) and I want to 
>> extract a variable RAINC and RAINNC 
>> using longitude and latitude for a single point location with all the time, 
>> but no lucky. The syntax is as follows;;
>> setwd( "/run/media/tuju/0767090047/extract_wrf_txt_file" )
>> rm( list = ls() )  
>> library( ncdf4 ) 
>> inp_file <- nc_open( "wrfout_d01_2016-01-07.nc" )time <- ncvar_get( 
>> inp_file, "Times" )  # Reading the time variabledar_lon 
>> <- 39.2dar_lat <- -6.87
>> RAINC <- ncvar_get( inp_file, varid = "RAINC", start  = c( dar_lon, dar_lat, 
>> 1 ), count = c( 1, 1, -1 ) )
>> RAINNC <- ncvar_get( inp_file, varid = "RAINNC", start  =  c( dar_lon, 
>> dar_lat, 1 ), count = c( 1, 1, -1 ) )
>> RAIN <- RAINC + RAINNCRAIN_TABLE <- cbind( time, RAIN )
>> write.table( RAIN_TABLE, "Dar_es_Salaam.txt", row.names = FALSE, 
>> col.names = c( "Valid Forecast Time",  "Rain (mm)", sep = "\t " )
>> 
>> # But no lucky with the red bolded syntax as I end up with the following 
>> error message> RAINC <- ncvar_get( inp_file, varid = "RAINC", start  = c( 
>> Lon[2], Lat[2], 1 ), count = c( 1, 1, -1 ) )
>> Error in Rsx_nc4_get_vara_double: NetCDF: Index exceeds dimension bound
>> Var: RAINC  Ndims: 3   Start: 0,4294967289,38 Count: 17,1,1
>> Error in ncvar_get_inner(ncid2use, varid2use, nc$var[[li]]$missval, 
>> addOffset,  : 
>>  C function R_nc4_get_vara_double returned error
>> However when I cahnge the latitude to postive it works fine. Note latitudes 
>> in the file data ranges from -16.71505 to 7.787529 as shown below;
>> head(ncvar_get(inp_file, "XLAT"))
>> [1] -16.71505 -16.71505 -16.71505 -16.71505 -16.71505 -16.71505
>>> tail(ncvar_get(inp_file, "XLAT"))
>> [1] 7.787529 7.787529 7.787529 7.787529 7.787529 7.787529
>> ## So, how can I get the syntax correct? Please help _
>> Peter  E. Tuju
>> Dar es Salaam
>> T A N Z A N I A
>> --
>> 
>> 
>> 
>> 
>> 
>>  [[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.
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Extracting point data using longitude and latitude from netcdf file using R

2016-01-09 Thread Ben Tupper
Hi,

Well, you have to extrapolate from that post that wherenearest is a function 
you must create on your own.  Maybe something like this?

#' Find the index into a dataset that is 'closest' to a specified point.
#' 
#' Adpated from https://stat.ethz.ch/pipermail/r-help/2011-March/272641.html
#' @param myPoint numeric, one point
#' @param allpoints numeric, one or more points
#' @return index into allPoints that myPoint falls closest to
wherenearest <- function(myPoint, allPoints){
d <- abs(allPoints-myPoint[1])
index <- which.min(d)
return( index )
}

I haven't tried the above.

You haven't provided much detail on what's in the file, but if it is a grid 
then perhaps you would find it easier to use the raster package.  It has 
functions to read gridded data stored in ncdf files.  It comes with a very good 
tutorial and makes working with gridded data a breeze. Using raster, you can 
bypass the nitty-gritty of getting data out of a ncdf file and just get to work 
on your data.

https://cran.r-project.org/web/packages/raster/index.html 
https://cran.r-project.org/web/packages/raster/vignettes/Raster.pdf

Bon chance!
Ben

P.S.  Do yourself (and everyone else on the list) a favor by making your email 
client use plain text rather than html or rich text when sending messages to 
the list.  The html/rich text scrambles your code making it hard to read.

> On Jan 9, 2016, at 9:01 AM, Peter Tuju  wrote:
> 
> Thank you Be for the good guide, however no luck with the syntax used namely;
> 
> ix0 = wherenearest( lower_left_lon_lat[1],  lon )
> ix1 = wherenearest( upper_right_lon_lat[1], lon )
> iy0 = wherenearest( lower_left_lon_lat[2],  lat )
> iy1 = wherenearest( upper_right_lon_lat[2], lat )
> 
> # I end up with this error,  "Error: could not find function "wherenearest"
> 
> Is there any other way I can get the index corresponding/or rearing to the
> longitude and latitude of interests?
>  
> _
> Peter  E. Tuju
> Dar es Salaam
> T A N Z A N I A
> --
> 
> 
> 
> From: Ben Tupper 
> To: "r-help@r-project.org"  
> Cc: Peter Tuju 
> Sent: Saturday, January 9, 2016 4:01 PM
> Subject: Re: [R] Extracting point data using longitude and latitude from 
> netcdf file using R
> 
> Hi,
> 
> This post gives more details on how to transform your lat/lon values to 
> row/column indices. The question and answer are specifically about the ncdf 
> package, but the workflow is identical when using the ncfd4 package.
> 
> https://stat.ethz.ch/pipermail/r-help/2011-March/272641.html
> 
> Cheers,
> Ben
> 
> > On Jan 9, 2016, at 7:14 AM, Anthoni, Peter (IMK)  
> > wrote:
> > 
> > Hi Peter,
> > 
> > the start in nc_varget requires a latitude and longitude index, not the 
> > latitude and longitude in double format.
> > So you need to figure out what index your latitude and longitude correspond 
> > to, which will depends on what data are in your netCDF.
> > 
> > it might have looked like that it worked for a positive latitude, but you 
> > got the data from the latitude index 6 or 7, depends on how the double was 
> > transformed into an integer.
> > 
> > best regards
> > Peter
> > 
> >> On 09 Jan 2016, at 12:28, Peter Tuju via R-help  
> >> wrote:
> >> 
> >> I have data file in netcdf with three dimensions (x, y, t) and I want to 
> >> extract a variable RAINC and RAINNC 
> >> using longitude and latitude for a single point location with all the 
> >> time, but no lucky. The syntax is as follows;;
> >> setwd( "/run/media/tuju/0767090047/extract_wrf_txt_file" )
> >> rm( list = ls() )  
> >> library( ncdf4 )
> >> inp_file <- nc_open( "wrfout_d01_2016-01-07.nc" )time <- ncvar_get( 
> >> inp_file, "Times" )  # Reading the time 
> >> variabledar_lon <- 39.2dar_lat <- -6.87
> >> RAINC <- ncvar_get( inp_file, varid = "RAINC", start  = c( dar_lon, 
> >> dar_lat, 1 ), count = c( 1, 1, -1 ) )
> >> RAINNC <- ncvar_get( inp_file, varid = "RAINNC", start  =  c( dar_lon, 
> >> dar_lat, 1 ), count = c( 1, 1, -1 ) )
> >> RAIN <- RAINC + RAINNCRAIN_TABLE <- cbind( time, RAIN )
> >> write.table( RAIN_TABLE, "Dar_es_Salaam.txt", row.names = FALSE, 
> >>col.names = c( "Valid Forecast Time",  "Rain (mm)", sep = "\t " 
> >> )
> >> 
> >> # But no lucky with the red bolded synta

Re: [R] EXTRACT POINT DATA FROM NETCDF FILE

2016-01-15 Thread Ben Tupper
Hello Peter,

It's not possible to help you resolve your difficulties with what you have 
shared. How we know what is mean to 'have no luck'?  What you need to do is 
provide a reproducible example - something anyone with R might be able to 
replicate.  Here is some terrific advice on how to make it easy for people to 
help you.

http://adv-r.had.co.nz/Reproducibility.html

In addition to the above, can you type at the R command line this...

> inp_file

And share the complete output.

Ben

> On Jan 15, 2016, at 9:16 AM, Peter Tuju  wrote:
> 
> Daer R, usersI want to get a point data from netcdf file using the longitude 
> and latitude, 
> but have no luck with the code I'm using. Here is the code. Please help!
> 
> rm( list = ls() )   # Clearing 
> the workspace
> setwd( "/run/media/tuju/0767090047/extract_wrf_txt_file" )
> library( ncdf4 )   # Loading the ncdf4 
> package to read the netcdf data
> library(ncdf)
> inp_file <- open.ncdf( "wrfout_d01_2015-12-30.nc" )  # Reading the netcdf 
> data
> time <- get.var.ncdf( inp_file, "Times" ) # Extracting the 
> forecasts time
> 
> sites <- read.csv("Station_Coordinates_TMA.csv", sep = "\t")
> attach(sites)
> 
> source( "whereis.R" )
> lat = get.var.ncdf(inp_file, "XLAT")  
> lon = get.var.ncdf(inp_file, "XLONG")
> 
> lower_left_lon_lat = c( 22, -16 )
> upper_right_lon_lat = c( 56, 7 )
> 
> ix0 = wherenearest( lower_left_lon_lat[1],  lon )
> ix1 = wherenearest( upper_right_lon_lat[1], lon )
> iy0 = wherenearest( lower_left_lon_lat[2],  lat )
> iy1 = wherenearest( upper_right_lon_lat[2], lat )
> 
> countx = ix1 - ix0 + 1
> county = iy1 - iy0 + 1
> 
> rainc = get.var.ncdf( inp_file, "RAINC", start = c( ix0, iy0, 1 ), count = c( 
> countx, county, 1 ))
>  _
> Peter  E. Tuju
> Dar es Salaam
> T A N Z A N I A
> --

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Reading a tab delimted file of varying length using read.table

2016-01-17 Thread Ben Tupper
Hi Pradeep,

Any software would be challenged to determine the boundaries between your 
columns.

ff <- 'http://data.princeton.edu/wws509/datasets/divorce.dat'
txt <- readLines(ff)
head(txt)
# [1] "   idheduc   heblack   mixed years   div  " "   9   
12-15 yearsNo  No10.546No  "
# [3] "  11< 12 yearsNo  No34.943No  " "  13
< 12 yearsNo  No 2.834   Yes  "
# [5] "  15< 12 yearsNo  No17.532   Yes  " "  33   
12-15 yearsNo  No 1.418No  

You don't have tab delimiters but instead have space delimiters (well sort of). 
 Your second column has either one ("12-15 years") or two ("< 12 years") spaces 
embedded in the values.  That will mess up any scheme using spaces to delineate 
the columns.  

Perhaps you can read this as fixed width - see ?read.fwf - but you'll have to 
fiddle with the width specifications.

Cheers,
Ben


> On Jan 17, 2016, at 10:31 AM, Pradeep Bisht  
> wrote:
> 
> Hello Experts  ,
> 
> Being a SAS developer I am finding it difficult to perform some of data
> cleaning in R that are quite easy to perform in SAS .
> 
> I have been trying to read a .dat file and after a lot of attempts have
> failed to find a solution . Maybe R doesn't have the functionality right
> now or I am not looking in the right place . Here is my code .
> 
> f5=read.table("http://data.princeton.edu/wws509/datasets/divorce.dat
> <http://www.linkedin.com/redir/redirect?url=http%3A%2F%2Fdata%2Eprinceton%2Eedu%2Fwws509%2Fdatasets%2Fdivorce%2Edat&urlhash=GVbR&_t=tracking_anet>
> ",
> header=T,
> sep="\t",
> colClasses = c("numeric", "character", "character","character", "double",
> "character" ) )
> The error i get i
> ​s​
> this .
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
> :
> scan() expected 'a real', got '912-15yearsNoNo10.546No'
> 
> Also does read.table always calls scan in background to do its job . If so
> why use read.table in first place .
> 
> Pradeep​
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Basic Problem with Data Input

2016-02-07 Thread Ben Tupper
Hi,

Using the full path specification, as you have done in your second example, is 
a good idea.   Have you tried forward slashes?  If I am reading the docs 
correctly you should be able to use either forward or back slashes.  I haven't 
used R in Windows for ages, but my memory is that switching to forward slashes 
skirted any troublesome issues.  Try this...

filename <- "C:/Program Files/R/R-3.2.3/Appendix/DATA1.txt"
if (file.exists(filename)){
X <- scan(file = filename, what = double())
} else {
cat('file not found\n')
}

Here's the doc page...

https://cran.r-project.org/doc/manuals/r-release/R-intro.html#OS-facilities

Ben

> On Feb 7, 2016, at 3:23 PM, Walter Niessen  wrote:
> 
> Helpers,
> 
> I am a pretty savvy computer user (over 40 years) but am having trouble with 
> the most basic process in using the R program.  I am taking a course to learn 
> the statistics utility of “R” but can’t seem to get past the opening where it 
> shows the student how to input data into R.
> 
> It suggests identifying as the a target folder in the Properties of the R x64 
> 3.2.3 icon (I use a 64-bit Windows 7 OS) the location where data files are 
> found. I entered: 
> 
> As the Target:  "C:\Program Files\R\R-3.2.3\bin\x64\Rgui.exe"  ... which 
> contains Rgui.exe and the supporting dlls etc.
> 
> As the Start in: "C:\Program Files\R\R-3.2.3\Appendix" ... where Appendix is 
> a folder which contains data files such as the text file DATA1.txt which I 
> created from an Excel file.
> 
> When I try and get R to input the data, I get the following sequence of 
> messages:
> 
> 
>> X=scan("DATA1.txt")
> Error in file(file, "r") : cannot open the connection
> In addition: Warning message:
> In file(file, "r") :
>  cannot open file 'DATA1.txt': No such file or directory
> 
> When I try again but use the complete file description, I get:
> 
> X=scan("C:\Program Files\R\R-3.2.3\Appendix\DATA1.txt")
> Error: '\P' is an unrecognized escape in character string starting ""C:\P"
> 
> I hate to ask a question not related to R or its features (that may come 
> later), but, clearly, the first baby step is to be able to load data into the 
> application . . . and, I am really frustrated with my inability to do so.  I 
> apologize for this but really need to get past this business to jump into the 
> REAL use of R.
> 
> Can you help?
> 
> Walt
> 
> Walter R. Niessen
> (978) 470-4622
> 
> P.S. I apologize, but I sent the first “edition” a few minutes ago without a 
> Subject and not quite finished up.
> 
> 
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Variable Argument Function

2016-02-07 Thread Ben Tupper
Hi,

> On Feb 7, 2016, at 6:24 PM, Duncan Murdoch  wrote:
> 
> On 07/02/2016 6:12 PM, Robert Sherry wrote:
>> 
>> I would like to write a function in R that would take a variable number
>> of integers as parameters. I do not have a pressing reason to do this, I
>> am just trying to learn R. I thought a good first step would be to print
>> out the arguments. So I wrote the following function:
>> 
>> f1 = function (...)
>> {
>>  list1 = as.list(...)
> 
> This is wrong.  The ... object is weird; it's not something that can be 
> coerced to a list.  However, you can pass it as list(...) and it will give 
> you what you were expecting.
> 

Do you mean that Bob should nest a function within f1?  Like this?

f1 = function (...){
   f2 <- function(list1){
  for( i in 1:length(list1) ) cat( "i is ", list1[[i]], "\n" )
  return (0)
}
f2(list(...))
}

f1(2,4,10,12)

> f1(2,4,10,12)
i is  2 
i is  4 
i is  10 
i is  12 

Ben


> The theory is that it will expand to multiple arguments to the list() 
> function, which constructs a list containing them.  as.list() doesn't want a 
> bunch of arguments, it will just ignore most of them.
> 
> Duncan Murdoch
> 
>>  for( i in 1:length(list1) )
>>  cat( "i is ", list1[[i]], "\n" )
>>  return (0)
>> }
>> 
>> I ran it as:
>>  f1(2,4,10,12)
>> and I get:
>>  i is  2
>>  [1] 0
>> I was hoping for
>>  i is  2
>>  i is  4
>>  i is  10
>>  i is  12
>> 
>> I am hoping somebody can tell me what I am doing wrong. Is using a list
>> a bad idea?
>> 
>> Thanks
>> Bob
>> 
>> __
>> 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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Split a character string with two separators

2016-02-18 Thread Ben Tupper
Hi,

Will substring work for you?  

?substring

Cheers,
Ben

> On Feb 18, 2016, at 12:36 PM, Marine Regis  wrote:
> 
> Hello,
> 
>> From this character string:
> 
> test <-"k0298_7832_8964"
> 
> how can I obtain:
> 
> [[1]]
> 
> "0298"
> 
> Thank you very much for your help.
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] KNN

2016-02-25 Thread Ben Tupper
Hi,

Do the knn() or knn1() functions in the 'class' package serve your purpose?

https://cran.r-project.org/web/packages/class/index.html

Ben
 
> On Feb 25, 2016, at 9:49 AM, David L Carlson  wrote:
> 
> Perhaps Alnazer is trying to implement "majority vote" kNN:
> 
>> From Wikipedia
> (https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm):
> 
> In k-NN classification, the output is a class membership. An object is 
> classified by a majority vote of its neighbors, with the object being 
> assigned to the class most common among its k nearest neighbors (k is a 
> positive integer, typically small). If k = 1, then the object is simply 
> assigned to the class of that single nearest neighbor.
> 
> But as Jim said, your function does not do this. It does not even run kNN. 
> 
> -
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon
> Sent: Thursday, February 25, 2016 4:15 AM
> To: Alnazer Elbedairy
> Cc: r-help mailing list
> Subject: Re: [R] KNN
> 
> Hi Alnazer,
> I'm not surprised that it didn't do what you expected. Even if I clean
> up the code so that it will actually run:
> 
> majorityGuessing<-function(trainingData,categories) {
> GuessMPG<-sample(1:length(categories),nrow(trainingData),replace=TRUE)
> return(GuessMPG)
> }
> 
> and call it like this (assuming that you are trying to do something
> like guessing MPG from the number of cylinders):
> 
> auto<-read.csv("auto.csv")
> majorityGuessing(auto$MPG,unique(auto$CYLINDERS))
> 
> the result is just a sample of 398 integers ranging from 1 to 5, which
> is not even a guess. Unfortunately, I can't work out what metric you
> want to select "nearest neighbors", but perhaps someone else can.
> 
> Jim
> 
> On Thu, Feb 25, 2016 at 5:30 PM, Alnazer Elbedairy
>  wrote:
>> Dear Jim
>> thanks you for your kind help.
>> KNN - is K- Nearest Neighbor, is a technique used in Machine Learning.
>> attached you will find a CSV file dataset, my question is :
>> use the attached Dataset, Use majority guessing technique to evaluate KNN ?
>> this is the solution I came up with, but I didn't work :-
>> majorityGuessing <- function(trainingData,categories)
>> {GuessMPG <- sample(1:length (categories-1, nrow(testingData),replace=T)
>> return(GuessMPG)
>> 
>> 
>> 
>> On Wed, Feb 24, 2016 at 8:18 PM, Jim Lemon  wrote:
>>> 
>>> Hi Alnazar,
>>> I looked at your question yesterday and was unable to find what a
>>> "majority guessing" function is. I think it may be related to the
>>> "Pandemonium" model of decision making, but that doesn't get me very
>>> far. Could you give us a hint as to what this function is?
>>> 
>>> 
>> 
>> On Wed, Feb 24, 2016 at 8:18 PM, Jim Lemon  wrote:
>>> 
>>> Hi Alnazar,
>>> I looked at your question yesterday and was unable to find what a
>>> "majority guessing" function is. I think it may be related to the
>>> "Pandemonium" model of decision making, but that doesn't get me very
>>> far. Could you give us a hint as to what this function is?
>>> 
>>> Jim
>>> 
>>> 
>>> On Wed, Feb 24, 2016 at 7:02 AM, Alnazer 
>>> wrote:
>>>> How I can use majority guessing function to evaluate KNN, if I have data
>>>> saved in CSV file
>>>> 
>>>> Alnazer Elbedairy
>>>> 
>>>> __
>>>> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Get object name inside lapply

2016-02-25 Thread Ben Tupper
Hi,

Using your example (note I called the list 'z')...

z <-list(a = seq(1:5), b = seq(10:20))

I picture lapply as extracting each element of z like this z[[i]] - the `[[` 
extracts the ith value from the context of residing in a list - hence it's name 
is 'lost' in the new context.  That's different than z[i] which extracts a list 
of elements.  Try..

z[['a']]  vs. z['a']

As an alternative and depending upon what you really want to do, you could 
iterate through the names of the list, and pass the list as a parameter.  

r <- lapply(names(z),
function(nm, dat = NULL){
sprintf("%s has %i elements", nm, length(dat[[nm]]) )
},
dat = z)
r
[[1]]
[1] "a has 5 elements"

[[2]]
[1] "b has 11 elements"

Ben

> On Feb 25, 2016, at 4:27 PM, Mohammad Tanvir Ahamed via R-help 
>  wrote:
> 
> Hello, 
> 
> I want to get object name of a list inside lapply 
> 
>> c<-list(a=seq(1:5),b=seq(10:20)) 
>> lapply(c,names) 
> $a 
> NULL 
> 
> $b 
> NULL 
> 
> Why NULL ? 
> 
> but i am expecting the names of object . Any help will be appreciated . 
> 
> I want to grab the names of object inside lapply for further process. 
> 
> Thanks . 
> 
> 
> Tanvir Ahamed 
> Göteborg, Sweden  |  mashra...@yahoo.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.

__
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] source() is 'bombing'

2016-03-01 Thread Ben Tupper
Hi,

I'm a little fuzzy on what a bomb is in this context, but the source() function 
expects the input argument to be either a connection object or character 
string.  See ...

?source

Try enclosing you filename with quotes.

Cheers,
Ben


> On Mar 1, 2016, at 11:29 AM, MAURICE Jean - externe 
>  wrote:
> 
> Hi,
> 
> This morning, we transfered 2 R files into Git because someone else is going 
> to work with me. A file is the 'main script' and the second contains the 
> functions.
> I had problem with the encoding of this second file : French accent were 
> replaced by question mark. Without Git, I could 'reopen with encoding' but 
> with Git, it doesn't work. I tried a lot of things in vain. At the end, I 
> deleted the whole content of the file and paste in it a copy of the same file 
> but in my own directory after a reopen with encoding. I save and commit all; 
> Quit R; restart the PC and open the Git project : all seems ok.
> 
> I have asked a question about 'starting directory' but waiting for an answer 
> I write the directory name in the code like :
> 
> Source(c:/RepoGit/ /plateforme.r)
> 
> But when this line is executed a bomb appears.
> I tried to add a encoding clause : in vain
> 
> I looked at the windows rights, they are the same for both files ...
> 
> I added a test.r file in the directory, I can 'source' it ...
> 
> The second person can source the second file on her PC,
> 
> I'am lost ! If someone has an idea ...
> 
> Jean
> 
> 
> 
> 
> Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis 
> à l'intention exclusive des destinataires et les informations qui y figurent 
> sont strictement confidentielles. Toute utilisation de ce Message non 
> conforme à sa destination, toute diffusion ou toute publication totale ou 
> partielle, est interdite sauf autorisation expresse.
> 
> Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le 
> copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. 
> Si vous avez reçu ce Message par erreur, merci de le supprimer de votre 
> système, ainsi que toutes ses copies, et de n'en garder aucune trace sur 
> quelque support que ce soit. Nous vous remercions également d'en avertir 
> immédiatement l'expéditeur par retour du message.
> 
> Il est impossible de garantir que les communications par messagerie 
> électronique arrivent en temps utile, sont sécurisées ou dénuées de toute 
> erreur ou virus.
> 
> 
> This message and any attachments (the 'Message') are intended solely for the 
> addressees. The information contained in this Message is confidential. Any 
> use of information contained in this Message not in accord with its purpose, 
> any dissemination or disclosure, either whole or partial, is prohibited 
> except formal approval.
> 
> If you are not the addressee, you may not copy, forward, disclose or use any 
> part of it. If you have received this message in error, please delete it and 
> all copies from your system and notify the sender immediately by return 
> message.
> 
> E-mail communication cannot be guaranteed to be timely secure, error or 
> virus-free.
> __________
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Please guide -- Error during export in csv format

2016-03-21 Thread Ben Tupper
Hi,

You are defeating the purpose of the file.path() function by providing a path 
separator in the first argument; you used './', but try instead...

my.file1 <- file.path('.', paste0('likes','_',name,'_',grp_id,'.csv'))

Also, there appear to be spaces in the 'name' argument - that might be causing 
you an issue but it is hard to know.  You might try wrapping the value of 
my.file1 in quotes using shQuote() or maybe even dQuote() - I'm not sure as I 
am not on Windows.

Cheers,
Ben

> On Mar 21, 2016, at 7:53 AM, Sunny Singha  
> wrote:
> 
> Please guide,
> I'm exporting data in '.csv' format in the Windows user directory, I
> have full access to. The write operation happens within a for loop.
> 
> Each iteration exports data in csv format in the user directory. The
> issue is that the  data gets exported for all the 9 iterations but
> fails for 10th iteration giving below error message.
> 
> Error in file(file, ifelse(append, "a", "w")) :
>  cannot open the connection
> In addition: Warning message:
> In file(file, ifelse(append, "a", "w")) :
>  cannot open file './/posts_Hi nhng ngui
> dng hành cùng line_752518568125567.csv': Invalid argument
> Called from: file(file, ifelse(append, "a", "w"))
> 
> The export directory path is current directory with 'name' extracted as below:
> my.file1:  .//likes_Hi nhng ngui dng
> hành cùng line_752518568125567.csv
> my.file2:  .//posts_Hi nhng ngui dng
> hành cùng line_752518568125567.csv
> 
> I wondering if the error is due to the the complicated filename ?
> Below is the line of code I have used within loop to export data.
> 
>   my.file1 <- file.path('./', paste0('likes','_',name,'_',grp_id,'.csv'))
>my.file2 <- file.path('./', paste0('posts','_',name,'_',grp_id,'.csv'))
> 
>write.csv(posts_frame, file=my.file2, row.names = F)
>write.csv(likes_frame, file = my.file1, row.names = F)
> 
> Regards,
> Sunny
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Question about Imager

2016-03-25 Thread Ben Tupper
Hi,

I can't answer your collage question but I am very glad that you brought imager 
to my attention - it looks great.  

That said, you might give ImageJ or its cousin Fiji a look for the task you 
have.  There are hundreds of examples and a nice (easy!) macro language coupled 
to the user interface.

http://rsb.info.nih.gov/ij/
http://imagej.net/Fiji

Cheers,
Ben

> On Mar 25, 2016, at 2:11 PM, Jenny Vander Pluym - NOAA Federal 
>  wrote:
> 
> Hello!
> 
> I found the imager package but have a question. Is it possible to construct
> a collage or 4 images after resizing them?
> 
> I would like to batch make some collages (A LOT of them) and have only been
> able to automate certain steps of the process in Photoshop. I would like to
> be able to automate the process and save a lot of time and clicking.
> 
> Thank you for your time,
> 
> Jenny Vander Pluym
> 
> -- 
> Jenny Vander Pluym
> NOAA's National Centers for Coastal Ocean Science
> Research and Communications Specialist
> 101 Pivers Island Rd.
> Beaufort, NC 28516-9722 cell: 252.728.8777
> What is NCCOS up to? <http://coastalscience.noaa.gov/news/>
> 
> "The contents of this message are mine personally and do not necessarily
> reflect any position of the Government or the National Oceanic and
> Atmospheric Administration."
> 
> 
> 
> 
> -- 
> Jenny Vander Pluym
> NOAA's National Centers for Coastal Ocean Science
> Research and Communications Specialist
> 101 Pivers Island Rd.
> Beaufort, NC 28516-9722 cell: 252.728.8777
> What is NCCOS up to? <http://coastalscience.noaa.gov/news/>
> 
> "The contents of this message are mine personally and do not necessarily
> reflect any position of the Government or the National Oceanic and
> Atmospheric Administration."
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Using R for cURL commands

2016-04-01 Thread Ben Tupper
Hi,

Have you looked at httr?  I have been very happy using it with RESTful systems.

https://cran.r-project.org/web/packages/httr/index.html


Cheers,
Ben

> On Apr 1, 2016, at 10:05 AM, Martijn Broeks  wrote:
> 
> Hello,
> 
> 
> I'm looking for a way in which R can make my live easier.
> 
> Currently i'm using R convert data from a dataframe to json's and then 
> sending these json's to a rest api using a curl command in the terminal (i'm 
> on a mac).
> 
> 
> I've been looking for a way to use R for sending data from R to the rest api. 
> My primairy focus was on using R for executing the curl command, however, I'm 
> open to other approaches. The method I've been using so far:
> 
> 
> 
> I found some information online suggesting i'd use this code:
> 
> *js is a json from my R environment
> 
> 
> Library(RCurl)
> 
> postForm("https://MYWEBSITE.eu/api/v2/organisations/abc/projects/cosson/datasets/DATABASE";,
> 
> .opts = list(postfields = js,
> 
> httpheader = c('Content-Type' = 'application/json', Accept = 
> 'application/json'),
> 
> userpwd = "name:pwd",
> 
> ssl.verifypeer = FALSE))
> 
> (userpwd and url have been changed to hide sensitive information)
> 
> 
> This leads to the following error: "Error: Unauthorized". I've filled out the 
> correct username and password, but I can't figure out why I'm getting this 
> error. This is the curl command I'm using:
> 
> 
> curl -X POST -s --user "USERNAME:PASSWORD" -H "Content-type: application/xml" 
> -d...@test.json 
> "https://MYWEBSITE.eu/api/v2/organisations/abc/projects/cosson/datasets/DATABASE";
> 
> (userpwd and url have been changed to hide sensitive information)
> 
> 
> The json file is build up like this:
> 
> {\n\"ID\": 601,\n\"100-100\": 0 }
> 
> But this is a small part, the actual json contains 555 variables
> 
> 
> Thanks in advance for the help and let me know if something is unclear.
> 
> 
> 
> Disclaimer | The information transmitted is intended only for use by the 
> addressee and may contain confidential and/or privileged material. Any 
> review, retransmission, dissemination or other use of it, or the taking of 
> any action in reliance upon this information by persons and/or entities other 
> than the intended recipient is prohibited. If you received this in error, 
> please inform the sender and/or addressee immediately and delete the 
> material. Thank you.
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] installation of dplyr

2016-04-19 Thread Ben Tupper
Hello,

I am getting a fresh CentOS 6.7 machine set up with all of the goodies for R 
3.2.3, including dplyr package. I am unable to successfully install it.  Below 
I show the failed installation using utils::install.packages() and then again 
using devtools::install_github().  Each yields an error similar to the other 
but not quite exactly the same - the error messages sail right over my head.

I can contact the package author if that would be better, but thought it best 
to start here.

Thanks!
Ben

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base   
  



#   utils::install.packages()


> install.packages("dplyr", repo = "http://cran.r-project.org";)
Installing package into ‘/usr/lib64/R/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.r-project.org/src/contrib/dplyr_0.4.3.tar.gz'
Content type 'application/x-gzip' length 655997 bytes (640 KB)
==
downloaded 640 KB

* installing *source* package ‘dplyr’ ...
** package ‘dplyr’ successfully unpacked and MD5 sums checked
** libs
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c RcppExports.cpp -o 
RcppExports.o
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c address.cpp -o address.o
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c api.cpp -o api.o
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c arrange.cpp -o arrange.o
In file included from ../inst/include/dplyr.h:131,
 from arrange.cpp:1:
../inst/include/dplyr/DataFrameSubsetVisitors.h: In constructor 
‘dplyr::DataFrameSubsetVisitors::DataFrameSubsetVisitors(const 
Rcpp::DataFrame&, const Rcpp::CharacterVector&)’:
../inst/include/dplyr/DataFrameSubsetVisitors.h:40: warning: ‘column’ may be 
used uninitialized in this function
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c between.cpp -o between.o
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c bind.cpp -o bind.o
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c combine_variables.cpp -o 
combine_variables.o
g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
-I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
-I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m64 -mtune=generic  -c distinct.cpp -o distinct.o
g++ -m64 -I/usr/include/R -

Re: [R] installation of dplyr

2016-04-19 Thread Ben Tupper
Hi,

OK - that can be fixed by our IT whizzes.  

Thanks,
Ben

P.S.  Thanks for dplyr!

> On Apr 19, 2016, at 4:10 PM, Hadley Wickham  wrote:
> 
> You normally see these errors when compiling on a vm that has very
> little memory.
> Hadley
> 
> On Tue, Apr 19, 2016 at 2:47 PM, Ben Tupper  wrote:
>> Hello,
>> 
>> I am getting a fresh CentOS 6.7 machine set up with all of the goodies for R 
>> 3.2.3, including dplyr package. I am unable to successfully install it.  
>> Below I show the failed installation using utils::install.packages() and 
>> then again using devtools::install_github().  Each yields an error similar 
>> to the other but not quite exactly the same - the error messages sail right 
>> over my head.
>> 
>> I can contact the package author if that would be better, but thought it 
>> best to start here.
>> 
>> Thanks!
>> Ben
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>>> sessionInfo()
>> R version 3.2.3 (2015-12-10)
>> Platform: x86_64-redhat-linux-gnu (64-bit)
>> Running under: CentOS release 6.7 (Final)
>> 
>> locale:
>> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>> [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>> [9] LC_ADDRESS=C   LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>> 
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>> 
>> 
>> 
>> 
>> #   utils::install.packages()
>> 
>> 
>>> install.packages("dplyr", repo = "http://cran.r-project.org";)
>> Installing package into ‘/usr/lib64/R/library’
>> (as ‘lib’ is unspecified)
>> trying URL 'http://cran.r-project.org/src/contrib/dplyr_0.4.3.tar.gz'
>> Content type 'application/x-gzip' length 655997 bytes (640 KB)
>> ==
>> downloaded 640 KB
>> 
>> * installing *source* package ‘dplyr’ ...
>> ** package ‘dplyr’ successfully unpacked and MD5 sums checked
>> ** libs
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c RcppExports.cpp -o 
>> RcppExports.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c address.cpp -o address.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c api.cpp -o api.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c arrange.cpp -o arrange.o
>> In file included from ../inst/include/dplyr.h:131,
>> from arrange.cpp:1:
>> ../inst/include/dplyr/DataFrameSubsetVisitors.h: In constructor 
>> ‘dplyr::DataFrameSubsetVisitors::DataFrameSubsetVisitors(const 
>> Rcpp::DataFrame&, const Rcpp::CharacterVector&)’:
>> ../inst/include/dplyr/DataFrameSubsetVisitors.h:40: warning: ‘column’ may be 
>> used uninitialized in this function
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c between.cpp -o between.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/

Re: [R] installation of dplyr

2016-04-20 Thread Ben Tupper
Increasing memory resolved the issue for me.

Thanks again,
Ben

> On Apr 19, 2016, at 4:10 PM, Hadley Wickham  wrote:
> 
> You normally see these errors when compiling on a vm that has very
> little memory.
> Hadley
> 
> On Tue, Apr 19, 2016 at 2:47 PM, Ben Tupper  wrote:
>> Hello,
>> 
>> I am getting a fresh CentOS 6.7 machine set up with all of the goodies for R 
>> 3.2.3, including dplyr package. I am unable to successfully install it.  
>> Below I show the failed installation using utils::install.packages() and 
>> then again using devtools::install_github().  Each yields an error similar 
>> to the other but not quite exactly the same - the error messages sail right 
>> over my head.
>> 
>> I can contact the package author if that would be better, but thought it 
>> best to start here.
>> 
>> Thanks!
>> Ben
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>>> sessionInfo()
>> R version 3.2.3 (2015-12-10)
>> Platform: x86_64-redhat-linux-gnu (64-bit)
>> Running under: CentOS release 6.7 (Final)
>> 
>> locale:
>> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>> [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>> [9] LC_ADDRESS=C   LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>> 
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>> 
>> 
>> 
>> 
>> #   utils::install.packages()
>> 
>> 
>>> install.packages("dplyr", repo = "http://cran.r-project.org";)
>> Installing package into ‘/usr/lib64/R/library’
>> (as ‘lib’ is unspecified)
>> trying URL 'http://cran.r-project.org/src/contrib/dplyr_0.4.3.tar.gz'
>> Content type 'application/x-gzip' length 655997 bytes (640 KB)
>> ==
>> downloaded 640 KB
>> 
>> * installing *source* package ‘dplyr’ ...
>> ** package ‘dplyr’ successfully unpacked and MD5 sums checked
>> ** libs
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c RcppExports.cpp -o 
>> RcppExports.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c address.cpp -o address.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c api.cpp -o api.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c arrange.cpp -o arrange.o
>> In file included from ../inst/include/dplyr.h:131,
>> from arrange.cpp:1:
>> ../inst/include/dplyr/DataFrameSubsetVisitors.h: In constructor 
>> ‘dplyr::DataFrameSubsetVisitors::DataFrameSubsetVisitors(const 
>> Rcpp::DataFrame&, const Rcpp::CharacterVector&)’:
>> ../inst/include/dplyr/DataFrameSubsetVisitors.h:40: warning: ‘column’ may be 
>> used uninitialized in this function
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 
>> -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" 
>> -I"/usr/lib64/R/library/BH/include"   -fpic  -O2 -g -pipe -Wall 
>> -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
>> --param=ssp-buffer-size=4 -m64 -mtune=generic  -c between.cpp -o between.o
>> g++ -m64 -I/usr/include/R -DNDEBUG -I../inst/include -DCOMPILING_DPLYR 

Re: [R] Could not find function "pointsToRaster"

2016-04-30 Thread Ben Tupper
Hi,

A terrific resource for this type of issue (and pretty much anything related to 
R) is http://rseek.org/  I'm sure I use it at least daily.  Check out ...

http://rseek.org/?q=pointsToRaster

The first hit is about pointsToRaster() - it has been replaced by 
raster::rasterize()

Cheers,
Ben

> On Apr 30, 2016, at 4:28 AM, Ogbos Okike  wrote:
> 
> Dear All,
> I have a script that draws longitude and latitude of lightning
> occurrence. This script was running fine before. But when I changed my
> system and do a fresh install on another laptop, this error persist.
> source("script")
> Error in eval(expr, envir, enclos) :
>  could not find function "pointsToRaster"
> 
> I have tried to see if  there is any other package I need to install
> to take of the problem, I could not see. Already, when I installed
> raster, it installed its dependencies such as sp.
> Can any body please bail me out.
> 
> Thanks
> Ogbos
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Could not find function "pointsToRaster"

2016-04-30 Thread Ben Tupper
Hi,

I think you need to check the order of your arguments to rasterize().  See the 
documentation with ?rasterize and compare to what you did below.

Cheers,
Ben

 
> On Apr 30, 2016, at 9:55 AM, Ogbos Okike  wrote:
> 
> Dear All,
> Thanks for your inputs. I did replace pointsToRaster () with
> raster::rasterize(). Below is part of my script.
> 
> But I got another error:
> Error in (function (classes, fdef, mtable)  :
>  unable to find an inherited method for function ‘rasterize’ for
> signature ‘"RasterLayer", "matrix"’
> 
> Thank you for more inputs.
> Ogbos
> 
> k<-read.table("Lat05w3.txt")
> colnames(k)<-c("y","x")
> xy<-cbind(k$x,k$y)
> library(raster)
> r<-raster()
> #library(sp)
> pr<-raster::rasterize(r,xy)
> 
> #pr<-pointsToRaster(r,xy)
> 
> library(maps)
> w = map("world")
> wc = cbind(w$x, w$y)
> wc=wc[!is.na(wc[,1]),]
> write.table(wc, file = "my.fileb", sep=" ",row=FALSE,col=FALSE)
> my<-read.table("my.out",col.names=c("a","b"))
> rena = function(X,Z){
> Y=rep(NA,length(X))
> Y[!is.na(X)]=Z
> Y
> }
> 
> 
> 
> 
> On 4/30/16, Ben Tupper  wrote:
>> Hi,
>> 
>> A terrific resource for this type of issue (and pretty much anything related
>> to R) is http://rseek.org/  I'm sure I use it at least daily.  Check out
>> ...
>> 
>> http://rseek.org/?q=pointsToRaster
>> 
>> The first hit is about pointsToRaster() - it has been replaced by
>> raster::rasterize()
>> 
>> Cheers,
>> Ben
>> 
>>> On Apr 30, 2016, at 4:28 AM, Ogbos Okike 
>>> wrote:
>>> 
>>> Dear All,
>>> I have a script that draws longitude and latitude of lightning
>>> occurrence. This script was running fine before. But when I changed my
>>> system and do a fresh install on another laptop, this error persist.
>>> source("script")
>>> Error in eval(expr, envir, enclos) :
>>> could not find function "pointsToRaster"
>>> 
>>> I have tried to see if  there is any other package I need to install
>>> to take of the problem, I could not see. Already, when I installed
>>> raster, it installed its dependencies such as sp.
>>> Can any body please bail me out.
>>> 
>>> Thanks
>>> Ogbos
>>> 
>>> __
>>> 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.
>> 
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>> 
>> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] projectRaster function no values

2016-05-18 Thread Ben Tupper
, -102.43234,
> -102.29720, -102.16207, -102.02693, -101.89180, -101.75666, -101.62153,
> -101.48639, -101.35126, -101.21612, -101.08099, -100.94585, -100.81072,
> -100.67558, -100.54045, -100.40531, -100.27018, -100.13504,  -99.1,
> -99.86477, -99.72964, -99.59450, -99.45937, -99.32423, -99.18910,
> -99.05396, -98.91883, -98.78369, -98.64856, -98.51342, -98.37829,
> -98.24315, -98.10802, -97.97288, -97.83775, -97.70261, -97.56748,
> -97.43234, -97.29721, -97.16207, -97.02694, -96.89180, -96.75667,
> -96.62153, -96.48640, -96.35126, -96.21613, -96.08099, -95.94586,
> -95.81072, -95.67559, -95.54045, -95.40532, -95.27018, -95.13505,
> -94.1, -94.86478, -94.72964, -94.59451, -94.45937, -94.32424,
> -94.18910, -94.05397, -93.91883, -93.78370, -93.64856, -93.51343,
> -93.37829, -93.24316, -93.10802, -92.97289, -92.83775, -92.70262,
> -92.56748, -92.43235, -92.29721, -92.16208, -92.02694, -91.89181,
> -91.75667, -91.62154, -91.48640, -91.35127, -91.21613, -91.08100,
> -90.94586, -90.81073, -90.67559, -90.54046, -90.40532, -90.27019,
> -90.13505, -89.2, -89.86478, -89.72965, -89.59451, -89.45938,
> -89.32424, -89.18911, -89.05397, -88.91884, -88.78370, -88.64857,
> -88.51343, -88.37830, -88.24316, -88.10803, -87.97289, -87.83776,
> -87.70262, -87.56749, -87.43235, -87.29722, -87.16208, -87.02695,
> -86.89181, -86.75668, -86.62154, -86.48641, -86.35127, -86.21614,
> -86.08100, -85.94587, -85.81073, -85.67560, -85.54046, -85.40533,
> -85.27019, -85.13506, -84.2, -84.86479, -84.72965, -84.59452,
> -84.45938, -84.32425, -84.18911, -84.05398, -83.91884, -83.78371,
> -83.64857, -83.51344, -83.37830, -83.24317, -83.10803, -82.97290,
> -82.83776, -82.70263, -82.56749, -82.43236, -82.29722, -82.16209,
> -82.02695, -81.89182, -81.75668, -81.62155, -81.48641, -81.35128,
> -81.21614, -81.08101, -80.94587, -80.81074, -80.67560, -80.54047,
> -80.40533, -80.27020, -80.13506, -79.3, -79.86479, -79.72966,
> -79.59452, -79.45939, -79.32425, -79.18912, -79.05398, -78.91885,
> -78.78371, -78.64858, -78.51344, -78.37831, -78.24317, -78.10804,
> -77.97290, -77.83777, -77.70263, -77.56750, -77.43236, -77.29723,
> -77.16209, -77.02696, -76.89182, -76.75669, -76.62155, -76.48642,
> -76.35128, -76.21615, -76.08101, -75.94588, -75.81074, -75.67561,
> -75.54047, -75.40534, -75.27020, -75.13507, -74.3, -74.86480,
> -74.72966, -74.59453, -74.45939, -74.32426, -74.18912, -74.05399)
> 
>> extent(newlocs) = c(min(newlon),max(newlon),min(newlat),max(newlat)) #
> dummy raster put to the right extent
> 
>> testproj2 = projectRaster(from=testvar2,to=newlocs,method="bilinear") #
> project raster itself
> 
>> testproj2 # literally no values.
> class   : RasterLayer
> dimensions  : 113, 215, 24295  (nrow, ncol, ncell)
> resolution  : 0.1345065, 0.1339391  (x, y)
> extent  : -102.9729, -74.05399, 25.13511, 40.27023  (xmin, xmax, ymin,
> ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names   : Avg.Max.Aneom.Temperature
> values  : NA, NA  (min, max)
> 
> 
> I'm quite perplexed with this one, I feel like I'm doing everything right
> so I'm not sure what's failing.  The R version is R 3.2.3 in a Linux/Unix
> environment.
> 
> Many thanks for your help!
> 
> Adrienne
> -- 
> Adrienne Wootten
> Ph.D Candidate / Graduate Research Assistant
> State Climate Office of North Carolina
> Department of Marine, Earth and Atmospheric Sciences
> North Carolina State University
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] lattice: control panel extent on device

2016-10-25 Thread Ben Tupper
Hello,

I am drawing a levelplot and an xyplot on a single device as shown in the 
runnable example below.  I would like the x axes to align - that is for them to 
cover the same extent left-to-right on the device. How do I go about doing that?

###
# START
###
library(lattice)

d <- dim(volcano)
xy <- data.frame(x = 1:d[1], y = volcano[,30] )

vol_p <- levelplot(volcano)
xy_p <- xyplot(y ~ x, data = xy)

print(vol_p, split = c(1, 2, 1, 2), more = TRUE)
print(xy_p,  split = c(1, 1, 1, 2), more = FALSE)
##
#END
##


Thanks!
Ben


> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

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] lattice_0.20-33

loaded via a namespace (and not attached):
[1] tools_3.3.1 grid_3.3.1 



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] lattice: control panel extent on device

2016-10-25 Thread Ben Tupper
Thanks, Bert.

I have used latticeExtra for layering graphics.  I'm not sure how I would use 
it to align graphics rather superimposing them.

I shall look into the the custom panel plot but that is very new territory for 
me.

Ben

> On Oct 25, 2016, at 9:13 AM, Bert Gunter  wrote:
> 
> Write a custom panel function for levelplot() that calls panel.xyplot after 
> panel.levelplot. I believe this can also be done by the +  operator of the 
> latticeExtra package.
> 
> You do *not* want to call xyplot after levelplot, as that completely redraws 
> the plot.
> 
> Cheers,
> Bert
> 
> 
> On Oct 25, 2016 2:55 PM, "Ben Tupper"  <mailto:btup...@bigelow.org>> wrote:
> Hello,
> 
> I am drawing a levelplot and an xyplot on a single device as shown in the 
> runnable example below.  I would like the x axes to align - that is for them 
> to cover the same extent left-to-right on the device. How do I go about doing 
> that?
> 
> ###
> # START
> ###
> library(lattice)
> 
> d <- dim(volcano)
> xy <- data.frame(x = 1:d[1], y = volcano[,30] )
> 
> vol_p <- levelplot(volcano)
> xy_p <- xyplot(y ~ x, data = xy)
> 
> print(vol_p, split = c(1, 2, 1, 2), more = TRUE)
> print(xy_p,  split = c(1, 1, 1, 2), more = FALSE)
> ##
> #END
> ##
> 
> 
> Thanks!
> Ben
> 
> 
> > sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-apple-darwin13.4.0 (64-bit)
> Running under: OS X 10.11.6 (El Capitan)
> 
> 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] lattice_0.20-33
> 
> loaded via a namespace (and not attached):
> [1] tools_3.3.1 grid_3.3.1
> 
> 
> 
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org <http://www.bigelow.org/>
> 
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
> 

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org




[[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] [FORGED] Re: lattice: control panel extent on device

2016-10-25 Thread Ben Tupper
Hi,

Almost but not quite.  It certainly moves the ball down the field, and, dang, 
that would be way too easy!  

I have been fiddling with the panel.widths to the lattice::plot method.  No joy 
yet.


Ben


> On Oct 25, 2016, at 5:14 PM, Paul Murrell  wrote:
> 
> Hi
> 
> Does this do what you want ?
> 
> library(latticeExtra)
> c(vol_p, xy_p, x.same=TRUE)
> 
> Paul
> 
> On 26/10/16 04:30, Ben Tupper wrote:
>> Thanks, Bert.
>> 
>> I have used latticeExtra for layering graphics.  I'm not sure how I
>> would use it to align graphics rather superimposing them.
>> 
>> I shall look into the the custom panel plot but that is very new
>> territory for me.
>> 
>> Ben
>> 
>>> On Oct 25, 2016, at 9:13 AM, Bert Gunter 
>>> wrote:
>>> 
>>> Write a custom panel function for levelplot() that calls
>>> panel.xyplot after panel.levelplot. I believe this can also be done
>>> by the +  operator of the latticeExtra package.
>>> 
>>> You do *not* want to call xyplot after levelplot, as that
>>> completely redraws the plot.
>>> 
>>> Cheers, Bert
>>> 
>>> 
>>> On Oct 25, 2016 2:55 PM, "Ben Tupper" >> <mailto:btup...@bigelow.org>> wrote: Hello,
>>> 
>>> I am drawing a levelplot and an xyplot on a single device as shown
>>> in the runnable example below.  I would like the x axes to align -
>>> that is for them to cover the same extent left-to-right on the
>>> device. How do I go about doing that?
>>> 
>>> ### # START ### library(lattice)
>>> 
>>> d <- dim(volcano) xy <- data.frame(x = 1:d[1], y = volcano[,30] )
>>> 
>>> vol_p <- levelplot(volcano) xy_p <- xyplot(y ~ x, data = xy)
>>> 
>>> print(vol_p, split = c(1, 2, 1, 2), more = TRUE) print(xy_p,  split
>>> = c(1, 1, 1, 2), more = FALSE) ## #END ##
>>> 
>>> 
>>> Thanks! Ben
>>> 
>>> 
>>>> sessionInfo()
>>> R version 3.3.1 (2016-06-21) Platform: x86_64-apple-darwin13.4.0
>>> (64-bit) Running under: OS X 10.11.6 (El Capitan)
>>> 
>>> 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] lattice_0.20-33
>>> 
>>> loaded via a namespace (and not attached): [1] tools_3.3.1
>>> grid_3.3.1
>>> 
>>> 
>>> 
>>> Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive,
>>> P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org
>>> <http://www.bigelow.org/>
>>> 
>>> __ R-help@r-project.org
>>> <mailto:R-help@r-project.org> mailing list -- To UNSUBSCRIBE and
>>> more, see https://stat.ethz.ch/mailman/listinfo/r-help
>>> <https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the
>>> posting guide http://www.R-project.org/posting-guide.html
>>> <http://www.r-project.org/posting-guide.html> and provide
>>> commented, minimal, self-contained, reproducible code.
>>> 
>> 
>> Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive,
>> P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org
>> 
>> 
>> 
>> 
>> [[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 Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> p...@stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] [FORGED] lattice: control panel extent on device

2016-10-25 Thread Ben Tupper
Wow!  That's exactly what I am looking for!

I have had both books* open in front of me all day to no avail, and, I was 
spinning round and round - I was waaay off in left field.

Thanks so much!
Ben


* https://www.r-project.org/doc/bib/R-books_bib.html#R:Sarkar:2008
  https://www.r-project.org/doc/bib/R-books_bib.html#R:Murrell:2011

> On Oct 25, 2016, at 8:07 PM, Paul Murrell  wrote:
> 
> Hi
> 
> This might work, though it's a teensy bit more complicated and a bit manual 
> (on the left axis labels) and it ignores heights and vertical whitespace ...
> 
> library(lattice)
> d <- dim(volcano)
> xy <- data.frame(x = 1:d[1], y = volcano[,30] )
> library(grid)
> grid.newpage()
> pushViewport(viewport(y=0, height=.5, just="bottom"))
> # Force identical widths where we can
> layout.widths <- lattice.options("layout.widths")[[1]]
> layout.widths$ylab <- list(x=1, units="cm", data=NULL)
> layout.widths$panel <- list(x=1, units="null", data=NULL)
> layout.widths$key.right <- list(x=1, units="cm", data=NULL)
> lattice.options(layout.widths=layout.widths)
> # Force (width of) left axis labels to be the same
> vol_p <- levelplot(volcano, scales=list(y=list(at=seq(10, 60, 10),
>   labels=rep(" ", 6
> print(vol_p, newpage=FALSE, prefix="vol_p")
> downViewport("vol_p.panel.1.1.off.vp")
> # Draw proper left axis labels
> grid.text(seq(10, 60, 10), x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(seq(10, 60, 10), "native"), just="right",
>  gp=gpar(cex=.8))
> # Determine width of levelplot panel
> border <- grid.get("border", grep=TRUE)
> width <- convertWidth(border$width, "in", valueOnly=TRUE)
> xscale <- current.viewport()$xscale
> upViewport(0)
> pushViewport(viewport(y=.5, height=.5, just="bottom"))
> # Force identical widths where we can
> layout.widths$ylab <- list(x=1, units="cm", data=NULL)
> layout.widths$panel <- list(x=width, units="in", data=NULL)
> layout.widths$key.right <- list(x=1, units="cm", data=NULL)
> lattice.options(layout.widths=layout.widths)
> # Force (width of) left axis labels to be the same
> xy_p <- xyplot(y ~ x, data = xy, xlim=xscale,
>   scales=list(y=list(at=seq(100, 200, 20),
>          labels=rep(" ", 11
> print(xy_p, newpage=FALSE, prefix="xy_p")
> downViewport("xy_p.panel.1.1.off.vp")
> # Draw proper left axis labels
> grid.text(seq(100, 200, 20), x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(seq(100, 200, 20), "native"), just="right",
>  gp=gpar(cex=.8))
> upViewport(0)
> 
> Paul
> 
> On 26/10/16 10:50, Ben Tupper wrote:
>> Hi,
>> 
>> Almost but not quite.  It certainly moves the ball down the field, and, 
>> dang, that would be way too easy!
>> 
>> I have been fiddling with the panel.widths to the lattice::plot method.  No 
>> joy yet.
>> 
>> 
>> Ben
>> 
>> 
>>> On Oct 25, 2016, at 5:14 PM, Paul Murrell  wrote:
>>> 
>>> Hi
>>> 
>>> Does this do what you want ?
>>> 
>>> library(latticeExtra)
>>> c(vol_p, xy_p, x.same=TRUE)
>>> 
>>> Paul
>>> 
>>> On 26/10/16 04:30, Ben Tupper wrote:
>>>> Thanks, Bert.
>>>> 
>>>> I have used latticeExtra for layering graphics.  I'm not sure how I
>>>> would use it to align graphics rather superimposing them.
>>>> 
>>>> I shall look into the the custom panel plot but that is very new
>>>> territory for me.
>>>> 
>>>> Ben
>>>> 
>>>>> On Oct 25, 2016, at 9:13 AM, Bert Gunter 
>>>>> wrote:
>>>>> 
>>>>> Write a custom panel function for levelplot() that calls
>>>>> panel.xyplot after panel.levelplot. I believe this can also be done
>>>>> by the +  operator of the latticeExtra package.
>>>>> 
>>>>> You do *not* want to call xyplot after levelplot, as that
>>>>> completely redraws the plot.
>>>>> 
>>>>> Cheers, Bert
>>>>> 
>>>>> 
>>>>> On Oct 25, 2016 2:55 PM, "Ben Tupper" >>>> <mailto:btup...@bigelow.org>> wrote: Hello,
>>>>> 
>>>>> I am drawing a levelplot and an xyplot on a single device as shown
>>>&g

Re: [R] [FORGED] lattice: control panel extent on device

2016-10-26 Thread Ben Tupper
 newpage=FALSE, prefix="vol_p")
> downViewport("vol_p.panel.1.1.off.vp")
> # Draw proper left axis labels
> grid.text(seq(10, 60, 10), x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(seq(10, 60, 10), "native"), just="right",
>  gp=gpar(cex=.8))
> # Determine width of levelplot panel
> border <- grid.get("border", grep=TRUE)
> width <- convertWidth(border$width, "in", valueOnly=TRUE)
> xscale <- current.viewport()$xscale
> upViewport(0)
> pushViewport(viewport(y=.5, height=.5, just="bottom"))
> # Force identical widths where we can
> layout.widths$ylab <- list(x=1, units="cm", data=NULL)
> layout.widths$panel <- list(x=width, units="in", data=NULL)
> layout.widths$key.right <- list(x=1, units="cm", data=NULL)
> lattice.options(layout.widths=layout.widths)
> # Force (width of) left axis labels to be the same
> xy_p <- xyplot(y ~ x, data = xy, xlim=xscale,
>   scales=list(y=list(at=seq(100, 200, 20),
>  labels=rep(" ", 11
> print(xy_p, newpage=FALSE, prefix="xy_p")
> downViewport("xy_p.panel.1.1.off.vp")
> # Draw proper left axis labels
> grid.text(seq(100, 200, 20), x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(seq(100, 200, 20), "native"), just="right",
>  gp=gpar(cex=.8))
> upViewport(0)
> 
> Paul
> 
> On 26/10/16 10:50, Ben Tupper wrote:
>> Hi,
>> 
>> Almost but not quite.  It certainly moves the ball down the field, and, 
>> dang, that would be way too easy!
>> 
>> I have been fiddling with the panel.widths to the lattice::plot method.  No 
>> joy yet.
>> 
>> 
>> Ben
>> 
>> 
>>> On Oct 25, 2016, at 5:14 PM, Paul Murrell  wrote:
>>> 
>>> Hi
>>> 
>>> Does this do what you want ?
>>> 
>>> library(latticeExtra)
>>> c(vol_p, xy_p, x.same=TRUE)
>>> 
>>> Paul
>>> 
>>> On 26/10/16 04:30, Ben Tupper wrote:
>>>> Thanks, Bert.
>>>> 
>>>> I have used latticeExtra for layering graphics.  I'm not sure how I
>>>> would use it to align graphics rather superimposing them.
>>>> 
>>>> I shall look into the the custom panel plot but that is very new
>>>> territory for me.
>>>> 
>>>> Ben
>>>> 
>>>>> On Oct 25, 2016, at 9:13 AM, Bert Gunter 
>>>>> wrote:
>>>>> 
>>>>> Write a custom panel function for levelplot() that calls
>>>>> panel.xyplot after panel.levelplot. I believe this can also be done
>>>>> by the +  operator of the latticeExtra package.
>>>>> 
>>>>> You do *not* want to call xyplot after levelplot, as that
>>>>> completely redraws the plot.
>>>>> 
>>>>> Cheers, Bert
>>>>> 
>>>>> 
>>>>> On Oct 25, 2016 2:55 PM, "Ben Tupper" >>>> <mailto:btup...@bigelow.org>> wrote: Hello,
>>>>> 
>>>>> I am drawing a levelplot and an xyplot on a single device as shown
>>>>> in the runnable example below.  I would like the x axes to align -
>>>>> that is for them to cover the same extent left-to-right on the
>>>>> device. How do I go about doing that?
>>>>> 
>>>>> ### # START ### library(lattice)
>>>>> 
>>>>> d <- dim(volcano) xy <- data.frame(x = 1:d[1], y = volcano[,30] )
>>>>> 
>>>>> vol_p <- levelplot(volcano) xy_p <- xyplot(y ~ x, data = xy)
>>>>> 
>>>>> print(vol_p, split = c(1, 2, 1, 2), more = TRUE) print(xy_p,  split
>>>>> = c(1, 1, 1, 2), more = FALSE) ## #END ##
>>>>> 
>>>>> 
>>>>> Thanks! Ben
>>>>> 
>>>>> 
>>>>>> sessionInfo()
>>>>> R version 3.3.1 (2016-06-21) Platform: x86_64-apple-darwin13.4.0
>>>>> (64-bit) Running under: OS X 10.11.6 (El Capitan)
>>>>> 
>>>>> 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] lattice_0.20-33
>>>>> 
>>

Re: [R] [FORGED] [FORGED] lattice: control panel extent on device

2016-10-27 Thread Ben Tupper
Hi,

I had not noticed the difference, but now that I can see them side-by-side it's 
obvious.  I see that I shouldn't have taken out those modifications you had 
originally set up.  They were sort of like extra those extra parts you find 
after assembling a new gizmo - "Nah, I don't need those things."  Oops!

I just realized that I was calling the alignment vertical (because the plots 
are over-under), but you referred to the alignment as horizontal which sounds 
'righter'.  I should challenge myself to do the same for vertical alignment for 
side-by-side plots.  If I get to it I'll post the results.

Thanks, again, for your time and help.

Cheers,
Ben


> On Oct 26, 2016, at 3:13 PM, Paul Murrell  wrote:
> 
> Hi
> 
> I think your plots are not *quite* horizontally aligned (because of 
> differences in the lengths of y-axis labels).  Here is a slight modification 
> that messes with the labels (but at least not manually) to get things exact 
> ...
> 
> valign_lattice <- function(x) {
> 
>if (inherits(x, "trellis")) x <- list(x)
> 
>if (!all(sapply(x, inherits, 'trellis')))
>stop("all elements of x must inherit from trellis class")
> 
>nx <- length(x)
>names(x) <- LETTERS[1:nx]
>h1 <- 1/nx
>y0 <- seq(from = 0, to = 1 - h1, length = nx)
>n <- 1
>grid.newpage()
>pushViewport(viewport(y=y0[n], height=h1, just="bottom"))
># Force identical widths where we can
>layout.widths <- lattice.options("layout.widths")[[1]]
>layout.widths$ylab <- list(x=1, units="cm", data=NULL)
>layout.widths$panel <- list(x=1, units="null", data=NULL)
>layout.widths$key.right <- list(x=1, units="cm", data=NULL)
>lattice.options(layout.widths=layout.widths)
># Force (width of) left axis labels to be the same
>yrange <- x[[n]]$y.limits
>yticks <- axisTicks(yrange, FALSE)
>x[[n]] <- update(x[[n]],
> scales=list(y=list(at=yticks,
>labels=rep(" ", length(yticks)
>prefix <- LETTERS[n]
>print(x[[n]], newpage=FALSE, prefix=prefix)
>downViewport(paste0(prefix,".panel.1.1.off.vp"))
># Draw proper left axis labels
>grid.text(yticks, x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(yticks, "native"), just="right",
>  gp=gpar(cex=.8))
># Determine width of levelplot panel
>border <- grid.get("border", grep=TRUE)
>width <- convertWidth(border$width, "in", valueOnly=TRUE)
>xscale <- current.viewport()$xscale
>upViewport(0)
> 
>if (nx > 1){
>for (n in 2:nx){
>pushViewport(viewport(y=y0[n], height=h1, just="bottom"))
># Force identical widths where we can
>layout.widths$ylab <- list(x=1, units="cm", data=NULL)
>layout.widths$panel <- list(x=width, units="in", data=NULL)
>layout.widths$key.right <- list(x=1, units="cm", data=NULL)
>lattice.options(layout.widths=layout.widths)
>x[[n]] <- update(x[[n]], xlim = xscale)
># Force (width of) left axis labels to be the same
>yrange <- x[[n]]$y.limits
>yticks <- axisTicks(yrange, FALSE)
>x[[n]] <- update(x[[n]],
> scales=list(y=list(at=yticks,
>        labels=rep(" ",
> length(yticks)
>prefix <- LETTERS[n]
>print(x[[n]], newpage=FALSE, prefix=prefix)
>downViewport(paste0(prefix,".panel.1.1.off.vp"))
># Draw proper left axis labels
>grid.text(yticks, x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(yticks, "native"), just="right",
>  gp=gpar(cex=.8))
>upViewport(0)
>} #n-loop
>}
> }
> 
> Paul
> 
> On 27/10/16 04:21, Ben Tupper wrote:
>> Hi,
>> 
>> The following encapsulates what I hoped for using Paul's method.  The
>> function accepts one or more trellis class objects and aligns them
>> vertically.  I think I have automated most of the manual fiddling.
>> Depending upon your graphics device you may need to fiddle with the
>> aspect of the levelplot as I did below.  There remains a good deal of
>> vertical white space but it is fine for my purposes as I only need
>> two objects aligned where it looks 

Re: [R] How to create a list of trellis objects for grid.arrange()

2016-10-30 Thread Ben Tupper
Hi,

You might try gridExtra::marrangeGrob()

require(raster)
require(sp)
require(gridExtra)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
p1 <- spplot(r)
p2 <- spplot(r/2)

ps <- list(p1,p2)
mm <- marrangeGrob(ps, ncol=1, nrow=2, top = 'foo')

mm


The above generates the two plots arranged vertically.  Note that if I use ps 
<- c(p1,p2) instead of ps <- list(p1,p2) the marrangeGrob() function throws an 
error.  Unlike list(), c() coerces the components to a common type, which, in 
this case, I guess isn't 'trellis'.  Check out the values of str(c(p1, p2)) vs 
str(list(p1,p2)).   


> ps <- c(p1,p2)
> mm <- marrangeGrob(ps, ncol=1, nrow=2, top = 'foo')
Error in (function (..., grobs = list(...), layout_matrix, vp = NULL,  : 
  could not find function "levelplot"


Cheers,
Ben

> On Oct 30, 2016, at 12:26 AM, Duncan Mackay  wrote:
> 
> Hi
> 
> I did not have a look at this when it was sent as I thought it dealt with
> ggplot objects 
> 
> If you have trellis objects (check by str())or ?class) try printing them 
> 
> print(p2, position = (c(0,0,1,0.5), more =T)
> print(p1, position = (c(0,0.5,1,1), more = F)
> 
> The only other way that I can think of is using viewports
> ? grid::viewports
> 
> If it is base graphics then ? layout  may fix it
> 
> 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 [mailto:r-help-boun...@r-project.org] On Behalf Of Agustin Lobo
> Sent: Thursday, 27 October 2016 23:58
> To: r-help@r-project.org
> Subject: [R] How to create a list of trellis objects for grid.arrange()
> 
> Given
> require(raster)
> require(sp)
> require(gridExtra)
> 
> f <- system.file("external/test.grd", package="raster")
> r <- raster(f)
> p1 <- spplot(r)
> p2 <- spplot(r)
> 
> I would like to plot the equivalent to
> 
> grid.arrange(p1,p2,ncol=1,nrow=2)
> 
> but keeping the trellis objects p1 and p2 within one single object (as
> in practice I have many objects generated within a for() loop).
> 
> The following used to work:
> ps <- c(p1,p2)
> grid.arrange(ps,ncol=1,nrow=2)
> 
> but does not work any more.
> 
> How should I combine p1 and p2 into one single object that would be
> accepted by grid.arrange?
> 
> Thanks
> -- 
> Agustin Lobo
> aloboa...@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.
> 
> __
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Question about using ggplot

2016-11-13 Thread Ben Tupper
Hi,

It's hard to know for sure, but perhaps the spelling of 'binomial' is not 
correct?

Ben

> On Nov 13, 2016, at 10:18 AM, overholi...@ajou.ac.kr wrote:
> 
> Hi. I’m a student from South Korea, and I’m studying R by myself.
> While I am studying, I have a trouble dealing with ggplot(especially, about 
> parameter ‘family’)
>> b <- biopsy
>> b$classn[b$class == "benign"] <- 0
>> b$classn[b$class == "malignant"] <- 1
>> ggplot(b, aes(x = V1, y = classn)) + geom_point(position = 
>> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size = 
>> 1.5) + stat_smooth(method = "glm", family = “bimomial")) #first code
> Warning: Ignoring unknown parameters: family
> 
> While studying, I am wondering why there is a warning message. And also, 
> there comes a wrong logistic model(Above picture). But in fact, I expect the 
> below picture from the above code.
> 
> 
> And the below code yields ‘the model’ that I expected(below picture)
> ggplot(b, aes(x = V1, y = classn)) + geom_point(position = 
> position_jitter(width = 0.3, height = 0.06), alpha = 0.4, shape = 21, size = 
> 1.5) + stat_smooth(method = "glm", method.args = list(family = "binomial"))
> 
> 
> 
> 
> What’s wrong with the first code? When I searched about that from online, 
> other people don’t seem to have a problem using family parameters.
> (I currently updated ggplot2, MASS, and sjPlot (Also, double checked it)
> Plus, I used code w/ or w/o using “”)
> 
> 
> I hope getting a good response from you.
> Thanks for reading my mail, and if my message has a rude expression, I’m 
> sorry for my bad english skills..:(
> 
> __
> 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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Merra2 files

2016-11-27 Thread Ben Tupper
Hi,

One of the best places to start a search for information is RSeek.org

http://rseek.org/?q=Merra

Ben

> On Nov 26, 2016, at 8:04 PM, Alemu Tadesse  wrote:
> 
> Dear R users,
> 
> I am wondering if someone has a script to download and read Merra 2 files.
> 
> I really appreciate your help.
> 
> Best,
> 
> Alemu
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Convert arc-second to degree

2016-11-29 Thread Ben Tupper
Hello,

I haven't downloaded the data, but a mock-up of your steps below does as you 
ask. You can see the resolution of y is 1 x 1 and each is filled with the sum 
of 120 x 120 original cells each of which had a value of 1.

In this case, the raster package faithfully interprets the fractional degree 
spatial units from the get-go.  So you needn't worry about the arc-second to 
degree issue.

Ben

P.S.  This question is about spatial data; your best results will be had by 
subscribing to and posting to the spatial mailing list for R.  
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

library(raster)
x <- raster(
 nrows = 17400, ncols = 43200,
 xmn = -180, xmx = 180, ymn = -60, ymx = 85, 
 crs = '+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')
x[] <- 1
x
  class   : RasterLayer 
  dimensions  : 17400, 43200, 75168  (nrow, ncol, ncell)
  resolution  : 0.00833, 0.00833  (x, y)
  extent  : -180, 180, -60, 85  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
  data source : in memory
  names   : layer 
  values  : 1, 1  (min, max)

y <- aggregate(x, fact = 120, fun = sum)
y
  class   : RasterLayer 
  dimensions  : 145, 360, 52200  (nrow, ncol, ncell)
  resolution  : 1, 1  (x, y)
  extent  : -180, 180, -60, 85  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
  data source : 
/private/var/folders/xx/nnm6q33102z059rfg4rh2y90gn/T/RtmpgsByoE/raster/r_tmp_2016-11-29_180022_89972_05480.grd
 
  names   : layer 
  values  : 14400, 14400  (min, max)




> On Nov 29, 2016, at 5:45 PM, Miluji Sb  wrote:
> 
> Dear all,
> 
> I am using the Gridded Population of the World (v4) for the year 2010. The
> data is in GeoTiFF format.
> 
> Source:
> http://sedac.ciesin.columbia.edu/data/set/gpw-v4-population-count-adjusted-to-2015-unwpp-country-totals/data-download
> 
> I imported the data using:
> 
> library(raster)
> library(maptools)
> library(ncdf4)
> library(rgdal)
> 
> population <-
> raster("gpw-v4-population-count-adjusted-to-2015-unwpp-country-totals_2010.tif")
> population1 <- stack(population )
> extent(population1 ) <- c(-180, 180,-58,85)
> 
> ### Information
> class   : RasterStack
> dimensions  : 17400, 43200, 75168, 1  (nrow, ncol, ncell, nlayers)
> resolution  : 0.00833, 0.00833  (x, y)
> extent  : -180, 180, -60, 85  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
> +towgs84=0,0,0
> names   :
> gpw.v4.population.count.adjusted.to.2015.unwpp.country.totals_2010
> min values  :
>   0
> max values  :
> 141715.3
> ###
> 
> I need to extract population by a set of coordinates which are at 1° x 1°,
> how can I convert from arc-second to degree in R? The information also
> shows that resolution is 0.00833° x 0.00833°, is it enough to do
> something like this?
> 
> pop_agg <- aggregate(population1 , fact=120, fun=sum)
> 
> Thank you very much.
> 
> Sincerely,
> 
> Milu
> 
>   [[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.



Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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] Error: XYZ is not an exported object

2016-12-10 Thread Ben Tupper
In addition to Bert's suggestion, you might want to check here...

http://r-pkgs.had.co.nz/man.html#man-data


> On Dec 10, 2016, at 10:25 AM, Bert Gunter  wrote:
> 
> Please post this to the R-package-devel list, not here.
> 
> 
> -- Bert
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Sat, Dec 10, 2016 at 6:47 AM, Witold E Wolski  wrote:
>> I am wrting a package and would like to be able to export it to access it 
>> with:
>> 
>> packagename::dataset
>> 
>> This is how my roxygen doc for the data object looks like:
>> #' Data frame with amino acid masses
>> #'
>> #' @name AminoAcids
>> #' @docType data
>> #' @keywords data
>> #' @export
>> NULL
>> 
>> It does end up in the namespace file with:
>> export(AminoAcids)
>> 
>> the data is in the data/ folder of the package.
>> and I can load it with data(AminoAcid)
>> 
>> Still R CMD build gives me the error:
>> Error : 'AminoAcids' is not an exported object from 'namespace:bibliospec'
>> 
>> because I am trying to access it with bibliospec::AminoAcids
>> 
>> Help highly appreciated.
>> 
>> Thank you
>> 
>> --
>> Witold Eryk Wolski
>> 
>> __
>> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
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.


  1   2   3   >