How to assign value to a variable dynamically constructed
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 1:53 PM, Jun Shen <jun.shen.ut at gmail.com> wrote:
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 paste()
id <- 1:4
# I can get the element by doing
get(test)[2]
# Now I want to assign a value to the second element of this dynamical
variable.
get(test)[2] <- 5 # doesn't work.
Thanks a lot.
Jun Shen
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.