search for: variable_003f

Displaying 16 results from an estimated 16 matches for "variable_003f".

2009 Aug 24
2
Assigning value of subset argument in "subset" function
Dear R users, I am using "subset" function to filter out specific conditions and would like to use the value of subsetted argument as a name of an object. Specifically, from the following statement: a <- subset(dat, dat$x == "A" & dat$xx == 1 & dat$xxx == "AB" & dat$y == "B" & dat$yy == 2) I would to assign the value of the 3rd
2008 Jan 27
1
calling a list element from a list name passed to a function
Hi, 'true_name' is a list of numerical, matrix, and text items I do pass_name <- "true_name" and pass the name of the list to a function so that the character class variable 'passed_name' contains the name of the list called 'true_name' Inside the function, how can I get a specified element from the list? For example, if I want to get
2012 Nov 10
2
For loop question
I have this code: IEF <- to.monthly(IEF, indexAt="endof") SPY <- to.monthly(SPY, indexAt="endof") I would like to use a for loop instead of separate entries, so the only code that needs to be modified is the list of symbols. symbols <- c("IEF", "SPY") for(symbol in symbols) { symbol <- to.monthly(symbol, indexAt="endof") } This
2007 Dec 16
2
clean programming
Hello the list, I am trying to write a "cleanProgramming" function to test the procedure I use. For example, I want to be sure that I am not using globals variables. The function "findGlobals" detect that. To list the globals used in function "fun", the syntax is : "findGlobals(fun,FALSE)$variable" My problem is that I want to use it in a function,
2007 Mar 09
2
piecing together statements (macro?)
Hi All I am pretty new to R but saw stata and sas's macro facilities and am looking for how such things work in R. I am trying to piece together a series of statements: n = 5 #want to have it dynamic with respect to n for (j in 1:n) { eval(paste("x", j, "=x[", j, "]", sep="")) } I want the created statements 'x1=x[1]' immediately executed
2009 Apr 24
1
function returns R object with name based on input
I wanted to ask how I can make a for loop or a function return an R object with a unique name based on either some XX of the for loop or some input for the function. For example if I have a function: fn<-function(data,year){ which does does some stuff } How do I return an object from the function called X.year, such that if I run fn(data,1989), the output is an object called X.1989? In
2008 Nov 01
3
how to iterate through a list using ls
Hi all, I know this is an idiotic question, but I am trying to iterate through a list of data.frame using ls (I have named the data frames in a way that lets me subset them with ls(pattern="test", for example). But ls returns a character vector. How to I refer to the data frames by their names in the list instead of the actual string? Thanks a bunch. Ken
2008 Nov 18
4
How do I generate multiple (similar) objects within R?
Hi, I wonder if anyone knows how to generate a list of objects, e.g. ten vectors with names: vect1, vect2, ... , vect10. My own idea was to use something like: for (i in 1:10) print(paste("vect", i,"<-NULL",sep="")) but the result is: "vect1<-NULL" ... "vect10<-NULL" and not vect1<-NULL ... vect10<-NULL as I would
2010 Dec 29
2
as.object: function doesn't exist but I wish it did
I seem to come to this problem alot, and I can find my way out of it with a loop, but I wish, and wonder if there is a better way. Here's an example (lmer1-5 are a series of lmer objects): bs=data.frame(bic=BIC(lmer1,lmer2,lmer3,lmer4,lmer5)$BIC) rownames(bs)=c('lmer1','lmer2','lmer3','lmer4','lmer5') best=rownames(bs)[bs==min(bs)] > best [1]
2008 Dec 12
2
Extracting the name of an object into a character string and vice versa
I am still struggling to map a character string to an object name and vice versa in R. I thought the as.name() function might work, but observe the following behaviour ... > attach(warpbreaks) > levels(tension) [1] "L" "M" "H" > levels(as.name("tension")) NULL > objectname<-as.name("tension") > objectname tension >
2009 Apr 14
3
Automating object creation
I am new to R. I would like to automate the creation of a number of vectors but can't seem to get the string formatting to work. Here's what I would like to be able to do: Suppose we have a vector: x <- c(2,4,5) I would like to be able to create a set of vectors whose names are associated with the values in x - e.g. x2 <- 0 x4 <- 0 x5 <- 0 I have tried with a for loop and
2009 Apr 18
4
Loop question
Hi everyone, I am trying to accomplish a small task that is giving me quite a headache. I would like to automatically generate a series of matrices and give them successive names. Here is what I thought at first: t1<-matrix(0, nrow=250, ncol=1) for(i in 1:10){ t1[i]<-rnorm(250) } What I intended was that the loop would create 10 different matrices with a single column of 250
2009 Nov 19
3
Reading in a series of files using a for loop
Dear R Users, I am trying to read in a series of csv files which vary by the letter on the end of he file name. When I input what seems to be a logical for loop I get an error message that doesn't make sense to me. > for(i in 1:12){ paste("G&P", LETTERS[i],sep='')
2009 Feb 25
3
indexing model names for AICc table
hi folks, I'm trying to build a table that contains information about a series of General Linear Models in order to calculate Akaike weights and other measures to compare all models in the series. i have an issue with indexing models and extracting the information (loglikehood, AIC's, etc.) that I need to compile them into the table. Below is some sample code that illustrates my
2007 Feb 25
3
Macros in R
Dear members, I have started to work with R recently and there is one thing which I could not solve so far. I don't know how to define macros in R. The problem at hand is the following: I want R to go through a list of 1:54 and create the matrices input1, input2, input3 up to input54. I have tried the following: for ( i in 1:54) { input[i] = matrix(nrow = 1, ncol = 107)
2008 Dec 08
3
Transforming a string to a variable's name? help me newbie...
Dear all, I'm a newbie in R. I have a 45x2x2x8 design. A dataframe stores the metadata of trials. And each trial has its own data file: I used "read.table" to import every trial into R as a dataframe (variable). Now I dynamically ask R to retrieve trials that fit certain selection criteria, so I use "subset", e.g. tmptrialinfo <- subset(trialinfo, (Subject==24 &