Loop through list programatically - r

I have a list in R that I want to loop through all the elements.
This is the structure of the object:
> str(AAPL.OPT[c])
List of 1
$ jun.12.2020:List of 2
..$ calls:'data.frame': 52 obs. of 7 variables:
.. ..$ Strike: num [1:52] 180 185 200 210 240 ...
.. ..$ Last : num [1:52] 123 118 131 120 85 ...
.. ..$ Chg : num [1:52] 0 0 7.61 9.48 0 ...
.. ..$ Bid : num [1:52] 149 144 129 119 89 ...
.. ..$ Ask : num [1:52] 153.3 148.5 133.5 123.7 93.5 ...
.. ..$ Vol : int [1:52] NA 15 16 2 1 1 3 36 1 2 ...
.. ..$ OI : int [1:52] 0 15 25 4 50 3 4 36 6 10 ...
..$ puts :'data.frame': 56 obs. of 7 variables:
.. ..$ Strike: num [1:56] 150 165 170 180 185 190 195 200 205 210 ...
.. ..$ Last : num [1:56] 0.05 0.02 0.14 0.05 0.03 0.02 0.01 0.02 0.01 0.01 ...
.. ..$ Chg : num [1:56] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ Bid : num [1:56] NA 0 0 0 0 0 0 0 0 0 ...
.. ..$ Ask : num [1:56] 2.13 0.11 0.11 1.8 1.87 0.01 1.88 0.5 1.88 2.13 ...
.. ..$ Vol : int [1:56] NA 1 1 2 1 16 1 17 1 21 ...
.. ..$ OI : int [1:56] 1 10 7 9 76 201 113 314 92 264 ...
I cannot access the next level of the object programatically (by indexing the value)
I want to do something like this:
AAPL.OPT[c][1]
instead of this
AAPL.OPT[c]$jun.12.2020
Sample data of AAPL.OPT[c]
$`jun.12.2020`$`calls`
Strike Last Chg Bid Ask Vol OI
AAPL200612C00180000 180.0 123.29 0.00000000 149.00 153.35 NA 0
AAPL200612C00185000 185.0 117.60 0.00000000 144.00 148.50 15 15
AAPL200612C00200000 200.0 131.15 7.60999300 129.00 133.50 16 25
AAPL200612C00210000 210.0 119.95 9.47999600 119.30 123.65 2 4
....

AAPL.OPT[c] gives a list of length 1 which has two other lists in them. If we use [[c]] it gives a list of length 2 andtTo access each dataframe you can subset them further using [[ so AAPL.OPT[[c]][[1]] and AAPL.OPT[[c]][[2]].

We can use
AAPL.OPT[[c]]$jun.12.2020

Related

issue with gbm.step() function in R

I'm trying to execute the Cross-Validation for the boosting regression/classification trees using the function gbm.step() from the R package dismo, but it returns a empty output and I can't figure out why. This is the code I'm using:
ColIndexCov <- match(names(myRS),colnames(DFbrt_df2))
ColIndexResp <- match(c("HasRes"),colnames(DFbrt_df2))
DFbrt_df <- DFbrt#data
DFbrt_df2 <- na.omit(DFbrt_df)
myBRT = gbm.step(data=DFbrt_df2,
gbm.x = ColIndexCov,
gbm.y = ColIndexResp,
tree.complexity = 3,
learning.rate = 10^(-8),
n.trees = 50,
family = "bernoulli",
n.folds = 4,
fold.vector = DFbrt_df2$Region.num,
step.size = 50,
verbose = F,
silent = T
)
str(DFbrt_df2)
'data.frame': 560845 obs. of 18 variables:
$ Nsamples : num 310 310 310 310 310 310 310 310 310 310 ...
$ cluster : num 39 39 39 39 39 39 39 39 39 39 ...
$ R : num 44.9 44.9 44.9 44.9 44.9 ...
$ P50 : num 0.565 0.544 0.609 0.605 0.593 ...
$ regions : Factor w/ 6 levels "China_east","China_middlesouth",..: 1 1 1 1 1 1 1 1 1 1 ...
$ HasRes : num 1 0 1 0 0 0 1 1 0 0 ...
$ use : num 10.02 9.75 0 9.38 8.77 ...
$ acc : num 0 0 0.4103 0.0769 0.0779 ...
$ tmp : num 2.46 2.46 2.46 2.46 2.45 ...
$ irg : num 1.788 0.399 1.205 1.836 1.841 ...
$ PgExt : num 3.11 0 3.7 3.11 3.18 ...
$ PgInt : num 4.69 2.76 0 3.99 2.22 ...
$ ChExt : num 3.74 0 4.33 3.74 3.81 ...
$ ChInt : num 5.01 5.99 5.35 4.88 4.97 ...
$ Ca : num 0 0 2.71 0 2.8 ...
$ veg : num 0 0 0 0 0 0 0 0 0 0 ...
$ Region.num: num 4 4 4 4 4 4 4 4 4 4 ...
$ Region : num 4 4 4 4 4 4 4 4 4 4 ...
- attr(*, "na.action")= 'omit' Named int 1 2 3 4 5 6 7 8 9 10 ...
..- attr(*, "names")= chr "1" "2" "3" "4" ...
the answer variable is the variable HasRes and the covariates are the variables use, acc, tmp, irg, PgExt, PgInt, ChExt, ChInt, ca, veg.

Meaning of "#" operator in R language?

I came across the following and I haven't figured out the purpose of the "#" operator. What's the meaning there? I didn't make heads/tails of the R manual language.
library(lattice)
library(sp)
data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")
p <- xyplot(copper ~ cadmium, data = meuse#data, col = "grey", pch = 20, cex = 2)
R manuals says
Usage
object#name
object#name <- value
Extract or replace the contents of a slot in a object with a formal (S4) class structure.
These operators support the formal classes of package methods, and are enabled only when package methods is loaded (as per default). See slot for further details, in particular for the differences between slot() and the # operator.
It is checked that object is an S4 object (see isS4), and it is an error to attempt to use # on any other object. (There is an exception for name .Data for internal use only.) The replacement operator checks that the slot already exists on the object (which it should if the object is really from the class it claims to be).
I checked the structure of "meuse" and found no references to a slot named "data".
meuse is an S4 object
isS4(meuse)
[1] TRUE
If you take the structure of of meuse (str_meuse) you'll see some fields are denoted with your # operator, including one called data. These slots can be accessed with # similar to how you might see other slots in other objects accessed using the $ operator. So meuse#data gives you the data portion of the meuse object.
str(meuse)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
..# data :'data.frame': 155 obs. of 12 variables:
.. ..$ cadmium: num [1:155] 11.7 8.6 6.5 2.6 2.8 3 3.2 2.8 2.4 1.6 ...
.. ..$ copper : num [1:155] 85 81 68 81 48 61 31 29 37 24 ...
.. ..$ lead : num [1:155] 299 277 199 116 117 137 132 150 133 80 ...
.. ..$ zinc : num [1:155] 1022 1141 640 257 269 ...
.. ..$ elev : num [1:155] 7.91 6.98 7.8 7.66 7.48 ...
.. ..$ dist : num [1:155] 0.00136 0.01222 0.10303 0.19009 0.27709 ...
.. ..$ om : num [1:155] 13.6 14 13 8 8.7 7.8 9.2 9.5 10.6 6.3 ...
.. ..$ ffreq : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ soil : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 2 1 1 2 ...
.. ..$ lime : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ...
.. ..$ landuse: Factor w/ 15 levels "Aa","Ab","Ag",..: 4 4 4 11 4 11 4 2 2 15 ...
.. ..$ dist.m : num [1:155] 50 30 150 270 380 470 240 120 240 420 ...
..# coords.nrs : int [1:2] 1 2
..# coords : num [1:155, 1:2] 181072 181025 181165 181298 18130
See how that subsetting is working?
str(meuse#data)
'data.frame': 155 obs. of 12 variables:
$ cadmium: num 11.7 8.6 6.5 2.6 2.8 3 3.2 2.8 2.4 1.6 ...
$ copper : num 85 81 68 81 48 61 31 29 37 24 ...
$ lead : num 299 277 199 116 117 137 132 150 133 80 ...
$ zinc : num 1022 1141 640 257 269 ...
$ elev : num 7.91 6.98 7.8 7.66 7.48 ...
$ dist : num 0.00136 0.01222 0.10303 0.19009 0.27709 ...
$ om : num 13.6 14 13 8 8.7 7.8 9.2 9.5 10.6 6.3 ...
$ ffreq : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
$ soil : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 2 1 1 2 ...
$ lime : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ...
$ landuse: Factor w/ 15 levels "Aa","Ab","Ag",..: 4 4 4 11 4 11 4 2 2 15 ...
$ dist.m : num 50 30 150 270 380 470 240 120 240 420 ...

How to deal with " rank-deficient fit may be misleading" in R?

I'm trying to predict the values of test data set based on train data set, it is predicting the values (no errors) however the predictions deviate A LOT by the original values. Even predicting values around -356 although none of the original values exceeds 200 (and there are no negative values). The warning is bugging me as I think the values deviates a lot because of this warning.
Warning message:
In predict.lm(fit2, data_test) :
prediction from a rank-deficient fit may be misleading
any way I can get rid of this warning? the code is simple
fit2 <- lm(runs~., data=train_data)
prediction<-predict(fit2, data_test)
prediction
I searched a lot but tbh I couldn't understand much about this error.
str of test and train data set in case someone needs them
> str(train_data)
'data.frame': 36 obs. of 28 variables:
$ matchid : int 57 58 55 56 53 54 51 52 45 46 ...
$ TeamName : chr "South Africa" "West Indies" "South Africa" "West Indies" ...
$ Opp_TeamName : chr "West Indies" "South Africa" "West Indies" "South Africa" ...
$ TeamRank : int 4 3 4 3 4 3 10 7 5 1 ...
$ Opp_TeamRank : int 3 4 3 4 3 4 7 10 1 5 ...
$ Team_Top10RankingBatsman : int 0 1 0 1 0 1 0 0 2 2 ...
$ Team_Top50RankingBatsman : int 4 6 4 6 4 6 3 5 4 3 ...
$ Team_Top100RankingBatsman: int 6 8 6 8 6 8 7 7 7 6 ...
$ Opp_Top10RankingBatsman : int 1 0 1 0 1 0 0 0 2 2 ...
$ Opp_Top50RankingBatsman : int 6 4 6 4 6 4 5 3 3 4 ...
$ Opp_Top100RankingBatsman : int 8 6 8 6 8 6 7 7 6 7 ...
$ InningType : chr "1st innings" "2nd innings" "1st innings" "2nd innings" ...
$ Runs_OverAll : num 361 705 348 630 347 ...
$ AVG_Overall : num 27.2 20 23.3 19.1 24 ...
$ SR_Overall : num 128 121 120 118 118 ...
$ Runs_Last10Matches : num 118.5 71 102.1 71 78.6 ...
$ AVG_Last10Matches : num 23.7 20.4 20.9 20.4 23.2 ...
$ SR_Last10Matches : num 120 106 114 106 116 ...
$ Runs_BatingFirst : num 236 459 230 394 203 ...
$ AVG_BatingFirst : num 30.6 23.2 24 21.2 27.1 ...
$ SR_BatingFirst : num 127 136 123 125 118 ...
$ Runs_BatingSecond : num 124 262 119 232 144 ...
$ AVG_BatingSecond : num 25.5 18.3 22.8 17.8 22.8 ...
$ SR_BatingSecond : num 125 118 112 117 114 ...
$ Runs_AgainstTeam2 : num 88.3 118.3 76.3 103.9 49.3 ...
$ AVG_AgainstTeam2 : num 28.2 23 24.7 22.1 16.4 ...
$ SR_AgainstTeam2 : num 139 127 131 128 111 ...
$ runs : int 165 168 231 236 195 126 143 141 191 135 ...
> str(data_test)
'data.frame': 34 obs. of 28 variables:
$ matchid : int 59 60 61 62 63 64 65 66 69 70 ...
$ TeamName : chr "India" "West Indies" "England" "New Zealand" ...
$ Opp_TeamName : chr "West Indies" "India" "New Zealand" "England" ...
$ TeamRank : int 2 3 5 1 4 8 6 2 10 1 ...
$ Opp_TeamRank : int 3 2 1 5 8 4 2 6 1 10 ...
$ Team_Top10RankingBatsman : int 1 1 2 2 0 0 1 1 0 2 ...
$ Team_Top50RankingBatsman : int 5 6 4 3 4 2 5 5 3 3 ...
$ Team_Top100RankingBatsman: int 7 8 7 6 6 5 7 7 7 6 ...
$ Opp_Top10RankingBatsman : int 1 1 2 2 0 0 1 1 2 0 ...
$ Opp_Top50RankingBatsman : int 6 5 3 4 2 4 5 5 3 3 ...
$ Opp_Top100RankingBatsman : int 8 7 6 7 5 6 7 7 6 7 ...
$ InningType : chr "1st innings" "2nd innings" "2nd innings" "1st innings" ...
$ Runs_OverAll : num 582 618 470 602 509 ...
$ AVG_Overall : num 25 21.8 20.3 20.7 19.6 ...
$ SR_Overall : num 113 120 123 120 112 ...
$ Runs_Last10Matches : num 182 107 117 167 140 ...
$ AVG_Last10Matches : num 37.1 43.8 21 24.9 27.3 ...
$ SR_Last10Matches : num 111 153 122 141 120 ...
$ Runs_BatingFirst : num 319 314 271 345 294 ...
$ AVG_BatingFirst : num 23.6 17.8 20.6 20.3 19.5 ...
$ SR_BatingFirst : num 116.9 98.5 118 124.3 115.8 ...
$ Runs_BatingSecond : num 264 282 304 256 186 ...
$ AVG_BatingSecond : num 28 23.7 31.9 21.6 16.5 ...
$ SR_BatingSecond : num 96.5 133.9 129.4 112 99.5 ...
$ Runs_AgainstTeam2 : num 98.2 95.2 106.9 75.4 88.5 ...
$ AVG_AgainstTeam2 : num 45.3 42.7 38.1 17.7 27.1 ...
$ SR_AgainstTeam2 : num 125 138 152 110 122 ...
$ runs : int 192 196 159 153 122 120 160 161 70 145 ...
In simple word, how can I get rid of this warning so that it doesn't effect my predictions?
(Intercept) matchid TeamNameBangladesh
1699.98232628 -0.06793787 59.29445330
TeamNameEngland TeamNameIndia TeamNameNew Zealand
347.33030177 -499.40074338 -179.19192936
TeamNamePakistan TeamNameSouth Africa TeamNameSri Lanka
-272.71610614 -3.54867488 -45.27920191
TeamNameWest Indies Opp_TeamNameBangladesh Opp_TeamNameEngland
-345.54349798 135.05901017 108.04227770
Opp_TeamNameIndia Opp_TeamNameNew Zealand Opp_TeamNamePakistan
-162.24418387 -60.55364436 -114.74599364
Opp_TeamNameSouth Africa Opp_TeamNameSri Lanka Opp_TeamNameWest Indies
196.90856999 150.70170068 -6.88997714
TeamRank Opp_TeamRank Team_Top10RankingBatsman
NA NA NA
Team_Top50RankingBatsman Team_Top100RankingBatsman Opp_Top10RankingBatsman
NA NA NA
Opp_Top50RankingBatsman Opp_Top100RankingBatsman InningType2nd innings
NA NA 24.24029455
Runs_OverAll AVG_Overall SR_Overall
-0.59935875 20.12721378 -13.60151334
Runs_Last10Matches AVG_Last10Matches SR_Last10Matches
-1.92526750 9.24182916 1.23914363
Runs_BatingFirst AVG_BatingFirst SR_BatingFirst
1.41001672 -9.88582744 -6.69780509
Runs_BatingSecond AVG_BatingSecond SR_BatingSecond
-0.90038727 -7.11580086 3.20915976
Runs_AgainstTeam2 AVG_AgainstTeam2 SR_AgainstTeam2
3.35936312 -5.90267210 2.36899131
You can have a look at this detailed discussion :
predict.lm() in a loop. warning: prediction from a rank-deficient fit may be misleading
In general, multi-collinearity can lead to a rank deficient matrix in logistic regression.
You can try applying PCA to tackle the multi-collinearity issue and then apply logistic regression afterwards.

Unexpected filled with color timeserie using ggplot

I'm a beginner at ggplot, and I tried to use it to draw some timeserie data.
I want to draw bound_transporter_in_evolution.mean as a function of time, in different conditions where the attribute p_off (float) varies.
p4 <- ggplot(data=df, aes(x=timesteps.mean)) +
geom_line(aes(y=bound_transporter_in_evolution.mean, color=p_off)) +
xlab(label="Time (s)") +
ylab(label="Number of bound 'in' transporters")
ggsave("p4.pdf", width=8, height=3.3)
I get the following plot:
I expected this result, but with a line instead of points:
Thank you
since p_off is a numeric variable, ggplot will create only one line connecting all the dots and color it along the values. If you want separated lines, you have do transform your colouring variable into a factor(assuming you have a limited number of different values). Let's take an example with a numeric color variable:
df=data.frame(x=c(1:5, 1:5), y=rnorm(10), z=c(1,1,1,1,1,2,2,2,2,2))
ggplot(data=df, aes(x=x)) + geom_line(aes(x=x, y=y, color=z))
Which doesn't make any sense since consecutive points come from different categories. And now turn it into a factor:
ggplot(data=df, aes(x=x)) + geom_line(aes(x=x, y=y, color=factor(z)))
In your first graph, the line constantly goes from one p_off value to another, and since you have a really big dataset it quickly saturates the screen.
Here is the output of str(df):
'data.frame': 150010 obs. of 34 variables:
$ bound_transporter_evolution.low : num [1:150010(1d)] 0 11.4 26.1 41.8 48.2 ...
$ bound_transporter_evolution.mean : num [1:150010(1d)] 0 15 28.2 45 53.8 63.8 71.6 77.8 86.2 91.2 ...
$ bound_transporter_evolution.up : num [1:150010(1d)] 0 18.6 30.3 48.2 59.4 ...
$ bound_transporter_in_evolution.low : num [1:150010(1d)] 0 11.4 26.1 41.8 48.2 ...
$ bound_transporter_in_evolution.mean : num [1:150010(1d)] 0 15 28.2 45 53.8 63.8 71.6 77.8 86.2 91.2 ...
$ bound_transporter_in_evolution.up : num [1:150010(1d)] 0 18.6 30.3 48.2 59.4 ...
$ bound_transporter_out_evolution.low : num [1:150010(1d)] 0 0 0 0 0 0 0 0 0 0 ...
$ bound_transporter_out_evolution.mean: num [1:150010(1d)] 0 0 0 0 0 0 0 0 0 0 ...
$ bound_transporter_out_evolution.up : num [1:150010(1d)] 0 0 0 0 0 0 0 0 0 0 ...
$ free_transporter_evolution.low : num [1:150010(1d)] 200 181 170 152 141 ...
$ free_transporter_evolution.mean : num [1:150010(1d)] 200 185 172 155 146 ...
$ free_transporter_evolution.up : num [1:150010(1d)] 200 189 174 158 152 ...
$ free_transporter_in_evolution.low : num [1:150010(1d)] 186 172 158 139 127 ...
$ free_transporter_in_evolution.mean : num [1:150010(1d)] 188 173 160 143 135 ...
$ free_transporter_in_evolution.up : num [1:150010(1d)] 191 175 162 148 142 ...
$ free_transporter_out_evolution.low : num [1:150010(1d)] 9.18 9.18 9.18 9.18 9.18 ...
$ free_transporter_out_evolution.mean : num [1:150010(1d)] 11.6 11.6 11.6 11.6 11.6 11.6 11.6 11.6 11.6 11.6 ...
$ free_transporter_out_evolution.up : num [1:150010(1d)] 14 14 14 14 14 ...
$ glutamate_evolution.low : num [1:150010(1d)] 2000 1981 1970 1951 1939 ...
$ glutamate_evolution.mean : num [1:150010(1d)] 2000 1985 1971 1954 1943 ...
$ glutamate_evolution.up : num [1:150010(1d)] 2000 1989 1973 1957 1948 ...
$ p_off : num [1:150010(1d)] 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 ...
$ simulation_name : Factor w/ 1 level "Variable p-off large diffusion-limited area": 1 1 1 1 1 1 1 1 1 1 ...
$ timesteps.low : num [1:150010(1d)] 0e+00 1e-06 2e-06 3e-06 4e-06 5e-06 6e-06 7e-06 8e-06 9e-06 ...
$ timesteps.mean : num [1:150010(1d)] 0e+00 1e-06 2e-06 3e-06 4e-06 5e-06 6e-06 7e-06 8e-06 9e-06 ...
$ timesteps.up : num [1:150010(1d)] 0e+00 1e-06 2e-06 3e-06 4e-06 5e-06 6e-06 7e-06 8e-06 9e-06 ...
$ transporter_in_evolution.low : num [1:150010(1d)] 186 186 186 186 186 ...
$ transporter_in_evolution.mean : num [1:150010(1d)] 188 188 188 188 188 ...
$ transporter_in_evolution.up : num [1:150010(1d)] 191 191 191 191 191 ...
$ transporter_out_evolution.low : num [1:150010(1d)] 9.18 9.18 9.18 9.18 9.18 ...
$ transporter_out_evolution.mean : num [1:150010(1d)] 11.6 11.6 11.6 11.6 11.6 11.6 11.6 11.6 11.6 11.6 ...
$ transporter_out_evolution.up : num [1:150010(1d)] 14 14 14 14 14 ...
$ variable_parameter : Factor w/ 1 level "p_off": 1 1 1 1 1 1 1 1 1 1 ...
$ variable_value : num [1:150010(1d)] 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 ...

How can I split a multiply imputed dataset created in Amelia?

I have imputed missing values using Amelia thereby creating 5 multiply imputed datasets. Now, I would like to split this multi-dataset, e.g. one set for year => 1990 and one set for year =<1990. Any ideas how I can do so? Many thanks!
data(freetrade)
freetrade$year #splitting variable
#Imputation of missing data
a.out <- amelia(freetrade, m=5, ts="year", cs="country")
#split of created dataset?
Amelia returns an object that contains a list of dataframes (for each imputations). You can see the structure of this object with str().
> library(Amelia)
> data(freetrade)
>
> a.out <- amelia(freetrade, m=5, ts="year", cs="country")
-- Imputation 1 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-- Imputation 2 --
1 2 3 4 5 6 7 8 9 10 11 12 13
-- Imputation 3 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
-- Imputation 4 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-- Imputation 5 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
> str(a.out)
List of 12
$ imputations:List of 5
..$ imp1:'data.frame': 171 obs. of 10 variables:
.. ..$ year : int [1:171] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ...
.. ..$ country : chr [1:171] "SriLanka" "SriLanka" "SriLanka" "SriLanka" ...
.. ..$ tariff : num [1:171] 30.6 22.4 41.3 26.8 31 ...
.. ..$ polity : num [1:171] 6 5 5 5 5 5 5 5 5 5 ...
.. ..$ pop : num [1:171] 14988000 15189000 15417000 15599000 15837000 ...
.. ..$ gdp.pc : num [1:171] 461 474 489 508 526 ...
.. ..$ intresmi: num [1:171] 1.94 1.96 1.66 2.8 2.26 ...
.. ..$ signed : num [1:171] 0 0 1 0 0 0 0 1 0 0 ...
.. ..$ fiveop : num [1:171] 12.4 12.5 12.3 12.3 12.3 ...
.. ..$ usheg : num [1:171] 0.259 0.256 0.266 0.299 0.295 ...
..$ imp2:'data.frame': 171 obs. of 10 variables:
.. ..$ year : int [1:171] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ...
.. ..$ country : chr [1:171] "SriLanka" "SriLanka" "SriLanka" "SriLanka" ...
.. ..$ tariff : num [1:171] 33.6 59.7 41.3 18.2 31 ...
.. ..$ polity : num [1:171] 6 5 5 5 5 5 5 5 5 5 ...
.. ..$ pop : num [1:171] 14988000 15189000 15417000 15599000 15837000 ...
.. ..$ gdp.pc : num [1:171] 461 474 489 508 526 ...
.. ..$ intresmi: num [1:171] 1.94 1.96 1.66 2.8 2.26 ...
.. ..$ signed : num [1:171] 0 0 1 0 0 0 0 1 0 0 ...
.. ..$ fiveop : num [1:171] 12.4 12.5 12.3 12.3 12.3 ...
.. ..$ usheg : num [1:171] 0.259 0.256 0.266 0.299 0.295 ...
..$ imp3:'data.frame': 171 obs. of 10 variables:
.. ..$ year : int [1:171] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ...
.. ..$ country : chr [1:171] "SriLanka" "SriLanka" "SriLanka" "SriLanka" ...
.. ..$ tariff : num [1:171] 48.5 32.9 41.3 47.2 31 ...
.. ..$ polity : num [1:171] 6 5 5 5 5 5 5 5 5 5 ...
.. ..$ pop : num [1:171] 14988000 15189000 15417000 15599000 15837000 ...
.. ..$ gdp.pc : num [1:171] 461 474 489 508 526 ...
.. ..$ intresmi: num [1:171] 1.94 1.96 1.66 2.8 2.26 ...
.. ..$ signed : num [1:171] 0 0 1 0 0 0 0 1 0 0 ...
.. ..$ fiveop : num [1:171] 12.4 12.5 12.3 12.3 12.3 ...
.. ..$ usheg : num [1:171] 0.259 0.256 0.266 0.299 0.295 ...
..$ imp4:'data.frame': 171 obs. of 10 variables:
.. ..$ year : int [1:171] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ...
.. ..$ country : chr [1:171] "SriLanka" "SriLanka" "SriLanka" "SriLanka" ...
.. ..$ tariff : num [1:171] 18.4 45.5 41.3 16.9 31 ...
.. ..$ polity : num [1:171] 6 5 5 5 5 5 5 5 5 5 ...
.. ..$ pop : num [1:171] 14988000 15189000 15417000 15599000 15837000 ...
.. ..$ gdp.pc : num [1:171] 461 474 489 508 526 ...
.. ..$ intresmi: num [1:171] 1.94 1.96 1.66 2.8 2.26 ...
.. ..$ signed : num [1:171] 0 0 1 0 0 0 0 1 0 0 ...
.. ..$ fiveop : num [1:171] 12.4 12.5 12.3 12.3 12.3 ...
.. ..$ usheg : num [1:171] 0.259 0.256 0.266 0.299 0.295 ...
..$ imp5:'data.frame': 171 obs. of 10 variables:
.. ..$ year : int [1:171] 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ...
.. ..$ country : chr [1:171] "SriLanka" "SriLanka" "SriLanka" "SriLanka" ...
.. ..$ tariff : num [1:171] 15.3 44.4 41.3 40.1 31 ...
.. ..$ polity : num [1:171] 6 5 5 5 5 5 5 5 5 5 ...
.. ..$ pop : num [1:171] 14988000 15189000 15417000 15599000 15837000 ...
.. ..$ gdp.pc : num [1:171] 461 474 489 508 526 ...
.. ..$ intresmi: num [1:171] 1.94 1.96 1.66 2.8 2.26 ...
.. ..$ signed : num [1:171] 0 0 1 0 0 0 0 1 0 0 ...
.. ..$ fiveop : num [1:171] 12.4 12.5 12.3 12.3 12.3 ...
.. ..$ usheg : num [1:171] 0.259 0.256 0.266 0.299 0.295 ...
..- attr(*, "class")= chr [1:2] "mi" "list"
$ m : num 5
$ missMatrix : logi [1:171, 1:10] FALSE FALSE FALSE FALSE FALSE FALSE ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:10] "year" "country" "tariff" "polity" ...
$ overvalues : NULL
$ theta : num [1:9, 1:9, 1:5] -1 -0.08456 -0.03404 -0.00193 0.06483 ...
$ mu : num [1:8, 1:5] -0.08456 -0.03404 -0.00193 0.06483 -0.11178 ...
$ covMatrices: num [1:8, 1:8, 1:5] 0.7881 -0.1869 -0.0531 0.2121 -0.0819 ...
$ code : num 1
$ message : chr "Normal EM convergence."
$ iterHist :List of 5
..$ : num [1:15, 1:3] 44 34 25 28 26 25 24 22 20 14 ...
..$ : num [1:13, 1:3] 44 27 24 22 22 21 18 17 14 11 ...
..$ : num [1:19, 1:3] 44 34 29 27 26 26 25 24 23 21 ...
..$ : num [1:15, 1:3] 44 34 27 28 23 24 23 23 19 19 ...
..$ : num [1:20, 1:3] 44 32 30 27 24 23 23 23 23 21 ...
$ arguments :List of 22
..$ idvars : NULL
..$ logs : NULL
..$ ts : num 1
..$ cs : num 2
..$ empri : NULL
..$ tolerance : num 1e-04
..$ polytime : NULL
..$ splinetime : NULL
..$ lags : NULL
..$ leads : NULL
..$ intercs : logi FALSE
..$ sqrts : NULL
..$ lgstc : NULL
..$ noms : NULL
..$ ords : NULL
..$ priors : NULL
..$ autopri : num 0.05
..$ bounds : NULL
..$ max.resample: num 100
..$ startvals : num 0
..$ overimp : NULL
..$ emburn : num [1:2] 0 0
..- attr(*, "class")= chr [1:2] "ameliaArgs" "list"
$ orig.vars : chr [1:10] "year" "country" "tariff" "polity" ...
- attr(*, "class")= chr "amelia"
From here you can see that the the "imputations" element of your a.out object contains your data frames, so you can reference each of your imputations from there. For example a.out$imputations[[1]]$year will give you the years from your first imputation. If you like to do that across each imputation then you can do so using an apply function or loop. To illustrate this, consider:
> sapply(a.out$imputations,function(x) head(x$year))
imp1 imp2 imp3 imp4 imp5
[1,] 1981 1981 1981 1981 1981
[2,] 1982 1982 1982 1982 1982
[3,] 1983 1983 1983 1983 1983
[4,] 1984 1984 1984 1984 1984
[5,] 1985 1985 1985 1985 1985
[6,] 1986 1986 1986 1986 1986
EDIT: I just re-read your question and I saw that you're actually looking for something more specific. You can take what's above an apply it to make subsets of each each data frame doing something like lapply(a.out$imputations,function(x) x[x$year > 1990,]). I'm not sure how you would like to combine these imputed datasets (split by years great than/less than 1990), but if you just want to append all rows together rbind() will do the trick (if not let me know how you'd like to and I can probably recommend a solution):
> df1 <- do.call(rbind,lapply(a.out$imputations,function(x) x[x$year > 1990,]))
> df2 <- do.call(rbind,lapply(a.out$imputations,function(x) x[x$year < 1990,]))
> head(df1)
year country tariff polity pop gdp.pc intresmi signed fiveop usheg
imp1.11 1991 SriLanka 26.9000 5 17247000 597.6987 2.285213 1.000000 12.8 0.2589872
imp1.12 1992 SriLanka 25.0000 5 17405000 618.3329 2.877877 0.515665 13.1 0.2623017
imp1.13 1993 SriLanka 24.2000 5 17628420 652.6205 4.280361 0.000000 13.2 0.2812928
imp1.14 1994 SriLanka 26.0000 5 17865000 680.0408 4.389912 0.000000 13.2 0.2783585
imp1.15 1995 SriLanka 20.0000 5 18112000 707.6591 3.995919 0.000000 13.2 0.2627195
imp1.16 1996 SriLanka 20.5646 5 18300000 727.0039 3.676763 0.000000 13.2 0.2681700
> head(df2)
year country tariff polity pop gdp.pc intresmi signed fiveop usheg
imp1.1 1981 SriLanka 30.56693 6 14988000 461.0236 1.937347 0 12.4 0.2593112
imp1.2 1982 SriLanka 22.39382 5 15189000 473.7634 1.964430 0 12.5 0.2558008
imp1.3 1983 SriLanka 41.30000 5 15417000 489.2266 1.663936 1 12.3 0.2655022
imp1.4 1984 SriLanka 26.81580 5 15599000 508.1739 2.797462 0 12.3 0.2988009
imp1.5 1985 SriLanka 31.00000 5 15837000 525.5609 2.259116 0 12.3 0.2952431
imp1.6 1986 SriLanka 17.76314 5 16117000 538.9237 1.832549 0 12.5 0.2886563

Resources