t for matrix || data.frame row-column exchange, 矩阵行列变换

简介:
t可用于矩阵或数据框的行列变换.
> x
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
第n行变成第n列.
> t(x)
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
[4,]   10   11   12

数据框行列交换
> x <- 1:10
> y <- 101:110
> data.frame(x,y)
    x   y
1   1 101
2   2 102
3   3 103
4   4 104
5   5 105
6   6 106
7   7 107
8   8 108
9   9 109
10 10 110
> t(data.frame(x,y))
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
x    1    2    3    4    5    6    7    8    9    10
y  101  102  103  104  105  106  107  108  109   110


[参考]
1. help(t)

t                     package:base                     R Documentation

Matrix Transpose

Description:

     Given a matrix or ‘data.frame’ ‘x’, ‘t’ returns the transpose of
     ‘x’.

Usage:

     t(x)
     
Arguments:

       x: a matrix or data frame, typically.

Details:

     This is a generic function for which methods can be written.  The
     description here applies to the default and ‘"data.frame"’
     methods.

     A data frame is first coerced to a matrix: see ‘as.matrix’.  When
     ‘x’ is a vector, it is treated as a column, i.e., the result is a
     1-row matrix.

Value:

     A matrix, with ‘dim’ and ‘dimnames’ constructed appropriately from
     those of ‘x’, and other attributes except names copied across.

Note:

     The _conjugate_ transpose of a complex matrix A, denoted A^H or
     A^*, is computed as ‘Conj(t(A))’.

References:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_.  Wadsworth & Brooks/Cole.

See Also:

     ‘aperm’ for permuting the dimensions of arrays.

Examples:

     a <- matrix(1:30, 5, 6)
     ta <- t(a) ##-- i.e.,  a[i, j] == ta[j, i] for all i,j :
     for(j in seq(ncol(a)))
       if(! all(a[, j] == ta[j, ])) stop("wrong transpose")

目录
相关文章
|
7月前
|
索引 Python
row[i] = col[j] = TrueIndexError: list assignment index out of range
row[i] = col[j] = TrueIndexError: list assignment index out of range
|
7月前
|
索引
根据索引值计算item所在行列(row,col)索引序号(index)
根据索引值计算item所在行列(row,col)索引序号(index)
207Echarts - 数据集(Series Layout By Column or Row)
207Echarts - 数据集(Series Layout By Column or Row)
50 0
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
|
存储 安全 关系型数据库
Column length too big for column ‘remark‘ (max=65535)解决办法
Column length too big for column ‘remark‘ (max=65535)解决办法
335 0
The Double Linknode for Linear table | Data
The some code in Data book (5th Edition) from the 54 page to 55 page
100 0
|
索引 Python
成功解决ValueError: column index (256) not an int in range(256)
成功解决ValueError: column index (256) not an int in range(256)
成功解决ValueError: column index (256) not an int in range(256)
halcon模板匹配实践(2)算子find_shape_model里的参数Row, Column, Angle含义是什么?
halcon模板匹配实践(2)算子find_shape_model里的参数Row, Column, Angle含义是什么?
780 0
halcon模板匹配实践(2)算子find_shape_model里的参数Row, Column, Angle含义是什么?
|
Web App开发 关系型数据库 Java
Data truncation: Data too long for column 'xxx' at row 1
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/78870542 ...
2144 0
|
Web App开发 Java 关系型数据库
Data truncation: Data too long for column &#39;xxx&#39; at row 1
Data truncation: Data too long for column 'xxx' at row 1 完整的错误内容可能是下面这样的: p.p1 {margin: 0.0px 0.0px 0.
2250 0