Displaying 9 results from an estimated 9 matches for "dimensions_003f".
2006 Nov 03
2
one row matrix
Hi,
when I assign a one row matrix to another variable, then somehow R
automatically convert that varaible into a list.
For example:
> a = matrix (12, 3, 4)
> b = a[1,]
> b
[1] 12 12 12 12
Is there a way to enable R automatically make b as a one row matrix , rather
than explicitly assign like matrix (b, ncol=1). I have come across a
couple of time, that when I try to check how many
2011 Sep 02
2
How to keep the same class?
Hello
Please see the example below
> class(testX)
[1] "matrix"
> class(testX[1,])
[1] "numeric"
Why not matrix? What am I missing here? Is there a way to keep the same
class?
The reason for the question is that I want to implement a k-step ahead
prediction for my own routines and R wrecks does not seem to like [1,] as
shown below.
>
2006 Oct 04
2
convert vector to matrix
Hi All,
I have vector containing 10 elements(odservations). I need to put this into a matrix, where the matrix should contain only one column.
I need this to be done using the cbind command because in the final table I should have a column of attributes( from adifferent vector) and a column of vectors from the matrix above
Please suggest me how this can be done
Thanks and
2014 Aug 06
2
Subscripting Matrices
There seems to be a result type difference when subscripting a 6 x 1
matrix as compared to a 3 x 2 matrix that is caused by the ncol = 1
compared to ncol > 1.
> ThinMatrix <- matrix(1:6,ncol=1)
> ThinMatrix
[,1]
[1,] 1
[2,] 2
[3,] 3
[4,] 4
[5,] 5
[6,] 6
> FatMatrix <- matrix(1:6,ncol=2)
> FatMatrix
[,1] [,2]
[1,] 1 4
[2,] 2 5
2012 Oct 12
3
Loss of dimensions in subsetting arrays
Hi all,
I've been wondering for a long time why R drops the dimensions of an
array/matrix when you try to take a subset of one column. I mean this:
dim(A)
[1] 2 5 2
B=A[1,,]
dim(B)
5 2 # so now dim(B)[3] doesn't work
C=B[2,]
dim(C)
NULL # so now nrow(C) doesn't work
Typically, you can get rid of this by writing as.matrix, as.array(...)
but that generates extra lines of code.
2010 Apr 06
2
respecting original matrix dimensions
Hi All,
I'm hoping someone else can help me out with this. I am doing some
matrix algebra using sub-parts of matrices, and sometimes I need only
a single row/column of the original matrix. However, whenever I pull
out only a single row/column, R returns a row vector, but often this
will break my matrix algebra. Is there any *easy* way to get R to
remember what the single row/column came out
2007 May 01
2
Matrix column name
Dear R users,
Having searched the mail archive I think the conclusion was that it is
not possible to have a column name when there is only one column in the
matrix. But I thought I'd check with the more experienced users.
What I tried to do was: in a loop I pick a column, record the column
name and remove the column from the matrix. But when there were 2
columns left, after one column was
2008 Oct 21
4
subscripting a one column matrix drops dimension
Hi all,
Why subscripting a one column matrix drops one dimension?
> x<- matrix(rnorm(100), ncol=1)
> str(x)
num [1:100, 1] -0.413 -0.845 -1.625 -1.393 0.507 ...
> str(x[20:30,])
num [1:11] -0.315 -0.693 -0.771 0.448 0.204 ...
> str(x[20:30])
num [1:11] -0.315 -0.693 -0.771 0.448 0.204 ...
This breaks:
> cov(x)
[,1]
[1,] 0.9600812
>
2007 May 03
0
unscrible pls
...t; > columns left, after one column was removed, the last column name
> > disappeared by default. It means that I always miss out the last column.
>
> See R FAQ 7.5 Why do my matrices lose dimensions:
>
>
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-my-matrices-lose-dimensions_003f
>
> which has some examples, along with ?Extract
>
> To wit:
>
> MAT <- matrix(1:12, ncol = 3)
>
> colnames(MAT) <- LETTERS[1:3]
>
> > MAT
> A B C
> [1,] 1 5 9
> [2,] 2 6 10
> [3,] 3 7 11
> [4,] 4 8 12
>
>
> > MAT[, 1]
> [1]...