Personal computing discussed
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 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]