similar to: assign a list using expression?

Displaying 20 results from an estimated 8000 matches similar to: "assign a list using expression?"

2009 Oct 25
3
NULL elements in lists ... a nightmare
I can define a list containing NULL elements: > myList <- list("aaa",NULL,TRUE) > names(myList) <- c("first","second","third") > myList $first [1] "aaa" $second NULL $third [1] TRUE > length(myList) [1] 3 However, if I assign NULL to any of the list element then such element is deleted from the list: > myList$second <-
2009 Aug 03
2
Variable names as inputs...
Hi, I have been using R for a bit, but never came across this simple issue... So, I wonder if anyone could give me a hint on it. I have calculated a bunch o models and now need to compare them using AIC(). The issue seem to be that I have placed each output in a list object. So, the question is how to convert a string into variable names. Lets say I have all my models in a variables called :
2010 Feb 08
2
the hat ^ in regular expression
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/20100208/52a6d080/attachment.pl>
2009 Jul 02
2
Passing expression as argument to do.call
Dear R-users, I would like to know how expressions could be passed as arguments to do.call functions. As illustrated in the short example below, concatenating lists objects and an expression creates an expression object, which is not an acceptable argument for do.call. Is there a way to avoid that? Thanks you Sebastien foo <- list(x=1:10, y=1:10) mylist <- list(pch=6, col=2) title
2008 Mar 24
1
How to assign multiple return values
Hi, I am moving from MATLAB, where one can easily assign a number of output values from a function like this: [x,y] = myfun(a,b) Then variables x and y can be directly used in the caller workspace. I understand that R functions return a single argument, which could be a list. This in a way makes it possible to return multiple values with a single function call, but accessing the list variables
2016 Feb 07
3
Assignment in environment
Dear all, I have a function "fn" with its own environment, i.e. env <- environment(fn) and env is not .GlobalEnv. And another function getValue <- function(x) environment(x)$mylist which returns the list object "mylist" which is in "env". If I want to modify "mylist", I could write 'getValue<-' <- function(x, value) {
2006 Dec 18
3
turning expression object to function
Dear all, I have the following problem. Given an expression object 'expr' containing a certain set of symbols (say 'a', 'b', 'c'), I would like to translate the expression object in an R function of, say, 'a', programmatically. Here an example of what I mean. Given: > expr <- expression(a+b+c) a call like: > asFunctionOf(expr, 'a',
2006 Jan 20
2
assign object to list
Dear all I want to generate a list like this: a <- data.frame(1:10) attr(a,'myattribute') <- 'something' b <- data.frame(11:20) attr(b,'myattribute') <- 'anything' mylist <- list(a,b) Is there a way to place the dataframes into the list giving them the attribute at the same time? I don't want to create all the dataframes in my workspace first.
2008 Jan 18
1
Assigning into each of a list of dataframes
What is the right way to assign a new variable into each a of list of data frames? Here is my failed attempt: mylist <- list(df1 = data.frame(A = runif(5), B = runif(5)), df2 = data.frame(A = runif(5), B= runif(5))) lapply(mylist, function(x){x$Y <- x$A * x$B}) $df1 [1] 0.25589928 0.03446026 0.94992362 0.21388326 0.08668821 $df2 [1] 0.08771839 0.05643553 0.09036894
2015 May 04
2
Define replacement functions
Hello I tried to define replacement functions for the class "mylist". When I test them in an active R session, they work -- however, when I put them into a package, they don't. Why and how to fix? make_my_list <- function( x, y ) { return(structure(list(x, y, class="mylist"))) } mylist <- make_my_list(1:4, letters[3:7]) mylist mylist[['x']] <- 4:6
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
2007 Oct 20
1
Getting at what a named object represents in a function...
Hi, I'm pretty new to R. I have an object (say a list) and I I have a function that I call on various columns in that list (excuse terminology if it's wrong/ambiguous). Imagine its like this (actual values are unimportant) and called mylist: >mylist A B 1 5 2 5 3 6 4 8 5 0 I have a function: foo = function(param){ #modify list A or B values depending on
2004 May 10
2
Lists and outer() like functionality?
Hi, I'm have a list of integer vectors and I want to perform an outer() like operation on the list. As an example, take the following list: mylist <- list(1:5,3:9,8:12) A simple example of the kind of thing I want to do is to find the sum of the shared numbers between each vector to give a result like: result <- array(c(15,12,0,12,42,17,0,17,50), dim=c(3,3)) Two for() loops is the
2011 Apr 05
1
Help in splitting a list
Dear R users, Let's say I have a list with components being 'm' matrices (as exemplified in the "mylist" object below). Now, I'd like to subset this list based on an index vector, which will partition each matrix 'm' in 2 sub-matrices. My questions are: 1. Is there an elegant way to have the results shown in mylist2 for an arbitrary number of matrices in mylist?
2017 Jun 15
4
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi I have a list : mylist <- list( a = NULL, b = 1, c = 2 ) > mylist[1] $a NULL > is.null(mylist[1]) [1] FALSE > is.null(mylist$a) [1] TRUE why? I need to use mylist[1]
2011 Dec 11
3
how to assign a value?
Hi there, I hope to modify values in a vector or matrix in the following code: for (i in 1:9) { assign(paste("a.", i, sep = ""), 1:i) get(paste("a.", i, sep = ""))[i] <- i+50 } I get the following error message: Error in get(paste("a.", i, sep = ""))[i] <- i + 50 : target of assignment expands to non-language object
2005 Jan 30
3
trellis graphics in loops
I have this awkward problem with trellis (lattice). I am trying to generate some plots through loops but the .eps file is empty. When I generate them in a list and print them outside the loop all is fine. this is an example below:( nothing shows up in foo.eps, but all show up in foo1.eps) R vesion 2.0.1, lattice version 0.10-16, on a debian 2.6.8-1 kernel. X <- data.frame(x=rnorm(10000),
2001 Oct 18
2
Parsing for list components
How do I parse an identifier of a list component, e.g. mylist$mycomponent or mylist[[1]] ? Parse does not do the job, e.g. parse(text="mylist$mycomponent") returns an expression with just one term, instead of "mylist", "$", "mycomponent". What I need is a way to extract the list name (e.g. "mylist"), given an identifier of a component.
2010 Sep 04
4
Please explain "do.call" in this context, or critique to "stack this list faster"
I've been doing some consulting with students who seem to come to R from SAS. They are usually pre-occupied with do loops and it is tough to persuade them to trust R lists rather than keeping 100s of named matrices floating around. Often it happens that there is a list with lots of matrices or data frames in it and we need to "stack those together". I thought it would be a simple
2011 Apr 03
1
Help in splitting ists into sub-lists
Dear List, Let's say I have a list whose components are 2 matrices (as exemplified in the "mylist" object below). I'd like to create a list with components being 4 matrices based on an logical index vector. is there a way to simplify what I'm doing to obtain the results in "mylist2"? I'd like something that would work on an arbitrary number of elements in