Suppose I have the following dataframe:
df <- data.frame(stock_code = c("600000", "300000", "000000"),
stock_price = c(10.00, 11.00, 12.00))
I would like to add some characters to the stock_code, the rules are:
- if the first number of stock_code is "6",then add".XSHG" to the stock_code, like 600000.XSHG
- if the first number of stock _code is "0" or "3", then add".XSHE" to the stock_code, like 300000.XSHE and 000000.XSHE
I know str_sub may be helpful, but can anybody tell me how to code in tidyverse with %>%
?