How to invert the values of a column in a Dataframe in R?

Asked

Viewed 83 times

1

For example, the column in my Data Frame has values from 1 to 7; I want to replace 1 by 7, 2 by 6, 3 by 5, and so on. How to do this in R?

variable = 1,2,2,4,3,6,7 desired result = 7,6,6,4,5,2,1

  • You can use the function rev() c<-data.frame((rev(x)),y)

  • That’s not 8 - x, where x is the vector to modify?

  • x <- c(1,2,2,4,3,6,7);y <- c(7,6,6,4,5,2,1);identical(y, 8 - x).

  • I collected data together with a group of respondents, the question was how interested you are in the TV show x. Respondents had to indicate their interest on a 7-point scale. In my data.frame there is a column whose title is "interest" which contains the responses of 1 to 7 out of 73 respondents. I want to know how to invert these values from the data.frame column, ie where there is 1 the value will be changed to 7, where there are 2 will be changed to 6, where there is 3 the value will be changed to 5, and so on.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.