Displaying 20 results from an estimated 900 matches similar to: "Function to Define a Function"
2013 Oct 14
0
how to prevent default argument values from being found
Here is a problem I ran across in RStudio, which uses masks a number of standard R functions with versions that do a bit more than the original does. The RStudio people have figured out a way to prevent default values of arguments from being found when an argument is missing from a call!
junk1 <- function(...) {
fun <- function(pkgs, lib = NULL)
{
list(missing=missing(lib),
2008 Jun 16
1
aggregate() function, strange behavior for augmented data
All,
I'm re-running some analysis that has been augmented with additional data.
When I use the exact same code for the augmented data, the behavior of the
aggregate function is very strange, viz., one of the resulting variables is
now coded as a factor while it was coded as numeric for the original data.
Unfortunately, I cannot provide a reproducible code example since it only
seems to occur
2010 Feb 04
4
xyplot 3 panels 3 different Y variables
Often, when exploring a dataset, I'd like to plot several very different Y variables against the same X variable, in panels stacked one over the other. Is there an easy way to do this?
I'd like to achieve an elegant look similar to the look achieved by lattice in conditioned plots--for instance no space between panels. But unlike in straightforward conditioned plot, each panel may be on a
2006 Jan 27
3
paging agi
Hello Everyone,
I've been playing with an agi script for paging sip phones.
page.agi will take all available sip extensions and assign them to the
global variable PAGE_GROUP. Allowing the phones to be paged from the
dialplan with the new Page cmd. Extensions to be excluded are presented as
arguments to the agi. Each time a page is made this agi refreshes the global
variable. This works with
2010 Mar 04
3
Issues when volume is full
I''ve been using btrfs as a spool space on our back-up server to get
familiar with it and things work fine until the volume fills up. Our
backup software (bacula) usually spools until the volume is full, then
despools and respools, etc. With btrfs, it fills up and bacula thinks
there is still space so it keeps trying and then finally errors out. I
thought this was a problem because I was
2017 Jun 01
5
Reversing one dimension of an array, in a generalized case
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
2010 Jan 21
1
Retrieving an evaluated gradient value (UNCLASSIFIED)
Classification: UNCLASSIFIED
Caveats: NONE
Dear R users,
How can I retrieve an evaluated gradient value from "deriv" function
provided below? I want to retrieve b0 value. Appreciate your help.
Kyong
junk1<-deriv(~(1/b1)*k-b0/b1,"b0",c("k","b0","b1"),formal=T)
junk1(k=0,b0=-14.0236,b1=2.44031)
[1] 5.746647
attr(, "gradient"):
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
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
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
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
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
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
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
2008 Nov 04
1
contour plot, failing to interpolate through all data
I'm having trouble making contour lines for this attached, sparse
dataset (low data:NA ratio!). Is it the high number of NA's, or funny
layout of the densities, or something else that's causing this? This is
a subsample of the dataset, and I get the same problem when using the
full data. The only reason I get any contours is because I'm forcing
specific levels. If no levels are
2004 Aug 17
1
An entire data frame which is a time-series?
I have :
raw <- read.table("monthly.text", skip=3, sep="|",
col.names=c("junk", "junk2",
"wpi", "g.wpi", "wpi.primary", "g.wpi.primary",
"wpi.fuel", "g.wpi.fuel", "wpi.manuf", "g.wpi.manuf",
2008 Jul 17
2
nested calls, variable scope
Below is an example of a problem I encounter repeatedly when I write functions. A call works at the command line, but it does not work inside a function, even when I have made sure that all required variables are available within the function. The only way I know to solve it is to make the required variable global, which of course is dangerous. What is the elegant or appropriate way to solve
2011 Mar 09
4
Help with read.csv
Hello,
I have a file that looks like this:
Date,Hour,DA_DMD,DMD,DA_RTP,RTP,,
1/1/2006,1,3393.9,3412,76.65,105.04,,
1/1/2006,2,3173.3,3202,69.20,67.67,,
1/1/2006,3,3040.0,3051,69.20,77.67,,
1/1/2006,4,2998.2,2979,67.32,69.10,,
1/1/2006,5,3005.8,2958,65.20,68.34,,
where the ',' is the separator and I tried to read it into R, but...
> y <- read.csv("Data/Data_tmp.csv",
2012 May 20
2
Remus network buffering problem
Hi all,
I have a following problem:
- Remus network buffering doesn''t work. It seems to be because of no vif is
reported by the function server.xend.domain on line 29 of
/usr/local/lib/python2.7/dist-packages/xen/remus/vm.py (seen using pdb) :
27 if domid:
28 try:
29 self.dominfo = server.xend.domain(domid, ''all'')
>