Andrea Ianni ௫ Andrea Ianni ௫ - 3 months ago 24
R Question

The name of my son is..... 6

I have an extremely simple issue that I cannot explain. I have this toy dataset:

> 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


If I want to select the name related to the 4th row I do:

> df3$name[4]
[1] Gioele
Levels: Andrea Benna Braugo Cacio Edola Gioele Giordano Paja Riggio Roro Salami


I use two methods to print this information:

> 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 .


Something goes wrong with the function
cat()
, but I cannot realize what.

Answer

It is a factor class, convert it to character and it should work

cat("The name of my son is ", as.character(df3$name[4]),".")
#The name of my son is  Gioele .>