Re: [R] Upper bands and lower bands

2017-06-01 Thread Bert Gunter
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, Jun 1, 2017 at 11:20 AM, Pedro páramo  wrote:
> Hi all
>
> I want to add a band of fluctuación (exponential decreading) to a linear
> deacrecing values
>
> Imagine: I have a matrix like c(10,9,8,7,6,5,4,3,2,1)

Ummm... That is not a matrix.  It's a vector.

-- Bert


>
> The thing is I want  two new lines so that the máximum value of the new
> colum on the máximum is from 10% to 5% higher and the same lower for the
> mínimum
>
> the final two matix will be something like
>
> c(10+0.10*10,9+0.089*9,8+0.075*8.,1+0.05*1)
> c(10-0.10*10,9-0.09*9,8-0.075*8.,1-0.05*1)
>
> What I´m looking for is a function tu calculate de "values, weights" so
> that including the 10% and 5% and the nunmber of decreasing values, in this
> case n=10, calculates de smotth weigths.
>
> I don´t know if I have expalined well so thar finally putting initial value
> final and periods I can find a matrix like
>
> g(0.1,0.89,0.79,0.075,...,0.05)
>
> Exists something like that?
>
> [[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.

[R] Upper bands and lower bands

2017-06-01 Thread Pedro páramo
Hi all

I want to add a band of fluctuación (exponential decreading) to a linear
deacrecing values

Imagine: I have a matrix like c(10,9,8,7,6,5,4,3,2,1)

The thing is I want  two new lines so that the máximum value of the new
colum on the máximum is from 10% to 5% higher and the same lower for the
mínimum

the final two matix will be something like

c(10+0.10*10,9+0.089*9,8+0.075*8.,1+0.05*1)
c(10-0.10*10,9-0.09*9,8-0.075*8.,1-0.05*1)

What I´m looking for is a function tu calculate de "values, weights" so
that including the 10% and 5% and the nunmber of decreasing values, in this
case n=10, calculates de smotth weigths.

I don´t know if I have expalined well so thar finally putting initial value
final and periods I can find a matrix like

g(0.1,0.89,0.79,0.075,...,0.05)

Exists something like that?

[[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] Upper bands and lower bands

2017-06-01 Thread Pedro páramo
I explain better:

I have this percentage z<-1/(n*365) where n=20 so z is
0,000136986

Imagine: a matrix with length(n*365) so that

matrix result is

resultc(
1,
1-z
result previous row-z
result previous row-z

0)

If I plot this is a linear decreasing line

I want to plot an upper line wich is 10% higher tan resultc on the first
values and then decreasing so that last value will be 0.05.
 the same in the lower, a line which values are at the beggining a 10%
lower and smoothly dreasing values till the last will be 5% lower.

Is it posible to make thins bands exponencially with a code?





2017-06-01 20:20 GMT+02:00 Pedro páramo :

> Hi all
>
> I want to add a band of fluctuación (exponential decreading) to a linear
> deacrecing values
>
> Imagine: I have a matrix like c(10,9,8,7,6,5,4,3,2,1)
>
> The thing is I want  two new lines so that the máximum value of the new
> colum on the máximum is from 10% to 5% higher and the same lower for the
> mínimum
>
> the final two matix will be something like
>
> c(10+0.10*10,9+0.089*9,8+0.075*8.,1+0.05*1)
> c(10-0.10*10,9-0.09*9,8-0.075*8.,1-0.05*1)
>
> What I´m looking for is a function tu calculate de "values, weights" so
> that including the 10% and 5% and the nunmber of decreasing values, in this
> case n=10, calculates de smotth weigths.
>
> I don´t know if I have expalined well so thar finally putting initial
> value final and periods I can find a matrix like
>
> g(0.1,0.89,0.79,0.075,...,0.05)
>
> Exists something like that?
>
>

[[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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread David Winsemius

> On Jun 1, 2017, at 9:51 AM, Roy Mendelssohn - NOAA Federal 
>  wrote:
> 
> Hi All:
> 
> I have been looking for an elegant way to do the following,  but haven't 
> found it,  I have never had a good understanding of any of the "apply" 
> functions.
> 
> A simplified idea is I have an array, say:
> 
> junk(5, 10, 3)
> 
> where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
> dimension, so I could do:
> 
> junk1 <- junk[, rev(seq_len(10), ]
> 
> but what I am after is a general function that will do that where the array 
> could be two, three or four dimensions,  and I pass to the function which 
> dimension I want to reverse, that is the function can not assume the number 
> of dimensions of the array nor which dimension to reverse.
> 
> For example,  if i try:
> 
> junk1 <- apply(junk, 2, rev)
> 
> junk1 comes out as two-dimensional,  not three-dimensional.
> 
> It is probably something obvious but I am not getting it.

It was clear whether you wanted every slice along a particular dimension 
reversed or just one particular slice in a particular dimension. I thought 
probably the former:

Try:

(arr <- array(1:(2*3*4), dim=c(2,3,4) ) )
 
array( apply(arr, 3, rev), dim (arr) )

-- 
David.
> 
> Thanks for any help.
> 
> -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.

David Winsemius
Alameda, CA, USA

__
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] [spatstat] Convert shapefile to pixel image

2017-06-01 Thread Michael Sumner
Try fasterize, converting to spatstat from raster is straightforward, happy
to help.

https://github.com/ecohealthalliance/fasterize

Cheers, Mije

On Fri, 2 Jun 2017, 07:45 Rolf Turner,  wrote:

>
> On 02/06/17 01:17, lluis.hurt...@uv.es wrote:
>
> > Dear all,
> >
> > I am currently working with the spatstat package, using windows and
> pixel images.
> >
> > First:
> >
> > My aim is to transform a shapefile (see attached) into a pixel image.
> >
> > My idea is to start transforming the shapefile into a Spatial Polygon
> file:
> >
> > x <- readShapeSpatial("21441.shp")
> > y <- as(x, "SpatialPolygons")
> > z <- as.owin(y)
> >
> > Given z, I want to identify each polygon with a single constant value.
> This is like adding marks to the SpatialPolygons file. Then I want to
> convert these polygons into an image, such that the value of each pixel
> corresponds to the value associated to the polygon where the pixel lies.
> >
> > I have been able to do this individually, polygon by polygon, but then I
> cannot merge the resulting images into a single one. Any idea?
> >
> > Second:
> >
> > I would also need a single window containing all the smallest polygons
> (the boundary). I have tried:
> >
> > w <- union.owin(z)
> >
> > But the resulting window w still shows internal polygons. As read in
> spatstas FAQ page:
> >
> > "First, convert each of the regions into a separate owin object. Then
> apply union.owin to combine them."
> >
> > So I try,
> >
> > regions <- slot(y, "polygons")
> > regions <- lapply(regions, function(x) { SpatialPolygons(list(x)) })
> > windows <- lapply(regions, as.owin)
> >
> > But windows is a list of 4307 polygons. How can introduce all of them as
> a single argument?
> >
> >> M <- union.owin(windows)
> > Warning messages:
> > 1: In union.owin(windows) : Some arguments were not windows
> > 2: In union.owin(windows) : No windows were given
> >
> >
> > Thank you very much for you help.
>
> As Don has said, this question would be better asked on R-sig-geo.
>
> A *reproducible* example would be nice, e.g. perhaps you could tell us
> how to get the shapefile in question.
>
> In respect of your last point:  Rather than "M <- union.owin(windows)"
> you should use:
>
>  M <- do.call(union.owin, windows)
>
> But that's rather off the track.  What I think you should do (it's hard
> to be certain without a reproducible example) is something like:
>
> tw <- tess(tiles=windows)
> iw <- as.im(funxy(as.function(tw,values=vvv),W=Window(tw)),dimyx=128)
>
> where "vvv" is a vector of the values that you wish to associate with
> the individual polygons.  There may be less cryptic ways of
> accomplishing the same thing, but this is the sexiest way, I think.
>
> The value chosen for "dimyx", i.e. 128, is just by way of example.  You
> can use whatever value suits you.  The larger it is, the smoother the
> individual polygons will look, in pixellated form, but the longer things
> will take.  With 4307 polygons, that might be a rather long time!
>
> HTH
>
> cheers,
>
> Rolf Turner
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
-- 
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] odfWeave - A loop of the "same" data

2017-06-01 Thread Henrik Bengtsson
This is what the R.rsp (https://cran.r-project.org/package=R.rsp; I'm
the author) and it's RSP markup is good at and was designed to handle.
We're using it lots in report generation where we iterate of elements,
e.g. over the 24 chromosomes.  See Section 2.3 in
https://cran.r-project.org/web/packages/R.rsp/vignettes/Dynamic_document_creation_using_RSP.pdf.
RSP is independent of input format - all it requires is that it's
text-based - so you can use RSP-embedded LaTeX, HTML, Markdown, ...,
and even RSP-embedded Sweave, knitr, Rmarkdown (where it then it
effectively works as a pre-processor to those formats).

Hope this helps

Henrik



On Thu, Jun 1, 2017 at 9:35 AM, Charles C. Berry  wrote:
> On Thu, 1 Jun 2017, POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS
> FOUNDATION TRUST) via R-help wrote:
>
>> Before I go and do this another way - can I check if anyone has a way of
>> looping through data in odfWeave (or possibly sweave) to do a repeating
>> analysis on subsets of data?
>>
>> For simplicity lets use mtcars dataset in R to explain.  Dataset looks
>> like this:
>>
>>> mtcars
>>
>>   mpg cyl disp  hp drat   wt ...
>> Mazda RX4 21.0   6  160 110 3.90 2.62 ...
>> Mazda RX4 Wag 21.0   6  160 110 3.90 2.88 ...
>> Datsun 71022.8   4  108  93 3.85 2.32 ...
>>   
>>
>> Say I wanted to have a 'catalogue' style report from mtcars, where on each
>> page I would perhaps have the Rowname as a heading and then plot a graph of
>> mpg highlighting that specific car
>>
>> Then add a page break and *do the same for the next car*.  I can manually
>> do this of course, but it is effectively a loop something like this:
>>
>> for (n in length(mtcars$mpg)) {
>> barplot (mtcars$mpg, col=c(rep(1,n-1),2,rep(1,length(mtcars$mpg)-n)))
>> }
>>
>> There is a odfWeave page break function so I can do that sort of thing (I
>> think).  But I don't think I can output more than one image can I? In
>> reality I will want several images and a table per "catalogue" page.
>>
>> At the moment I think I need to create a master odt document, and create
>> individual catalogue pages.  And merge them into one document - but that
>> feels clunky (unless I can script the merge!)
>>
>> Anyone got a better way?
>
>
>
> For a complex template inside a loop, I'd probably do as Jeff suggests and
> use a knitr child document for ease of developing and debugging the
> template.
>
> But for the simple case you describe I'd use a brew script to
> unroll the loop.
>
> You would write your input file as usual, but put a brew script in the
> right place, then run brew on the input file to produce an
> intermediate file that unrolls the loop, then weave the intermediate
> file to get your desired result.  Here is a simple example of such you can
> run in an R session (assuming the brew package is installed) and see the
> results printed out.
>
> --8<---cut here---start->8---
>
> brew::brew(text="
>
> Everything before the loop
>
> <% for (i in 1:10) { %>
> Print the value of i
> <% print(i) %> or better yet
> \\Sexpr{<%= i %>}
> <% } %>
>
> everything after
>
> ")
>
> --8<---cut here---end--->8---
>
> The double backslash is needed in the literal string used here.  If
> you put that script in a file using an editor, you would just use a
> single backslash.
>
> HTH,
>
> Chuck
>
>
> __
> 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] [spatstat] Convert shapefile to pixel image

2017-06-01 Thread Rolf Turner


On 02/06/17 01:17, lluis.hurt...@uv.es wrote:


Dear all,

I am currently working with the spatstat package, using windows and pixel 
images.

First:

My aim is to transform a shapefile (see attached) into a pixel image.

My idea is to start transforming the shapefile into a Spatial Polygon file:

x <- readShapeSpatial("21441.shp")
y <- as(x, "SpatialPolygons")
z <- as.owin(y)

Given z, I want to identify each polygon with a single constant value. This is 
like adding marks to the SpatialPolygons file. Then I want to convert these 
polygons into an image, such that the value of each pixel corresponds to the 
value associated to the polygon where the pixel lies.

I have been able to do this individually, polygon by polygon, but then I cannot 
merge the resulting images into a single one. Any idea?

Second:

I would also need a single window containing all the smallest polygons (the 
boundary). I have tried:

w <- union.owin(z)

But the resulting window w still shows internal polygons. As read in spatstas 
FAQ page:

"First, convert each of the regions into a separate owin object. Then apply 
union.owin to combine them."

So I try,

regions <- slot(y, "polygons")
regions <- lapply(regions, function(x) { SpatialPolygons(list(x)) })
windows <- lapply(regions, as.owin)

But windows is a list of 4307 polygons. How can introduce all of them as a 
single argument?


M <- union.owin(windows)

Warning messages:
1: In union.owin(windows) : Some arguments were not windows
2: In union.owin(windows) : No windows were given


Thank you very much for you help.


As Don has said, this question would be better asked on R-sig-geo.

A *reproducible* example would be nice, e.g. perhaps you could tell us 
how to get the shapefile in question.


In respect of your last point:  Rather than "M <- union.owin(windows)" 
you should use:


M <- do.call(union.owin, windows)

But that's rather off the track.  What I think you should do (it's hard 
to be certain without a reproducible example) is something like:


tw <- tess(tiles=windows)
iw <- as.im(funxy(as.function(tw,values=vvv),W=Window(tw)),dimyx=128)

where "vvv" is a vector of the values that you wish to associate with 
the individual polygons.  There may be less cryptic ways of 
accomplishing the same thing, but this is the sexiest way, I think.


The value chosen for "dimyx", i.e. 128, is just by way of example.  You 
can use whatever value suits you.  The larger it is, the smoother the 
individual polygons will look, in pixellated form, but the longer things 
will take.  With 4307 polygons, that might be a rather long time!


HTH

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Roy Mendelssohn - NOAA Federal
Thanks again.  I am going to try the different versions.   But I probably won't 
be able to get to it till next week.

This is probably at the point where anything further should be sent to me 
privately.

-Roy



> On Jun 1, 2017, at 1:56 PM, David L Carlson  wrote:
> 
> On the off chance that anyone is still interested, here is the corrected 
> function using aperm():
> 
> z <- array(1:120,dim=2:5)
> f2 <- function(a, wh) {
>idx <- seq_len(length(dim(a)))
>dims <- setdiff(idx, wh)
>idx <- append(idx[-1], idx[1], wh-1)
>aperm(apply(a, dims, rev), idx)
> }
> 
> all.equal(f(z, 1), f2(z, 1))
> # [1] TRUE
> all.equal(f(z, 2), f2(z, 2))
> # [1] TRUE
> all.equal(f(z, 3), f2(z, 3))
> # [1] TRUE
> all.equal(f(z, 4), f2(z, 4))
> # [1] TRUE
> 
> David C
> 
> 
> From: Ismail SEZEN [mailto:sezenism...@gmail.com] 
> Sent: Thursday, June 1, 2017 3:35 PM
> To: Roy Mendelssohn - NOAA Federal 
> Cc: David L Carlson ; R-help 
> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
> 
> 
> On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal 
>  wrote:
> 
> Thanks to all for responses/.  There was a question of exactly what was 
> wanted.  It is the generalization of the obvious example I gave,  
> 
> 
> junk1 <- junk[, rev(seq_len(10), ]
> 
> 
> so that
> 
> junk[1,1,1 ] = junk1[1,10,1]
> junk[1,2,1]  = junk1[1,9,1]
> 
> etc.
> 
> The genesis of this is the program is downloading data from a variety of 
> sources on (time, altitude, lat, lon) coordinates,  but all the coordinates 
> are not always there, and sometime the latitude coordinates go from north to 
> south and sometimes from south to north.  I want to always return the data 
> going from south to north, so if I find that the data is north to south,  I 
> have to first reverse the array with the coordinate values (easy enough),  
> and then reverse the one dimension in the data array that corresponds to 
> latitude. The downloaded information tells me which dimension is latitude 
> plus how many coordinates are in the data.
> 
> Hello Roy,
> Perhaps you are aware of but I want to mention anyway. Basic issue is that 
> you always want latitudes are monotonously increasing. Let me tell what I do 
> when I read a ncdf file:
> 
> 1- Set latitudes always monotonously decreasing (from 90 to -90)
> 2- Set longitudes always mononously increasing but from -180 to 180.
> 3- Set levels always monotonously decreasing (this is not relevant)
> 
> Why? If you plan to plot variables in R, you will need coordinates in this 
> order. For instance, if you set latitudes monotonously increasing, your map 
> will be plotted upside down. To fix this, you will need reverse dimension 
> again. And also if your longitudes ranges from 0 to 360, you will see the 
> only the east side of the plot on a world map. West of Greencwich will be 
> empty.  They were the problems that I faced last year when I tried to plot 
> netcdf files using lattice and rasterVis packages. 
> 
> 
> 
> 
> As I the said,  I haven't done extensive testing on what Bert sent,  but on a 
> toy 3-dimensional example I have it appeared to do what I want.
> 
> Thanks again,
> 
> -Roy
> 
> 
> On Jun 1, 2017, at 12:22 PM, David L Carlson  wrote:
> 
> My error. Clearly I did not do enough testing.
> 
> z <- array(1:24,dim=2:4)
> 
> all.equal(f(z,1),f2(z,1))
> [1] TRUE
> 
> all.equal(f(z,2),f2(z,2))
> [1] TRUE
> 
> all.equal(f(z,3),f2(z,3))
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.6109091"
> 
> # Your earlier example
> 
> z <- array(1:120, dim=2:5)
> all.equal(f(z,1),f2(z,1))
> [1] TRUE
> 
> all.equal(f(z,2),f2(z,2))
> [1] TRUE
> 
> all.equal(f(z,3),f2(z,3))
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.1262209" 
> 
> all.equal(f(z,4),f2(z,4))
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.5714286 >"
> [2] "Mean relative difference: 0.5855162"  
> 
> David C
> 
> -Original Message-
> From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
> Sent: Thursday, June 1, 2017 2:00 PM
> To: David L Carlson 
> Cc: Roy Mendelssohn - NOAA Federal ; R-help 
> 
> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
> 
> ??
> 
> 
> z <- array(1:24,dim=2:4)
> all.equal(f(z,3),f2(z,3))
> 
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.6109091"
> 
> In fact,
> 
> 
> dim(f(z,3))
> [1] 2 3 4
> 
> 
> dim(f2(z,3))
> [1] 3 4 2
> 
> Have I made some sort of stupid error here? Or have I misunderstood
> what was wanted?
> 
> Cheers,
> Bert
> 
> 
> 
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming 

Re: [R] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread David L Carlson
On the off chance that anyone is still interested, here is the corrected 
function using aperm():

z <- array(1:120,dim=2:5)
f2 <- function(a, wh) {
idx <- seq_len(length(dim(a)))
dims <- setdiff(idx, wh)
idx <- append(idx[-1], idx[1], wh-1)
aperm(apply(a, dims, rev), idx)
}

all.equal(f(z, 1), f2(z, 1))
# [1] TRUE
all.equal(f(z, 2), f2(z, 2))
# [1] TRUE
all.equal(f(z, 3), f2(z, 3))
# [1] TRUE
all.equal(f(z, 4), f2(z, 4))
# [1] TRUE

David C


From: Ismail SEZEN [mailto:sezenism...@gmail.com] 
Sent: Thursday, June 1, 2017 3:35 PM
To: Roy Mendelssohn - NOAA Federal 
Cc: David L Carlson ; R-help 
Subject: Re: [R] Reversing one dimension of an array, in a generalized case


On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal 
 wrote:

Thanks to all for responses/.  There was a question of exactly what was wanted. 
 It is the generalization of the obvious example I gave,  


junk1 <- junk[, rev(seq_len(10), ]


so that

junk[1,1,1 ] = junk1[1,10,1]
junk[1,2,1]  = junk1[1,9,1]

etc.

The genesis of this is the program is downloading data from a variety of 
sources on (time, altitude, lat, lon) coordinates,  but all the coordinates are 
not always there, and sometime the latitude coordinates go from north to south 
and sometimes from south to north.  I want to always return the data going from 
south to north, so if I find that the data is north to south,  I have to first 
reverse the array with the coordinate values (easy enough),  and then reverse 
the one dimension in the data array that corresponds to latitude. The 
downloaded information tells me which dimension is latitude plus how many 
coordinates are in the data.

Hello Roy,
Perhaps you are aware of but I want to mention anyway. Basic issue is that you 
always want latitudes are monotonously increasing. Let me tell what I do when I 
read a ncdf file:

1- Set latitudes always monotonously decreasing (from 90 to -90)
2- Set longitudes always mononously increasing but from -180 to 180.
3- Set levels always monotonously decreasing (this is not relevant)

Why? If you plan to plot variables in R, you will need coordinates in this 
order. For instance, if you set latitudes monotonously increasing, your map 
will be plotted upside down. To fix this, you will need reverse dimension 
again. And also if your longitudes ranges from 0 to 360, you will see the only 
the east side of the plot on a world map. West of Greencwich will be empty.  
They were the problems that I faced last year when I tried to plot netcdf files 
using lattice and rasterVis packages. 




As I the said,  I haven't done extensive testing on what Bert sent,  but on a 
toy 3-dimensional example I have it appeared to do what I want.

Thanks again,

-Roy


On Jun 1, 2017, at 12:22 PM, David L Carlson  wrote:

My error. Clearly I did not do enough testing.

z <- array(1:24,dim=2:4)

all.equal(f(z,1),f2(z,1))
[1] TRUE

all.equal(f(z,2),f2(z,2))
[1] TRUE

all.equal(f(z,3),f2(z,3))
[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.6109091"    

# Your earlier example

z <- array(1:120, dim=2:5)
all.equal(f(z,1),f2(z,1))
[1] TRUE

all.equal(f(z,2),f2(z,2))
[1] TRUE

all.equal(f(z,3),f2(z,3))
[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.1262209" 

all.equal(f(z,4),f2(z,4))
[1] "Attributes: < Component “dim”: Mean relative difference: 0.5714286 >"
[2] "Mean relative difference: 0.5855162"  

David C

-Original Message-
From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
Sent: Thursday, June 1, 2017 2:00 PM
To: David L Carlson 
Cc: Roy Mendelssohn - NOAA Federal ; R-help 

Subject: Re: [R] Reversing one dimension of an array, in a generalized case

??


z <- array(1:24,dim=2:4)
all.equal(f(z,3),f2(z,3))

[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.6109091"

In fact,


dim(f(z,3))
[1] 2 3 4


dim(f2(z,3))
[1] 3 4 2

Have I made some sort of stupid error here? Or have I misunderstood
what was wanted?

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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:

Here is an alternative approach using apply(). Note that with apply() you are 
reversing rows or columns not indices of rows or columns so apply(junk, 2, rev) 
reverses the values in each column not the column indices. We actually need to 
use rev() on everything but the index we are interested in reversing:

f2 <- function(a, wh) {
  dims <- seq_len(length(dim(a)))
  dims <- setdiff(dims, wh)
  apply(apply(a, dims, rev), 

Re: [R] [FORGED] Re: Question on function "scatterplot3d"

2017-06-01 Thread Rolf Turner

On 02/06/17 03:02, Uwe Ligges wrote:



On 01.06.2017 10:03, Rolf Turner wrote:

On 01/06/17 19:54, Uwe Ligges wrote:
A design flaw, whether the labels are cut depends somewhat on the 
sizce of the device, hence there is the argument


y.margin.add

add additional space between tick mark labels and axis label of the y 
axis


for working around that limittation that can be set to some positive 
value



This seems to be addressing Hannah's (li li's) original enquiry, not 
my follow-up in which I worried about the position, along the y-axis, 
of the y-axis label.


Ah, that is intended as a smart way of rotating it along the axis is not 
easy (if not impossible) with the bas egraohics system.


OK.  Fair enuff.  Thanks.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Roy Mendelssohn - NOAA Federal
Thank you.  That ignores certain standards in the communities I work in,  it 
also ignore the fact that whether I decide to always return increasing or 
decreasing latitudes,  if the sources aren't consistent,  then I need to 
reverse some of the data,  no matter which way I decide.

Increasing latitudes  (and longitudes) among other things  have the nice 
property that the array indices are also increasing in the same way. I do a lot 
of mapping in R, and a number of the mapping routines actually require you to  
"melt" the data to long-form  in which case the order of the latitudes in the 
array is irrelevant,  as long as the mapping is correct.


-Roy



> On Jun 1, 2017, at 1:35 PM, Ismail SEZEN  wrote:
> 
>> 
>> On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal 
>>  wrote:
>> 
>> Thanks to all for responses/.  There was a question of exactly what was 
>> wanted.  It is the generalization of the obvious example I gave,  
>> 
> junk1 <- junk[, rev(seq_len(10), ]
>> 
>> 
>> so that
>> 
>> junk[1,1,1 ] = junk1[1,10,1]
>> junk[1,2,1]  = junk1[1,9,1]
>> 
>> etc.
>> 
>> The genesis of this is the program is downloading data from a variety of 
>> sources on (time, altitude, lat, lon) coordinates,  but all the coordinates 
>> are not always there, and sometime the latitude coordinates go from north to 
>> south and sometimes from south to north.  I want to always return the data 
>> going from south to north, so if I find that the data is north to south,  I 
>> have to first reverse the array with the coordinate values (easy enough),  
>> and then reverse the one dimension in the data array that corresponds to 
>> latitude. The downloaded information tells me which dimension is latitude 
>> plus how many coordinates are in the data.
> 
> Hello Roy,
> Perhaps you are aware of but I want to mention anyway. Basic issue is that 
> you always want latitudes are monotonously increasing. Let me tell what I do 
> when I read a ncdf file:
> 
> 1- Set latitudes always monotonously decreasing (from 90 to -90)
> 2- Set longitudes always mononously increasing but from -180 to 180.
> 3- Set levels always monotonously decreasing (this is not relevant)
> 
> Why? If you plan to plot variables in R, you will need coordinates in this 
> order. For instance, if you set latitudes monotonously increasing, your map 
> will be plotted upside down. To fix this, you will need reverse dimension 
> again. And also if your longitudes ranges from 0 to 360, you will see the 
> only the east side of the plot on a world map. West of Greencwich will be 
> empty.  They were the problems that I faced last year when I tried to plot 
> netcdf files using lattice and rasterVis packages. 
> 
> 
>> 
>> As I the said,  I haven't done extensive testing on what Bert sent,  but on 
>> a toy 3-dimensional example I have it appeared to do what I want.
>> 
>> Thanks again,
>> 
>> -Roy
>> 
>>> On Jun 1, 2017, at 12:22 PM, David L Carlson  wrote:
>>> 
>>> My error. Clearly I did not do enough testing.
>>> 
>>> z <- array(1:24,dim=2:4)
 all.equal(f(z,1),f2(z,1))
>>> [1] TRUE
 all.equal(f(z,2),f2(z,2))
>>> [1] TRUE
 all.equal(f(z,3),f2(z,3))
>>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
>>> [2] "Mean relative difference: 0.6109091"
>>> 
>>> # Your earlier example
 z <- array(1:120, dim=2:5)
 all.equal(f(z,1),f2(z,1))
>>> [1] TRUE
 all.equal(f(z,2),f2(z,2))
>>> [1] TRUE
 all.equal(f(z,3),f2(z,3))
>>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
>>> [2] "Mean relative difference: 0.1262209" 
 all.equal(f(z,4),f2(z,4))
>>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.5714286 >"
>>> [2] "Mean relative difference: 0.5855162"  
>>> 
>>> David C
>>> 
>>> -Original Message-
>>> From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
>>> Sent: Thursday, June 1, 2017 2:00 PM
>>> To: David L Carlson 
>>> Cc: Roy Mendelssohn - NOAA Federal ; R-help 
>>> 
>>> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
>>> 
>>> ??
>>> 
 z <- array(1:24,dim=2:4)
 all.equal(f(z,3),f2(z,3))
>>> 
>>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
>>> [2] "Mean relative difference: 0.6109091"
>>> 
>>> In fact,
>>> 
 dim(f(z,3))
>>> [1] 2 3 4
>>> 
 dim(f2(z,3))
>>> [1] 3 4 2
>>> 
>>> Have I made some sort of stupid error here? Or have I misunderstood
>>> what was wanted?
>>> 
>>> 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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:
 Here is an alternative 

Re: [R] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Ismail SEZEN

> On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal 
>  wrote:
> 
> Thanks to all for responses/.  There was a question of exactly what was 
> wanted.  It is the generalization of the obvious example I gave,  
> 
 junk1 <- junk[, rev(seq_len(10), ]
> 
> 
> so that
> 
> junk[1,1,1 ] = junk1[1,10,1]
> junk[1,2,1]  = junk1[1,9,1]
> 
> etc.
> 
> The genesis of this is the program is downloading data from a variety of 
> sources on (time, altitude, lat, lon) coordinates,  but all the coordinates 
> are not always there, and sometime the latitude coordinates go from north to 
> south and sometimes from south to north.  I want to always return the data 
> going from south to north, so if I find that the data is north to south,  I 
> have to first reverse the array with the coordinate values (easy enough),  
> and then reverse the one dimension in the data array that corresponds to 
> latitude. The downloaded information tells me which dimension is latitude 
> plus how many coordinates are in the data.

Hello Roy,
Perhaps you are aware of but I want to mention anyway. Basic issue is that you 
always want latitudes are monotonously increasing. Let me tell what I do when I 
read a ncdf file:

1- Set latitudes always monotonously decreasing (from 90 to -90)
2- Set longitudes always mononously increasing but from -180 to 180.
3- Set levels always monotonously decreasing (this is not relevant)

Why? If you plan to plot variables in R, you will need coordinates in this 
order. For instance, if you set latitudes monotonously increasing, your map 
will be plotted upside down. To fix this, you will need reverse dimension 
again. And also if your longitudes ranges from 0 to 360, you will see the only 
the east side of the plot on a world map. West of Greencwich will be empty.  
They were the problems that I faced last year when I tried to plot netcdf files 
using lattice and rasterVis packages. 


> 
> As I the said,  I haven't done extensive testing on what Bert sent,  but on a 
> toy 3-dimensional example I have it appeared to do what I want.
> 
> Thanks again,
> 
> -Roy
> 
>> On Jun 1, 2017, at 12:22 PM, David L Carlson  wrote:
>> 
>> My error. Clearly I did not do enough testing.
>> 
>> z <- array(1:24,dim=2:4)
>>> all.equal(f(z,1),f2(z,1))
>> [1] TRUE
>>> all.equal(f(z,2),f2(z,2))
>> [1] TRUE
>>> all.equal(f(z,3),f2(z,3))
>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
>> [2] "Mean relative difference: 0.6109091"
>> 
>> # Your earlier example
>>> z <- array(1:120, dim=2:5)
>>> all.equal(f(z,1),f2(z,1))
>> [1] TRUE
>>> all.equal(f(z,2),f2(z,2))
>> [1] TRUE
>>> all.equal(f(z,3),f2(z,3))
>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
>> [2] "Mean relative difference: 0.1262209" 
>>> all.equal(f(z,4),f2(z,4))
>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.5714286 >"
>> [2] "Mean relative difference: 0.5855162"  
>> 
>> David C
>> 
>> -Original Message-
>> From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
>> Sent: Thursday, June 1, 2017 2:00 PM
>> To: David L Carlson 
>> Cc: Roy Mendelssohn - NOAA Federal ; R-help 
>> 
>> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
>> 
>> ??
>> 
>>> z <- array(1:24,dim=2:4)
>>> all.equal(f(z,3),f2(z,3))
>> 
>> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
>> [2] "Mean relative difference: 0.6109091"
>> 
>> In fact,
>> 
>>> dim(f(z,3))
>> [1] 2 3 4
>> 
>>> dim(f2(z,3))
>> [1] 3 4 2
>> 
>> Have I made some sort of stupid error here? Or have I misunderstood
>> what was wanted?
>> 
>> 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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:
>>> Here is an alternative approach using apply(). Note that with apply() you 
>>> are reversing rows or columns not indices of rows or columns so apply(junk, 
>>> 2, rev) reverses the values in each column not the column indices. We 
>>> actually need to use rev() on everything but the index we are interested in 
>>> reversing:
>>> 
>>> f2 <- function(a, wh) {
>>>   dims <- seq_len(length(dim(a)))
>>>   dims <- setdiff(dims, wh)
>>>   apply(apply(a, dims, rev), dims, t)
>>> }
>>> 
>>> # Your example
>>> j1 <- junk[ , rev(1:10), ]
>>> j2 <- f2(junk, 2)
>>> all.equal(j1, j2)
>>> # [1] TRUE
>>> 
>>> # Bert's example
>>> z1 <- f(z, 2)
>>> z2 <- f2(z, 2)
>>> all.equal(z1, z2)
>>> # [1] TRUE
>>> 
>>> -
>>> David L Carlson
>>> Department of Anthropology
>>> Texas A University
>>> College Station, TX 77840-4352
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> -Original Message-

Re: [R-es] errores con openair

2017-06-01 Thread Carlos Ortega
Mira lo que aparece en el conjunto de ejemplo que trae el paquete
("mydata")...

Note

openair functions generally require data frames with a field "date" that
can be in either POSIXct or Date format but should be GMT time zone. This
can be hourly data or higher resolution data.

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 1 de junio de 2017, 22:09, Carlos Ortega 
escribió:

> Hola,
>
> El paquete "openair" tiene una pequeña trampa y es el nombre de las
> variables.
> Si no recuerdo mal, tienes que llamar a la columna de la fecha de una
> forma especial ("date").
> Mira el ejemplo que viene incluido en el propio paquete y respeta el mismo
> nombre, superado esto, no hay problema.
>
> Gracias,
> Carlos Ortega
> www.qualityexcellence.es
>
>
> El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) <
> javier.val...@mop.gov.cl> escribió:
>
>> Estimados como les va.
>>
>>
>>
>> He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS.
>> Sin embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira
>> este error. En definitiva, no he podido hacer absolutamente nada¡¡
>>
>> He probado de todo, pero ya me estoy aburriendo, a pesar que al parecer
>> es una muy buena herramienta.
>>
>> Saludos.
>>
>>
>>
>> Error in as.POSIXct.default(x) :
>>
>>   do not know how to convert 'x' to class “POSIXct”
>>
>> In addition: Warning message:
>>
>> In is.na(mydata$date) :
>>
>>   is.na() applied to non-(list or vector) of type 'NULL'
>>
>>
>>
>> [image: Descripción: FIRMA3]
>>
>>
>>
>> --
>>
>> CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los
>> archivos adjuntos es de carácter confidencial o privilegiada y está
>> destinada al uso exclusivo del emisor y/o de la persona o entidad a quien
>> va dirigida. Si usted no es el destinatario, cualquier almacenamiento,
>> divulgación, distribución o copia de esta información está estrictamente
>> prohibido y sancionado por la ley. Si recibió este mensaje por error, por
>> favor infórmenos inmediatamente respondiendo este mismo mensaje y borre
>> todos los archivos adjuntos. Gracias.
>>
>> CONFIDENTIAL NOTE: The information transmitted in this message and/or
>> attachments is confidential and/or privileged and is intented only for use
>> of the person or entity to whom it is addressed. If you are not the
>> intended recipient, any retention, dissemination, distribution or copy of
>> this information is strictly prohibited and sanctioned by law. If you
>> received this message in error, please reply us this same message and
>> delete this message and all attachments. Thank you.
>>
>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] errores con openair (Javier Valdes Cantallopts (DGA))

2017-06-01 Thread Javier Valdes Cantallopts (DGA)
OK¡¡ SOLUCIONADO
Lo volví a intentar cambiando FECHA A "date" y funcionó




-Mensaje original-
De: Novvier Marco Uscuchagua Cornelio [mailto:novv...@hotmail.com]
Enviado el: jueves, 01 de junio de 2017 16:03
Para: r-help-es@r-project.org
CC: Javier Valdes Cantallopts (DGA)
Asunto: RE: errores con openair (Javier Valdes Cantallopts (DGA))

Intenta cambiando el nombre de la columna por "date"

>colnames(TOTAL)[which(names(TOTAL) == "fecha")] <- "date"

Atte.
Novvier Uscuchagua

-Mensaje original-

Date: Thu, 1 Jun 2017 19:56:16 +
From: "Javier Valdes Cantallopts (DGA)" 
To: "Carlos J. Gil Bellosta " 
Cc: "r-help-es@r-project.org" 
Subject: Re: [R-es] errores con openair
Message-ID:
<023ae46828930542b1f3839f47a15400220a1...@exmbx02.moptt.gov.cl>
Content-Type: text/plain; charset="utf-8"

Al parecer está bien el formato, lo trabajé con lubridate..
> str(TOTAL$fecha)
POSIXct[1:131478], format: "2014-01-24 04:10:00" "2014-01-24 04:20:00" 
"2014-01-24 04:30:00" .


[Descripción: FIRMA3]

De: gilbello...@gmail.com [mailto:gilbello...@gmail.com] En nombre de Carlos J. 
Gil Bellosta Enviado el: jueves, 01 de junio de 2017 15:51
Para: Javier Valdes Cantallopts (DGA)
CC: r-help-es@r-project.org
Asunto: Re: [R-es] errores con openair

Revisa el formato de tus fechas.

El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) 
> escribió:
Estimados como les va.

He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS. Sin 
embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira este 
error. En definitiva, no he podido hacer absolutamente nada¡¡ He probado de 
todo, pero ya me estoy aburriendo, a pesar que al parecer es una muy buena 
herramienta.
Saludos.

Error in as.POSIXct.default(x) :
  do not know how to convert 'x' to class ?POSIXct?
In addition: Warning message:
In is.na(mydata$date) :
  is.na() applied to non-(list or vector) of type 'NULL'

[Descripción: FIRMA3]







CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] errores con openair (Javier Valdes Cantallopts (DGA))

2017-06-01 Thread Javier Valdes Cantallopts (DGA)
Hola.
Ya lo intenté pero no funcionó cambiando a "date".
Quizás el tema vaya por no usar LUBRIDATE y cambiarte a Strptime..Sería una 
lástima ya que lubridate es una muy buena herramienta y fácil de aplicar.



-Mensaje original-
De: Novvier Marco Uscuchagua Cornelio [mailto:novv...@hotmail.com]
Enviado el: jueves, 01 de junio de 2017 16:03
Para: r-help-es@r-project.org
CC: Javier Valdes Cantallopts (DGA)
Asunto: RE: errores con openair (Javier Valdes Cantallopts (DGA))

Intenta cambiando el nombre de la columna por "date"

>colnames(TOTAL)[which(names(TOTAL) == "fecha")] <- "date"

Atte.
Novvier Uscuchagua

-Mensaje original-

Date: Thu, 1 Jun 2017 19:56:16 +
From: "Javier Valdes Cantallopts (DGA)" 
To: "Carlos J. Gil Bellosta " 
Cc: "r-help-es@r-project.org" 
Subject: Re: [R-es] errores con openair
Message-ID:
<023ae46828930542b1f3839f47a15400220a1...@exmbx02.moptt.gov.cl>
Content-Type: text/plain; charset="utf-8"

Al parecer está bien el formato, lo trabajé con lubridate..
> str(TOTAL$fecha)
POSIXct[1:131478], format: "2014-01-24 04:10:00" "2014-01-24 04:20:00" 
"2014-01-24 04:30:00" .


[Descripción: FIRMA3]

De: gilbello...@gmail.com [mailto:gilbello...@gmail.com] En nombre de Carlos J. 
Gil Bellosta Enviado el: jueves, 01 de junio de 2017 15:51
Para: Javier Valdes Cantallopts (DGA)
CC: r-help-es@r-project.org
Asunto: Re: [R-es] errores con openair

Revisa el formato de tus fechas.

El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) 
> escribió:
Estimados como les va.

He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS. Sin 
embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira este 
error. En definitiva, no he podido hacer absolutamente nada¡¡ He probado de 
todo, pero ya me estoy aburriendo, a pesar que al parecer es una muy buena 
herramienta.
Saludos.

Error in as.POSIXct.default(x) :
  do not know how to convert 'x' to class ?POSIXct?
In addition: Warning message:
In is.na(mydata$date) :
  is.na() applied to non-(list or vector) of type 'NULL'

[Descripción: FIRMA3]







CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] subletting an array according to dimnames

2017-06-01 Thread li li
Hi all,
  I have a three dimensional array with the corresponding dimension names.
I would like to subset the array according to the dimension names. For
example,
suppose I want to extract the values corresponding to A=20, B=10, C=0.  I
know I
can do:
 P2[dimnames(P2)$A==20, dimnames(P2)$B==10, dimnames(P2)$C==0]

But is there a better way for doing this? Thanks for your help!
  Hanna

> dimnames(P2)

$A

[1] "20" "25" "30" "35" "40"


$B

[1] "5"  "10" "15" "20" "25" "30" "35" "40"


$C

[1] "0"  "5" "10" "15" "20" "25" "30" "35"

[[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-es] errores con openair

2017-06-01 Thread Carlos Ortega
Hola,

El paquete "openair" tiene una pequeña trampa y es el nombre de las
variables.
Si no recuerdo mal, tienes que llamar a la columna de la fecha de una forma
especial ("date").
Mira el ejemplo que viene incluido en el propio paquete y respeta el mismo
nombre, superado esto, no hay problema.

Gracias,
Carlos Ortega
www.qualityexcellence.es


El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) <
javier.val...@mop.gov.cl> escribió:

> Estimados como les va.
>
>
>
> He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS.
> Sin embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira
> este error. En definitiva, no he podido hacer absolutamente nada¡¡
>
> He probado de todo, pero ya me estoy aburriendo, a pesar que al parecer es
> una muy buena herramienta.
>
> Saludos.
>
>
>
> Error in as.POSIXct.default(x) :
>
>   do not know how to convert 'x' to class “POSIXct”
>
> In addition: Warning message:
>
> In is.na(mydata$date) :
>
>   is.na() applied to non-(list or vector) of type 'NULL'
>
>
>
> [image: Descripción: FIRMA3]
>
>
>
> --
>
> CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los
> archivos adjuntos es de carácter confidencial o privilegiada y está
> destinada al uso exclusivo del emisor y/o de la persona o entidad a quien
> va dirigida. Si usted no es el destinatario, cualquier almacenamiento,
> divulgación, distribución o copia de esta información está estrictamente
> prohibido y sancionado por la ley. Si recibió este mensaje por error, por
> favor infórmenos inmediatamente respondiendo este mismo mensaje y borre
> todos los archivos adjuntos. Gracias.
>
> CONFIDENTIAL NOTE: The information transmitted in this message and/or
> attachments is confidential and/or privileged and is intented only for use
> of the person or entity to whom it is addressed. If you are not the
> intended recipient, any retention, dissemination, distribution or copy of
> this information is strictly prohibited and sanctioned by law. If you
> received this message in error, please reply us this same message and
> delete this message and all attachments. Thank you.
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] errores con openair

2017-06-01 Thread Javier Marcuzzi
Estimado Javier Valdes Cantallopts

Yo no utilizo libridate, luego de tener muchos inconvenientes con las fechas 
encontré una forma que dejo de darme dolores de cabeza, básicamente utilizo 
strptime.

 https://stat.ethz.ch/R-manual/R-devel/library/base/html/strptime.html

Es algo más de código pero en mi caso anda (me encontré con código que andaba 
en la prueba pero no en la producción, strptime no dio inconveniente).

Javier Rubén Marcuzzi

De: Javier Valdes Cantallopts (DGA)
Enviado: jueves, 1 de junio de 2017 16:55
Para: Carlos J. Gil Bellosta 
CC: r-help-es@r-project.org
Asunto: Re: [R-es] errores con openair

Al parecer está bien el formato, lo trabajé con lubridate..
> str(TOTAL$fecha)
POSIXct[1:131478], format: "2014-01-24 04:10:00" "2014-01-24 04:20:00" 
"2014-01-24 04:30:00" .




De: gilbello...@gmail.com [mailto:gilbello...@gmail.com] En nombre de Carlos J. 
Gil Bellosta 
Enviado el: jueves, 01 de junio de 2017 15:51
Para: Javier Valdes Cantallopts (DGA)
CC: r-help-es@r-project.org
Asunto: Re: [R-es] errores con openair

Revisa el formato de tus fechas.

El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) 
 escribió:
Estimados como les va.
 
He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS. Sin 
embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira este 
error. En definitiva, no he podido hacer absolutamente nada¡¡
He probado de todo, pero ya me estoy aburriendo, a pesar que al parecer es una 
muy buena herramienta.
Saludos.
 
Error in as.POSIXct.default(x) : 
  do not know how to convert 'x' to class “POSIXct”
In addition: Warning message:
In is.na(mydata$date) :
  is.na() applied to non-(list or vector) of type 'NULL'
 

 



CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es




CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] [FORGED] How to create my own grDevices using java

2017-06-01 Thread Paul Murrell

Hi

The 'RGraphicsDevice' package might be useful for this job.

http://www.omegahat.net/RGraphicsDevice/

Paul

On 01/06/17 07:09, Peter Cheung wrote:

Hi All

How to create my own grDevices using java, so that i can display the 
graphic from plot() in my java software?

thanks

from Peter

[[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/

__
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-es] errores con openair

2017-06-01 Thread Javier Valdes Cantallopts (DGA)
Al parecer está bien el formato, lo trabajé con lubridate..
> str(TOTAL$fecha)
POSIXct[1:131478], format: "2014-01-24 04:10:00" "2014-01-24 04:20:00" 
"2014-01-24 04:30:00" .


[Descripción: FIRMA3]

De: gilbello...@gmail.com [mailto:gilbello...@gmail.com] En nombre de Carlos J. 
Gil Bellosta
Enviado el: jueves, 01 de junio de 2017 15:51
Para: Javier Valdes Cantallopts (DGA)
CC: r-help-es@r-project.org
Asunto: Re: [R-es] errores con openair

Revisa el formato de tus fechas.

El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) 
> escribió:
Estimados como les va.

He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS. Sin 
embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira este 
error. En definitiva, no he podido hacer absolutamente nada¡¡
He probado de todo, pero ya me estoy aburriendo, a pesar que al parecer es una 
muy buena herramienta.
Saludos.

Error in as.POSIXct.default(x) :
  do not know how to convert 'x' to class “POSIXct”
In addition: Warning message:
In is.na(mydata$date) :
  is.na() applied to non-(list or vector) of type 'NULL'

[Descripción: FIRMA3]




CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es




CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-06-01 Thread Suzen, Mehmet
No it is an R programming questions.  Nelly specifically asked you:

"how can I use your code to apply my model to each of the 50 rows of
the data frame “tabLHS”?"

__
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-es] errores con openair

2017-06-01 Thread Carlos J. Gil Bellosta
Revisa el formato de tus fechas.

El 1 de junio de 2017, 21:46, Javier Valdes Cantallopts (DGA) <
javier.val...@mop.gov.cl> escribió:

> Estimados como les va.
>
>
>
> He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS.
> Sin embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira
> este error. En definitiva, no he podido hacer absolutamente nada¡¡
>
> He probado de todo, pero ya me estoy aburriendo, a pesar que al parecer es
> una muy buena herramienta.
>
> Saludos.
>
>
>
> Error in as.POSIXct.default(x) :
>
>   do not know how to convert 'x' to class “POSIXct”
>
> In addition: Warning message:
>
> In is.na(mydata$date) :
>
>   is.na() applied to non-(list or vector) of type 'NULL'
>
>
>
> [image: Descripción: FIRMA3]
>
>
>
> --
>
> CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los
> archivos adjuntos es de carácter confidencial o privilegiada y está
> destinada al uso exclusivo del emisor y/o de la persona o entidad a quien
> va dirigida. Si usted no es el destinatario, cualquier almacenamiento,
> divulgación, distribución o copia de esta información está estrictamente
> prohibido y sancionado por la ley. Si recibió este mensaje por error, por
> favor infórmenos inmediatamente respondiendo este mismo mensaje y borre
> todos los archivos adjuntos. Gracias.
>
> CONFIDENTIAL NOTE: The information transmitted in this message and/or
> attachments is confidential and/or privileged and is intented only for use
> of the person or entity to whom it is addressed. If you are not the
> intended recipient, any retention, dissemination, distribution or copy of
> this information is strictly prohibited and sanctioned by law. If you
> received this message in error, please reply us this same message and
> delete this message and all attachments. Thank you.
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[R-es] errores con openair

2017-06-01 Thread Javier Valdes Cantallopts (DGA)
Estimados como les va.

He tratado de profundizar sobre el paquete OPENAIR PARA MANEJO DE DATOS. Sin 
embargo, cada cosa que intento hacer, por muy pequeña que sea, me tira este 
error. En definitiva, no he podido hacer absolutamente nada¡¡
He probado de todo, pero ya me estoy aburriendo, a pesar que al parecer es una 
muy buena herramienta.
Saludos.

Error in as.POSIXct.default(x) :
  do not know how to convert 'x' to class "POSIXct"
In addition: Warning message:
In is.na(mydata$date) :
  is.na() applied to non-(list or vector) of type 'NULL'

[Descripción: FIRMA3]




CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Roy Mendelssohn - NOAA Federal
Thanks to all for responses/.  There was a question of exactly what was wanted. 
 It is the generalization of the obvious example I gave,  

>>> junk1 <- junk[, rev(seq_len(10), ]


so that

junk[1,1,1 ] = junk1[1,10,1]
junk[1,2,1]  = junk1[1,9,1]

etc.

The genesis of this is the program is downloading data from a variety of 
sources on (time, altitude, lat, lon) coordinates,  but all the coordinates are 
not always there, and sometime the latitude coordinates go from north to south 
and sometimes from south to north.  I want to always return the data going from 
south to north, so if I find that the data is north to south,  I have to first 
reverse the array with the coordinate values (easy enough),  and then reverse 
the one dimension in the data array that corresponds to latitude. The 
downloaded information tells me which dimension is latitude plus how many 
coordinates are in the data.

As I the said,  I haven't done extensive testing on what Bert sent,  but on a 
toy 3-dimensional example I have it appeared to do what I want.

Thanks again,

-Roy

> On Jun 1, 2017, at 12:22 PM, David L Carlson  wrote:
> 
> My error. Clearly I did not do enough testing.
> 
> z <- array(1:24,dim=2:4)
>> all.equal(f(z,1),f2(z,1))
> [1] TRUE
>> all.equal(f(z,2),f2(z,2))
> [1] TRUE
>> all.equal(f(z,3),f2(z,3))
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.6109091"
> 
> # Your earlier example
>> z <- array(1:120, dim=2:5)
>> all.equal(f(z,1),f2(z,1))
> [1] TRUE
>> all.equal(f(z,2),f2(z,2))
> [1] TRUE
>> all.equal(f(z,3),f2(z,3))
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.1262209" 
>> all.equal(f(z,4),f2(z,4))
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.5714286 >"
> [2] "Mean relative difference: 0.5855162"  
> 
> David C
> 
> -Original Message-
> From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
> Sent: Thursday, June 1, 2017 2:00 PM
> To: David L Carlson 
> Cc: Roy Mendelssohn - NOAA Federal ; R-help 
> 
> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
> 
> ??
> 
>> z <- array(1:24,dim=2:4)
>> all.equal(f(z,3),f2(z,3))
> 
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.6109091"
> 
> In fact,
> 
>> dim(f(z,3))
> [1] 2 3 4
> 
>> dim(f2(z,3))
> [1] 3 4 2
> 
> Have I made some sort of stupid error here? Or have I misunderstood
> what was wanted?
> 
> 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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:
>> Here is an alternative approach using apply(). Note that with apply() you 
>> are reversing rows or columns not indices of rows or columns so apply(junk, 
>> 2, rev) reverses the values in each column not the column indices. We 
>> actually need to use rev() on everything but the index we are interested in 
>> reversing:
>> 
>> f2 <- function(a, wh) {
>>dims <- seq_len(length(dim(a)))
>>dims <- setdiff(dims, wh)
>>apply(apply(a, dims, rev), dims, t)
>> }
>> 
>> # Your example
>> j1 <- junk[ , rev(1:10), ]
>> j2 <- f2(junk, 2)
>> all.equal(j1, j2)
>> # [1] TRUE
>> 
>> # Bert's example
>> z1 <- f(z, 2)
>> z2 <- f2(z, 2)
>> all.equal(z1, z2)
>> # [1] TRUE
>> 
>> -
>> David L Carlson
>> Department of Anthropology
>> Texas A University
>> College Station, TX 77840-4352
>> 
>> 
>> 
>> 
>> 
>> 
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
>> Sent: Thursday, June 1, 2017 12:46 PM
>> To: Roy Mendelssohn - NOAA Federal 
>> Cc: R-help 
>> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
>> 
>> How about this:
>> 
>> f <- function(a,wh){ ## a is the array; wh is the index to be reversed
>>   l<- lapply(dim(a),seq_len)
>>   l[[wh]]<- rev(l[[wh]])
>>   do.call(`[`,c(list(a),l))
>> }
>> 
>> ## test
>> z <- array(1:120,dim=2:5)
>> 
>> ##  I omit the printouts
>> 
>> f(z,2)
>> 
>> f(z,3)
>> 
>> 
>> 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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
>>  wrote:
>>> Hi All:
>>> 
>>> I have been looking for an elegant way to do the following,  but haven't 
>>> found it,  I have never had a good understanding of any of the "apply" 
>>> functions.
>>> 
>>> A simplified idea is I have 

Re: [R] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Ismail SEZEN
And my 2 cents,

Rev <- function(x, margin) {
newdim <- rep("", length(dim(x)))
newdim[margin] <- paste(dim(x), ":1", sep = "")[margin]
z <- eval(parse(text = gettextf("x[%s,drop = F]", paste(newdim, sep = "",
collapse = ","
class(z) <- oldClass(x)
return(z)
}

z <- array(1:24,dim=2:4)
dim(f(z, 3)) # 2 3 4
dim(f2(z, 3)) # 3 4 2
dim(Rev(z, 3)) # 2 3 4
dim(revdim(z,3)) # 2 3 4

microbenchmark::microbenchmark(f(z, 3), Rev(z, 3), revdim(z,3), f2(z,3))

Unit: microseconds
 expr min   lq  mean   median   uq max neval
  f(z, 3)   6.356   7.6090   9.74268   9.3285  11.2325  35.571   100
Rev(z, 3) 161.079 166.9660 175.26906 172.1450 176.8130 273.078   100
 revdim(z, 3)   5.011   6.1300   7.88565   7.5695   9.0500  21.301   100
 f2(z, 3)  68.454  71.6815  82.85703  81.6700  87.9285 126.496   100

and strangely,

all.equal(f(z, 3), Rev(z, 3), revdim(z,3), f2(z,3))
[1] TRUE

?

> On 1 Jun 2017, at 22:00, Bert Gunter  wrote:
> 
> ??
> 
>> z <- array(1:24,dim=2:4)
>> all.equal(f(z,3),f2(z,3))
> 
> [1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
> [2] "Mean relative difference: 0.6109091"
> 
> In fact,
> 
>> dim(f(z,3))
> [1] 2 3 4
> 
>> dim(f2(z,3))
> [1] 3 4 2
> 
> Have I made some sort of stupid error here? Or have I misunderstood
> what was wanted?
> 
> 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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:
>> Here is an alternative approach using apply(). Note that with apply() you 
>> are reversing rows or columns not indices of rows or columns so apply(junk, 
>> 2, rev) reverses the values in each column not the column indices. We 
>> actually need to use rev() on everything but the index we are interested in 
>> reversing:
>> 
>> f2 <- function(a, wh) {
>>dims <- seq_len(length(dim(a)))
>>dims <- setdiff(dims, wh)
>>apply(apply(a, dims, rev), dims, t)
>> }
>> 
>> # Your example
>> j1 <- junk[ , rev(1:10), ]
>> j2 <- f2(junk, 2)
>> all.equal(j1, j2)
>> # [1] TRUE
>> 
>> # Bert's example
>> z1 <- f(z, 2)
>> z2 <- f2(z, 2)
>> all.equal(z1, z2)
>> # [1] TRUE
>> 
>> -
>> David L Carlson
>> Department of Anthropology
>> Texas A University
>> College Station, TX 77840-4352
>> 
>> 
>> 
>> 
>> 
>> 
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
>> Sent: Thursday, June 1, 2017 12:46 PM
>> To: Roy Mendelssohn - NOAA Federal 
>> Cc: R-help 
>> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
>> 
>> How about this:
>> 
>> f <- function(a,wh){ ## a is the array; wh is the index to be reversed
>>   l<- lapply(dim(a),seq_len)
>>   l[[wh]]<- rev(l[[wh]])
>>   do.call(`[`,c(list(a),l))
>> }
>> 
>> ## test
>> z <- array(1:120,dim=2:5)
>> 
>> ##  I omit the printouts
>> 
>> f(z,2)
>> 
>> f(z,3)
>> 
>> 
>> 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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
>>  wrote:
>>> Hi All:
>>> 
>>> I have been looking for an elegant way to do the following,  but haven't 
>>> found it,  I have never had a good understanding of any of the "apply" 
>>> functions.
>>> 
>>> A simplified idea is I have an array, say:
>>> 
>>> junk(5, 10, 3)
>>> 
>>> where  (5, 10, 3) give the dimension sizes, and I want to reverse the 
>>> second dimension, so I could do:
>>> 
>>> junk1 <- junk[, rev(seq_len(10), ]
>>> 
>>> but what I am after is a general function that will do that where the array 
>>> could be two, three or four dimensions,  and I pass to the function which 
>>> dimension I want to reverse, that is the function can not assume the number 
>>> of dimensions of the array nor which dimension to reverse.
>>> 
>>> For example,  if i try:
>>> 
>>> junk1 <- apply(junk, 2, rev)
>>> 
>>> junk1 comes out as two-dimensional,  not three-dimensional.
>>> 
>>> It is probably something obvious but I am not getting it.
>>> 
>>> Thanks for any help.
>>> 
>>> -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
>>> 

Re: [R] [FORGED] Re: Question on function "scatterplot3d"

2017-06-01 Thread li li
Thanks so much for the help!!
   Hanna


2017-06-01 11:02 GMT-04:00 Uwe Ligges :

>
>
> On 01.06.2017 10:03, Rolf Turner wrote:
>
>> On 01/06/17 19:54, Uwe Ligges wrote:
>>
>>> A design flaw, whether the labels are cut depends somewhat on the sizce
>>> of the device, hence there is the argument
>>>
>>> y.margin.add
>>>
>>> add additional space between tick mark labels and axis label of the y
>>> axis
>>>
>>> for working around that limittation that can be set to some positive
>>> value
>>>
>>
>>
>> This seems to be addressing Hannah's (li li's) original enquiry, not my
>> follow-up in which I worried about the position, along the y-axis, of the
>> y-axis label.
>>
>
> Ah, that is intended as a smart way of rotating it along the axis is not
> easy (if not impossible) with the bas egraohics system.
>
> Best,
> Uwe Ligges
>
>
>
>
>> Or am I misunderstanding/missing something?
>>
>> cheers,
>>
>> Rolf
>>
>>
> __
> 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.


Re: [R] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread David L Carlson
My error. Clearly I did not do enough testing.

z <- array(1:24,dim=2:4)
> all.equal(f(z,1),f2(z,1))
[1] TRUE
> all.equal(f(z,2),f2(z,2))
[1] TRUE
> all.equal(f(z,3),f2(z,3))
[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.6109091"

# Your earlier example
> z <- array(1:120, dim=2:5)
> all.equal(f(z,1),f2(z,1))
[1] TRUE
> all.equal(f(z,2),f2(z,2))
[1] TRUE
> all.equal(f(z,3),f2(z,3))
[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.1262209" 
> all.equal(f(z,4),f2(z,4))
[1] "Attributes: < Component “dim”: Mean relative difference: 0.5714286 >"
[2] "Mean relative difference: 0.5855162"  

David C

-Original Message-
From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
Sent: Thursday, June 1, 2017 2:00 PM
To: David L Carlson 
Cc: Roy Mendelssohn - NOAA Federal ; R-help 

Subject: Re: [R] Reversing one dimension of an array, in a generalized case

??

> z <- array(1:24,dim=2:4)
> all.equal(f(z,3),f2(z,3))

[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.6109091"

In fact,

> dim(f(z,3))
[1] 2 3 4

> dim(f2(z,3))
[1] 3 4 2

Have I made some sort of stupid error here? Or have I misunderstood
what was wanted?

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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:
> Here is an alternative approach using apply(). Note that with apply() you are 
> reversing rows or columns not indices of rows or columns so apply(junk, 2, 
> rev) reverses the values in each column not the column indices. We actually 
> need to use rev() on everything but the index we are interested in reversing:
>
> f2 <- function(a, wh) {
> dims <- seq_len(length(dim(a)))
> dims <- setdiff(dims, wh)
> apply(apply(a, dims, rev), dims, t)
> }
>
> # Your example
> j1 <- junk[ , rev(1:10), ]
> j2 <- f2(junk, 2)
> all.equal(j1, j2)
> # [1] TRUE
>
> # Bert's example
> z1 <- f(z, 2)
> z2 <- f2(z, 2)
> all.equal(z1, z2)
> # [1] TRUE
>
> -
> David L Carlson
> Department of Anthropology
> Texas A University
> College Station, TX 77840-4352
>
>
>
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
> Sent: Thursday, June 1, 2017 12:46 PM
> To: Roy Mendelssohn - NOAA Federal 
> Cc: R-help 
> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
>
> How about this:
>
> f <- function(a,wh){ ## a is the array; wh is the index to be reversed
>l<- lapply(dim(a),seq_len)
>l[[wh]]<- rev(l[[wh]])
>do.call(`[`,c(list(a),l))
> }
>
> ## test
> z <- array(1:120,dim=2:5)
>
> ##  I omit the printouts
>
> f(z,2)
>
> f(z,3)
>
>
> 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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
>  wrote:
>> Hi All:
>>
>> I have been looking for an elegant way to do the following,  but haven't 
>> found it,  I have never had a good understanding of any of the "apply" 
>> functions.
>>
>> A simplified idea is I have an array, say:
>>
>> junk(5, 10, 3)
>>
>> where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
>> dimension, so I could do:
>>
>> junk1 <- junk[, rev(seq_len(10), ]
>>
>> but what I am after is a general function that will do that where the array 
>> could be two, three or four dimensions,  and I pass to the function which 
>> dimension I want to reverse, that is the function can not assume the number 
>> of dimensions of the array nor which dimension to reverse.
>>
>> For example,  if i try:
>>
>> junk1 <- apply(junk, 2, rev)
>>
>> junk1 comes out as two-dimensional,  not three-dimensional.
>>
>> It is probably something obvious but I am not getting it.
>>
>> Thanks for any help.
>>
>> -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 

Re: [R] [spatstat] Convert shapefile to pixel image

2017-06-01 Thread MacQueen, Don
This looks like to would be better to ask on R-sig-geo, instead of R-help.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062


On 6/1/17, 6:17 AM, "R-help on behalf of lluis.hurt...@uv.es" 
 wrote:

Dear all,

I am currently working with the spatstat package, using windows and pixel 
images.

First:

My aim is to transform a shapefile (see attached) into a pixel image. 

My idea is to start transforming the shapefile into a Spatial Polygon file:

x <- readShapeSpatial("21441.shp")
y <- as(x, "SpatialPolygons")
z <- as.owin(y)

Given z, I want to identify each polygon with a single constant value. This 
is like adding marks to the SpatialPolygons file. Then I want to convert these 
polygons into an image, such that the value of each pixel corresponds to the 
value associated to the polygon where the pixel lies. 

I have been able to do this individually, polygon by polygon, but then I 
cannot merge the resulting images into a single one. Any idea?

Second:

I would also need a single window containing all the smallest polygons (the 
boundary). I have tried:

w <- union.owin(z)

But the resulting window w still shows internal polygons. As read in 
spatstas FAQ page:

"First, convert each of the regions into a separate owin object. Then apply 
union.owin to combine them."

So I try,

regions <- slot(y, "polygons")
regions <- lapply(regions, function(x) { SpatialPolygons(list(x)) })
windows <- lapply(regions, as.owin) 

But windows is a list of 4307 polygons. How can introduce all of them as a 
single argument?

> M <- union.owin(windows)
Warning messages:
1: In union.owin(windows) : Some arguments were not windows
2: In union.owin(windows) : No windows were given


Thank you very much for you help.

Lluís Hurtado.
__
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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Bert Gunter
??

> z <- array(1:24,dim=2:4)
> all.equal(f(z,3),f2(z,3))

[1] "Attributes: < Component “dim”: Mean relative difference: 0.444 >"
[2] "Mean relative difference: 0.6109091"

In fact,

> dim(f(z,3))
[1] 2 3 4

> dim(f2(z,3))
[1] 3 4 2

Have I made some sort of stupid error here? Or have I misunderstood
what was wanted?

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, Jun 1, 2017 at 11:34 AM, David L Carlson  wrote:
> Here is an alternative approach using apply(). Note that with apply() you are 
> reversing rows or columns not indices of rows or columns so apply(junk, 2, 
> rev) reverses the values in each column not the column indices. We actually 
> need to use rev() on everything but the index we are interested in reversing:
>
> f2 <- function(a, wh) {
> dims <- seq_len(length(dim(a)))
> dims <- setdiff(dims, wh)
> apply(apply(a, dims, rev), dims, t)
> }
>
> # Your example
> j1 <- junk[ , rev(1:10), ]
> j2 <- f2(junk, 2)
> all.equal(j1, j2)
> # [1] TRUE
>
> # Bert's example
> z1 <- f(z, 2)
> z2 <- f2(z, 2)
> all.equal(z1, z2)
> # [1] TRUE
>
> -
> David L Carlson
> Department of Anthropology
> Texas A University
> College Station, TX 77840-4352
>
>
>
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
> Sent: Thursday, June 1, 2017 12:46 PM
> To: Roy Mendelssohn - NOAA Federal 
> Cc: R-help 
> Subject: Re: [R] Reversing one dimension of an array, in a generalized case
>
> How about this:
>
> f <- function(a,wh){ ## a is the array; wh is the index to be reversed
>l<- lapply(dim(a),seq_len)
>l[[wh]]<- rev(l[[wh]])
>do.call(`[`,c(list(a),l))
> }
>
> ## test
> z <- array(1:120,dim=2:5)
>
> ##  I omit the printouts
>
> f(z,2)
>
> f(z,3)
>
>
> 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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
>  wrote:
>> Hi All:
>>
>> I have been looking for an elegant way to do the following,  but haven't 
>> found it,  I have never had a good understanding of any of the "apply" 
>> functions.
>>
>> A simplified idea is I have an array, say:
>>
>> junk(5, 10, 3)
>>
>> where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
>> dimension, so I could do:
>>
>> junk1 <- junk[, rev(seq_len(10), ]
>>
>> but what I am after is a general function that will do that where the array 
>> could be two, three or four dimensions,  and I pass to the function which 
>> dimension I want to reverse, that is the function can not assume the number 
>> of dimensions of the array nor which dimension to reverse.
>>
>> For example,  if i try:
>>
>> junk1 <- apply(junk, 2, rev)
>>
>> junk1 comes out as two-dimensional,  not three-dimensional.
>>
>> It is probably something obvious but I am not getting it.
>>
>> Thanks for any help.
>>
>> -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.
>
> __
> 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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread David L Carlson
Here is an alternative approach using apply(). Note that with apply() you are 
reversing rows or columns not indices of rows or columns so apply(junk, 2, rev) 
reverses the values in each column not the column indices. We actually need to 
use rev() on everything but the index we are interested in reversing:

f2 <- function(a, wh) {
dims <- seq_len(length(dim(a)))
dims <- setdiff(dims, wh)
apply(apply(a, dims, rev), dims, t)
}

# Your example
j1 <- junk[ , rev(1:10), ]
j2 <- f2(junk, 2)
all.equal(j1, j2)
# [1] TRUE

# Bert's example
z1 <- f(z, 2)
z2 <- f2(z, 2)
all.equal(z1, z2)
# [1] TRUE

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352






-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter
Sent: Thursday, June 1, 2017 12:46 PM
To: Roy Mendelssohn - NOAA Federal 
Cc: R-help 
Subject: Re: [R] Reversing one dimension of an array, in a generalized case

How about this:

f <- function(a,wh){ ## a is the array; wh is the index to be reversed
   l<- lapply(dim(a),seq_len)
   l[[wh]]<- rev(l[[wh]])
   do.call(`[`,c(list(a),l))
}

## test
z <- array(1:120,dim=2:5)

##  I omit the printouts

f(z,2)

f(z,3)


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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
 wrote:
> Hi All:
>
> I have been looking for an elegant way to do the following,  but haven't 
> found it,  I have never had a good understanding of any of the "apply" 
> functions.
>
> A simplified idea is I have an array, say:
>
> junk(5, 10, 3)
>
> where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
> dimension, so I could do:
>
> junk1 <- junk[, rev(seq_len(10), ]
>
> but what I am after is a general function that will do that where the array 
> could be two, three or four dimensions,  and I pass to the function which 
> dimension I want to reverse, that is the function can not assume the number 
> of dimensions of the array nor which dimension to reverse.
>
> For example,  if i try:
>
> junk1 <- apply(junk, 2, rev)
>
> junk1 comes out as two-dimensional,  not three-dimensional.
>
> It is probably something obvious but I am not getting it.
>
> Thanks for any help.
>
> -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.

__
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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Jeff Newmiller

Not sure it is "obvious", but this function implements what you describe:

revdim <- function( a, d ) {
   dims <- attr( a, "dim" )
   idxs <- lapply( seq_along( dims )
 , function( dd ) {
 if ( d == dd ) seq.int( dims[ dd ], 1, -1 )
 else seq.int( dims[ dd ] )
   }
 )
   do.call( `[`, c( list( a ), idxs ) )
}

revdim( junk1, 2 )

On Thu, 1 Jun 2017, Roy Mendelssohn - NOAA Federal wrote:


Hi All:

I have been looking for an elegant way to do the following, but haven't 
found it, I have never had a good understanding of any of the "apply" 
functions.


A simplified idea is I have an array, say:

junk(5, 10, 3)

where (5, 10, 3) give the dimension sizes, and I want to reverse the 
second dimension, so I could do:


junk1 <- junk[, rev(seq_len(10), ]

but what I am after is a general function that will do that where the 
array could be two, three or four dimensions, and I pass to the function 
which dimension I want to reverse, that is the function can not assume 
the number of dimensions of the array nor which dimension to reverse.


For example,  if i try:

junk1 <- apply(junk, 2, rev)

junk1 comes out as two-dimensional,  not three-dimensional.

It is probably something obvious but I am not getting it.

Thanks for any help.

-Roy




---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
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] Problem of a function I wrote

2017-06-01 Thread b88207001

Hello everyone,

I know where is wrong. I forget to specify the parameters in my  
function. Thank you for anyone who was trying to help me!


Best,
Yen

引述 b88207...@ntu.edu.tw:


Hello everyone,

It seems that I was not successfully attached the code. Here is the  
code. I appreciate any help!


Best,
Yen

引述 b88207...@ntu.edu.tw:


Hello everyone,

I have been working on a code which simply repeatedly appends a  
number into a vector and write a file. However, it could not be  
properly implemented when I use it. It works when I run it line by  
line. I wonder what is the problem and I appreciate anyone who is  
willing to help.


The function and the example code is attached. Any advice is appreciated!

Best,
Yen
__
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] Problem of a function I wrote

2017-06-01 Thread b88207001

Hello everyone,

It seems that I was not successfully attached the code. Here is the  
code. I appreciate any help!


Best,
Yen

引述 b88207...@ntu.edu.tw:


Hello everyone,

I have been working on a code which simply repeatedly appends a  
number into a vector and write a file. However, it could not be  
properly implemented when I use it. It works when I run it line by  
line. I wonder what is the problem and I appreciate anyone who is  
willing to help.


The function and the example code is attached. Any advice is appreciated!

Best,
Yen
__
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] Problem of a function I wrote

2017-06-01 Thread b88207001

Hello everyone,

I have been working on a code which simply repeatedly appends a number  
into a vector and write a file. However, it could not be properly  
implemented when I use it. It works when I run it line by line. I  
wonder what is the problem and I appreciate anyone who is willing to  
help.


The function and the example code is attached. Any advice is appreciated!

Best,
Yen
__
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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Roy Mendelssohn - NOAA Federal
Thank you very much.  I have a little test example I have been working with,  
and it does seem to work.I will have to go through and parse this to 
understand what you are doing

What I had been doing is building up a string with the arguments and calling 
it,  it works but very kludgy and very fragile.

Thanks again.

-Roy


> On Jun 1, 2017, at 10:45 AM, Bert Gunter  wrote:
> 
> How about this:
> 
> f <- function(a,wh){ ## a is the array; wh is the index to be reversed
>   l<- lapply(dim(a),seq_len)
>   l[[wh]]<- rev(l[[wh]])
>   do.call(`[`,c(list(a),l))
> }
> 
> ## test
> z <- array(1:120,dim=2:5)
> 
> ##  I omit the printouts
> 
> f(z,2)
> 
> f(z,3)
> 
> 
> 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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
>  wrote:
>> Hi All:
>> 
>> I have been looking for an elegant way to do the following,  but haven't 
>> found it,  I have never had a good understanding of any of the "apply" 
>> functions.
>> 
>> A simplified idea is I have an array, say:
>> 
>> junk(5, 10, 3)
>> 
>> where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
>> dimension, so I could do:
>> 
>> junk1 <- junk[, rev(seq_len(10), ]
>> 
>> but what I am after is a general function that will do that where the array 
>> could be two, three or four dimensions,  and I pass to the function which 
>> dimension I want to reverse, that is the function can not assume the number 
>> of dimensions of the array nor which dimension to reverse.
>> 
>> For example,  if i try:
>> 
>> junk1 <- apply(junk, 2, rev)
>> 
>> junk1 comes out as two-dimensional,  not three-dimensional.
>> 
>> It is probably something obvious but I am not getting it.
>> 
>> Thanks for any help.
>> 
>> -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.

**
"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.


Re: [R] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Bert Gunter
How about this:

f <- function(a,wh){ ## a is the array; wh is the index to be reversed
   l<- lapply(dim(a),seq_len)
   l[[wh]]<- rev(l[[wh]])
   do.call(`[`,c(list(a),l))
}

## test
z <- array(1:120,dim=2:5)

##  I omit the printouts

f(z,2)

f(z,3)


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, Jun 1, 2017 at 9:51 AM, Roy Mendelssohn - NOAA Federal
 wrote:
> Hi All:
>
> I have been looking for an elegant way to do the following,  but haven't 
> found it,  I have never had a good understanding of any of the "apply" 
> functions.
>
> A simplified idea is I have an array, say:
>
> junk(5, 10, 3)
>
> where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
> dimension, so I could do:
>
> junk1 <- junk[, rev(seq_len(10), ]
>
> but what I am after is a general function that will do that where the array 
> could be two, three or four dimensions,  and I pass to the function which 
> dimension I want to reverse, that is the function can not assume the number 
> of dimensions of the array nor which dimension to reverse.
>
> For example,  if i try:
>
> junk1 <- apply(junk, 2, rev)
>
> junk1 comes out as two-dimensional,  not three-dimensional.
>
> It is probably something obvious but I am not getting it.
>
> Thanks for any help.
>
> -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.

__
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] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread William Dunlap via R-help
Re-importing the data with read.table's strip.white=TRUE argument may be an
easier way to deal with the problem (if the problem is leading or trailing
whitespace).

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Jun 1, 2017 at 9:17 AM, David Winsemius 
wrote:

>
> > On Jun 1, 2017, at 8:57 AM, William Dunlap via R-help <
> r-help@r-project.org> wrote:
> >
> > Check for leading or trailing spaces in the strings in your data.
> > dput(dataset) would show them.
>
> This function would strip any leading or trailing spaces from a column:
>
> trim <-
>function (s)
> {
> s <- as.character(s)
> s <- sub(pattern = "^[[:blank:]]+", replacement = "", x = s)
> s <- sub(pattern = "[[:blank:]]+$", replacement = "", x = s)
> s
>  }
>
> You could restrict it to non-mumeric columns with:
>
> my_dfrm[ !sapply(my_dfrm, is.numeric) ] <- lapply( my_dfrm[
> !sapply(my_dfrm, is.numeric) ], trim)
>
> It would have the side-effect, (desirable in my opinion but opinions do
> vary on this matter), of converting any factor columns to character-class.
>
>
>
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com
> >
> > On Thu, Jun 1, 2017 at 8:49 AM, Ulrik Stervbo 
> > wrote:
> >
> >> Hi Tara,
> >>
> >> It seems that you categorise and count for each category. Could it be
> that
> >> the method you use puts everything that doesn't match the predefined
> >> categories in Other?
> >>
> >> I'm only guessing because without a minimal  reproducible example it's
> >> difficult to do anything else.
> >>
> >> Best wishes
> >> Ulrik
> >>
> >> Rui Barradas  schrieb am Do., 1. Juni 2017,
> 17:30:
> >>
> >>> Hello,
> >>>
> >>> In order for us to help we need to know how you've imported your data.
> >>> What was the file type? What instructions have you used to import it?
> >>> Did you use base R or a package?
> >>> Give us a minimal but complete code example that can reproduce your
> >>> situation.
> >>>
> >>> Hope this helps,
> >>>
> >>> Rui Barradas
> >>>
> >>> Em 01-06-2017 11:02, Tara Adcock escreveu:
>  Hi,
> 
>  I have a question regarding data importing into R.
> 
>  When I import my data into R and review the summary, some of my
> >>> explanatory variables are being reported as if instead of being one
> >>> variable, they are two with the same name. See below for an example;
> 
> Behav person Behav dog   Position
>    **combination  : 38   combination  :  4** Bank:372
>    **combination  :  7   combination  :  4**   **Island  :119**
>  fast :123   fast : 15 **Island  : 11**
>  slow :445   slow : 95   Land:  3
>  stat :111   stat : 14   Water   :230
> 
>  Also, all of the distances I have imported are showing up in the
> >> summary
> >>> along with a line entitled "other". However, I haven't used any other
> >>> distances?
> 
> DistanceDistance.dog
> 2-10m  :184 <50m   : 35
> <50m   :156 2-10m  : 27
> 10-20m :156 20-30m : 23
> 20-30m : 91 30-40m : 16
> 40-50m : 57 10-20m : 13
> **(Other): 82   (Other): 18**
> 
>  I have checked my data sheet over and over again and I think
> >>> standardised the data, but the issue keeps arising. I'm assuming I need
> >> to
> >>> clean the data set but as a nearly complete novice in R I am not
> certain
> >>> how to do this. Any help at all with this would be much appreciated.
> >> Thanks
> >>> so much.
> 
>  Kind Regards,
> 
>  Tara Adcock.
> 
> 
>   [[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.
> >>>
> >>
> >>[[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 

Re: [R] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread Charles C. Berry

On Thu, 1 Jun 2017, Rui Barradas wrote:


Hello,

In order for us to help we need to know how you've imported your data. What 
was the file type? What instructions have you used to import it? Did you use 
base R or a package?
Give us a minimal but complete code example that can reproduce your 
situation.


Hope this helps,

Rui Barradas


Absolutely.

It would also help to see what the unique values of each column 
*really* are. To that end run and report the results of this:


lapply(your.data.frame, function(x) unique(as.character(x)))

I'll bet you have both "combination" and "combination " as values or 
something similar where two different strings look to your eye to be the 
same when printed by summary().


HTH,

Chuck



Em 01-06-2017 11:02, Tara Adcock escreveu:

Hi,

I have a question regarding data importing into R.

When I import my data into R and review the summary, some of my explanatory 
variables are being reported as if instead of being one variable, they are 
two with the same name. See below for an example;


Behav person Behav dog   Position
   **combination  : 38   combination  :  4** Bank:372
   **combination  :  7   combination  :  4**   **Island  :119**
 fast :123   fast : 15 **Island  : 11**
 slow :445   slow : 95   Land:  3
 stat :111   stat : 14   Water   :230

Also, all of the distances I have imported are showing up in the summary 
along with a line entitled "other". However, I haven't used any other 
distances?


DistanceDistance.dog
2-10m  :184 <50m   : 35
<50m   :156 2-10m  : 27
10-20m :156 20-30m : 23
20-30m : 91 30-40m : 16
40-50m : 57 10-20m : 13
**(Other): 82   (Other): 18**

I have checked my data sheet over and over again and I think standardised 
the data, but the issue keeps arising. I'm assuming I need to clean the 
data set but as a nearly complete novice in R I am not certain how to do 
this. Any help at all with this would be much appreciated. Thanks so much.


Kind Regards,

Tara Adcock.


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





Charles C. Berry Dept of Family Medicine & Public Health
cberry at ucsd edu   UC San Diego / La Jolla, CA 92093-0901
http://biostat.ucsd.edu/ccberry.htm

__
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] Reversing one dimension of an array, in a generalized case

2017-06-01 Thread Roy Mendelssohn - NOAA Federal
Hi All:

I have been looking for an elegant way to do the following,  but haven't found 
it,  I have never had a good understanding of any of the "apply" functions.

A simplified idea is I have an array, say:

junk(5, 10, 3)

where  (5, 10, 3) give the dimension sizes, and I want to reverse the second 
dimension, so I could do:

junk1 <- junk[, rev(seq_len(10), ]

but what I am after is a general function that will do that where the array 
could be two, three or four dimensions,  and I pass to the function which 
dimension I want to reverse, that is the function can not assume the number of 
dimensions of the array nor which dimension to reverse.

For example,  if i try:

junk1 <- apply(junk, 2, rev)

junk1 comes out as two-dimensional,  not three-dimensional.

It is probably something obvious but I am not getting it.

Thanks for any help.

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


Re: [R] odfWeave - A loop of the "same" data

2017-06-01 Thread Charles C. Berry

On Thu, 1 Jun 2017, POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION 
TRUST) via R-help wrote:

Before I go and do this another way - can I check if anyone has a way of 
looping through data in odfWeave (or possibly sweave) to do a repeating 
analysis on subsets of data?


For simplicity lets use mtcars dataset in R to explain.  Dataset looks like 
this:


mtcars

  mpg cyl disp  hp drat   wt ...
Mazda RX4 21.0   6  160 110 3.90 2.62 ...
Mazda RX4 Wag 21.0   6  160 110 3.90 2.88 ...
Datsun 71022.8   4  108  93 3.85 2.32 ...
  

Say I wanted to have a 'catalogue' style report from mtcars, where on 
each page I would perhaps have the Rowname as a heading and then plot a 
graph of mpg highlighting that specific car


Then add a page break and *do the same for the next car*.  I can manually do 
this of course, but it is effectively a loop something like this:

for (n in length(mtcars$mpg)) {
barplot (mtcars$mpg, col=c(rep(1,n-1),2,rep(1,length(mtcars$mpg)-n)))
}

There is a odfWeave page break function so I can do that sort of thing 
(I think).  But I don't think I can output more than one image can I? 
In reality I will want several images and a table per "catalogue" page.


At the moment I think I need to create a master odt document, and create 
individual catalogue pages.  And merge them into one document - but that 
feels clunky (unless I can script the merge!)


Anyone got a better way?



For a complex template inside a loop, I'd probably do as Jeff suggests and 
use a knitr child document for ease of developing and debugging the 
template.


But for the simple case you describe I'd use a brew script to
unroll the loop.

You would write your input file as usual, but put a brew script in the
right place, then run brew on the input file to produce an
intermediate file that unrolls the loop, then weave the intermediate
file to get your desired result.  Here is a simple example of such you 
can run in an R session (assuming the brew package is installed) and see 
the results printed out.


--8<---cut here---start->8---

brew::brew(text="

Everything before the loop

<% for (i in 1:10) { %>
Print the value of i
<% print(i) %> or better yet
\\Sexpr{<%= i %>}
<% } %>

everything after

")

--8<---cut here---end--->8---

The double backslash is needed in the literal string used here.  If
you put that script in a file using an editor, you would just use a
single backslash.

HTH,

Chuck

__
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] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread David Winsemius

> On Jun 1, 2017, at 8:57 AM, William Dunlap via R-help  
> wrote:
> 
> Check for leading or trailing spaces in the strings in your data.
> dput(dataset) would show them.

This function would strip any leading or trailing spaces from a column:

trim <-
   function (s) 
{
s <- as.character(s)
s <- sub(pattern = "^[[:blank:]]+", replacement = "", x = s)
s <- sub(pattern = "[[:blank:]]+$", replacement = "", x = s)
s
 }

You could restrict it to non-mumeric columns with:

my_dfrm[ !sapply(my_dfrm, is.numeric) ] <- lapply( my_dfrm[ !sapply(my_dfrm, 
is.numeric) ], trim)

It would have the side-effect, (desirable in my opinion but opinions do vary on 
this matter), of converting any factor columns to character-class.



> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
> 
> On Thu, Jun 1, 2017 at 8:49 AM, Ulrik Stervbo 
> wrote:
> 
>> Hi Tara,
>> 
>> It seems that you categorise and count for each category. Could it be that
>> the method you use puts everything that doesn't match the predefined
>> categories in Other?
>> 
>> I'm only guessing because without a minimal  reproducible example it's
>> difficult to do anything else.
>> 
>> Best wishes
>> Ulrik
>> 
>> Rui Barradas  schrieb am Do., 1. Juni 2017, 17:30:
>> 
>>> Hello,
>>> 
>>> In order for us to help we need to know how you've imported your data.
>>> What was the file type? What instructions have you used to import it?
>>> Did you use base R or a package?
>>> Give us a minimal but complete code example that can reproduce your
>>> situation.
>>> 
>>> Hope this helps,
>>> 
>>> Rui Barradas
>>> 
>>> Em 01-06-2017 11:02, Tara Adcock escreveu:
 Hi,
 
 I have a question regarding data importing into R.
 
 When I import my data into R and review the summary, some of my
>>> explanatory variables are being reported as if instead of being one
>>> variable, they are two with the same name. See below for an example;
 
Behav person Behav dog   Position
   **combination  : 38   combination  :  4** Bank:372
   **combination  :  7   combination  :  4**   **Island  :119**
 fast :123   fast : 15 **Island  : 11**
 slow :445   slow : 95   Land:  3
 stat :111   stat : 14   Water   :230
 
 Also, all of the distances I have imported are showing up in the
>> summary
>>> along with a line entitled "other". However, I haven't used any other
>>> distances?
 
DistanceDistance.dog
2-10m  :184 <50m   : 35
<50m   :156 2-10m  : 27
10-20m :156 20-30m : 23
20-30m : 91 30-40m : 16
40-50m : 57 10-20m : 13
**(Other): 82   (Other): 18**
 
 I have checked my data sheet over and over again and I think
>>> standardised the data, but the issue keeps arising. I'm assuming I need
>> to
>>> clean the data set but as a nearly complete novice in R I am not certain
>>> how to do this. Any help at all with this would be much appreciated.
>> Thanks
>>> so much.
 
 Kind Regards,
 
 Tara Adcock.
 
 
  [[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.
>>> 
>> 
>>[[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.

David Winsemius
Alameda, CA, USA

__
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 

Re: [R] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread David L Carlson
It looks like your printouts are based on the R summary() function? The 
function lists the number of cases in the 5 largest categories when the 
variable is coded as a FACTOR.

David C

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson
Sent: Thursday, June 1, 2017 11:07 AM
To: Ulrik Stervbo ; Rui Barradas 
; Tara Adcock ; 
r-help@r-project.org
Cc: William Dunlap via R-help 
Subject: Re: [R] Data import R: some explanatory variables not showing up 
correctly in summary

It looks like your printouts are based on the R summary() function? The 
function lists the number of cases in the 5 largest categories when the 
variable is coded as a function. Then it indicates how many other categories 
are present. This is described on the manual page for function summary().

In the first case the duplicates probably represent cases in your source data 
(a spreadsheet?), where you have inadvertently put a space at the end of the 
label, e.g. "combination", and "combination ". The answers to both questions 
are easy to find with the levels() function:

levels(yourdataframe$Position) 

This will list all of the factor levels in variable Position for you. If there 
are extras spaces and you were using read.csv() to import the data, use the 
strip.white=TRUE argument to delete leading and trailing spaces. This is also 
documented on the manual page for function read.csv(). One of the problems with 
spreadsheets is that these extra spaces are not readily apparent.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ulrik Stervbo
Sent: Thursday, June 1, 2017 10:50 AM
To: Rui Barradas ; Tara Adcock ; 
r-help@r-project.org
Subject: Re: [R] Data import R: some explanatory variables not showing up 
correctly in summary

Hi Tara,

It seems that you categorise and count for each category. Could it be that
the method you use puts everything that doesn't match the predefined
categories in Other?

I'm only guessing because without a minimal  reproducible example it's
difficult to do anything else.

Best wishes
Ulrik

Rui Barradas  schrieb am Do., 1. Juni 2017, 17:30:

> Hello,
>
> In order for us to help we need to know how you've imported your data.
> What was the file type? What instructions have you used to import it?
> Did you use base R or a package?
> Give us a minimal but complete code example that can reproduce your
> situation.
>
> Hope this helps,
>
> Rui Barradas
>
> Em 01-06-2017 11:02, Tara Adcock escreveu:
> > Hi,
> >
> > I have a question regarding data importing into R.
> >
> > When I import my data into R and review the summary, some of my
> explanatory variables are being reported as if instead of being one
> variable, they are two with the same name. See below for an example;
> >
> > Behav person Behav dog   Position
> >**combination  : 38   combination  :  4** Bank:372
> >**combination  :  7   combination  :  4**   **Island  :119**
> >  fast :123   fast : 15 **Island  : 11**
> >  slow :445   slow : 95   Land:  3
> >  stat :111   stat : 14   Water   :230
> >
> > Also, all of the distances I have imported are showing up in the summary
> along with a line entitled "other". However, I haven't used any other
> distances?
> >
> > DistanceDistance.dog
> > 2-10m  :184 <50m   : 35
> > <50m   :156 2-10m  : 27
> > 10-20m :156 20-30m : 23
> > 20-30m : 91 30-40m : 16
> > 40-50m : 57 10-20m : 13
> > **(Other): 82   (Other): 18**
> >
> > I have checked my data sheet over and over again and I think
> standardised the data, but the issue keeps arising. I'm assuming I need to
> clean the data set but as a nearly complete novice in R I am not certain
> how to do this. Any help at all with this would be much appreciated. Thanks
> so much.
> >
> > Kind Regards,
> >
> > Tara Adcock.
> >
> >
> >   [[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] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread David L Carlson
It looks like your printouts are based on the R summary() function? The 
function lists the number of cases in the 5 largest categories when the 
variable is coded as a function. Then it indicates how many other categories 
are present. This is described on the manual page for function summary().

In the first case the duplicates probably represent cases in your source data 
(a spreadsheet?), where you have inadvertently put a space at the end of the 
label, e.g. "combination", and "combination ". The answers to both questions 
are easy to find with the levels() function:

levels(yourdataframe$Position) 

This will list all of the factor levels in variable Position for you. If there 
are extras spaces and you were using read.csv() to import the data, use the 
strip.white=TRUE argument to delete leading and trailing spaces. This is also 
documented on the manual page for function read.csv(). One of the problems with 
spreadsheets is that these extra spaces are not readily apparent.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ulrik Stervbo
Sent: Thursday, June 1, 2017 10:50 AM
To: Rui Barradas ; Tara Adcock ; 
r-help@r-project.org
Subject: Re: [R] Data import R: some explanatory variables not showing up 
correctly in summary

Hi Tara,

It seems that you categorise and count for each category. Could it be that
the method you use puts everything that doesn't match the predefined
categories in Other?

I'm only guessing because without a minimal  reproducible example it's
difficult to do anything else.

Best wishes
Ulrik

Rui Barradas  schrieb am Do., 1. Juni 2017, 17:30:

> Hello,
>
> In order for us to help we need to know how you've imported your data.
> What was the file type? What instructions have you used to import it?
> Did you use base R or a package?
> Give us a minimal but complete code example that can reproduce your
> situation.
>
> Hope this helps,
>
> Rui Barradas
>
> Em 01-06-2017 11:02, Tara Adcock escreveu:
> > Hi,
> >
> > I have a question regarding data importing into R.
> >
> > When I import my data into R and review the summary, some of my
> explanatory variables are being reported as if instead of being one
> variable, they are two with the same name. See below for an example;
> >
> > Behav person Behav dog   Position
> >**combination  : 38   combination  :  4** Bank:372
> >**combination  :  7   combination  :  4**   **Island  :119**
> >  fast :123   fast : 15 **Island  : 11**
> >  slow :445   slow : 95   Land:  3
> >  stat :111   stat : 14   Water   :230
> >
> > Also, all of the distances I have imported are showing up in the summary
> along with a line entitled "other". However, I haven't used any other
> distances?
> >
> > DistanceDistance.dog
> > 2-10m  :184 <50m   : 35
> > <50m   :156 2-10m  : 27
> > 10-20m :156 20-30m : 23
> > 20-30m : 91 30-40m : 16
> > 40-50m : 57 10-20m : 13
> > **(Other): 82   (Other): 18**
> >
> > I have checked my data sheet over and over again and I think
> standardised the data, but the issue keeps arising. I'm assuming I need to
> clean the data set but as a nearly complete novice in R I am not certain
> how to do this. Any help at all with this would be much appreciated. Thanks
> so much.
> >
> > Kind Regards,
> >
> > Tara Adcock.
> >
> >
> >   [[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.
>

[[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, 

Re: [R] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread William Dunlap via R-help
Check for leading or trailing spaces in the strings in your data.
 dput(dataset) would show them.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Jun 1, 2017 at 8:49 AM, Ulrik Stervbo 
wrote:

> Hi Tara,
>
> It seems that you categorise and count for each category. Could it be that
> the method you use puts everything that doesn't match the predefined
> categories in Other?
>
> I'm only guessing because without a minimal  reproducible example it's
> difficult to do anything else.
>
> Best wishes
> Ulrik
>
> Rui Barradas  schrieb am Do., 1. Juni 2017, 17:30:
>
> > Hello,
> >
> > In order for us to help we need to know how you've imported your data.
> > What was the file type? What instructions have you used to import it?
> > Did you use base R or a package?
> > Give us a minimal but complete code example that can reproduce your
> > situation.
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Em 01-06-2017 11:02, Tara Adcock escreveu:
> > > Hi,
> > >
> > > I have a question regarding data importing into R.
> > >
> > > When I import my data into R and review the summary, some of my
> > explanatory variables are being reported as if instead of being one
> > variable, they are two with the same name. See below for an example;
> > >
> > > Behav person Behav dog   Position
> > >**combination  : 38   combination  :  4** Bank:372
> > >**combination  :  7   combination  :  4**   **Island  :119**
> > >  fast :123   fast : 15 **Island  : 11**
> > >  slow :445   slow : 95   Land:  3
> > >  stat :111   stat : 14   Water   :230
> > >
> > > Also, all of the distances I have imported are showing up in the
> summary
> > along with a line entitled "other". However, I haven't used any other
> > distances?
> > >
> > > DistanceDistance.dog
> > > 2-10m  :184 <50m   : 35
> > > <50m   :156 2-10m  : 27
> > > 10-20m :156 20-30m : 23
> > > 20-30m : 91 30-40m : 16
> > > 40-50m : 57 10-20m : 13
> > > **(Other): 82   (Other): 18**
> > >
> > > I have checked my data sheet over and over again and I think
> > standardised the data, but the issue keeps arising. I'm assuming I need
> to
> > clean the data set but as a nearly complete novice in R I am not certain
> > how to do this. Any help at all with this would be much appreciated.
> Thanks
> > so much.
> > >
> > > Kind Regards,
> > >
> > > Tara Adcock.
> > >
> > >
> > >   [[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.
> >
>
> [[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.


Re: [R] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread Ulrik Stervbo
Hi Tara,

It seems that you categorise and count for each category. Could it be that
the method you use puts everything that doesn't match the predefined
categories in Other?

I'm only guessing because without a minimal  reproducible example it's
difficult to do anything else.

Best wishes
Ulrik

Rui Barradas  schrieb am Do., 1. Juni 2017, 17:30:

> Hello,
>
> In order for us to help we need to know how you've imported your data.
> What was the file type? What instructions have you used to import it?
> Did you use base R or a package?
> Give us a minimal but complete code example that can reproduce your
> situation.
>
> Hope this helps,
>
> Rui Barradas
>
> Em 01-06-2017 11:02, Tara Adcock escreveu:
> > Hi,
> >
> > I have a question regarding data importing into R.
> >
> > When I import my data into R and review the summary, some of my
> explanatory variables are being reported as if instead of being one
> variable, they are two with the same name. See below for an example;
> >
> > Behav person Behav dog   Position
> >**combination  : 38   combination  :  4** Bank:372
> >**combination  :  7   combination  :  4**   **Island  :119**
> >  fast :123   fast : 15 **Island  : 11**
> >  slow :445   slow : 95   Land:  3
> >  stat :111   stat : 14   Water   :230
> >
> > Also, all of the distances I have imported are showing up in the summary
> along with a line entitled "other". However, I haven't used any other
> distances?
> >
> > DistanceDistance.dog
> > 2-10m  :184 <50m   : 35
> > <50m   :156 2-10m  : 27
> > 10-20m :156 20-30m : 23
> > 20-30m : 91 30-40m : 16
> > 40-50m : 57 10-20m : 13
> > **(Other): 82   (Other): 18**
> >
> > I have checked my data sheet over and over again and I think
> standardised the data, but the issue keeps arising. I'm assuming I need to
> clean the data set but as a nearly complete novice in R I am not certain
> how to do this. Any help at all with this would be much appreciated. Thanks
> so much.
> >
> > Kind Regards,
> >
> > Tara Adcock.
> >
> >
> >   [[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.
>

[[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] Post for R

2017-06-01 Thread David L Carlson
As Hasan notes, your code is scrambled because you sent your message in html 
format. This list converts all mail to plain text to make it readable to a 
wider variety of computers and operating systems around the world. One 
consequence is that the html code for newline gets ignored. The attached .png 
file shows how to send plain text messages using yahoo mail. Also use a subject 
line that is a bit more descriptive, e.g. Splitting a data frame on two 
variables.

Without knowing more about your data we cannot know if your method of dividing 
the data into groups is sound. As Jim points out, some of your groups could be 
empty depending on how the variables max and submax are coded. Using str(df) 
would help, but we really need a sample data set to try possible approaches. 
That data set should not be your entire data and can be entirely made up if 
your data is proprietary.

Your loop does not work because it overwrites Z and G on each step. Also it is 
completely unnecessary if I understand what you are trying to do. Here's a 
simple reproducible example, that you can try. It uses only 24 cases divided 
into 4 max groups and 2 submax groups, but it should show you how you might 
handle your data. I'll divide the groups into equal ranges, not an equal number 
of observations, but it is not clear which you want. As a result some groups 
could be empty, but that does not happen in this example:

# Set a random seed so you will get the same numbers
set.seed(42)
# Create a simple data set with 3 variables
# Name it dfr instead of df which is a function name
# R will normally figure out which you mean unless you make an error
# in which case you will get a cryptic error message about "a closure"
dfr <- data.frame(var=LETTERS[1:24], max=sample.int(100, 24), 
submax=sample.int(100, 24))
# Create your data into 4 and 2 groups
L1 <- cut(dfr$max, 4)
L2 <- cut(dfr$submax, 2)
# Create the combinations of the two groups
L12 <- expand.grid(levels(L1), levels(L2))
# Split the data
dfr.sp <- split(dfr, L12)
length(dfr.sp)
# We get 8 groups, 4x2

-
David L Carlson
Department of Anthropology
Texas A 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, June 1, 2017 2:53 AM
To: carrie wang ; r-help mailing list 

Subject: Re: [R] Post for R

Hi Carrie,
You may have a problem with this if some subsets are empty:

L3<-lapply(split(df,cut(df$max,seq(0,1,by=0.01))),
 split,cut(df$submax,seq(0,0.2,by=0.02)))

Jim

On Thu, Jun 1, 2017 at 12:48 PM, carrie wang via R-help
 wrote:
>
> Hello,
> I want to split the dataframe into 1000 groups based on two column values(max 
> value and second max value). First, I made two lists L1 and L2.  L1 is the 
> list divided into 100 groups based on the range of max value and L2 is 
> divided into 10 groups based on the second max values. Now I want to do the 
> combinations based on L1 and L2. I want to do a for loop for L1 and for each 
> element in L1, I split it into 10 groups based on L2. I tried to write the 
> code, but it does not work.
>
> L1<-split(df,cut(df$max,seq(0,1,by=0.01)))L2<-split(df,cut(df$submax,seq(0,0.2,by=0.02)))
> Z<-list()G<-list()for (i in length(L1)){  Z=data.frame(L1[i])  G <- 
> split(Z$submax,"0.02")  print(G)  }
> Thanks so much!Carrie
> [[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.
__
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] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread Rui Barradas

Hello,

In order for us to help we need to know how you've imported your data. 
What was the file type? What instructions have you used to import it? 
Did you use base R or a package?
Give us a minimal but complete code example that can reproduce your 
situation.


Hope this helps,

Rui Barradas

Em 01-06-2017 11:02, Tara Adcock escreveu:

Hi,

I have a question regarding data importing into R.

When I import my data into R and review the summary, some of my explanatory 
variables are being reported as if instead of being one variable, they are two 
with the same name. See below for an example;

Behav person Behav dog   Position
   **combination  : 38   combination  :  4** Bank:372
   **combination  :  7   combination  :  4**   **Island  :119**
 fast :123   fast : 15 **Island  : 11**
 slow :445   slow : 95   Land:  3
 stat :111   stat : 14   Water   :230

Also, all of the distances I have imported are showing up in the summary along with a 
line entitled "other". However, I haven't used any other distances?

DistanceDistance.dog
2-10m  :184 <50m   : 35
<50m   :156 2-10m  : 27
10-20m :156 20-30m : 23
20-30m : 91 30-40m : 16
40-50m : 57 10-20m : 13
**(Other): 82   (Other): 18**

I have checked my data sheet over and over again and I think standardised the 
data, but the issue keeps arising. I'm assuming I need to clean the data set 
but as a nearly complete novice in R I am not certain how to do this. Any help 
at all with this would be much appreciated. Thanks so much.

Kind Regards,

Tara Adcock.


[[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] installed.packages() does not work properly

2017-06-01 Thread Anil Dabral
Thank you. The patched version worked. Installing R 3.4 patched was little 
tricky because windows SmartScreen Filter kept blocking. But finally, I got it 
installed.


Regards,

Anil


Sent from Outlook

From: Uwe Ligges 
Sent: Thursday, June 1, 2017 1:24:49 PM
To: Anil Dabral; r-help@r-project.org
Subject: Re: [R] installed.packages() does not work properly

Try R-3.4.0 patched.

Best,
Uwe Ligges



On 01.06.2017 03:54, Anil Dabral wrote:
> Hi,
>
> I tried executing the following statement multiple times on R 3.4 and it 
> worked only the first time. In older versions of R it seems to have worked. 
> Am I doing anything wrong?
>
>
> In R 3.4 (works only the first time)
>
> tmp <- installed.packages()  #this works
>
> tmp <- installed.packages() ## See error below
>
>
> Error in if (file.exists(dest) && file.mtime(dest) > file.mtime(lib) &&  :
>missing value where TRUE/FALSE needed
>
>
>
> in R 3.3.3 works well when executed multiple times.
>
> tmp <- installed.packages() #this works
>
> tmp <- installed.packages() #this works
>
> tmp <- installed.packages() #this works
>
>
> Thanks and Regards,
>
> Anil
>
> Sent from Outlook
>
>[[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.


[R] [spatstat] Convert shapefile to pixel image

2017-06-01 Thread Lluis.Hurtado
Dear all,

I am currently working with the spatstat package, using windows and pixel 
images.

First:

My aim is to transform a shapefile (see attached) into a pixel image. 

My idea is to start transforming the shapefile into a Spatial Polygon file:

x <- readShapeSpatial("21441.shp")
y <- as(x, "SpatialPolygons")
z <- as.owin(y)

Given z, I want to identify each polygon with a single constant value. This is 
like adding marks to the SpatialPolygons file. Then I want to convert these 
polygons into an image, such that the value of each pixel corresponds to the 
value associated to the polygon where the pixel lies. 

I have been able to do this individually, polygon by polygon, but then I cannot 
merge the resulting images into a single one. Any idea?

Second:

I would also need a single window containing all the smallest polygons (the 
boundary). I have tried:

w <- union.owin(z)

But the resulting window w still shows internal polygons. As read in spatstas 
FAQ page:

"First, convert each of the regions into a separate owin object. Then apply 
union.owin to combine them."

So I try,

regions <- slot(y, "polygons")
regions <- lapply(regions, function(x) { SpatialPolygons(list(x)) })
windows <- lapply(regions, as.owin) 

But windows is a list of 4307 polygons. How can introduce all of them as a 
single argument?

> M <- union.owin(windows)
Warning messages:
1: In union.owin(windows) : Some arguments were not windows
2: In union.owin(windows) : No windows were given


Thank you very much for you help.

Lluís Hurtado.
__
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] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread Tara Adcock
Hi,

I have a question regarding data importing into R.

When I import my data into R and review the summary, some of my explanatory 
variables are being reported as if instead of being one variable, they are two 
with the same name. See below for an example;

   Behav person Behav dog   Position
  **combination  : 38   combination  :  4** Bank:372
  **combination  :  7   combination  :  4**   **Island  :119**
fast :123   fast : 15 **Island  : 11**
slow :445   slow : 95   Land:  3
stat :111   stat : 14   Water   :230

Also, all of the distances I have imported are showing up in the summary along 
with a line entitled "other". However, I haven't used any other distances?

   DistanceDistance.dog
   2-10m  :184 <50m   : 35
   <50m   :156 2-10m  : 27
   10-20m :156 20-30m : 23
   20-30m : 91 30-40m : 16
   40-50m : 57 10-20m : 13
   **(Other): 82   (Other): 18**

I have checked my data sheet over and over again and I think standardised the 
data, but the issue keeps arising. I'm assuming I need to clean the data set 
but as a nearly complete novice in R I am not certain how to do this. Any help 
at all with this would be much appreciated. Thanks so much.

Kind Regards,

Tara Adcock.


[[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] [spatstat] Convert shapefile to pixel image

2017-06-01 Thread Lluis.Hurtado
Dear all,

I am currently working with the spatstat package, using windows and pixel 
images.

First:

My aim is to transform a shapefile (see attached) into a pixel image. 

My idea is to start transforming the shapefile into a Spatial Polygon file:

x <- readShapeSpatial("21441.shp")
y <- as(x, "SpatialPolygons")
z <- as.owin(y)

Given z, I want to identify each polygon with a single constant value. This is 
like adding marks to the SpatialPolygons file. Then I want to convert these 
polygons into an image, such that the value of each pixel corresponds to the 
value associated to the polygon where the pixel lies. 

I have been able to do this individually, polygon by polygon, but then I cannot 
merge the resulting images into a single one. Any idea?

Second:

I would also need a single window containing all the smallest polygons (the 
boundary). I have tried:

w <- union.owin(z)

But the resulting window w still shows internal polygons. As read in spatstas 
FAQ page:

"First, convert each of the regions into a separate owin object. Then apply 
union.owin to combine them."

So I try,

regions <- slot(y, "polygons")
regions <- lapply(regions, function(x) { SpatialPolygons(list(x)) })
windows <- lapply(regions, as.owin) 

But windows is a list of 4307 polygons. How can introduce all of them as a 
single argument?

> M <- union.owin(windows)
Warning messages:
1: In union.owin(windows) : Some arguments were not windows
2: In union.owin(windows) : No windows were given


Thank you very much for you help.

Lluís Hurtado.

__
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: Question on function "scatterplot3d"

2017-06-01 Thread Uwe Ligges



On 01.06.2017 10:03, Rolf Turner wrote:

On 01/06/17 19:54, Uwe Ligges wrote:
A design flaw, whether the labels are cut depends somewhat on the 
sizce of the device, hence there is the argument


y.margin.add

add additional space between tick mark labels and axis label of the y 
axis


for working around that limittation that can be set to some positive 
value



This seems to be addressing Hannah's (li li's) original enquiry, not my 
follow-up in which I worried about the position, along the y-axis, of 
the y-axis label.


Ah, that is intended as a smart way of rotating it along the axis is not 
easy (if not impossible) with the bas egraohics system.


Best,
Uwe Ligges





Or am I misunderstanding/missing something?

cheers,

Rolf



__
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] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-06-01 Thread Bert Gunter
I think you should take this conversation private or seek local
statistical expertise. This is about strategies for analysis, not
about programming in R.

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 Wed, May 31, 2017 at 9:49 PM, Nelly Reduan  wrote:
> Thank you very much Rob for your answer. I have some difficulties to 
> understand how to apply my agent-based model to each parameter combination 
> generated by the LHS, in particular when parameters are defined by 
> probability distributions. Indeed, I have multiple parameters in my model: 
> parameters which are defined by a single value (like “temperature", 
> "pressure”) and parameters which are defined by probability distributions 
> (like “dispersal distance”). It’s correct for me to treat distance as a 
> class. When all parameters are defined by a single value, I need first to 
> create a data frame in which each column represents a different parameter, 
> and each row represents a different combination of parameter values. Then, I 
> apply my model to each row of the data frame. But, it’s not clear for me how 
> to do this when parameters are defined from probability distributions? In 
> particular, how can I use your code to apply my model to each of the 50 rows 
> of the data frame “tabLHS”? Given that one row corresponds to one model 
> simulation, I should have a value generated by the LHS for all distance 
> classes at the first line of the data frame.
>
>
>
> library(pse)
> q <- list("qexp", "qunif", "qunif")
> q.arg <- list(list(rate=exponential_rate), list(min=0, max=1),
> list(min=0, max=1))
> uncoupledLHS <- LHS(model=model_function, input_parameters, N, q, q.arg)
> hist(uncoupledLHS$data$dispersal_distance, breaks=10)
>
> tabLHS <- get.data(uncoupledLHS)
>
>
>
> Sorry, it’s the first time that I perform a sensitivity analysis using the 
> LHS.
>
>
> Thank you very much for your time.
>
> Have a nice day
>
> Nell
>
>
> 
> De : Rob C 
> Envoyé : mardi 30 mai 2017 16:26:08
> À : Nelly Reduan
> Cc : r-help@r-project.org
> Objet : Re: [R] Latin Hypercube Sampling when parameters are defined 
> according to specific probability distributions
>
> Nell,
>
> I still might not be interpreting your question correctly, but I will try.
>
> When you say that the sum of the probabilities of all distance classes
> must equal one, I am going to treat distance as a class, instead of as a
> continuous variable.
>
> distance_class_probabilities <- c(9, 11, 10, 8.9, 8, 7, 6, 5.8, 5.1,
> 4, 3.9, 3.7, 3.4, 3.1, 2, 1.9, 1.6, 1.4, 1, 0.9, 0.8, 0.7, 0.4, 0.3,
> 0.1)/100
> sum(distance_class_probabilities)
> distance_classes <- factor(paste0("d", 1:25), ordered = TRUE,
> levels=paste0("d", 1:25))
> input_parameters <- c("dispersal_distance", "temperature", "pressure")
> N <- 1000
>
> plot(1:25, distance_class_probabilities, type="h", lwd=5)
>
> set.seed(1)
> require(lhs)
> X <- randomLHS(N, length(input_parameters))
> dimnames(X) <- list(NULL, input_parameters)
> Y <- X
> Y[,"dispersal_distance"] <-
> approx(x=cumsum(distance_class_probabilities), y=1:25,
> xout=X[,"dispersal_distance"], method="constant", yleft=0)$y + 1
>
> hist(Y[,"dispersal_distance"], breaks=c(seq(0.5, 25.5, by=1)))
> plot(table(distance_classes[Y[,"dispersal_distance"]]))
>
>
> Is it still a Latin hypercube?
>
> This is a more difficult question.  In some ways, the sample is still a Latin
> hypercube since it was drawn that way.  But once the sample has been 
> discretized
> into the distance classes, then it loses the latin property of having only one
> sample per "row".  It might be close enough for your purposes though.
>
> Rob
>
>
>
> On Tue, May 30, 2017 at 10:59 AM, Nelly Reduan  wrote:
>> Thanks a lot Rob for your answer. I need to add a condition for the
>> parameter “dispersal distance”. The sum of the probabilities of all distance
>> classes must be equal to 1:
>>
>> y <- c(9, 11, 10, 8.9, 8, 7, 6, 5.8, 5.1, 4, 3.9, 3.7, 3.4, 3.1, 2, 1.9,
>> 1.6, 1.4, 1, 0.9, 0.8, 0.7, 0.4, 0.3, 0.1)
>>
>> x <- seq(1, 25, by = 1)
>>
>> barplot(y/100, names.arg=x, ylab="Probability", xlab="Distance (km)")
>>
>>
>>
>> With this condition, is it possible to perform a LHS?
>>
>> Thanks a lot for your time.
>>
>> Nell
>>
>>
>> 
>> De : R-help  de la part de Rob C
>> 
>> Envoyé : samedi 27 mai 2017 13:32:23
>> À : r-help@r-project.org
>> Objet : Re: [R] Latin Hypercube Sampling when parameters are defined
>> according to specific probability distributions
>>
>>>May 26, 2017; 11:41am  Nelly Reduan Latin Hypercube Sampling when
>>> parameters are >defined according to specific probability distributions
>>>Hello,
>>> I would like to perform a sensitivity analysis using a 

Re: [R] odfWeave - A loop of the "same" data

2017-06-01 Thread Jeff Newmiller
I do this regularly with knitr [1]. I have never used odfWeave, but would 
imagine that similar principles apply. 

If you make a child document that assumes that the desired data are stored in 
one or more objects, then you can use a for loop in the master document that 
repeatedly extracts the desired subsets and puts them into the objects the 
child document expects them to be in, parses the child document, and then 
"cat"s the parsed results into the master document output.

[1] https://yihui.name/knitr/demo/child/
-- 
Sent from my phone. Please excuse my brevity.

On June 1, 2017 3:55:33 AM PDT, "POLWART,  Calum (COUNTY DURHAM AND DARLINGTON 
NHS FOUNDATION TRUST) via R-help"  wrote:
>Before I go and do this another way - can I check if anyone has a way
>of looping through data in odfWeave (or possibly sweave) to do a
>repeating analysis on subsets of data?
>
>For simplicity lets use mtcars dataset in R to explain.  Dataset looks
>like this:
>
>> mtcars
>   mpg cyl disp  hp drat   wt ...
>Mazda RX4 21.0   6  160 110 3.90 2.62 ...
>Mazda RX4 Wag 21.0   6  160 110 3.90 2.88 ...
>Datsun 71022.8   4  108  93 3.85 2.32 ...
>   
>
>Say I wanted to have a 'catalogue' style report from mtcars, where on
>each page I would perhaps have the Rowname as a heading and then plot a
>graph of mpg highlighting that specific car
>
>Then add a page break and *do the same for the next car*.  I can
>manually do this of course, but it is effectively a loop something like
>this:
>
>for (n in length(mtcars$mpg)) {
>barplot (mtcars$mpg, col=c(rep(1,n-1),2,rep(1,length(mtcars$mpg)-n)))
>}
>
>There is a odfWeave page break function so I can do that sort of thing
>(I think).  But I don't think I can output more than one image can I? 
>In reality I will want several images and a table per "catalogue" page.
>
>At the moment I think I need to create a master odt document, and
>create individual catalogue pages.  And merge them into one document -
>but that feels clunky (unless I can script the merge!)
>
>Anyone got a better way?
>
>
>
>
>
>
>This message may contain confidential information. If
>yo...{{dropped:21}}
>
>__
>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] odfWeave - A loop of the "same" data

2017-06-01 Thread POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) via R-help
Before I go and do this another way - can I check if anyone has a way of 
looping through data in odfWeave (or possibly sweave) to do a repeating 
analysis on subsets of data?

For simplicity lets use mtcars dataset in R to explain.  Dataset looks like 
this:

> mtcars
   mpg cyl disp  hp drat   wt ...
Mazda RX4 21.0   6  160 110 3.90 2.62 ...
Mazda RX4 Wag 21.0   6  160 110 3.90 2.88 ...
Datsun 71022.8   4  108  93 3.85 2.32 ...
   

Say I wanted to have a 'catalogue' style report from mtcars, where on each page 
I would perhaps have the Rowname as a heading and then plot a graph of mpg 
highlighting that specific car

Then add a page break and *do the same for the next car*.  I can manually do 
this of course, but it is effectively a loop something like this:

for (n in length(mtcars$mpg)) {
barplot (mtcars$mpg, col=c(rep(1,n-1),2,rep(1,length(mtcars$mpg)-n)))
}

There is a odfWeave page break function so I can do that sort of thing (I 
think).  But I don't think I can output more than one image can I?  In reality 
I will want several images and a table per "catalogue" page.

At the moment I think I need to create a master odt document, and create 
individual catalogue pages.  And merge them into one document - but that feels 
clunky (unless I can script the merge!)

Anyone got a better way?






This message may contain confidential information. If yo...{{dropped:21}}

__
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] (Somewhat?) Off topic: Containerization software

2017-06-01 Thread Suzen, Mehmet
This is a nice summary addressing the same with R:
https://arxiv.org/pdf/1410.0846.pdf

On 30 May 2017 at 17:43, Bert Gunter  wrote:
> Folks:
>
> This is **off topic**, but I thought it might be informative to this
> community. Consequently: please **no on list public comments or
> discussion**. Feel free to respond to me privately, if you like; but I
> have neither knowledge nor opinions, so why bother? This is just FYI.
> My apology if it is deemed inappropriate.
>
> http://www.nature.com/news/software-simplified-1.22059
>
> 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 )
>
> __
> 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] [FORGED] Re: Question on function "scatterplot3d"

2017-06-01 Thread Rolf Turner

On 01/06/17 19:54, Uwe Ligges wrote:
A design flaw, whether the labels are cut depends somewhat on the sizce 
of the device, hence there is the argument


y.margin.add

add additional space between tick mark labels and axis label of the y axis

for working around that limittation that can be set to some positive 
value



This seems to be addressing Hannah's (li li's) original enquiry, not my 
follow-up in which I worried about the position, along the y-axis, of 
the y-axis label.


Or am I misunderstanding/missing something?

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] installed.packages() does not work properly

2017-06-01 Thread Uwe Ligges

Try R-3.4.0 patched.

Best,
Uwe Ligges



On 01.06.2017 03:54, Anil Dabral wrote:

Hi,

I tried executing the following statement multiple times on R 3.4 and it worked 
only the first time. In older versions of R it seems to have worked. Am I doing 
anything wrong?


In R 3.4 (works only the first time)

tmp <- installed.packages()  #this works

tmp <- installed.packages() ## See error below


Error in if (file.exists(dest) && file.mtime(dest) > file.mtime(lib) &&  :
   missing value where TRUE/FALSE needed



in R 3.3.3 works well when executed multiple times.

tmp <- installed.packages() #this works

tmp <- installed.packages() #this works

tmp <- installed.packages() #this works


Thanks and Regards,

Anil

Sent from Outlook

[[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] [FORGED] Re: Question on function "scatterplot3d"

2017-06-01 Thread Uwe Ligges
A design flaw, whether the labels are cut depends somewhat on the sizce 
of the device, hence there is the argument


y.margin.add

add additional space between tick mark labels and axis label of the y axis

for working around that limittation that can be set to some positive 
value


Best,
Uwe Ligges


On 01.06.2017 07:15, Rolf Turner wrote:

On 01/06/17 13:17, Ismail SEZEN wrote:



On 1 Jun 2017, at 03:41, li li  wrote:

Hi all,
  I have a question with regard to making plots using function
"scatterplot3d".
Please see the example below. It looks like, for y axis, the tickmark 
text

was cutoff.
The number "10" does not show up completely. I tried to work with 
par(mpg).

It does not
seem to work. Hope to get some advice here. Thanks much!
   Hanna

C <- runif(30)
B <- rep(1:3, each=10)
A <- rep(1:10,3)
scatterplot3d(B,A,C, type = "h", lwd = 1, pch = 16, color="red",  main =
"",
  grid=TRUE,  col.grid="lightgreen",
  xlab="x", ylab="y", zlab="z”)


Everything seems ok to me. Try to reset/clear all plots in your 
plotting window and try only to run the code above. Perhaps You 
changed par settings before in some point?



I tried the code given above, and after I replaced the deleted> incorrect double quote mark (after the final "z"), it ran and 
looked OK *except* for the positioning of the "y" axis label, which is 
at the "far end" of the y-axis rather than being at the "centre" of the 
y-axis.  (See attached.)


Is this a bug?

cheers,

Rolf Turner

P.S. I have also attached the code in the file "scatScript.txt", for 
convenience.


P^2. S.:

 > sessionInfo()
R Under development (unstable) (2017-04-21 r72585)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

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

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

other attached packages:
[1] scatterplot3d_0.3-40 misc_0.0-16

loaded via a namespace (and not attached):
  [1] compiler_3.5.0   deldir_0.1-15Matrix_1.2-8
  [4] spatstat.utils_1.4-1 tools_3.5.0  mgcv_1.8-17
  [7] abind_1.4-5  spatstat_1.50-0  rpart_4.1-11
[10] nlme_3.1-131 grid_3.5.0   polyclip_1.6-1
[13] lattice_0.20-35  goftest_1.1-1tensor_1.5


scatScript.txt


library(scatterplot3d)
set.seed(42)
C <- runif(30)
B <- rep(1:3, each=10)
A <- rep(1:10,3)
scatterplot3d(B,A,C, type = "h", lwd = 1, pch = 16, color="red",
   main = "", grid=TRUE,  col.grid="lightgreen",
   xlab="x", ylab="y", zlab="z")



__
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] Post for R

2017-06-01 Thread Jim Lemon
Hi Carrie,
You may have a problem with this if some subsets are empty:

L3<-lapply(split(df,cut(df$max,seq(0,1,by=0.01))),
 split,cut(df$submax,seq(0,0.2,by=0.02)))

Jim

On Thu, Jun 1, 2017 at 12:48 PM, carrie wang via R-help
 wrote:
>
> Hello,
> I want to split the dataframe into 1000 groups based on two column values(max 
> value and second max value). First, I made two lists L1 and L2.  L1 is the 
> list divided into 100 groups based on the range of max value and L2 is 
> divided into 10 groups based on the second max values. Now I want to do the 
> combinations based on L1 and L2. I want to do a for loop for L1 and for each 
> element in L1, I split it into 10 groups based on L2. I tried to write the 
> code, but it does not work.
>
> L1<-split(df,cut(df$max,seq(0,1,by=0.01)))L2<-split(df,cut(df$submax,seq(0,0.2,by=0.02)))
> Z<-list()G<-list()for (i in length(L1)){  Z=data.frame(L1[i])  G <- 
> split(Z$submax,"0.02")  print(G)  }
> Thanks so much!Carrie
> [[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] Post for R

2017-06-01 Thread Hasan Diwan
Carrie,
I would suggest a few things before posting your code here:
- Put a dput(df)
- Format it properly, as it stands it won't compile, because you're missing
newlines/semicolons between, e.g. Z <- list()*; *G <- list(); for (i in
length(L1)){  Z=data.frame(L1[i])*;* G <- split(Z$submax,"0.02")*;*
 print(G)  }
-- H

On 31 May 2017 at 19:48, carrie wang via R-help 
wrote:

>
> Hello,
> I want to split the dataframe into 1000 groups based on two column
> values(max value and second max value). First, I made two lists L1 and L2.
> L1 is the list divided into 100 groups based on the range of max value and
> L2 is divided into 10 groups based on the second max values. Now I want to
> do the combinations based on L1 and L2. I want to do a for loop for L1 and
> for each element in L1, I split it into 10 groups based on L2. I tried to
> write the code, but it does not work.
>
> L1<-split(df,cut(df$max,seq(0,1,by=0.01)))L2<-split(df,cut(d
> f$submax,seq(0,0.2,by=0.02)))
> Z<-list()G<-list()for (i in length(L1)){  Z=data.frame(L1[i])  G <-
> split(Z$submax,"0.02")  print(G)  }
> Thanks so much!Carrie
> [[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.




-- 
OpenPGP: https://sks-keyservers.net/pks/lookup?op=
get=0xFEBAD7FFD041BBA1
If you wish to request my time, please do so using http://bit.ly/
hd1ScheduleRequest.
Si vous voudrais faire connnaisance, allez a http://bit.ly/
hd1ScheduleRequest.

Sent
from my mobile device
Envoye de mon portable

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