1

I have difficulties in extracting certain line from a data. Let's say I use this command and I get a set of data, as below.

fpe <- read.table("http://data.princeton.edu/wws509/datasets/effort.dat")

fpe

               setting effort change

Bolivia             46      0      1
Brazil              74      0     10
Chile               89     16     29
Colombia            77     16     25
CostaRica           84     21     29
Cuba                89     15     40
DominicanRep        68     14     21
Ecuador             70      6      0
ElSalvador          60     13     13
Guatemala           55      9      4
Haiti               35      3      0
Honduras            51      7      7
Jamaica             87     23     21
Mexico              83      4      9
Nicaragua           68      0      7
Panama              84     19     22
Paraguay            74      3      6
Peru                73      0      2
TrinidadTobago      84     15     29
Venezuela           91      7     11

Now, if i just want the reading of setting, effort and change for certain countries, say Bolivia, Cuba and Mexico, what type of coding should I use?

I'm very new to R and I really need help. Thanking in advance.

thelatemail
  • 91,185
  • 12
  • 128
  • 188
shubha
  • 15
  • 4
  • 1
    I think it might be a good idea to read an introductory R site like Quick-R to get yourself started: http://www.statmethods.net/ In this case, your countries are actually a `rowname` instead of a proper column inside the `fpe` dataset. – thelatemail May 02 '13 at 03:17
  • Thank you for a prompt reply. The website is helpful. But, may I know what do you mean by proper column? Do I need to do a data.frame in order to get a proper column? – shubha May 02 '13 at 03:41
  • @shuba - try this - `fpe$country <- rownames(fpe)` then try printing `fpe` again. Also read here: http://ww2.coastal.edu/kingw/statistics/R-tutorials/dataframes.html the section called `Data Frame Indexing and Row Names` – thelatemail May 02 '13 at 03:45
  • I don't think that the question was the same as the supposed duplicate, nor was it clear from the answer how one would have selected rows based on rownames values. – IRTFM May 02 '13 at 14:00

1 Answers1

1

So you want to select by rownames:

 fpe[ rownames(fpe) %in% c('Bolivia', 'Cuba', 'Mexico'), ]
IRTFM
  • 258,963
  • 21
  • 364
  • 487