在Shiny r中以美元显示数据列值 [英] Displaying datatable column values in dollars in Shiny r
问题描述
更复杂的部分是我有另一个数据表,其中只有某些条目需要表示为美元(即不是整行或整列) - 有一种方法来处理这个?
想象你的datatable(myData)是2列乘10行。
您希望第二行为美元:
myData [,2]< -sapply(myData [,2],function(x)paste0($,x))
或者,您希望第一列中的第6到10行为百分比:
myData [6 :10,1]< -sapply(myData [6:10,1],function(x)paste0(x,%))
或者,您希望第二列中的第1到5行以美元为单位,您可以执行以下操作:
myData [1:5,2]< -sapply(myData [1:5,2],function(x)paste0($,x))
I have a datatable where one of the columns should be expressed in dollars and some as percentages. I've been looking around and I'm still not sure how to do it - seems like it would be easy?
The trickier part is I have another data table where only certain entries need to be expressed as dollars (i.e. not whole rows or whole columns) - is there a way to handle this?
Imagine your datatable (myData) is 2 columns by 10 rows.
You want the second row to be in dollars:
myData[,2]<-sapply(myData[,2],function(x) paste0("$",x))
Or, you want rows 6 to 10 in the first column to be percentages:
myData[6:10,1]<-sapply(myData[6:10,1],function(x) paste0(x,"%"))
Or, you want rows 1 to 5 in the second column to be in dollars, you can do:
myData[1:5,2]<-sapply(myData[1:5,2],function(x) paste0("$",x))
这篇关于在Shiny r中以美元显示数据列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!