每当我用Sweave运行一些R代码时,它会在文档中显示终端箭头(">").这适用于会话输入,但有时我想包含自定义函数.当箭头显示在文档中时,复制和粘贴重要的代码片段会更加困难.有快速的方法吗?
我知道我可以在一起抑制输出的同时运行代码,然后将该代码复制到\ Verbatim,但这需要额外的输入.
谢谢
dumbo <- function(x)
2*x
Run Code Online (Sandbox Code Playgroud)
代替
> dumbo <- function(x)
> 2*x
Run Code Online (Sandbox Code Playgroud) 我认为这还没有被问到,但是有没有办法将列表的信息与多个级别和不均匀的结构组合成一个"长"格式的数据框?
特别:
library(XML)
library(plyr)
xml.inning <- "http://gd2.mlb.com/components/game/mlb/year_2009/month_05/day_02/gid_2009_05_02_chamlb_texmlb_1/inning/inning_5.xml"
xml.parse <- xmlInternalTreeParse(xml.inning)
xml.list <- xmlToList(xml.parse)
## $top$atbat
## $top$atbat$pitch
## des id type x y
## "Ball" "310" "B" "70.39" "125.20"
Run Code Online (Sandbox Code Playgroud)
以下是结构:
> llply(xml.list, function(x) llply(x, function(x) table(names(x))))
$top
$top$atbat
.attrs pitch
1 4
$top$atbat
.attrs pitch
1 4
$top$atbat
.attrs pitch
1 5
$bottom
$bottom$action
b des event o pitch player s
1 1 1 1 1 1 1
$bottom$atbat
.attrs pitch
1 5
$bottom$atbat
.attrs pitch
1 5
$bottom$atbat
.attrs …Run Code Online (Sandbox Code Playgroud)