Displaying 20 results from an estimated 10000 matches similar to: "sort a data frame by a vector"
2009 Dec 11
4
get the enclosing function name
Hi,
Is there a way to get the enclosing function name within a function?
For example, I would like to have a function getEnclosingFunctionName().
It works like below
f = function(){
print(getEnclosingFunctionName())
}
f() # will print "f"
Thanks
Jeff
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 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.
2012 Mar 18
3
assign a value to an element
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?...
Nom : non disponible
URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20120318/d68edf35/attachment.pl>
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",
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
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
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]]
}
2006 Apr 04
1
Indexing a vector by a list of vectors
Hello R-help -
I have
vec <- c("string1", "string2", "string3")
ind <- list(c(1,2),c(1,2,3))
I want "vec" indexed by each vector in the list "ind".
The first element of the list I want would be vec[c(1,2)],
the second element would be vec[c(1,2,3)], like the following.
[[1]]
[1] "string1" "string2"
[[2]]
[1]
2007 May 18
2
Split a vector(list) into 3 list
Hi,
I have a vector contains values 1,2,3.
Can I call a function split to split it into 3 vectors with 1 corresponds
to value ==1, which contain all the indexes for value==1.
2 corresponds to value ==2 which contain all the indexes for value=2
Thanks
pat
2002 Sep 09
2
lapply-related question
Dear R-gurus,
I would like to use a lapply on a kind of "bivariate" problem. I have
a vector and a list, components of which are vectors, e.g.
vec <- c(1,2,3)
lst <- list(1, c(2,3), c(4,5,6))
I want to apply a function to each component of the list, using the
corresponding component of the vector as a parameter. E.g. I want a
list in the form
list(lst[[1]] + vec[1], lst[[2]]