I am trying to select a subset of observations. I’m not sure what I’m doing makes sense since it involves two different datasets. Still, I’m bothered by receiving an error that, in my opinion, shouldn’t be there and makes no sense: “$ operator is invalid for atomic vectors”.
With the dataset “Anxiety”, I run a set of commands without getting any error:
dim(Anxiety)
# [1] 69 41
dim(Anxiety_arm)
# [1] 123 355
Anxiety_arm= as.data.frame(Anxiety_arm)
dim(Anxiety_arm)
# [1] 123 355
Anxiety_arm=subset(Anxiety_arm,Anxiety$LeveloftreatmentInt1=="group")
Instead, with the dataset “PTSD”, after running the same set of commands,
dim(PTSD)
# [1] 71 413
dim(PTSD_arm)
# [1] 130 350
PTSD_arm= as.data.frame(PTSD_arm)
dim(PTSD_arm)
# [1] 130 350
I get an error with the last command:
PTSD_arm=subset(PTSD_arm,PTSD$LeveloftreatmentInt1=="group")
the error being:
Error in PTSD$LeveloftreatmentInt1 :
operator is invalid for atomic vectors
However, by checking, I find that R-Studio tells me not only that “PTSD” is not an atomic vector:
is.atomic(PTSD)
# [1] FALSE
but also that it’s recursive:
is.recursive(PTSD)
# [1] TRUE
Federico Tedeschi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1