我正在寻找一个函数或库来转换data.frame中重要性星中的数字。
使用pander package的add.significance.stars()函数,我可以将数字转换为有效星号。我希望构建一个函数,以便将数字转换为以有效星数表示的data.frame。例
mydata <- data.frame("Su1"=c(1,1,0.0004),"Su2"=c(NA,1,0.03),"Su3"=c(NA,NA,0.007))
rownames(mydata) <- c("Su2","Su3","Su4")
mydata
Su1 Su2 Su3
Su2 1.0000 NA NA
Su3 1.0000 1.0000 NA
Su4 0.0004 0.03 0.007
使用add.significance.stars()我希望有一个像这样的表:
mydata
Su1 Su2 Su3
Su2 "_1.0000_" NA NA
Su3 "_1.0000_" "_1.0000_" NA
Su4 "_0.0004_ * * *" "_0.03_ *" "_0.007_ * *"
最佳答案
sapply
丢失row.names,但是您可以将其放回
mystars = sapply(mydata, add.significance.stars)
rownames(mystars) = rownames(mydata)
mystars
# Su1 Su2 Su3
# Su2 "_1_" "_NA_NA" "_NA_NA"
# Su3 "_1_" "_1_" "_NA_NA"
# Su4 "_4e-04_ * * *" "_0.03_ *" "_0.007_ * *"
关于r - 将数据转换为data.frame中R中的重要星号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31014822/