在 R 中使用 as.xts() 缩放到 xts 时的引号 [英] Quotation marks when zoo to xts using as.xts() in R

查看:40
本文介绍了在 R 中使用 as.xts() 缩放到 xts 时的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将以下数据(动物园"类)转换为 xts 时,我使用 returns.xts<-as.xts(returns).效果是在新数据周围添加引号.然后在函数中变得无法使用.

When transforming the below data (class "zoo") into xts, I use returns.xts<-as.xts(returns). The effect is to add quotation marks around the new Data. And then becomes unusable in functions.

这是为什么?

类(动物园")

           UK.EQUITY    EUR.EQUITY   NA.EQUITY    ASIA.EQUITY  JPN.EQUITY   EM.EQUITY    WORLD.EQUITY.EX.UK
2006-04-30 0.010552982  -0.003337229 -0.033739353 0.025092643  -0.020920633 0.020016007  -0.021165353      
2006-05-31 -0.048962517 -0.071924029 -0.059684763 -0.102475485 -0.098121902 -0.141877111 -0.067793295    

类(动物园"xts")

class ("zoo" "xts")

           UK.EQUITY      EUR.EQUITY     NA.EQUITY      ASIA.EQUITY    JPN.EQUITY     EM.EQUITY     
2006-04-30 "0.010552982"  "-0.003337229" "-0.033739353" "0.025092643"  "-0.020920633" "0.020016007" 
2006-05-31 "-0.048962517" "-0.071924029" "-0.059684763" "-0.102475485" "-0.098121902" "-0.141877111"

推荐答案

xts 不是添加引号".xts 打印带引号的字符数据,但 zoo 不打印.str(returns)str(as.xts(returns)) 应该都表明对象的核心数据是字符.这是因为#N/A"无法转换为数字.

xts is not "adding quotation marks". xts prints character data with quotation marks, but zoo does not. str(returns) and str(as.xts(returns)) should both show that the coredata of the objects is character. This is because "#N/A" cannot be converted to a number.

您没有说明如何从 Excel 中读取(尽管您添加的标签表明您是这样),但通常有多种方法可以指定 NA 值的表示方式.例如,read.csv 有一个 na.strings 参数,您可以将其设置为 "#N/A".

You don't say how you're reading from Excel (though the tags you added suggest you are), but there are usually ways to specify how NA values are represented. For example, read.csv has a na.strings argument you can set to "#N/A".

这篇关于在 R 中使用 as.xts() 缩放到 xts 时的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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