如何防止R在运行列表中的代码后将小数位从2减少到1?
我想在列表中运行代码,刚刚发现,R 将我在列表中使用“子集”的列中的数字小数位从 2 减少到 1,并将原始两位向上或向下舍入。 我希望 R 保留两位小数,或者为那些只有一位的人添加零。 这是一个示例数据框:
set.seed(94756)
mat1 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat1 <- as.data.frame(mat1)
colnames(mat1) <- c("C1","C2", "C3","C4", "C5")
mat2 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat2 <- as.data.frame(mat2)
colnames(mat2) <- c("C1","C2", "C3","C4", "C5")
mat3 <- matrix(sample(seq(-1,100, 0.11), 50,replace = TRUE),ncol = 5)
mat3 <- as.data.frame(mat2)
colnames(mat3) <- c("C1","C2", "C3","C4", "C5")
data <- list(mat1, mat2, mat3)
data2 <- lapply(data, subset, C4 > 10 & C4 <= 70)
提前致谢!
I want to run a code within a list and just discovered, that R reduced the decimal places of the numbers from 2 to 1 in the column I use 'subset' in the list and rounds those with original two places up or down.
I would like R to let both decimal places or add a zero to those who only have one.
Here an example data frame:
set.seed(94756)
mat1 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat1 <- as.data.frame(mat1)
colnames(mat1) <- c("C1","C2", "C3","C4", "C5")
mat2 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat2 <- as.data.frame(mat2)
colnames(mat2) <- c("C1","C2", "C3","C4", "C5")
mat3 <- matrix(sample(seq(-1,100, 0.11), 50,replace = TRUE),ncol = 5)
mat3 <- as.data.frame(mat2)
colnames(mat3) <- c("C1","C2", "C3","C4", "C5")
data <- list(mat1, mat2, mat3)
data2 <- lapply(data, subset, C4 > 10 & C4 <= 70)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论