Conditional cluster subsetting from a data.frame in R
In my data.frame below, I wonder how to conditionally subset the following (Desired output for each is below):
- subset all rows of every study in which
group
is constant butoutcome
varies. - subset all rows of every study in which
outcome
is constant butgroup
varies. - subset all rows of every study in which
outcome
&group
both vary. - subset all rows of every study in which
outcome
&group
both don't vary.
h = "
study outcome group
a 1 1
a 2 1
b 1 1
b 1 2
c 2 1
c 3 2
d 1 1
d 1 1
e 1 1"
h = read.table(text = h,h=T)
#DESIRED OUTPUT (either as one data.frame or a list of data.frames):
# 1:
#a 1 1
#a 2 1
# 2:
#b 1 1
#b 1 2
# 3:
#c 2 1
#c 3 2
# 4:
#d 1 1
#d 1 1
#e 1 1
from Recent Questions - Stack Overflow https://ift.tt/37j6pj7
https://ift.tt/eA8V8J
Comments
Post a Comment