为基本问题道歉,但我对R很新。我有一个两行数据框,我将导出到Latex并尝试修改第二行(当前数字),以便它保留4个小数位并被封装在括号中。
这可能吗?
当前数据框:df:
col1 | col2 | col3
-------------------------------
0.0553 0.1354 0.1403
0.0000 0.0956 0.9110
所需数据框:
col1 | col2 | col3
-------------------------------
0.0553 0.1354 0.1403
(0.0000) (0.0956) (0.9110)
答案 0 :(得分:5)
尝试
df1[2,] <- paste0("(", format(unlist(df1[2,])),")")
df1
# col1 col2 col3
#1 0.0553 0.1354 0.1403
#2 (0.0000) (0.0956) (0.9110)
df1 <- structure(list(col1 = c(0.0553, 0), col2 = c(0.1354, 0.0956),
col3 = c(0.1403, 0.911)), .Names = c("col1", "col2", "col3"
), class = "data.frame", row.names = c(NA, -2L))