在Shiny r中以美元显示数据列值 [英] Displaying datatable column values in dollars in Shiny r

查看:134
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆