[R] Updating an object
Ben Bolker
bolker at ufl.edu
Tue Jul 21 15:02:59 CEST 2009
Uwe Ligges-3 wrote:
>
>
>
> megh wrote:
>> Let say, I have an arbitrary vector :
>>
>> i=1
>> assign(paste("dat",i,sep=""), rnorm(5))
>>
>> Now I want to update that "dat1" vector by ommiting last 2 elements i.e.
>>
>> dat1 = dat1[c(1:3)]
>>
>> However here my problem is, as "dat1" depends on another variable "i", I
>> cannot use above syntax directly. I want to automate above syntax such
>> that
>> I can run this for any "i". Is there any way?
>
>
> Yes, but actually you want a list "dat" that contains vectors at
> positions i.
>
> Uwe Ligges
>
>
To expand on this slightly: you can use get() and assign() to retrieve
and assign, respectively, values from "constructed" variable names,
but it is generally much easier to do this with a list: this is a version
of R FAQ 7.21:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f
--
View this message in context: http://www.nabble.com/Updating-an-object-tp24583524p24587245.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list