[R] selecting subsets of data for analysis

Marc Schwartz MSchwartz at MedAnalytics.com
Wed Feb 2 04:27:43 CET 2005


On Wed, 2005-02-02 at 13:54 +1300, Brett Stansfield wrote:
> can you tell me how to ask R to analyse a subset of data
> 
> eg. supposing the data set consists of 9 columns and I only want R to
> analyse columns 1, 3 and 5 
> 
> how would I command R to conduct eg. boxplots of those variables only?

#Create a matrix with 9 columns
mat <- matrix(rnorm(90), ncol = 9)

# create a boxplot from cols 1,3 and 5
boxplot(data.frame(mat[, c(1, 3, 5)]))

In this case, passing the 3 columns of the matrix as a data frame
enables boxplot() to plot the 3 columns in a single call. There is an
example of this in ?boxplot.

You might also want to review the help for extracting sections of multi-
dimensional objects:

?Extract or ?"["

and the examples therein.

HTH,

Marc Schwartz




More information about the R-help mailing list