I was working on R with the following command to bring my data into long format:
NewData <- melt(data, id.vars = c("numberofSubject", "ID", "group", "gender", "age", "mmse"), measured.vars = c("CSvol_left", "CSvol_right ", "CSvol_total", "PHGvol_left", "PHGvol_right", "PHGvol_total", "PSR_left", "PSR_right", "PSR_total"))
The problem in the long format is: with PHGvol_right and PHGvol_total incorrect values suddenly came out. However, the values from the first few PHGvol_right lines were correct. It is also strange: As soon as I scroll up in my data set in long format, some values change from the correct to the incorrect value. For example, the correct value was: 10.37489683 and the new/incorrect value 7412.000000. Incidentally, the other variables also have the same number of decimal places and it works there. Does anyone have an idea how I can solve the problem? Would be very grateful.
I tried to melt the columns one by one and merge the melted dataset into one total dataset. But that didn't work.
library(tidyr)
melted_data_list <- list()
measured_vars <- c("CSvol_left", "CSvol_right", "CSvol_total", "PHGvol_left", "PHGvol_right", "PHGvol_total", "PSR_left", "PSR_right", "PSR_total")
for (var in measured_vars) {
melted_data_list[[var]] <- data %>%
select(c("numberofSubject", "ID", "group", "gender", "age", "mmse", var)) %>%
gather(key = "variable", value = "value", -c("numberofSubject", "ID", "group", "gender", "age", "mmse")) %>%
mutate(variable = var)
}
NewData <- bind_rows(melted_data_list)