Economics of Money and Banking / Perry G Mehrling / Ders 1

R Studio Monthly Treasury Statement

Download dataset.
Name is "mts2"

attach(mts2)

 mts2$`Classification Description`<-as.character(mts2$`Classification Description`)


mts3<-dplyr::select(mts2, `Record Date`, `Current Month Budget Amount`, `Classification Description`)

mts4<-tidyr:: spread(mts3,`Classification Description`,`Current Month Budget Amount`)


 mts4$`Reduction of Operating Cash, Increase (-)`<-as.numeric(mts4$`Reduction of Operating Cash, Increase (-)`)

mts4$`Reduction of Operating Cash, Increase (-)`= -1 * mts4$`Reduction of Operating Cash, Increase (-)`


 mts4$`Borrowing from the Public`<-as.numeric(mts4$`Borrowing from the Public`)
 mts4$`Borrowing from the Public`= format(mts4$`Borrowing from the Public`, big.mark =",", nsmall=0)


 mts4$`By Other Means`<-as.numeric(mts4$`By Other Means`)
mts4$`By Other Means`= format(mts4$`By Other Means`, big.mark =",", nsmall=0)


 mts4$`Total Surplus (+) or Deficit (-)`<-as.numeric(mts4$`Total Surplus (+) or Deficit (-)`)
mts4$`Total Surplus (+) or Deficit (-)`= format(mts4$`Total Surplus (+) or Deficit (-)`, big.mark =",", nsmall=0)


 mts4$`Reduction of Operating Cash, Increase (-)`<-as.numeric(mts4$`Reduction of Operating Cash, Increase (-)`)


 mts4$`Reduction of Operating Cash, Increase (-)`= format(mts4$`Reduction of Operating Cash, Increase (-)`, big.mark =",", nsmall=0)

 

.....................................................................................
other





Download dataset.
Name is "mts2"
We need only some columns not all.



There are 2 options.

We take from 1 to  5 columns and we delete from 2 and 3.

m0=mts2[, 1:5]
m1=m0[, -2:-3]

But other option is more and more easy. 

Vectors.

m0=mts2[ , c(1,4,5)]



Type of "Record Date" will be date.


library(lubridate)

m0$`Record Date`<- ymd(m0$`Record Date`)

class(m0$`Record Date`)

[1] "Date"

......................................................................................

Type of "Classification of Description" will be factor.


m0$`Classification Description` <-as.factor(m0$`Classification Description`)

class(m0$`Classification Description`)

[1] "factor"


......................................................................................

Type of "Budget Amount" will be numeric.

m0$`Current Month Budget Amount` <-as.numeric(m0$`Current Month Budget Amount`)

......................................................................................

Format numbers with both thousands separator

m0$`Current Month Budget Amount`= format(m0$`Current Month Budget Amount`, big.mark =",", nsmall=0)

......................................................................................


m1 <- subset(m0,`Classification Description`=="Borrowing from the Public" | `Classification Description`=="By Other Means"  | `Classification Description`=="Reduction of Operating Cash, Increase (-)" |`Classification Description`=="Total Surplus (+) or Deficit (-)")

yada

m1 <- m0[m0$`Classification Description` %in% levels(m1$`Classification Description`)[c(1, 15, 2, 10)],]

......................................................................................

order the dataset by "Record date"

m1=m1[order(m1$`Record Date`), ]

.............................................................................................

EXTRAAAAA


Yorumlar