2021-07-28

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):

  1. subset all rows of every study in which group is constant but outcome varies.
  2. subset all rows of every study in which outcome is constant but group varies.
  3. subset all rows of every study in which outcome & group both vary.
  4. 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

No comments:

Post a Comment