Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

练习题的答案也有错误,没有勘误表。 #16

Open
@realalien

Description

比如第四章习题7(g),答案使用的是(f)的代码。这道题有些搞脑子,花了我一两个小时。
毕竟大家是在学习工具;当工具稍微复杂了点,就照葫芦画瓢吧,节省大家时间。

#(g) Extract the <name> node for all presidents whose term started in or after the year 1960.
library(stringr) 
choose <- function(x) {
 start <- xmlValue(xmlChildren(x)[["start"]])
 name <- xmlValue(xmlChildren(x)[["name"]])
 year_pat <- "([0-9]{4}$)"
 year <- as.numeric( str_extract(start, year_pat ))
 after1960 <- ifelse( year >= 1960 , name, NA )
 return(after1960)
}
temp <- xpathSApply(potus, "//document/president", choose)
presidents_after_1960 <- temp[!is.na(temp)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /