vendredi 28 décembre 2018

Is there a way to let biggest value on X (out of X, Y, Z) decide value on V in R?

I have a dataset (ft.mutate.topics) with five variables (four numeric are ft_technical, ft_performative, ft_procedural and ft_moral). The fifth is "topic_lab" and I would like for it to take on the name (as a character) related to the variable with the highest value of the four other.

I have tried the following with a combination of if-commands:

if (ft.mutate.topics$ft_technical > ft.mutate.topics$ft_performative &
    ft.mutate.topics$ft_technical > ft.mutate.topics$ft_procedural &
    ft.mutate.topics$ft_technical > ft.mutate.topics$ft_moral)
  ft.mutate.topics$topic_lab = "technical"

if (ft.mutate.topics$ft_performative > ft.mutate.topics$ft_technical &
    ft.mutate.topics$ft_performative > ft.mutate.topics$ft_procedural &
    ft.mutate.topics$ft_performative > ft.mutate.topics$ft_moral)
  ft.mutate.topics$topic_lab = "performative"

if (ft.mutate.topics$ft_procedural > ft.mutate.topics$ft_performative &
    ft.mutate.topics$ft_procedural > ft.mutate.topics$ft_technical &
    ft.mutate.topics$ft_procedural > ft.mutate.topics$ft_moral)
  ft.mutate.topics$topic_lab = "procedural"

if (ft.mutate.topics$ft_moral > ft.mutate.topics$ft_performative &
    ft.mutate.topics$ft_moral > ft.mutate.topics$ft_procedural &
    ft.mutate.topics$ft_moral > ft.mutate.topics$ft_technical)
  ft.mutate.topics$topic_lab = "moral"

It says: "the condition has length > 1 and only the first element will be used" and substitutes the whole variable with "performative" because it is has the highest value in row 1. Anybody know what is up?

Thank you!

Aucun commentaire:

Enregistrer un commentaire