我有一个非常简单的问题,我无法解释。我有这个玩具数据集:
> df3
name height team fun_index title age desc Y
1 Andrea 195 Lazio 97 6 33 eccellente 1
2 Paja 165 Fiorentina 87 6 31 deciso 1
3 Roro 190 Lazio 65 6 28 strano 0
4 Gioele 70 Lazio 100 0 2 simpatico 1
5 Cacio 170 Juventus 81 3 33 duro 0
6 Edola 171 Lazio 72 5 32 svampito 1
7 Salami 175 Inter 75 3 30 doppiopasso 1
8 Braugo 180 Inter 79 5 32 gjn 0
9 Benna 158 Juventus 80 6 28 esaurito 0
10 Riggio 182 Lazio 92 5 31 certezza 1
11 Giordano 185 Roma 79 5 29 buono 1
如果我想选择与第4行相关的名称:
> df3$name[4]
[1] Gioele
Levels: Andrea Benna Braugo Cacio Edola Gioele Giordano Paja Riggio Roro Salami
我使用两种方法来打印此信息:
> paste("The name of my son is ",df3$name[4],".")
[1] "The name of my son is Gioele ."
> cat("The name of my son is ",df3$name[4],".")
The name of my son is 6 .
函数cat()
出了问题,但我无法实现。
答案 0 :(得分:1)
这是一个factor
类,将其转换为character
,它应该可以正常工作
cat("The name of my son is ", as.character(df3$name[4]),".")
#The name of my son is Gioele .>