Case and/or Variable Selection (Subsets of Data)
You may select cases (or variables) from a data set for further analysis. Actually, there is a huge number of ways this can be accomplished
The subset command
The easiest way of case selection is probably subset
. Here is an example:
sub1.xdata <- subset(xdata, inc > 1000)
This assigns a subset of xdata
to the new object sub1.xdata
. This subset consist of all cases that have values larger than 1000 in variable 'inc'.
The subset
command can be used for variable selection as well, as in:
sub1.xdata <- subset(xdata, inc > 1000, select=c(var1,var2))
The "[]" operator
The same effect as demonstrated above with the help of subset
can be achieved like this:
sub2.xdata <- xdata[xdata$inc >1000]
© W. Ludwig-Mayerhofer, R Guide | Last update: 22 Apr 2017