R语言备忘录
Posted 无安书
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R语言备忘录相关的知识,希望对你有一定的参考价值。
A 33 87 31 99 38 42 33 85
B 59 75 83 50 55 33 33 52
C 98 88 59 96 32 89 45 78
"
33 87 31 99 38 42 33 85
59 75 83 50 55 33 33 52
98 88 59 96 32 89 45 78 " %>%
read.table(text =.) %>% t %>% data.frame(row.names = 1:8)
read.table('clipboard') %>% t %>%
as.data.frame(row.names = 1:8)
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.
"
as tg ty qw af kl de pl
59 75 83 50 55 33 33 52
98 88 59 96 32 89 45 78 " %>%
read.table(text =.) %>% t %>%
data.frame(row.names = 1:8) %>% str
'data.frame': 8 obs. of 3 variables:
$ X1: chr "as" "tg" "ty" "qw" ...
$ X2: chr "59" "75" "83" "50" ...
$ X3: chr "98" "88" "59" "96" ...
> str(p)
'data.frame': 8 obs. of 3 variables:
$ V1: chr "as" "tg" "ty" "qw" ...
$ V2: chr "59" "75" "83" "50" ...
$ V3: chr "98" "88" "59" "96" ...
> p[,2:3] <- sapply(p[,2:3],as.integer)
> str(p)
'data.frame': 8 obs. of 3 variables:
$ V1: chr "as" "tg" "ty" "qw" ...
$ V2: int 59 75 83 50 55 33 33 52
$ V3: int 98 88 59 96 32 89 45 78
转置
功能, 实在没有必要瞎折腾。同时所谓的
t()
其实就是取
transpose
的首字母。Excel 中也有 转置功能的函数:
TRANSPOSE()
意为:转置单元格区域。
$33.00 ¥59.00 9800%
$87.00 ¥75.00 8800%
$31.00 ¥83.00 5900%
$99.00 ¥50.00 9600%
$38.00 ¥55.00 3200%
$42.00 ¥33.00 8900%
$33.00 ¥33.00 4500%
$85.00 ¥52.00 7800%
以上是关于R语言备忘录的主要内容,如果未能解决你的问题,请参考以下文章