0

I have a dataframe but the numbering of the months is all jumbled. I need to change the following rows to the following, but i'm struggling to see an easy way through. I'm aware that this code changes the data, but it's just a case of working out the puzzle without adding columns together.

data$column[data$column == "0"] <- "7" 
  • 0 <- 7
  • 1 <- 8
  • 2 <- 9
  • 3 <- 10
  • 4 <- 1
  • 5 <- 2
  • 6 <- 3
  • 7 <- 4
  • 8 <- 5
  • 9 <- 6

Thank you

1
  • 1
    It seems that you could use simple indexing like c(7, 8, 9, 10, 1, 2, 3, 4, 5, 6)[as.numeric(data$column) + 1] Commented Dec 2, 2016 at 19:17

2 Answers 2

2

maybe plyr::mapvalues() can help you here:

library(plyr)
df$column <- mapvalues(df$column, from = c(0,1:9), to = c(7:10, 1:6))
Sign up to request clarification or add additional context in comments.

Comments

0

Use

data$column <- (data$column + 7) %% 10

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.