similar to: extracting the last row of each group in a data frame

Displaying 20 results from an estimated 10000 matches similar to: "extracting the last row of each group in a data frame"

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 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
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
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
2009 Nov 16
3
Sum over indexed value
I am sure this is easy but I am not finding a function to do this. I have two columns in a matrix. The first column contains multiple entries of numbers from 1 to 100 (i.e. 10 ones, 8 twos etc.). The second column contains unique numbers. I want to sum the numbers in column two based on the indexed values in column one (e.g. sum of all values in column two associated with the value 1 in column
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 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 Jun 12
1
Extracting the name of an object
With apologies if I missed the answer in the response given to my previous question. How do I extract the name of an object and assign it to a string variable? For example, I have a dataframe named comnoglyc How do I assign this name to a variable dfname such that print(dfname) returns "comnoglyc"? Thank you very much. Payam [[alternative HTML version deleted]]
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 May 20
1
sqldf: issues with natural joins
Hello, I'm having trouble discovering what's going wrong with my use of natural joins via sqldf. Following the instructions under 4i at http://code.google.com/p/sqldf/, which discusses creating indices to speed joins, I have been only unreliably able to get natural joins to work. For example, > Tid <- c('AES 01-01-02 10:58:00', 'AES 01-01-02 11:53:00', 'AES
2014 Jun 24
2
using C code to create data frame but always return as list
there is my code,  expect return value  is a data frame but R say it is list: SEXP Julia_R_MD_NA_DataFrame(jl_value_t* Var) {  SEXP ans,names,rownames;  char evalcmd[4096];  int i;  const char* dfname="DataFrameName0tmp";  jl_set_global(jl_main_module, jl_symbol(dfname), (jl_value_t*)Var);  //Get Frame cols   sprintf(evalcmd,"size(%s,2)",dfname);  jl_value_t*
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 Jan 02
7
the first and last observation for each subject
I have the following data ID x y time 1 10 20 0 1 10 30 1 1 10 40 2 2 12 23 0 2 12 25 1 2 12 28 2 2 12 38 3 3 5 10 0 3 5 15 2 ..... x is time invariant, ID is the subject id number, y is changing over time. I want to find out the difference between the first and last observed y value for each subject and get a table like ID x y 1 10 20 2 12 15 3 5 5 ...... Is there any easy way to generate
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]] }