如何在R中垂直打印矢量元素?
默认情况下,矢量元素在R环境中水平打印,假设矢量x具有五个值,则它们将被打印为1、2、3、4、5。如果我们要垂直打印它们,则输出将为-
12
3
4
5
可以使用以下命令以垂直形式打印这些值-
cat(paste(x),sep="\n")
示例
x1<-rnorm(20)输出结果x1
[1] -0.21762527 -0.41558602 1.31715506 1.29395466 -0.18461247 0.01315274[7] 0.57771289 0.20604628 1.94438915 0.60161282 0.99330286 2.01009149
[13] 0.92017331 -1.85041327 -1.80692023 -1.82755564 1.11699829 0.64647509
[19] -1.10505253 0.28583539
cat(paste(x1),sep =“ \ n”)
-0.217625267942574-0.415586019985825
1.31715505907589
1.29395466104286
-0.184612472150405
0.0131527375687808
0.577712886566497
0.206046280839523
1.94438915282256
0.601612819106714
0.993302860745902
2.01009149024866
0.920173312461327
-1.85041326987246
-1.80692023263947
-1.82755563513533
1.11699829377698
0.64647509397493
-1.10505253347078
0.285835386881493
示例
x2<-rpois(20,5)输出结果x2
[1] 6 6 3 6 6 10 4 6 9 9 2 5 7 1 7 5 5 6 2 8
cat(paste(x2),sep =“ \ n”)
66
3
6
6
10
4
6
9
9
2
5
7
1
7
5
5
6
2
8
示例
x3<-LETTERS[1:26]输出结果x3
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"[20] "T" "U" "V" "W" "X" "Y" "Z"
cat(paste(x3),sep =“ \ n”)
AB
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
以上是 如何在R中垂直打印矢量元素? 的全部内容, 来源链接: utcz.com/z/320639.html