0

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.

Andrea Ianni
  • 829
  • 12
  • 24
  • 3
    Use `as.character(df3$name[4])` – Ronak Shah Sep 02 '16 at 18:06
  • Then find another one that is better. This is a pretty basic problem. – IRTFM Sep 02 '16 at 18:23
  • Do you likme this one better? http://stackoverflow.com/questions/24634499/r-sink-cat-output-something-else-than-numbers – IRTFM Sep 02 '16 at 18:34
  • You've spent 1 hour... but at the end you've really found something related to the answer (to the answer, not to the question obviously so... knowing the answer BEFORE asking I could have avoided the question itself)! :) – Andrea Ianni Sep 02 '16 at 20:14

1 Answers1

1

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 .> 
akrun
  • 874,273
  • 37
  • 540
  • 662