My understanding is that you want to extract the
dv values for year 1980:
color <- with( Test.dataset2, dv[ year == 1980 ] )
---
Date: Mon, 8 Mar 2004 19:36:45 -0800
From: Jens Hainmueller <jens_hainmueller at ksg05.harvard.edu>
To: R-Help <r-help at stat.math.ethz.ch>
Subject: [R] vector extraction
Hello,
I could need some help on this one:
>From the data.frame "Test.dataset2" below (TSCS data for 151
"countries.to.map" for "year" 1973-95; each
"country.to.map" is described by
a unique code), I would like to extract a vector "color" that for each
"country.to.map" takes on the value of "dv" (a categorical
variable with
values 1,2,..4) for a specified "year". Thus, for a specified
"year",
"color" should have 151 obs - one for each "country.to.map"
represented by
its respective value of "dv").
I tried this:
> color <- dv[country.to.map][(year == 1980)[country.to.map]]
but it does not give me what I need. I can't figure out where my error is,
however.
Thanks,
Jens
> Test.dataset2[1:40,]
country.to.map dv year
1 1936 NA 1973
2 1936 NA 1974
3 1936 NA 1975
4 1936 NA 1976
5 1936 NA 1977
6 1936 NA 1978
7 1936 NA 1979
8 1936 NA 1980
9 1936 NA 1981
10 1936 NA 1982
11 1936 NA 1983
12 1936 NA 1984
13 1936 NA 1985
14 1936 NA 1986
15 1936 NA 1987
16 1936 NA 1988
17 1936 4 1989
18 1936 4 1990
19 1936 4 1991
20 1936 4 1992
21 1936 4 1993
22 1936 4 1994
23 1936 4 1995
24 56 4 1973
25 56 4 1974
26 56 2 1975
27 56 2 1976
28 56 2 1977
29 56 2 1978
30 56 2 1979
31 56 2 1980
32 56 2 1981
33 56 2 1982
34 56 4 1983
35 56 4 1984
36 56 4 1985
37 56 4 1986
38 56 4 1987
39 56 4 1988
40 56 4 1989