[R] attributing values to dataframe positions following eval

John Kane jrkrideau at yahoo.ca
Tue Jul 8 16:12:17 CEST 2008


Does not just 
polyList[[1]])[1, 1] <- 5 

work?


--- On Tue, 7/8/08, Stephane Bourgeois <sb20 at sanger.ac.uk> wrote:

> From: Stephane Bourgeois <sb20 at sanger.ac.uk>
> Subject: [R] attributing values to dataframe positions following eval
> To: r-help at r-project.org
> Received: Tuesday, July 8, 2008, 5:40 AM
> Hi everybody,
> 
>  
> 
> I've been looking around, but can't seem to find
> the answer.
> 
>  
> 
> I get a list of names (which vary, so I never know them in
> advance), and
> transform them into variables, each of which is a
> dataframe, using
> assign:
> 
>  
> 
> polyList <- c("rs123", "rs124",
> "rs555", "rs000")
> 
> numPoly <- length(polyList)
> 
>  
> 
> for (k in 1:numPoly) {
> 
>   assign(polyList[k], data.frame(matrix(NA, ncol=3,
> nrow=3)))
> 
> }
> 
>  
> 
> polyList <- lapply(polyList, as.name)
> 
>  
> 
> I can see the resulting dataframe associated to rs123 (for
> example)
> using:
> 
>  
> 
> > eval(polyList[[1]])
> 
>   X1 X2 X3
> 
> 1 NA NA NA
> 
> 2 NA NA NA
> 
> 3 NA NA NA
> 
>  
> 
> And see the value in row 1, column 1 with:
> 
>  
> 
> > eval(polyList[[1]])[1,1]
> 
> [1] NA
> 
>  
> 
> Now, I want to change the values in the dataframe...
> that's what I can't
> manage to do:
> 
>  
> 
> > eval(polyList[[1]])[1,1] <- 5
> 
> Error in eval(polyList[[1]])[1, 1] <- 5 : 
> 
>   could not find function "eval<-"
> 
>  
> 
> Anybody has an idea on how to do that?
> 
>  
> 
> Thank you,
> 
>  
> 
> Stephane
> 
>  
> 
> PS:  yes, I'm aware that using arrays and dataframes
> instead of going
> through the creation of variables may be more practical,
> but the context
> is much more complex than the presented example (and in
> that specific
> case, having these variables is a requirement)
> 
>  
> 
> 
> 
> 
> -- 
>  The Wellcome Trust Sanger Institute is operated by Genome
> Research 
> 
>  Limited, a charity registered in England with number
> 1021457 and a 
>  compa
> ny registered in England with number 2742969, whose
> registered 
>  office is 2
> 15 Euston Road, London, NW1 2BE. 
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



More information about the R-help mailing list