[R] [Fwd: Re: Assigning to multiple variables]

From: Tom Backer Johnsen <backer_at_psych.uib.no>
Date: Sun, 13 Apr 2008 23:36:03 +0200


Scott Romans wrote:
> If we have a function that returns 2 or more values (such as dim as
> applied to a matrix), can we assign these 2 or more values to an equal
> number of differently named variables in one line? For example, is
> there any way to do something like this:
>
> [NumberRows NumberColumns] <- dim(MatrixA)

In that case R returns an object (a vector) with two values where the first is the number of rows and the second is the number of columns. Almost everything in R are objects.

So:

> d <- dim(attitude)
> rows <- d[1]
> rows

[1] 30

Tom



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. Received on Sun 13 Apr 2008 - 21:38:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Apr 2008 - 22:30:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive