I am trying to combine the third column of several data frames, which are called and renamed in a nested for loop, within the same looping process.
# Sample Data
ecvec_msa6_1998=matrix( round(rnorm(200, 5,15)), ncol=4)
ecvec_msa6_1999=matrix( round(rnorm(200, 4,16)), ncol=4)
ecvec_msa6_2000=matrix( round(rnorm(200, 3,17)), ncol=4)
datasets=c("msa")
num_industrys=c(6)
years=c(1998, 1999, 2000)
alist=list()
for (d in 1:length(datasets)) {
dataset=datasets[d]
for (n in 1:length(num_industrys)){
num_industry=num_industrys[n]
for (y in 1:length(years)) {
year=years[y]
eval(parse(text=paste0("newly_added = ecvec_", dataset, num_industry, "_", year)))
# renaming the old data frames
alist = list(alist, newly_added) # combining them in a list
extracted_cols <- lapply(alist, function(x) x[3]) # selecting the third column
result <- do.call("cbind", extracted_cols) # trying to cbind the third colum
}
}
}
Can somebody show me the right way to do this?