Personal computing discussed

**Moderator:** Dposcorp

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

>

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

Users browsing this forum: No registered users and 2 guests