Skip to content

Commit

Permalink
add non aggregate, make default
Browse files Browse the repository at this point in the history
  • Loading branch information
bquast committed Jun 8, 2015
1 parent 7a43266 commit a6ee005
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
23 changes: 12 additions & 11 deletions R/ffddva.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#' # load the decompr package
#' library(decompr)
#'
#' # load the example data set
#' data(leather)
#'
#' # create a leontief decomposed data set
#' l <- decomp(inter,
#' final,
Expand All @@ -24,7 +21,7 @@
#' # apply ffddva
#' ffddva( l )

ffddva <- function ( x, aggregate=TRUE ) {
ffddva <- function ( x, aggregate=FALSE ) {

# read attributes
k <- attr(x, "k")
Expand All @@ -39,19 +36,23 @@ ffddva <- function ( x, aggregate=TRUE ) {
# remove exports to self
x <- diagonals::minus_rectangle_matrix( x, N )

# sum across rows
x <- rowSums(x)

# create output format
x <- data.frame(Source_Country = rep(k, each=N), Source_Industry = rep(i, times=G), ffddva = x)

# aggregate or not
if (aggregate) {
x <- colSums(x)
f <- as.factor(x[,1])

# put in output format
x <- data.frame(country = k, ffddva = x)
x <- tapply(x[,3], f, sum)

# present output
return (x)

} else {
x <- data.frame(Source_Country = k, ffddva = x)

row.names(x) <- NULL
}

return(x)

}
5 changes: 1 addition & 4 deletions man/ffddva.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\alias{ffddva}
\title{Foreign Final Demand Domestic Value Added}
\usage{
ffddva(x, aggregate = TRUE)
ffddva(x, aggregate = FALSE)
}
\arguments{
\item{x}{A Leontief decomposed Inter-Country Input Output table as created by decompr, which should be post multiplied with final demand (using the parameter: post="final_demand")}
Expand All @@ -18,9 +18,6 @@ Foreign Final Demand Domestic Value Added
# load the decompr package
library(decompr)

# load the example data set
data(leather)

# create a leontief decomposed data set
l <- decomp(inter,
final,
Expand Down

0 comments on commit a6ee005

Please sign in to comment.