| ... | @@ -372,23 +372,23 @@ show.data.dir.contents() |
... | @@ -372,23 +372,23 @@ show.data.dir.contents() |
|
|
### information)
|
|
### information)
|
|
|
|
|
|
|
|
# To load raw r-data, only for BEL and 2009
|
|
# To load raw r-data, only for BEL and 2009
|
|
|
my.data = load.fadn.raw.rds(
|
|
my.raw.data.BEL = load.fadn.raw.rds(
|
|
|
countries = "BEL",
|
|
countries = "BEL",
|
|
|
years = 2009
|
|
years = 2009
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
# my.data is a single large data.table, with the original csv columns and rows
|
|
# my.data is a single large data.table, with the original csv columns and rows
|
|
|
nrow(my.data) #Number of rows
|
|
nrow(my.raw.data.BEL) #Number of rows
|
|
|
names(my.data) #Column names
|
|
names(my.raw.data.BEL) #Column names
|
|
|
length(names(my.data)) #Number of columns
|
|
length(names(my.raw.data.BEL)) #Number of columns
|
|
|
str(my.data) #Overall structure
|
|
str(my.raw.data.BEL) #Overall structure
|
|
|
|
|
|
|
|
##################################################################
|
|
##################################################################
|
|
|
## LOAD STRUCTURED R-DATA ##
|
|
## LOAD STRUCTURED R-DATA ##
|
|
|
##################################################################
|
|
##################################################################
|
|
|
|
|
|
|
|
#To load structured data, for BEL and 2009
|
|
#To load structured data, for BEL and 2009
|
|
|
my.data.2009 = load.fadn.str.rds(
|
|
my.str.data.2009.BEL = load.fadn.str.rds(
|
|
|
countries = "BEL",
|
|
countries = "BEL",
|
|
|
years = 2009,
|
|
years = 2009,
|
|
|
extraction_dir = new.str.name # Location of the str r-data
|
|
extraction_dir = new.str.name # Location of the str r-data
|
| ... | @@ -396,19 +396,19 @@ my.data.2009 = load.fadn.str.rds( |
... | @@ -396,19 +396,19 @@ my.data.2009 = load.fadn.str.rds( |
|
|
|
|
|
|
|
|
|
|
|
|
# You can see that my.data is a list, with three elements: info, costs, crops
|
|
# You can see that my.data is a list, with three elements: info, costs, crops
|
|
|
str(my.data.2009)
|
|
str(my.str.data.2009.BEL)
|
|
|
|
|
|
|
|
# You can access each individual element like this
|
|
# You can access each individual element like this
|
|
|
str(my.data.2009$info)
|
|
str(my.str.data.2009.BEL$info)
|
|
|
str(my.data.2009$costs)
|
|
str(my.str.data.2009.BEL$costs) # NULL
|
|
|
str(my.data.2009$crops)
|
|
str(my.str.data.2009.BEL$crops)
|
|
|
|
|
|
|
|
|
|
|
|
|
# The first columns of each of the above elements (info, costs, crops)
|
|
# The first columns of each of the above elements (info, costs, crops)
|
|
|
# are created according to the ID section of the raw_str_map
|
|
# are created according to the ID section of the raw_str_map
|
|
|
names(my.data.2009$info)
|
|
names(my.str.data.2009.BEL$info)
|
|
|
names(my.data.2009$costs)
|
|
names(my.str.data.2009.BEL$costs) # NULL
|
|
|
names(my.data.2009$crops)
|
|
names(my.str.data.2009.BEL$crops)
|
|
|
|
|
|
|
|
|
|
|
|
|
# info and costs data.tables are in wide-format (each observation in a single row,
|
|
# info and costs data.tables are in wide-format (each observation in a single row,
|
| ... | @@ -418,29 +418,29 @@ names(my.data.2009$crops) |
... | @@ -418,29 +418,29 @@ names(my.data.2009$crops) |
|
|
#
|
|
#
|
|
|
# See https://seananderson.ca/2013/10/19/reshape/ for
|
|
# See https://seananderson.ca/2013/10/19/reshape/ for
|
|
|
# discussion of the two types of data formats
|
|
# discussion of the two types of data formats
|
|
|
head(my.data.2009$info)
|
|
head(my.str.data.2009.BEL$info)
|
|
|
head(my.data.2009$costs)
|
|
head(my.str.data.2009.BEL$costs) # NULL
|
|
|
head(my.data.2009$crops)
|
|
head(my.str.data.2009.BEL$crops)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Also on the attributes section of each of the above elements, we can access
|
|
# Also on the attributes section of each of the above elements, we can access
|
|
|
# the column formulas and descriptions, as defined in the raw_str_map file.
|
|
# the column formulas and descriptions, as defined in the raw_str_map file.
|
|
|
View(
|
|
View(
|
|
|
attr(my.data.2009$info,"column.descriptions")
|
|
attr(my.str.data.2009.BEL$info,"column.descriptions")
|
|
|
)
|
|
)
|
|
|
|
# View(
|
|
|
|
# attr(my.str.data.2009.BEL$costs,"column.descriptions")
|
|
|
|
# ) # NULL
|
|
|
View(
|
|
View(
|
|
|
attr(my.data.2009$costs,"column.descriptions")
|
|
attr(my.str.data.2009.BEL$crops,"column.descriptions")
|
|
|
)
|
|
|
|
|
View(
|
|
|
|
|
attr(my.data.2009$crops,"column.descriptions")
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
# Especially for the crops element, we can also see the description
|
|
# Especially for the crops element, we can also see the description
|
|
|
# CROP column
|
|
# CROP column
|
|
|
View(
|
|
View(
|
|
|
attr(my.data.2009$crops,"crops.descriptions")
|
|
attr(my.str.data.2009.BEL$crops,"crops.descriptions")
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
#################################################################
|
|
#################################################################
|
| ... | @@ -487,7 +487,7 @@ my.data = load.fadn.str.rds(extraction_dir = new.str.name) |
... | @@ -487,7 +487,7 @@ my.data = load.fadn.str.rds(extraction_dir = new.str.name) |
|
|
############################################################################
|
|
############################################################################
|
|
|
|
|
|
|
|
#We load structured data for all available countries and years
|
|
#We load structured data for all available countries and years
|
|
|
my.str.data = load.fadn.str.rds(extraction_dir = new.str.name)
|
|
my.str.data = load.fadn.str.rds(extraction_dir = "a")
|
|
|
|
|
|
|
|
##----------------------------------------------------------------
|
|
##----------------------------------------------------------------
|
|
|
## HOW MANY FARMS FOR EACH COUNTY AND EACH YEAR --
|
|
## HOW MANY FARMS FOR EACH COUNTY AND EACH YEAR --
|
| ... | @@ -609,7 +609,7 @@ my.str.data$info[,list(Nobs_sample=.N,Nobs_represented=sum(WEIGHT)), |
... | @@ -609,7 +609,7 @@ my.str.data$info[,list(Nobs_sample=.N,Nobs_represented=sum(WEIGHT)), |
|
|
by=.(COUNTRY,YEAR)]
|
|
by=.(COUNTRY,YEAR)]
|
|
|
|
|
|
|
|
# only for full sample (common id over years in selected data)
|
|
# only for full sample (common id over years in selected data)
|
|
|
my.str.data$info[id %in% collected.common.id_str[[1]],
|
|
my.str.data$info[ID %in% collected.common.id_str[[1]],
|
|
|
list(Nobs_sample=.N,
|
|
list(Nobs_sample=.N,
|
|
|
Nobs_represented=sum(WEIGHT)),
|
|
Nobs_represented=sum(WEIGHT)),
|
|
|
by=.(COUNTRY,YEAR)]
|
|
by=.(COUNTRY,YEAR)]
|
| ... | | ... | |