[R] accessing return variables from a function

Noah Silverman noah at smartmediacorp.com
Sat Jul 10 21:36:23 CEST 2010


Thanks!

-N

On 7/9/10 2:20 AM, Noah Silverman wrote:
> Hi,
>
> I am trying to figure out a "short" way to access two values output from
> the sort function.
>
>   
>> x <- c(3,4,3,6,78,3,1,2)
>> sort(x, index.return=T)
>>     
> $x
> [1]  1  2  3  3  3  4  6 78
>
> $ix
> [1] 7 8 1 3 6 2 4 5
>
>
> It would be great to do something like this (doesn't work.):
>
> c(y, indexes) <- sort(x, index.return=T)
>
> But that doesn't work.
>
> I CAN grab the output of sort in a variable and then access it twice to
> get the values, but that seems wasteful.
>
> Any  ideas?
>
> -N
>
> ______________________________________________
> 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