0

I have this dataframe df:

C           S

F           7.6
O           8
T           9

I want to convert it to a numeric vector like this. Not wide format

F      O       T
7.6    8       9

I want to check with class(df) after and see numeric

How can I do that?

v_head
  • 759
  • 4
  • 13

1 Answers1

1

You can use setNames to create a named vector :

vec <- setNames(df$S, df$C)
vec 
# F   O   T 
#7.6 8.0 9.0 

class(vec)
#[1] "numeric"
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213