Displaying 20 results from an estimated 7000 matches similar to: "get the enclosing function name"
2009 Nov 16
8
extracting the last row of each group in a data frame
Hi,
I would like to extract the last row of each group in a data frame.
The data frame is as follows
Name Value
A 1
A 2
A 3
B 4
B 8
C 2
D 3
I would like to get a data frame as
Name Value
A 3
B 8
C 2
D 3
Thank you for your suggestions in advance
Jeff
2009 Dec 02
4
sort a data frame by a vector
Hi,
I have a a vector and a data frame with two columns
vec = c("C", "A", "B")
dataDF = data.frame(A1 = c("B", "A", "C"), A2 = c(1,2,3))
I would like to sort the data frame by column A1 such that the order of
elements in A1 is as the same as in vec.
After the ordering, the data frame would be
A1 A2
C
2009 Dec 29
2
pass functions and arguments to function
Hi,
I wonder how to pass several functions and their arguments as arguments to
a function. For example, the main function is
f = function(X ) {
process1(X)
...
process2(X)
}
I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2),
g3(X, par3). par1, par2 and par3 are parameters and of different types. I
would like to pass g1, g2, g3 and their arguments to f and g1,
2009 Dec 29
1
(no subject)
Hi,
I wonder how to pass several functions and their arguments as arguments to
a function. For example, the main function is
f = function(X ) {
process(X)
...
process(X)
}
I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2),
g3(X, par3). par1, par2 and par3 are parameters and of different types.
2009 Nov 24
1
ow to have R automatically print traceback upon errors
Hi,
I wonder how to have R automatically print stack trace produced by
traceback upon errors during interactive uses. I tried the suggestions on
http://old.nabble.com/Automatically-execute-traceback-when-execution-of-script-causes-error--td22368483.html#a22368775
and used options(error = recover)
options(showErrorCalls = T)
It just produces an extra message like "recover called
2009 Dec 29
1
how to append new data to saved data on disk efficiently
Hi,
I currently combine multiple processed data (data frame) into a list and
save the list as ".rda" using the save command. When new data come, I load
the rda file, process the new data into a data frame, append the data
frame to the end of the list, and save the whole list to the disk. The
loading and saving steps are quite time consuming. Since I don't need to
change the old data
2008 Nov 17
5
how to calculate another vector based on the data from a combination of two factors
Hi,
I have a data set similar to the following
State Gender Quantity
TX Male 1
NY Female 2
TX Male 3
NY Female 4
I need to calculate cumulative sum of the quantity by State and Gender. The
expected output is
State Gender Quantity CumQuantity
TX Male 1 1
TX Male 3 4
NY Female 2 2
NY Female 4 6
I highly appreciate if someone can give me some hints on solving that in R.
Hao
--
View this
2010 Jan 08
2
how to organize a lot of R source files
Hi,
I wonder what is a better way to organize a lot of R source files. I have
a lot of utility functions written and store them in several source files
(e.g util1.R, util2.R,..utilN.R). I also have a master file in which the
source command is used to load all the util.R files. When I need to use
the utility functions in a new project, I create a new R file (e.g main.R)
in which I
2009 Nov 25
3
questions on the ff package
Hi,
I have two questions on using the ff package and wonder if anyone who used
ff can share some thoughts.
I need to save a matrix as a memory-mapped file and load it back later. To
save the matrix, I use
mat = matrix(1:20, 4, 5)
matFF = ff(mat, dim=dim(mat), filename="~/a.mat", overwrite=TRUE, dimnames
= dimnames(mat))
To load it back, I use
matFF2 = ff(vmode = "double",
2009 Nov 02
2
save an object by dynamicly created name
Hi,
I would like to save a few dynamically created objects to disk. The
following is the basic flow of the code segment
for(i = 1:10) {
m = i:5
save(m, file = ...) ## ???
}
To distinguish different objects to be saved, I would like to save m as m1,
m2, m3 ..., to file /home/data/m1, /home/data/m2, home/data/m3, ...
I tried a couple of methods on translating between object names and
2008 Nov 20
2
how to replace NA with previous numbers
Hi,
I have a vector with lots of NAs. e.g.
vec = c(NA, NA, 2, NA, NA, 5, NA, 6, NA)
> vec
[1] NA NA 2 NA NA 5 NA 6 NA
I would like to replace NAs with their immediately previous non NA number.
After replacement, the above vector will become
> vec
[1] 0 0 2 2 2 5 5 6 6.
I understand how to do that with a loop but the actual vector is very long
and the loop takes too much time in R.
2009 Dec 24
2
how to do multiple responses in a linear regression
Hi,
I have multiple responses y1, y2, .., yn, and would like to do linear
regression for each of them with x1, x2, ..., xm. Instead of doing
regression n times, it it possible to do it all at once?
I tried lm(y1+y2 ~ x1 + x2 + x3) and lm added y1 y2 and then did the
regression.
thanks
Jeff
2010 Feb 01
2
how to write a function that remembers its state across its calls
Hi,
I wonder how to write a function that remembers its state across its
calls. For example, I would like to compute the average of the pass three
values the function has seen
f(1) # NA
f(2) # NA
f(3) # 2
f(4) # 3
This would require f to keep track of the values it has seen. In other
languages like c++ or java it is easy to do by having a member variable. I
am not sure how to do similar
2010 Jan 25
1
ff package: ff objects don't reload completely on NFS drives from a different machine
Try to close the file on the first nfs client before reopening it on the second nfs client. NFS has something called "close-to-open cache consistency".
This means that two clients which have the same nfs file open, cannot rely on seeing the updates from the respective other client. If one clients closes, and the other client opens thereafter, it should see the changes. If you want
2005 Jan 25
4
typo in ?NotYetImplemented
The `examples' section says
plot.mlm # to see how the "NotYetImplemented"
# reference is made automagically
^
Best,
Torsten
2010 Jan 13
1
"select: bad file descriptor" in the multicore package
Hi,
I wonder anyone knows what causes the error message "select: bad file
descriptor" in the multicore package. This error sometimes occurs and
sometimes doesn't. I couldn't find any documentation on this error about
this package.
thanks
Jeff
2009 Nov 20
1
how to link C code with gsl from R CMD and dyn.load
Hi,
I am writing a function in C that is meant to be called by R. In the C
function, I used a gsl function gsl_stats_mean. The code is as simple as
below
void gsl(double *m, int *dim){
int r, c;
r = dim[0];
c = dim[1];
double mean = gsl_stats_mean(&m[0], 1, r);
Rprintf("mean = %f\n", mean);
}
The C code is succesfully compiled and the output is as follows.
$ R CMD SHLIB
2009 Nov 12
1
how to pass matrices from C to R effectively
Hi,
I have C code to produce a lot of matrices to be analyzed. As these
matrices are large (> 1000*10000) and are a lot (> 1000), I am thinking
about how to pass them from C to R effectively.
Would you think about the following solution? In R, I create a wrapper
function
passDataFromCToR = function(row, col) {
mat = matrix(0, row, col)
.C("passDataFromCToR",mat)[[1]]
}
2011 Aug 08
2
enclosing with() in a function
Hi All,
I want to enclose with() in a function mean_on_element. Obviously, it
is not working. The problem is how to specify the element name with a
function body. Does anybody have any suggestion? Thanks!
> data=list(x=1:10)
> with(data, mean(x))
[1] 5.5
>
> mean_on_element=function(data, elem_name) {
+ with(data, mean(elem_name))
+ }
> mean_on_element(data, 'x')
[1] NA
2004 Sep 05
1
Question to NLME, ML vs. REML
Dear all,
I am planning to use nlme library for analysis of experiments in semiconductor
industry. Currently I am using "lm" but plan to move to "lme" to handle
within wafer / wafer-to-wafer and lot-to-lot variation correctly.
So far everything is working well, but I have a fundamentel question:
NLME offers "maximum likelihood" and "restricted maximum