我的收藏夹:第七期

我的收藏夹:第七期

由于最近在写毕业论文,所以没有太多时间看有意思的东西了,所以本周的东西很少。

R 语言

一个通过逐行运行演示的ggplot2教程。

一个通过逐行运行演示的tidyverse教程。

R
1
2
install.packages(c("shinyBS", "shinythemes"))
shinyLP::runExample()

例如计算 IRR:

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# IRR Calculation
library(dplyr)
dates <-
c("2015-10-09", "2016-09-26") %>% lubridate::ymd()

land_purchase_price <-
-1000000 %>% formattable::currency()

land_sale_price <-
1300000 %>% formattable::currency()

cash_flows <-
c(land_purchase_price, land_sale_price)

fundManageR::calculate_irr_periods(dates = dates, cash_flows = cash_flows, return_wide = T)

Stata

Stata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
* Timestamp
* ---------

clear
timestamp
set seed 1729
set obs 1000
timestamp

* Generate data
* -------------

gen x1 = runiform()
gen x2 = rnormal()
gen x3 = runiform() * 10
gen x4 = rnormal()
gen y = 1 + x1 - x2 + 2 * (x3 <= 5) - 3 / x4 + rnormal() * 2
gen var1 = int(100 * runiform())
gen var2 = int(100 * runiform())

* Heads and tails
* ---------------

head
tail
head 7 x?
tail 12 var* if mod(_n, 4)

* Genfly
* ------

genfly: tab {s1: var1<=60} {s2: var2<=70}
genfly: tab {{s3 "Log v1 * 10": log(var1 * 10)}<=60} {var2<=70}
genfly: reg y x1 x2 {x3<=5} {x5 "Inverse of x4": 1/x4}
desc

* Switchcase
* ----------

clear
set obs 1
gen foo_bar_long_version = 1
gen foo_bar = 1
gen m_foo_b_ = 1
foreach what in camel snake mixed toggle toggle lower upper {
switchcase `what'
ds, varwidth(32)
}

* Benchmark
* ---------

sysuse auto, clear
bench, reps(10) trace last: reg price mpg
return list
bench, reps(5) restore last: gen x = 1
ds x

* Todatetime
* ----------

sysuse gnp96, clear
tostring date, format(%td_NN/DD/CCYY) gen(datestr) force
todatetime datestr, gen(dateback) datefmt(MDY)
assert date == dateback
Stata
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
. sysuse auto
(1978 Automobile Data)

. reg price mpg

Source | SS df MS Number of obs = 74
-------------+---------------------------------- F(1, 72) = 20.26
Model | 139449474 1 139449474 Prob > F = 0.0000
Residual | 495615923 72 6883554.48 R-squared = 0.2196
-------------+---------------------------------- Adj R-squared = 0.2087
Total | 635065396 73 8699525.97 Root MSE = 2623.7

------------------------------------------------------------------------------
price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg | -238.8943 53.07669 -4.50 0.000 -344.7008 -133.0879
_cons | 11253.06 1170.813 9.61 0.000 8919.088 13587.03
------------------------------------------------------------------------------

.
. cowsay "Mooo! The R2 is `e(r2)'"

-----------------------------------
< Mooo! The R2 is .2195828561874973 >
-----------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

简单来说就是这个命令可以用于各种加密算法。

博客文章

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
readr::read_csv("colors.csv")
# Parsed with column specification:
# cols(
# R = col_double(),
# G = col_double(),
# B = col_double(),
# Category = col_character(),
# Family = col_character()
# )
# # A tibble: 15 x 5
# R G B Category Family
# <dbl> <dbl> <dbl> <chr> <chr>
# 1 255 0 0 A Reds
# 2 255 128 0 B Oranges
# 3 255 255 0 C Yellows
# 4 128 255 0 D Greens
# 5 0 255 0 E Greens
# 6 0 255 128 F Cyans
# 7 0 255 255 G Cyans
# 8 0 128 255 H Blues
# 9 0 0 255 I Blues
# 10 128 0 255 J Violets
# 11 255 0 255 K Magentas
# 12 255 0 128 L Magentas
# 13 0 0 0 M Blacks
# 14 128 128 128 N Greys
# 15 255 255 255 O Whites

suppressMessages(readr::read_csv("colors.csv"))
# # A tibble: 15 x 5
# R G B Category Family
# <dbl> <dbl> <dbl> <chr> <chr>
# 1 255 0 0 A Reds
# 2 255 128 0 B Oranges
# 3 255 255 0 C Yellows
# 4 128 255 0 D Greens
# 5 0 255 0 E Greens
# 6 0 255 128 F Cyans
# 7 0 255 255 G Cyans
# 8 0 128 255 H Blues
# 9 0 0 255 I Blues
# 10 128 0 255 J Violets
# 11 255 0 255 K Magentas
# 12 255 0 128 L Magentas
# 13 0 0 0 M Blacks
# 14 128 128 128 N Greys
# 15 255 255 255 O Whites

Python

好玩的东西

relaxedjs 可以将 markdown 文档转换成排版精美的 HTML 或 PDF 文件。

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×