similar to: dropping variables from a data frame inside a function

Displaying 20 results from an estimated 10000 matches similar to: "dropping variables from a data frame inside a function"

2012 Nov 01
4
Loop over several variables
Hey everybody, I am looking for a way to loop commands over several variables in a dataframe. Basically I want to do something like this: ti1<-aggregate(dataframename$y1, by=data.frame(dataframename$aggregationvar), sum,na.rm=TRUE) This works fine as it is but i want to do it for several variables thereby generating several tix. I tried with a for-loop but the
2008 Dec 18
2
understanding lexical scope
I am trying to understand the concept of lexical scope in "An Introduction to R" by the R Core development team. I'd appreciate it if someone would explain why the following example does not work: q <- function(y) {x + y}; w <- function(x){q(x)}; w(2); According to the discussion of Scope on page 46, it seems to me that R will interpret the free variable x in q as the
2016 Apr 23
2
Data Frame Column Name Attribute
I am attempting to add a calculated column to a data frame. Basically, adding a column called "newcol2" which are the stock closing prices from 1 day to the next. The one little hang up is the name of the column. There seems to be an additional data column name included in the attributes (dimnames?). So when i run HEAD(DATAFRAMENAME) i get the column name = "Open". but
2011 Jan 19
2
how to get old packages to work on R 2.12.1
I just installed R 2.12.1, and when I went to run a few old programs with it, nothing worked. I got a ton of error messages saying such and such package was built before R 2.10.0 and needed to be reinstalled. These were not just warning messages, but error messages that prevent the programs from running when they were running just fine with R 2.10.1 For some of those packages, such as deSolve, I
2006 Jul 13
2
simple question about variables....
Dear R users, I have a simple question on variable manipulation. Imagine I have an object "OBJ" that has "toto" as one of its variables. I would like to understand why if I do > varname <- "toto" >OBJ$varname returns no results whereas > OBJ[varname] returns the column entitled
2006 Sep 15
1
Formula aruguments with NLS and model.frame()
I could use some help understanding how nls parses the formula argument to a model.frame and estimates the model. I am trying to utilize the functionality of the nls formula argument to modify garchFit() to handle other variables in the mean equation besides just an arma(u,v) specification. My nonlinear model is y<-nls(t~a*sin(w*2*pi/365*id+p)+b*id+int,data=t1,
2010 Feb 11
4
Access variables by string
Dear all, I have two probably very easy questions: (1) Is there a way to access certain variables by their string-based name representation? Example: numbers <- c("one", "two", "three") varname <- "numbers" print(varname[2]) (2) I need this functionality for a customized na.exclude() function that I am building, which should only exclude rows
2007 Dec 13
1
creating lagged variables
Hi all. I'm looking for robust ways of building lagged variables in a dataset with multiple individuals. Consider a dataset with variables like the following: ## set.seed(123) d <- data.frame(id = rep(1:2, each=3), time=rep(1:3, 2), value=rnorm(6)) ## >d id time value 1 1 1 -0.56047565 2 1 2 -0.23017749 3 1 3 1.55870831 4 2 1 0.07050839 5 2 2 0.12928774 6
2009 Feb 02
1
executing R batch files
The following command, issued from the DOS command prompt (running Windows XP), produces the intended result of a .csv file created by program.R: ?c:\program files\R\R-2.8.0\bin\Rterm.exe? --save < "c:\TEMP\program.R" However, when I create a file called Rbatch.bat that contains exactly the line above, and try to execute it (by double clicking or via the Shell command in an Excel
2009 Feb 11
1
Hollander's test of bivariate symmetry
Does anyone know if any R package has a function that will conduct Hollander's test of bivariate symmetry? (Hollander, Biometrika, 1971) Either the exact test or an asymptotic version would be sufficient for my purposes. Thanks. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[alternative HTML version deleted]]
2008 Oct 12
1
Conditionally skip over "for(..){" and "}"??
Hi Folks, I'm wondering if there's a secret trick to achieve the following. I have some big code for analysis related to a named variable, which will be one of several in the columns of a dataframe, and I would like to be able to choose between a run for just one of these variables, or a run which loops over them all. So, for a single run, I could have the following kind of thing in a
2011 May 20
2
Variability plot in R
Is there a package in R that can do a variability plot? A variability plot is a kind of categorized dot plot. (If there is a lot of data in each category, box plots are used rather than dot plots.) Usually, the categories are factor level combinations. All the dot plots appear in the same window; below the x-axis a hierarchy of factors shows which dot plot corresponds to which factor-level
2008 Dec 18
1
understanding recursive functions
I'm trying to understand the use of recursive functions described on page 45 of An Introduction to R by the R core development team. A function is a list of expressions, which all get executed with only the last being assigned to a global variable, right? So if a function refers recursively to itself, it should simply start with the first expression and go from there. At least that is my
2009 Jan 14
1
referring to calls in functions
The first program generates an error message and does not execute the regression of y on x. x<-1:10; y<-rnorm(10) + x; prac <- function( model, wghts ){ lm(model, weights = wghts) } prac(model = y~x, wghts = rep(1, 10)) But the next program works: x<-1:10; y<-rnorm(10) + x; prac <- function( y, x, wghts ){ lm(y~x,
2007 Jan 26
2
Use a text variable's value to specify another varaible?
Greetings guRus -- If a variable, e.g., 'varname', is a character string, e.g. varname <- "datavector", and I want to apply a function, such as table(), to datavector, what syntax or method will do so using only the variable varname? This seems similar to indirect addressing, but I have not seen a method for it in the R manuals. Is there a general name for such indirect
2007 Sep 11
1
storing text and decimal values in a matrix form
Hi, I would like to store some text and decimal values in the following form: name dec.val dec.val ... dec.val name dec.val dec.val ... dec.val ... name dec. val dec.val ... dec.val To do so, I created a matrix of the necessary size (x row per y cols) with the command matrixname <- matrix(0,x,y) and proceeded to fill in the matrix with information drawn from a data frame. The
2003 May 31
5
parse on left hand side of R assignment
I keep finding myself in a situation where I want to calculate a variable name and then use it on the left hand side of an assignment. For example iteration <- 1 varName <- paste("run",iteration,sep="") myList$parse(text=varName) <- aColumn I want to take some existing variable "aColumn" and use the name "varName" name for it and put it into a
1999 Sep 29
1
getenv() can't differentiate "defined but empty" and "undefined"
getenv(<varname>) currently returns "" if the <varname> is undefined. However, if <varname> is defined but empty, getenv(<varname>) still only returns "". I think this is quite unfortunate but consistent with the prototype. --- I'd propose to change the current behavior. Something which should be pretty back compatible would for the first
2010 Dec 16
1
my function does not work for large data set
Dear R community, I have one function, it works for small data set, but does not work on large data set, can anyone help me with this? > #creat new variable by dividing each aa dimer by total_length. > imper<-function(x, file) { + round(x/file$length, 5) + } > dim(test) [1] 999 2402 > test[varname[2:2401]]<-
2011 Apr 27
1
Eval to write many files
Dear all I am looking for a shorter way and more elegant to write the following for (i in c(1:length(Shadowlist))){ filename<-paste('/home/apa/maps/',model,i,'.mat',sep="") varname<-paste(model,'_shadow',i,sep="") eval(parse(text=paste('writeMat(filename,',varname,'=Shadowlist[[i]])',sep=""))) } actually I do not