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

Tom Backer Johnsen backer at psych.uib.no
Sun Apr 13 23:36:03 CEST 2008


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



More information about the R-help mailing list