This question already has an answer here:
I'm new to R and I have a little problem with switching values of list elements by using conditions.
I've got the following list:
listA <- list(",", ",", "_", "_", "A", "B")
First I tried to switch them with the following code:
listA[listA==","] <- as.character(".")
In this case everything works fine. Elements which are equal to "," are switched into a ".". Now I want to switch values by using multiple conditions. Something like this:
listA[listA!=","&& listA!="_"] <- as.character(".")
When I try that one nothing happens. Also no error message comes up. I also tested if the condition gives the right results but that's the next (maybe the main?) problem:
which(listA!=","&& listA!="_")
That snippet gives the result integer(0)
. Seems like R does not accept multiple conditions for indexing lists in the way I tried. Hope you can help me with this one.