Help with R and matrix dimension

The place for all kinds of software for all kinds of operating systems.

Moderator: Dposcorp

Help with R and matrix dimension

Postposted on Wed May 02, 2012 12:03 pm

Is there anyway to set a variable in R to be equal to the row/column dimension of a matrix? If so, how would I do so? Thank you for any help!
apkellogg
Gerbil Elite
 
Posts: 921
Joined: Wed Feb 25, 2004 10:15 am

Re: Help with R and matrix dimension

Postposted on Wed May 02, 2012 1:39 pm

apkellogg wrote:Is there anyway to set a variable in R to be equal to the row/column dimension of a matrix? If so, how would I do so? Thank you for any help!


Code: Select all
> matrix(data=c(1:8),nrow=2,ncol=4)
     [,1] [,2] [,3] [,4]
[1,]    1    3    5    7
[2,]    2    4    6    8
> dim(matrix(data=c(1:8),nrow=2,ncol=4))
[1] 2 4
> dim(matrix(data=c(1:8),nrow=2,ncol=4))[1]
[1] 2
> dim(matrix(data=c(1:8),nrow=2,ncol=4))[2]
[1] 4
>
ptsant
Gerbil
Gold subscriber
 
 
Posts: 57
Joined: Mon Oct 05, 2009 12:45 pm

Re: Help with R and matrix dimension

Postposted on Wed May 02, 2012 2:02 pm

Thank you, but I don't think that is doing what I was asking about. What I want to do is import a CSV file as a matrix and then set a variable equal to the row or column count from the dim function so that functions that are done downstream can be set to the variable, instead of having to go in and customize it each time I import a new file.
apkellogg
Gerbil Elite
 
Posts: 921
Joined: Wed Feb 25, 2004 10:15 am

Re: Help with R and matrix dimension

Postposted on Wed May 02, 2012 2:07 pm

apkellogg wrote:Thank you, but I don't think that is doing what I was asking about. What I want to do is import a CSV file as a matrix and then set a variable equal to the row or column count from the dim function so that functions that are done downstream can be set to the variable, instead of having to go in and customize it each time I import a new file.

Code: Select all
> x <- dim(matrix(data=c(1:8),nrow=2,ncol=4))[2]
ptsant
Gerbil
Gold subscriber
 
 
Posts: 57
Joined: Mon Oct 05, 2009 12:45 pm


Return to General Software

Who is online

Users browsing this forum: No registered users and 2 guests