我有一个数据框,可以对列size进行分组。当数据框按大小排列时,我想将每个组的每列的总计显示为 df 中的一行。
library(dplyr)
dat <- data.frame(size = c("S", "XS", "L", "M", "L", "L", "XS"),
category = c("shirt", "shirt", "shirt", "shirt", "pants", "hat", "pants"),
store1 = c(22, 3, 52, 10, 5, 37, 21),
store2 = c(43, 13, 2, 24, 6, 12, 40))
dat %>%
arrange(size)
size category store1 store2
1 L shirt 52 2
2 L pants 5 6
3 L hat 37 12
4 M shirt 10 24
5 S shirt 22 43
6 XS shirt 3 …Run Code Online (Sandbox Code Playgroud) 在西班牙,数字格式例如:4.000.000,25(4 百万和 1/4)。有没有办法更改数字格式(最好是整个 R 项目)而不将其更改为字符?
现在我在所有数据帧上执行一个函数。函数看起来像:
fnx = function(x){print(formatC(x, format = "d", big.mark = ".", decimal.mark = ","), quote=F)}
fnx(567*4325)
# 2.452.275
class(fnx(567*4325))
# "character"
Run Code Online (Sandbox Code Playgroud)
还有其他方法吗?以及不将其转换为字符类的方法?