I would like to rearrange the positions of certain cells in my Excel spreadsheet using R. There are two columns, place_x and place_y, where the coordinates are not correct. I intend to swap some values in these two columns to ensure cleanliness. I want to swatch, line by line, the value of the cell of column"place_x" with the cell of "place_y" when the cell of "place_x" is above 30.
Below is an example of my Excel spreadsheet that I want to change :

I tried this...
#######DEFINITION DU WORKING DIRECTORY#####
# Installer la bibliothèque readxl si ce n'est pas déjà fait
install.packages("Rtools")
install.packages("readxl")
install.packages("openxlsx")
# Charger la bibliothèque openxlsx
library(openxlsx)
# Charger la bibliothèque readxl
library(readxl)
# Spécifier le chemin du fichier Excel
data <- read_excel("Example.xlsx")
# Condition to check if place_x is greater than 30
condition <- data$place_x > 30
# Swap values of place_x and place_y where the condition is met
temp <- data[condition, "place_x"]
data[condition, "place_x"] <- data[condition, "place_y"]
data[condition, "place_y"] <- temp
# Write the result to a new Excel file
output_file <- "INVERSE.xlsx"
write.xlsx(data, file = output_file)
And I would like to have this at the end :

For some reason I toyed around with this a bit. Below are a few variations of possible answers: