Personal computing discussed

Moderator: Dposcorp

apkellogg
Gerbil Elite
Topic Author
Posts: 954
Joined: Wed Feb 25, 2004 10:15 am

### Help with R and matrix dimension

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!

ptsant
Posts: 263
Joined: Mon Oct 05, 2009 12:45 pm

### Re: Help with R and matrix dimension

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!

``> 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>``

apkellogg
Gerbil Elite
Topic Author
Posts: 954
Joined: Wed Feb 25, 2004 10:15 am

### Re: Help with R and matrix dimension

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.

ptsant
Posts: 263
Joined: Mon Oct 05, 2009 12:45 pm

### Re: Help with R and matrix dimension

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.

``> x <- dim(matrix(data=c(1:8),nrow=2,ncol=4))[2]``

### Who is online

Users browsing this forum: No registered users and 1 guest