原油价格和汽油价格对美国经济的重要影响:
20 实际 70 年代初期石油危机展示了石油资源的战略意义。
2008 年汽油价格高涨影响了居民生活:
– 交通成本上涨
– 供热成本上涨
– 食品,服务价格上涨 ==> 通货膨胀
– 降低了消费者在其它消费项目上的可支配收入,可能导致经济萧条
研究美国汽油价格以及原油价格对其影响。数据为美国普通石油价格周数据,从 1997-01-06 到 2010-09-27 。时间是每周三 , 共 717 个时间点 ; 美国原油价格周数据,从 1997-01-03 到 2010-09-24 。时间是每周日。共717 个时间点。原油价格比汽油价格早 3 天发布。
读入数据: w-petroprice.txt 又是一个用单个空格、多个空格、制表符、空格加制表符分隔的文件。这种
文件千万不要自己制造出来。最简单的解决办法是用文本编辑器编辑,将制表符都替换成单个空格。下面的R 程序用了 R 语言的文件操作和正则表达式进行替换:
la <- readLines("w-petroprice.txt")
la <- gsub("\\s+", " ", la)
la <- gsub("^\\s+|\\s$", "", la)
Regular Expression Syntax:
R gsub Function Examples – EndMemo
http://www.endmemo.com/program/R/gsub.php
gsub() function replaces all matches of a string, if the parameter is a string vector, returns a string vector of the same length and with the same attributes (after possible coercion to character). elements of string vectors which are not substituted will be returned unchanged (including any declared encoding).
替换字符串的所有匹配,如果参数是字符串向量,则返回相同长度和相同属性的字符串向量(在可能强制字符之后)。 未被替换的字符串向量的元素将不变地返回(包括任何声明的编码)。
gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
pattern: string to be matched, supports regular expression
模式:要匹配的字符串,支持正则表达式
replacement: string for replacement
替换:字符串进行替换
x: string or string vector
x:字符串或字符串向量
perl: logical. should perl-compatible regexps be used? has priority over extended
应该使用Perl兼容的regexps吗? 优先于扩展
fixed: logical. if true, pattern is a string to be matched as is. overrides all conflicting arguments
如果为真,则模式是要匹配的字符串。 覆盖所有冲突的参数
usebytes: logical. if true the matching is done byte-by-byte rather than character-by-character
如果为真,则匹配是逐字节完成的,而不是逐字符完成的
附录:原题
这本书在这里下载:https://www.quantsummaries.com/Li_FTSA.pdf