Re: [R] How to assign value to a variable dynamically constructed

2015-07-10 Thread Bert Gunter
I'll let Bill respond in detail if he cares to(he is both more knowledgable and fluent at this than I), but as a nearly unbreakable rule, get() and assign() should not be used in R. Basically, they represent a macro (script)-oriented strategy for handling R's objects, whereas R is designed to use

Re: [R] How to assign value to a variable dynamically constructed

2015-07-10 Thread Bastien Tran
Dear all, Provided I understood correctly, shouldn't assign() do the trick? Most similar threads seem to include this approach (among others, indeed). Regards, Bastien On Wednesday, July 8, 2015 at 7:30:04 PM UTC+2, William Dunlap wrote: You can use an environment instead of a list using the

Re: [R] How to assign value to a variable dynamically constructed

2015-07-10 Thread William Dunlap
Yes, assign() and get() can do this, but I think the [[]] syntax is simpler and makes it easier to switch between lists and environments for data organization. E.g., the translation of myData[[varName]][4] - myData[[varName]][4] * 100 where myData is an environment to the get/assign style

Re: [R] How to assign value to a variable dynamically constructed

2015-07-08 Thread William Dunlap
You can use an environment instead of a list using the same [[ syntax. It is like 'get0(..., inherit=FALSE)' on the left side of the - and like 'assign(...)' on the right side. E.g., myData - new.env() varName - v1 myData[[varName]] - 1:10 myData[[varName]][4] - myData[[varName]][4]

Re: [R] How to assign value to a variable dynamically constructed

2015-07-08 Thread Greg Snow
This is FAQ 7.21. The most important part of the answer in FAQ 7.21 is the last section where it states that it is often easier to use a list rather than messing around with trying to dynamically name global variables. If you tell us what you are trying to accomplish then we may have better

[R] How to assign value to a variable dynamically constructed

2015-07-07 Thread Jun Shen
Dear list, Let's say we have a variable (id), whose name is dynamically constructed. This variable represents a vector or data frame with many elements. Now I want to specifically assign a value to one of the elements. I couldn't get it right. test - 'id' # id is dynamically constructed through

Re: [R] How to assign value to a variable dynamically constructed

2015-07-07 Thread Bert Gunter
Try reading the Help files before posting here. That's what they're for. ?get provides the answer in a note in the Help page. Cheers, Bert Bert Gunter Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. -- Clifford Stoll On Tue, Jul 7, 2015 at