I think that the better approach in R, if you really need to do this, is to
convert your array to a list, assign the names to the list, then attach the
list to the search path so you can access the variables by name.  For
example:

> x <- c(1,2,3)
> x2 <- as.list(x)
> names(x2) <- c('a','b','c')
> attach(x2)
> a
[1] 1
> b
[1] 2
> c
[1] 3
> detach()

Or you can do most of the dirty work in 1 line:

> attach( setNames( as.list(x), c('a','b','c') ) )
> a
[1] 1
> b
[1] 2
> c
[1] 3
> detach()
> a
Error: object 'a' not found
>


This gives all the advantages of being able to access the different pieces
by the variable names that you want without cluttering up the global
workspace.
Just be careful that you don't have other variables of the same name
already in the global environment.  If you do then using functions like
with or within will work better than attaching.





On Thu, Mar 14, 2013 at 11:17 AM, Sahana Srinivasan <
sahanasrinivasan...@gmail.com> wrote:

> HI, I'm looking for a function that does the same as deal() in MATLAB, i,e,
> for an array x[1 2 3]
> [a,b,c]=x;
> such that
> a=1, b=2, c=3
>
> Does R have any functions similar to this?
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to