• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

R语言datacamp搬运日记

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

都说三天打鱼两天晒网,我是三天打鱼晒了很多天网hhh~本来以为五一小长假可以有充分时间好好刷SQL,没想到突然有十五个DDL突然来袭,于是也有了现在正在赶R语言作业的我,本来想水水但是没想到做了下感觉还挺有价值的,所以做个小小搬运工,快乐搬砖现在开始(嘿哈!
String Manipulation with stringr in R
这部分是R语音操作字符串相关的内容
最基础的是双引号单引号以及转义的用法,句子中没有单双引号的时候优先考虑用双引号,如果已有双引号则用单引号加以区分,如果已经有了单引号和双引号,添加/进行区分。转义部分除了换行等常规操作,要注意如果想显示//需要输入////,另外就是WriteLine()的用法。
知识点是从format()函数的出现开始的,此刻搬运工也正式上线啦~
1.Using format() with numbers
要求:
Format c(0.0011, 0.011, 1) with digits = 1.
Now, format c(1.0011, 2.011, 1) with digits = 1.
Format percent_change by choosing the digits argument so that the values are presented with one place after the decimal point.
Format income by choosing the digits argument so that the values are presented as whole numbers (i.e. no places after the decimal point).
Format p_values using a fixed representation.
答案:
2.Controlling other aspects of the string
Not only does format() control the way the number is represented, it also controls some of the properties of the resulting string that affect its display.
问题:
We’ve assigned your formatted income from the previous exercise to formatted_income.
Print formatted_income Notice the spaces at the start of the strings.
Call writeLines() on the formatted income. Notice how the numbers line up on the decimal point.
Define trimmed_income by using format() on income with digits = 2 and trim = TRUE.
Call writeLines() on trimmed_income. Notice how this removes the spaces at the start of the strings and the values line up on left.
Define pretty_income by using format() on income with digits = 2 and big.mark = “,”.
Call writeLines() on pretty_income.
答案:

嚯嚯嚯~~format函数用起来就是这么棒棒!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
R语言-laohuji发布时间:2022-07-18
下一篇:
[译]用R语言做挖掘数据《一》发布时间:2022-07-18
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap