dataframe - R: how to change values in a data.frame -


> dummy <- data.frame(x  = c(1, 2, 3, 4, 5, 5, 2, 6, 7, 2), y = c(3, 2, 1, 4, 5, 6, 7, 3, 4, 2)) > dummy    x y 1  1 3 2  2 2 3  3 1 4  4 4 5  5 5 6  5 6 7  2 7 8  6 3 9  7 4 10 2 2 

i have data.frame consists of values 1 7. want change 1's 7's (and vice versa), 2's 6's (and vice versa), 3's 5's (and vice versa), , 4's stay 4's. i.e. want 'reverse' numbers. thought writing loop iterate on each value in each column , use ifelse statements, how can change, say, 7's 1's , 1's 7s simultaneously?

considering pairs of numbers want switch have sum of 8, can subtract original data frame 8 , values should reverted want, can 8 - dummy:

dummy = 8 - dummy dummy #   x y #1  7 5 #2  6 6 #3  5 7 #4  4 4 #5  3 3 #6  3 2 #7  6 1 #8  2 5 #9  1 4 #10 6 6 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -