I have a data set in the following format and want to extract data-value for each combination like A_ALL, B_ALL, A_Part, B_part for stastical analysis.
Currently, what I can do is
A_ALL <- data[data$variable=="All" & data$Set=="A",1]
A_Part <- data[data$variable=="Part" & data$Set=="A",1]
I wonder if there is a more efficient way to extract all these data.
Thanks!
Tong Chen
**Input File format**
value variable Set
24.4003 All A
21.2582 All A
1.91043 All A
34.9642 All B
33.794 All B
16.6093 All B
16.6095 All B
24.4003 Part A
21.2582 Part A
34.9642 Part B
33.794 Part B
16.6093 Part B
You can use
split
, which will create alist
of the values you're interested in:Here, instead of splitting on the entire dataset, I'm splitting on the values where
Set == "A"
, as you've indicated you need in your current solution.Alternatively, if you want to split according to all factors of "Set" and "variable" in one go:
I would recommend sticking with a
list
, as I've created above. However, if you really want to have a whole bunch of objects in your workspace, you can uselist2env
to extract the list items to your environment: