我编写了绘制棋盘的函数。我想用字母命名每个列和行。但是,我不知道该怎么做。
我的代码:
library(tidyverse)
dt = read.table(text = "
Group Vol OI CumVol Rd
2008-08-10 0 0 0 0
2008-08-10 100 100 100 1
2008-08-10 0 100 300 1
2008-08-10 0 100 400 1
2008-08-10 50 150 550 0.27
2009-12-10 0 150 0 0
2009-12-10 50 30 50 0.6
2009-12-10 0 20 50 0.6
",header=T)
dt %>%
group_by(Group) %>%
mutate(Rd1 = ifelse(Vol==0,NA,OI/CumVol),# calculate
Rd1 = ifelse(row_number() == 1,Rd1)) %>% # replace NAs with 0 in 1st rows only
fill(Rd1) %>% # get the previous non NA value
ungroup()
# # A tibble: 8 x 6
# Group Vol OI CumVol Rd Rd1
# <fct> <int> <int> <int> <dbl> <dbl>
# 1 2008-08-10 0 0 0 0 0
# 2 2008-08-10 100 100 100 1 1
# 3 2008-08-10 0 100 300 1 1
# 4 2008-08-10 0 100 400 1 1
# 5 2008-08-10 50 150 550 0.27 0.273
# 6 2009-12-10 0 150 0 0 0
# 7 2009-12-10 50 30 50 0.6 0.6
# 8 2009-12-10 0 20 50 0.6 0.6
现在我有:
但是,我想要拥有: