You can refer to parts of vectors, matrices, data frames and list using either a direct reference or a list of indices. Examples:

  1. world[1,] the first row and all columns.
  2. world["AFGH",] the row labelled "AFGH" and all columns.
  3. world[c("AFGH","CHIN","TUNI"),] several rows (countries) with all columns.
  4. world[world$continent=='Europe ',] a logical expression that selects only european countries. Note that world$continent=='Europe 'generates a logical vector where all element are TRUE when continent=='Europe ' and FALSE otherwise.ls()
  5. world[,1] all countries and the first row.
  6. world[,"gnpserv"] the column labelled "tert"
  7. world[,c("gnpagr","gnpind,"gnpserv")] three columns selected by name

Note to make life easier you could prepare a series of definitions and use them later to access the data you are interested in:

sect <- c("gnpagr","gnpind,"gnpserv") 

and then use

world[,sect]

and defining rich countries, defined as countries having a GNP per captia above the median

rich <- world$gnpcap > median(gnpcap)

and then simply write

world[rich,sect]

to list the GNP produced by the three economic sectors for rich counties

Other useful definitions could be

europe <- world$continent == 'Europe '
asia <- world$continent == 'Asia '