-1

I have a data set for exploration. There are some string variables as well as integer variables.

For the integer variables, I have to convert them to numeric. How do i transform the string variables?

Structure of data set

Juliet
  • 1
  • 1
  • What exactly do you want to do to the string variable? You can transform data using `transform(movie)` but I don't think that's what you want to do. Unless I am mistaken – neuron Oct 10 '21 at 15:52
  • And you want to convert your integers into numeric? – neuron Oct 10 '21 at 15:56
  • Actually, I just checked each variable, not all the characters are actually character. For instance, Genre was meant to be a categorical variable (nominal), so i will be using the as.factor to make it usable by R. However, I still have variables like Director (which is a name), how do i make these type of variables useable? Sorry for not explaining properly – Juliet Oct 10 '21 at 16:16
  • `type.convert(data, asis = TRUE)` – Onyambu Oct 10 '21 at 19:31

1 Answers1

0

If you want to change the class of data, you can convert int to num using the following. Note that you need to select the columns that you want to change. This answer came from here

cols = c(1, 3, 4, 5);    
df[,cols] = apply(df[,cols], 2, function(x) as.numeric(as.character(x)));
neuron
  • 1,949
  • 1
  • 15
  • 30
  • Thank you. That's one of the things I need to do. How about the names e.g Director? They are still characters (string precisely). Can these be used as characters? – Juliet Oct 10 '21 at 16:22