I am new to R and I am doing some exercises but I do not get the expected output. I created a data frame with 4 columns. a b,c,d I want to see in my output column c when column d only has values ( B and C) only.
The way I am doing is subset(DFAsg1, b == "B" | y == "C")
this returns all the columns in the data frame, but I want to select only column c.
CodePudding user response:
subset(DFAsg1, b == "B" | y == "C", select = "c")
CodePudding user response:
We could do
if(all(DFAsg1$d %in% c("B", "C"), na.rm = TRUE)) DFAsg1['c']