I have an integrated object with 4 data sets (Veh1, Exp1, Veh2, Exp2)
These tags are appended in the object meta data under object$cond
What I would like to do is create a new metadata column called "exp", and label any cell that was labeled as Veh1 or Veh2 as VEH and any cell that was labeled as Exp1/Exp2 as EXP so that it would look something like this when finished:
orig.ident cond seurat_clusters exp
Veh1_AAACCTGAGATCCTGT VEH1 6 VEH
Veh2_AAACCTGCAGTACACT VEH2 9 VEH
Exp1_AAACCTGGTCCCTTGT EXP1 12 EXP
Exp2_AAACCTGTCAAAGACA EXP2 7 EXP
I have tried using 4 seperate if statements for each condition:
if (object$cond == "VEH1") {
object$exp <- "VEH"
}
and I have tried using an ifelse statement like this:
if (object$cond == "VEH1") {
object$exp <- "VEH"
} else if (object$cond == "VEH2") {
object$exp <- "VEH"
} else if (object$cond == "EXP1") {
object$exp <- "EXP"
} else {object$cond == "EXP2"
object$exp <- "EXP"
}
both of these labeled every cell as VEH, and I got the warning
Warning message:
In if (object$cond == "VEH") { :
the condition has length > 1 and only the first element will be used
> head(x = object[[]])
lastly I tried using a for loop like this, where 48,000 is the number of cells I have
for (i in 1:48000)
{
if (object$cond[[i]] == "VEH1") {
object$exp <- "VEH"
}
}
This didn't work etihe.
Does anyone have a recommendation? I fell like this simple task shouldn't be that difficult but I can't figure out how to get it
Thanks in advance!
Thanks for the hint. I tried:
and got returned an error.
But I found the solution here!!