我正在尝试使用以下内容打印矢量
total_nb_visits <- 20302079
total_nb_visits_y1 <- 19299803
total_nb_visitors <- 17707555
total_nb_visitors_y1 <- 17196674
CVR <- 0.02274954
CVR_y1 <- 0.02293334
当我这样做时:
exportable <- rbind(c(total_nb_visits,total_nb_visits_y1,((total_nb_visits-total_nb_visits_y1)/total_nb_visits_y1)*100),
c(total_nb_visitors,total_nb_visitors_y1,((total_nb_visitors-total_nb_visitors_y1)/total_nb_visitors_y1)*100),
c(CVR,CVR_y1,((CVR-CVR_y1)/CVR_y1)))
我得到了:
exportable
[,1] [,2] [,3]
[1,] 20302079.00000000 19299803.00000000 5.193192905
[2,] 17707555.00000000 17196674.00000000 2.970812844
[3,] 0.02274954 0.02293334 -0.008014533
我想得到:
[,1] [,2] [,3]
[1,] 20302079 19299803 5.193192905
[2,] 17707555 17196674 2.970812844
[3,] 0.02274954 0.02293334 -0.008014533
且round()
无效...
我应该补充一点,我一直在玩options(scipen=999)
来删除科学记数法......
任何人都可以帮助我吗?
谢谢!
答案 0 :(得分:0)
你可以像这样使用prettynum:
exportable <- as.data.table(
rbind(
c(prettyNum(total_nb_visits),
total_nb_visits_y1, round(((total_nb_visits - total_nb_visits_y1) / total_nb_visits_y1) * 100, 9)),
c(total_nb_visitors,
total_nb_visitors_y1,
round(((total_nb_visitors - total_nb_visitors_y1) / total_nb_visitors_y1) * 100, 9)),
c(CVR,CVR_y1, round((CVR-CVR_y1) / CVR_y1, 9))))
唯一的缺点是它会将值转换为字符,但你会得到漂亮的输出!