**Moderator:** Dposcorp

4 posts
• Page **1** of **1**

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:**937**Joined:**Wed Feb 25, 2004 10:15 am

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:**72**Joined:**Mon Oct 05, 2009 12:45 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:**937**Joined:**Wed Feb 25, 2004 10:15 am

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:**72**Joined:**Mon Oct 05, 2009 12:45 pm

4 posts
• Page **1** of **1**

Users browsing this forum: No registered users and 4 guests