Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
68184a1
Add comments while walking through code.
sgoodm Aug 17, 2015
d3b8471
Clean BuildTimeSeries.R
sgoodm Sep 4, 2015
c8bb7ad
Fix bug.
sgoodm Sep 4, 2015
4f7240f
Fix bug.
sgoodm Sep 4, 2015
cd1193a
Remove some eval statments from buildtimeseries func.
sgoodm Sep 4, 2015
a2a378c
Testing.
sgoodm Sep 4, 2015
6f3ffbe
Testing.
sgoodm Sep 4, 2015
8858142
Testing.
sgoodm Sep 4, 2015
f9e28e2
Testing.
sgoodm Sep 4, 2015
00f9515
Testing.
sgoodm Sep 4, 2015
02b3a6e
Testing.
sgoodm Sep 4, 2015
849e133
Testing.
sgoodm Sep 4, 2015
fca8884
Get rid of eval statements in SAT.R.
sgoodm Sep 4, 2015
604dc43
Fix bug.
sgoodm Sep 4, 2015
2c4bb58
Testing.
sgoodm Sep 4, 2015
977e68e
Testing.
sgoodm Sep 4, 2015
c5fe38f
Testing.
sgoodm Sep 4, 2015
8726c83
Testing.
sgoodm Sep 4, 2015
0cee107
Remove evals from fastNN_binary_func.R.
sgoodm Sep 4, 2015
0ca43a0
Testing.
sgoodm Sep 4, 2015
0451211
Testing.
sgoodm Sep 4, 2015
eeff4db
Remove unnecessary interpolation from buildtimeseries func.
sgoodm Sep 4, 2015
f68e73e
Update.
sgoodm Sep 4, 2015
2bc1f94
Clean up.
sgoodm Sep 4, 2015
3b3d4b8
Clean up.
sgoodm Sep 4, 2015
f53f7f7
Clean up.
sgoodm Sep 4, 2015
94a6546
Update how timeRangeTrend finds year.
sgoodm Sep 11, 2015
d9227e4
Update how timeRangeTrend handles NA data.
sgoodm Sep 11, 2015
716bd55
Fix syntax.
sgoodm Sep 11, 2015
a8f17ec
Update how SpatialCausalPSM handles NAs.
sgoodm Sep 14, 2015
cb314e6
Update SpatialCausalPSM.
sgoodm Sep 15, 2015
3013570
Update.
sgoodm Sep 15, 2015
4f7a3a1
Update.
sgoodm Sep 15, 2015
7bbb448
Add debug prints to fastNN.
sgoodm Sep 15, 2015
5809656
Test.
sgoodm Sep 15, 2015
76ea9b3
Test.
sgoodm Sep 15, 2015
823a2e3
Test.
sgoodm Sep 15, 2015
0998551
Test.
sgoodm Sep 15, 2015
e81c87e
Fix bug.
sgoodm Sep 15, 2015
1f036d1
Test.
sgoodm Sep 15, 2015
6eb42dc
Test.
sgoodm Sep 15, 2015
9352e0b
Test.
sgoodm Sep 15, 2015
622e914
Test.
sgoodm Sep 15, 2015
a06df24
Test.
sgoodm Sep 15, 2015
bf2f2a2
Test.
sgoodm Sep 15, 2015
2fa6bfb
Test.
sgoodm Sep 15, 2015
1595c8f
Test.
sgoodm Sep 15, 2015
a5ff1bf
Test.
sgoodm Sep 15, 2015
dd1bf12
Test.
sgoodm Sep 15, 2015
0e8838b
Test.
sgoodm Sep 15, 2015
70a5e48
Test.
sgoodm Sep 15, 2015
1ec1c1c
Test.
sgoodm Sep 15, 2015
0d5bc8e
Test.
sgoodm Sep 15, 2015
8515cdf
Test.
sgoodm Sep 15, 2015
4a0702d
Test.
sgoodm Sep 15, 2015
73c7027
Test.
sgoodm Sep 15, 2015
df96e72
Test.
sgoodm Sep 15, 2015
b9f6057
Test.
sgoodm Sep 15, 2015
6e0788e
Test.
sgoodm Sep 15, 2015
b73c000
Test.
sgoodm Sep 15, 2015
3764280
Test.
sgoodm Sep 15, 2015
9840b3b
Test.
sgoodm Sep 15, 2015
f96c62d
Test.
sgoodm Sep 15, 2015
a8d737f
Test.
sgoodm Sep 15, 2015
68ca7a5
Test.
sgoodm Sep 15, 2015
296caa8
Test.
sgoodm Sep 15, 2015
fd97e1b
Test.
sgoodm Sep 15, 2015
0f36d65
Test.
sgoodm Sep 15, 2015
2627231
Test.
sgoodm Sep 15, 2015
f0b6890
Test.
sgoodm Sep 15, 2015
700d531
Test.
sgoodm Sep 15, 2015
7aba41a
Test.
sgoodm Sep 15, 2015
8baad95
Test.
sgoodm Sep 15, 2015
4a148fb
Test.
sgoodm Sep 15, 2015
ef5a7f3
Test.
sgoodm Sep 15, 2015
9cc855b
Test.
sgoodm Sep 15, 2015
3957e71
Test.
sgoodm Sep 15, 2015
ced445e
Test.
sgoodm Sep 15, 2015
c4f322b
Test.
sgoodm Sep 15, 2015
c9e154a
Test.
sgoodm Sep 15, 2015
ce55dea
Test.
sgoodm Sep 15, 2015
cf33f9a
Test.
sgoodm Sep 15, 2015
e49d4fc
Test.
sgoodm Sep 15, 2015
2b03b4c
Test.
sgoodm Sep 15, 2015
f91c1eb
Test.
sgoodm Sep 15, 2015
2766df7
Test.
sgoodm Sep 15, 2015
fd96062
Test.
sgoodm Sep 15, 2015
9f4c52d
Test.
sgoodm Sep 15, 2015
b2eccca
Test.
sgoodm Sep 15, 2015
705aba7
Test.
sgoodm Sep 15, 2015
d904678
Test.
sgoodm Sep 15, 2015
d6536bf
Test.
sgoodm Sep 15, 2015
bbd6e0f
Test.
sgoodm Sep 15, 2015
e4e99f8
Test.
sgoodm Sep 15, 2015
512341e
Test.
sgoodm Sep 15, 2015
c9c9ad9
Test.
sgoodm Sep 15, 2015
c799e4b
Test.
sgoodm Sep 15, 2015
15d6156
Test.
sgoodm Sep 15, 2015
f161ffe
Test.
sgoodm Sep 16, 2015
82352dd
Test.
sgoodm Sep 16, 2015
669d7bd
Test.
sgoodm Sep 16, 2015
2e89179
Test.
sgoodm Sep 16, 2015
099bcd5
Test.
sgoodm Sep 16, 2015
4d9ef9d
Test.
sgoodm Sep 16, 2015
b02c0c4
Test.
sgoodm Sep 16, 2015
48b8d1a
Test.
sgoodm Sep 16, 2015
a4ca785
Test.
sgoodm Sep 16, 2015
3f4b18f
Test.
sgoodm Sep 16, 2015
691db70
Test.
sgoodm Sep 16, 2015
227718e
Test.
sgoodm Sep 16, 2015
a6b8b76
Test.
sgoodm Sep 16, 2015
3d5c4a5
Test.
sgoodm Sep 16, 2015
de90481
Test.
sgoodm Sep 16, 2015
1ad0acc
Test.
sgoodm Sep 16, 2015
21f881e
Test.
sgoodm Sep 17, 2015
7d1e738
Test.
sgoodm Sep 17, 2015
292d0b1
Test.
sgoodm Sep 17, 2015
3831022
Test.
sgoodm Sep 17, 2015
cb15892
Fix fitting same model multiple times in stage2psm.
sgoodm Oct 9, 2015
2c5d8a5
Temp. remove timerangetrend.
sgoodm Oct 9, 2015
3a1313d
Fix empty check on SAT constraints.
sgoodm Oct 14, 2015
d6b02a5
Add spatialcausalpsm drop option back in. Remove some debug prints.
sgoodm Oct 14, 2015
7867fc3
Test.
sgoodm Oct 14, 2015
6b6a215
Test.
sgoodm Oct 14, 2015
85a4e30
Testing edits to the BuildTimeSeries module to fix panel null error
DanRunfola Oct 16, 2015
3474995
Update NN function use.
sgoodm Oct 19, 2015
08ee057
Merge branch 'master' of github.com:sgoodm/SCI
sgoodm Oct 19, 2015
2c54d98
Test
sgoodm Oct 19, 2015
3807331
Test
sgoodm Oct 19, 2015
4d39760
Test
sgoodm Oct 19, 2015
c983349
Test
sgoodm Oct 19, 2015
8f69f06
Test
sgoodm Oct 19, 2015
64d39e4
Test
sgoodm Oct 19, 2015
90e136a
Test
sgoodm Oct 19, 2015
0f914bd
Test
sgoodm Oct 19, 2015
417ec95
Test
sgoodm Oct 19, 2015
98b0f86
Test
sgoodm Oct 19, 2015
e3e8255
Test
sgoodm Oct 19, 2015
cb72f92
Test
sgoodm Oct 19, 2015
868b357
Test
sgoodm Oct 19, 2015
e78a2ab
Test
sgoodm Oct 19, 2015
0fd3007
Test
sgoodm Oct 19, 2015
607b759
Test
sgoodm Oct 19, 2015
e1b0078
Test
sgoodm Oct 19, 2015
07c8576
Test
sgoodm Oct 19, 2015
344535d
Test
sgoodm Oct 19, 2015
f21621b
Test
sgoodm Oct 19, 2015
7253a3b
Test
sgoodm Oct 19, 2015
c8d0833
Test
sgoodm Oct 19, 2015
8beeb51
Test
sgoodm Oct 19, 2015
7c833b6
Test
sgoodm Oct 19, 2015
8a45f4f
Test
sgoodm Oct 19, 2015
919d1c2
Test
sgoodm Oct 19, 2015
c46cdbc
Test nn issue.
sgoodm Nov 3, 2015
6b8d97f
Test nn issue.
sgoodm Nov 3, 2015
6fcc5d6
Test nn issue.
sgoodm Nov 3, 2015
5c33df7
test nn
sgoodm Nov 6, 2015
0875a69
test nn
sgoodm Nov 6, 2015
17b1bb7
test nn
sgoodm Nov 6, 2015
7697483
test nn
sgoodm Nov 6, 2015
e607657
data table test for nn
sgoodm Nov 9, 2015
77a292e
data table test for nn
sgoodm Nov 10, 2015
db5cb11
data table test for nn
sgoodm Nov 10, 2015
f7ea0e6
data table test for nn
sgoodm Nov 10, 2015
8c15100
data table test for nn
sgoodm Nov 10, 2015
642344d
data table test for nn
sgoodm Nov 10, 2015
2ef7491
data table test for nn
sgoodm Nov 10, 2015
c18bff9
data table test for nn
sgoodm Nov 10, 2015
d33a14f
data table test for nn
sgoodm Nov 10, 2015
7346d54
data table test for nn
sgoodm Nov 10, 2015
efb3780
data table test for nn
sgoodm Nov 10, 2015
d546f8c
data table test for nn
sgoodm Nov 10, 2015
3ff4191
data table test for nn
sgoodm Nov 10, 2015
6dc5d4b
data table test for nn
sgoodm Nov 10, 2015
7c6ece5
data table test for nn
sgoodm Nov 10, 2015
921b77e
data table test for nn
sgoodm Nov 10, 2015
2b33b8d
data table test for nn
sgoodm Nov 10, 2015
bc96f18
data table test for nn
sgoodm Nov 10, 2015
dcde297
data table test for nn
sgoodm Nov 10, 2015
55d4753
data table test for nn
sgoodm Nov 10, 2015
3f04e6d
data table test for nn
sgoodm Nov 10, 2015
be8cb34
data table test for nn
sgoodm Nov 10, 2015
c1b5654
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
3aae82f
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
975c502
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
9fa1103
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
83bb0a0
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
b8f1a1a
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
fecb052
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
c3f1859
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
50c67c1
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
866f21d
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
c1015ba
Cleaning up fastnn and sat.
sgoodm Nov 10, 2015
a0f9eca
Test matchit lib.
sgoodm Nov 12, 2015
f654052
Test matchit lib.
sgoodm Nov 12, 2015
54c3d72
Test matchit lib.
sgoodm Nov 12, 2015
80759e7
Test matchit lib.
sgoodm Nov 12, 2015
85b06fe
Test matchit lib.
sgoodm Nov 12, 2015
f72ebf2
Test matchit lib.
sgoodm Nov 12, 2015
4b66844
Test matchit lib.
sgoodm Nov 12, 2015
4af586e
Test matchit lib.
sgoodm Nov 12, 2015
32cce26
Test matchit lib.
sgoodm Nov 12, 2015
c37946e
Test matchit lib.
sgoodm Nov 12, 2015
b0d2bc7
Test matchit lib.
sgoodm Nov 12, 2015
d266959
Test matchit lib.
sgoodm Nov 12, 2015
ede4adc
Test matchit lib.
sgoodm Nov 13, 2015
a38e71f
Test matchit lib.
sgoodm Nov 13, 2015
648eb89
Test matchit lib.
sgoodm Nov 13, 2015
8497861
Test matchit lib.
sgoodm Nov 13, 2015
08a63fc
Test matchit lib.
sgoodm Nov 13, 2015
128c3db
Test matchit lib.
sgoodm Nov 13, 2015
b9edba9
Fix type.
sgoodm May 6, 2016
530b6dd
Fix maybe.
sgoodm May 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Package: SCI
Package: SCI2
Title: Spatial Cauasal Inference
Version: 0.0.0.1
Authors@R: person("Dan", "Runfola", , "[email protected]", role = c("aut", "cre"))
Description: An alpha release of a package designed to make impact evaluation that includes spatial data easier within R. See http://www.aiddata.org for more information.
Depends: R (>= 3.0.2), sp, maptools, reshape, ggplot2, grid, gridExtra, spdep,proj4, FNN, psych
License: Creative Commons with Attribution
LazyData: true
Imports:sp, maptools, reshape, ggplot2, grid, gridExtra, spdep,proj4, FNN, psych
Imports:sp, maptools, reshape, ggplot2, grid, gridExtra, spdep,proj4, FNN, psych
350 changes: 219 additions & 131 deletions R/BuildTimeSeries.R
Original file line number Diff line number Diff line change
@@ -1,147 +1,235 @@
BuildTimeSeries <- function(dta,idField,varList_pre,startYear,endYear,colYears=NULL,interpYears=NULL)
{
years <- startYear:endYear
#If there is a "colYears" variable, convert to binaries.
#Eventually could be extended to more than one column.
if(!is.null(colYears))
{
#For each variable, for each year, create a binary representing the treatment status.
for(k in 1:length(years))
{
for(j in 1:length(colYears))
{
varN <- paste("TrtMnt_",colYears[j],years[k],sep="")
exec <- paste("dta$",varN,"=0",sep="")
eval(parse(text=exec))

dta@data[varN][dta@data[colYears[j]] <= as.numeric(years[k])] <- 1
}
}
}
for (j in 1:length(colYears))
{
trt_id = paste("TrtMnt_",colYears[j],sep="")
interpYears <- c(interpYears,trt_id)
}
print(interpYears)
#If there is an "interpVars" variable, linearly interpolate values based on at least 2 known points in time.
if(!is.null(interpYears))
{
for(AncInt in 1:length(interpYears))
{
cur_ancVi <- interpYears[AncInt]
interpFrame <- dta@data[idField]
interpFrame[idField] <- dta@data[idField]
cnt = 2
for(k in 1:length(years))
{
#First, build a model describing the relationship between years and any data in the interp field.
varI <- paste(cur_ancVi,years[[k]],sep="")
#Check if data exists for the year - if not, ignore. If so, include in the new modeling frame.
if(varI %in% colnames(dta@data))
{
add_data <- paste("interpFrame[cnt] <- dta@data$",varI)
eval(parse(text=add_data))
colnames(interpFrame)[cnt] <- years[[k]]
cnt = cnt + 1
} else
{
#Exception for a single-point interpolation
varC <- paste(cur_ancVi,sep="")
if(varC %in% colnames(dta@data))
{
add_data <- paste("interpFrame[cnt] <- dta@data$",varC)
eval(parse(text=add_data))
cnt = 3
BuildTimeSeries <- function (dta, idField, varList_pre, startYear, endYear, colYears=NULL, interpYears=NULL) {

# generate year range
years <- startYear:endYear



print("bts1")

# If there is a "colYears" variable, convert to binaries.
# Eventually could be extended to more than one column.
if (!is.null(colYears)) {
# For each variable, for each year, create a binary representing the treatment status.
for (j in 1:length(colYears)) {

for (k in 1:length(years)) {

varN = paste("TrtMnt_",colYears[j],"_",years[k], sep="")
print(varN)

dta@data[varN] <- 0
dta@data[varN][dta@data[colYears[j]] <= years[k]] <- 1
dta@data[varN][is.na(dta@data[colYears[j]])] <- 0

}
}


# add the "TrtMnt_" + colYears[j] prefix to interpYears
trt_id = paste("TrtMnt_",colYears[j],"_....", sep="")
interpYears <- c(interpYears, trt_id)
}
#Only one time point, so no interpolation is done - value is simply copied to all other columns.
if(cnt == 3)
{
for(k in 1:length(years))
{
varI <- paste("dta@data$",cur_ancVi,years[[k]]," <- interpFrame[2]",sep="")
eval(parse(text=varI))
}
} else {
tDframe <- dta@data[idField]
#Here, we model out everything.
#Melt the dataframe for modeling
melt_Model_dta <- melt(data.frame(interpFrame),id=idField)
melt_Model_dta["variable"] <- as.numeric(gsub("X","",melt_Model_dta$variable))

#Fit the model for interpolation
execstr <- paste("mdl <- lm(value ~ variable + factor(",idField,"),data=melt_Model_dta)",sep="")
eval(parse(text=execstr))
#Apply the model to interpolate
for(u in 1:length(years))
{
varI <- paste(cur_ancVi,years[[u]],sep="")
if(!(varI %in% colnames(dta@data)))
{
#Variable doesn't exist, so we need to interpolate.
tDframe[idField] <- dta@data[idField]
tDframe["variable"] <- years[[u]]
dta@data[varI] <- predict(mdl,newdata=tDframe)
}

# View(dta)
# print(interpYears)




print("bts2")
timer <- proc.time()

# If there is an "interpVars" variable, linearly interpolate values based on at least 2 known points in time.
if (!is.null(interpYears)) {

for (AncInt in 1:length(interpYears)) {

print(interpYears[AncInt])


cur_ancVi <- interpYears[AncInt]

# create interpolation data frame and add id field
interpFrame <- dta@data[idField]
interpFrame[idField] <- dta@data[idField]

cnt = 2


print("bts2.0.1")

# add data to interpolation data frame
if (cur_ancVi %in% colnames(dta@data)) {
# Exception for a single-point interpolation
interpFrame[cnt] <- dta@data[,cur_ancVi]
cnt = 3

} else {
for (k in 1:length(years)) {
# First, build a model describing the relationship between years and any data in the interp field.

# Check if data exists for the year - if not, ignore. If so, include in the new modeling frame.
varI <- gsub('....', years[[k]], cur_ancVi, fixed=TRUE)
if (varI %in% colnames(dta@data)) {

interpFrame[cnt] <- dta@data[,varI]
colnames(interpFrame)[cnt] <- years[[k]]
cnt = cnt + 1

}
}
}

print(cnt)


print("bts2.0.2")

if (cnt == 3) {
# only one time point, so no interpolation is done - value is simply copied to all other columns.

print("bts2.0.2a")
for (k in 1:length(years)) {
# add _year to end of non temporal data
dta@data[,paste(cur_ancVi,years[[k]],sep="_")] <- interpFrame[2]
}

} else if (cnt < length(years) + 2) {
# run model if data exists for at least two years but not for all years
print("bts2.0.2b0")

# Melt the dataframe for modeling
melt_Model_dta <- melt(data.frame(interpFrame), id=idField)
melt_Model_dta["variable"] <- as.numeric(gsub("X", "", melt_Model_dta[,"variable"]))


print("bts2.0.2b1")

# Fit the model for interpolation
# this is a slow part
execstr <- paste("mdl <- lm(value ~ variable + factor(",idField,"),data=melt_Model_dta)", sep="")
eval(parse(text=execstr))
# mdl <- lm(value ~ variable + factor(idField), data=melt_Model_dta)


print("bts2.0.2b2")

# Apply the model to interpolate
tDframe <- dta@data[idField]

for (u in 1:length(years)) {

varI <- gsub('....', years[[u]], cur_ancVi, fixed=TRUE)
if (!(varI %in% colnames(dta@data))) {
# Variable doesn't exist, so we need to interpolate.
tDframe[idField] <- dta@data[idField]
tDframe["variable"] <- years[[u]]
dta@data[varI] <- predict(mdl, newdata=tDframe)

}
}
}
}

}

}

#Append interpolated fields to our melting lists
for(v in 1:length(interpYears))
{
varList_pre[[length(varList_pre)+1]] <- interpYears[v]
}

print("bts2.1")
# Append interpolated fields to our melting lists
varList_pre <- c(varList_pre, interpYears)

}


#Run the melts

meltList <- list()
for (i in 1:length(varList_pre))
{
#grep_str = paste(idField,"|",varList_pre[i],"[0-9][0-9][0-9][0-9]",sep="")
#Limit to only relevant years
grepStrYrs = idField
for(j in 1:length(years))
{
tempGrep <- grepStrYrs
grepStrYrs <- paste(tempGrep,"|",varList_pre[[i]],years[[j]],sep="")
}
tDF <- dta@data[grepl(grepStrYrs,names(dta@data))]
meltList[[i]] <- melt(tDF,id=idField)

#Keep only years in the year column, rename columns
colnames(meltList[[i]])[2] <- "Year"
colnames(meltList[[i]])[3] <- varList_pre[[i]]

#Clean up year column
gsub_command <- paste("^",varList_pre[[i]],sep="")
meltList[[i]][2] <- gsub(gsub_command, "", as.matrix(meltList[[i]][2]))


#Remove ID and year if this is at least the second variable to avoid duplications.
if(i > 1)
{
meltList[[i]] <- meltList[[i]][3]

print(varList_pre)

timer <- proc.time() - timer
print(paste("section completed in", timer[3], "seconds."))




print("bts3")
timer <- proc.time()

# Run the melts
meltList <- list()
for (i in 1:length(varList_pre)) {

print("bts3.0")
print(varList_pre[[i]])

# Limit to only relevant years
grepStrYrs = idField

for (j in 1:length(years)) {
tempGrep <- grepStrYrs

if (regexpr("....", varList_pre[[i]], fixed=TRUE)[1] == -1) {
grepStrYrs <- paste(tempGrep,"|",paste(varList_pre[[i]],years[[j]], sep="_"), sep="")
} else {
grepStrYrs <- paste(tempGrep,"|",gsub('....', years[[j]], varList_pre[[i]], fixed=TRUE), sep="")
}
}

print(grepStrYrs)

print("bts3.1")
# print(names(dta@data))

tDF <- dta@data[grepl(grepStrYrs, names(dta@data))]
meltList[[i]] <- melt(tDF, id=idField)

print("bts3.2")
# print(colnames(meltList[[i]]))
# Keep only years in the year column, rename columns
colnames(meltList[[i]])[2] <- "Year"

print("bts3.3")

colnames(meltList[[i]])[3] <- varList_pre[[i]]


print("bts3.4")

if (i == 1) {
# set field to use for regex when formatting year field later
year_regex_field <- varList_pre[[i]]

} else {
# remove id and year after first pass to avoid duplications
meltList[[i]] <- meltList[[i]][3]

}

}

}
timer <- proc.time() - timer
print(paste("section completed in", timer[3], "seconds."))

#Finish up with a cherry on top
meltListRet <- data.frame(meltList)

return(meltListRet)



print("bts4")

# convert meltList to data frame
meltListRet <- data.frame(meltList)

# format year
regex_test <- regexpr("....", year_regex_field, fixed=TRUE)[1]
if (regex_test > -1) {
meltListRet['Year'] <- lapply(meltListRet['Year'], function (z) {
return(as.integer(substr(z, regex_test, regex_test+nchar("....")-1)))
})

} else {
meltListRet['Year'] <- lapply(meltListRet['Year'], function (z) {
return(as.integer(substr(z, nchar(z)-nchar("....")+1, nchar(z))))
})
}

return(meltListRet)
}


# dm1 <- melt(d[,c("Type","I.alt","idx06","idx07","idx08")], id=c("Type","I.alt"))
# dm2 <- melt(d[,c("Type","I.alt","farve1","farve2")], id=c("Type","I.alt"))
# colnames(dm2) <- c("Type", "I.alt", "variable2", "value2")
# dm <- merge(dm1, dm2)
# dm <- merge(dm1, dm2)
Loading