How to rename Conditions

Hello,
I need some help with R studio.
i am trying to rename my conditions, I have so far managed to rename my column of condition to factor, but need to rename the conditions. My code so far is this:
my_longer_data %>%
mutate(Condition = factor(Condition)) %>%
head()

my_longer_data %>%
mutate(Condition = factor(Condition)) %>%
head()

then read my data as tidy data from the csv.

tidy_data %>%
mutate(Condition = recode(Condition,
"Condition1" = "Number_Number",
"Condition2" = "Number_Letter",
"Condition3" = "Letter_Number",
"Condition4" = "Letter_Letter",)) %>%
head()

then the error occurs

Any help would be appreciated :slight_smile:

Hi, welcome!

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

If I understand well, you need rename somes columns names?

dat <- iris[1:5,]
#  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#1          5.1         3.5          1.4         0.2  setosa
#2          4.9         3.0          1.4         0.2  setosa
#3          4.7         3.2          1.3         0.2  setosa
#4          4.6         3.1          1.5         0.2  setosa
#5          5.0         3.6          1.4         0.2  setosa

#For change somes columns  names:

names(dat)[1] <- 'Condition'
names(dat)[2] <- 'Condition2'

#  Condition1 Condition2 Petal.Length Petal.Width Species
#1        5.1        3.5          1.4         0.2  setosa
#2        4.9        3.0          1.4         0.2  setosa
#3        4.7        3.2          1.3         0.2  setosa
#4        4.6        3.1          1.5         0.2  setosa
#5        5.0        3.6          1.4         0.2  setosa

what error occurs ? please be specific.

p.s. transforming some data to factor and then writing that out to csv only to read it in again, seems to me a bit pointless as csv's are pure text and wont contain any signifiers of your factor intentions so it seems like wasted effort....

Thank you for all your responses.

I think I have worked it out.

my_longer_data %>%
mutate(Condition = recode(Condition,
"Condition1" = "",
"Condition2" = "
",
"Condition3" = "",
"Condition4" = "
",)) %>%
separate(col = "Condition", into = c("", ""), sep = "_") %>%
mutate(*** = factor(), *** = factor())

this is the code i used (obviously where the stars are I have named data).

I have another query... Is it possible to find the mean median etc when data is in long format? or would i need to place it in wide format?
I have four conditions (as above) and need to summarise my data

Yeah i got rid of that coding part.

The error stated condition not found but I have figured that out now and managed to rename the conditions.

I now need to summarise data which is confusing me as i need to do this in long format...

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.