Displaying 20 results from an estimated 8000 matches similar to: "Reversing one dimension of an array, in a generalized case"
2017 Jun 01
0
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
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
> On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal <roy.mendelssohn at noaa.gov> 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] =
2017 Jun 01
2
Reversing one dimension of an array, in a generalized case
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.4444444 >"
[2] "Mean relative difference: 0.6109091"
# Your earlier example
> z <- array(1:120, dim=2:5)
>
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
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 <-
2017 Jun 01
1
Reversing one dimension of an array, in a generalized case
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 <dcarlson at tamu.edu> wrote:
>
> On the off chance that anyone is still interested, here is the corrected function using
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
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
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
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
2017 Jun 01
0
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.4444444 >"
[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
2018 Jan 02
4
httr::content without message
Hi All:
I am using httr to download files form a service, in this case a .csv file. When I use httr::content on the result, I get a message. Since this will be in a package. I want to suppress the message, but haven't figured out how to do so.
The following should reproduce the result:
myURL <-
2017 Aug 29
3
RMarkdown question
Hi All:
In creating a R Notebook I know that in the text I can link to a (sub) section by using the command:
[Header 1](#anchor)
and putting the appropriate anchor name at the appropriate header. But can the same be done for code chunks, if the code chunk is named? What I want to do is say that such and such code chunk is an example of how to do something, and have that link to the
2017 Oct 17
2
ggridges help
yes, thanks, and I was getting close to that. One thing I found is the manual says the height is the distance above the y-line, which should be, but doesn't have to be positive. In fact, the time series are estimates of a cycle, and has negative values, which unfortunately are not included in my sub-sample. And the negative values are not handled properly (the series disappears for
2017 Oct 17
2
ggridges help
I have tried:
ggplot(plotFrame, aes(x = time, y = cycle, height = cycle, group = depth)) + geom_ridgeline()
ggplot(plotFrame, aes(x = time, y = depth, height = cycle, group = depth)) + geom_ridgeline()
ggplot(plotFrame, aes(x = time, y = depth, group = depth)) + geom_density_ridges()
none are producing a plot that was a ridgeline for each depth showing the time series at that depth. The plot
2017 Oct 17
0
ggridges help
The min_height = -0.25 is there to make it show cycle values down to -1/4.
You may want to change it to -1 so it shows more of the cycle values.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Tue, Oct 17, 2017 at 1:26 PM, Roy Mendelssohn - NOAA Federal <
roy.mendelssohn at noaa.gov> wrote:
> yes, thanks, and I was getting close to that. One thing I found is the
> manual says the
2017 Oct 17
0
ggridges help
Does the following work for you?
ggplot2::ggplot(plotFrame, aes(x = time, y = depth, height = cycle,
group = depth)) + ggridges::geom_ridgeline(fill="red", min_height=-0.25)
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Tue, Oct 17, 2017 at 12:43 PM, Roy Mendelssohn - NOAA Federal <
roy.mendelssohn at noaa.gov> wrote:
> I have tried:
>
> ggplot(plotFrame, aes(x =
2017 Aug 29
0
RMarkdown question
Although it is not an elegant solution, but if your output format is
HTML, you can add an arbitrary empty HTML element like <span
id="foo"></span> before your code chunk. Then you can jump to this
<span> via a link like "see [this code chunk](#foo)".
Regards,
Yihui
--
https://yihui.name
On Tue, Aug 29, 2017 at 1:30 PM, Roy Mendelssohn - NOAA Federal
2017 Oct 17
2
ggridges help
Hi All:
I am just not understanding ggridges. The data I have are time series at different depths in the ocean. I want to make a joy plot of the time series by depth.
If I was just doing a ggplot2 line plot I would be doing:
ggplot(plotFrame, aes(x = time, y = cycle, group = depth)) + geom_line()
but translating that to ggridges has not worked right. Below is the result from dput() of a
2018 Jan 02
1
httr::content without message
Thanks to all that replied. I had just looked through the httr code and sure enough for a .csv mime time it calls readr::read_csv(). The httr::content docs suggest not using automatic parsing in a package, rather to determine mime type and parse yourself and Ben's suggestion also works if I do:
junk <- readr::read_csv(r1$content, col_types = cols())
Perfect. Using httr rather than
2018 Jan 02
0
httr::content without message
Ahoy!
That's a message generated by the readr::read_table() function (or it's friends). You can suppress it a number of ways, but this should work as httr::content() will pass through arguments, like col_types = cols(), to the file reader.
junk <- httr::content(r1, col_types = cols())
See more here...
https://blog.rstudio.com/2016/08/05/readr-1-0-0/
2017 Oct 17
0
ggridges help
...and your question is...?
... and the code you tried that didn't work was?
Bert
On Oct 17, 2017 12:22 PM, "Roy Mendelssohn - NOAA Federal" <
roy.mendelssohn at noaa.gov> wrote:
> Hi All:
>
> I am just not understanding ggridges. The data I have are time series at
> different depths in the ocean. I want to make a joy plot of the time
> series by depth.
2017 Oct 18
1
dygraphs, multiple graphs and shiny
Hi All:
This is really getting into the weeds, but I am hoping someone will have a solution. I am trying to use dygrahs for R, within Shiny.
The situation arises when I am combining a number of dygraphs into one plot. If I am just in an RNotebook, if you look at:
https://stackoverflow.com/questions/30509866/for-loop-over-dygraph-does-not-work-in-r
the solution to have the plot shown from a