このread.tableを実行するときに正しくインポートされませんいくつかの値があります。列を分割するためのより効率的な方法があり
hs.industry <- read.table("https://download.bls.gov/pub/time.series/hs/hs.industry", header = TRUE, fill = TRUE, sep = "\t", quote = "", stringsAsFactors = FALSE)
は、具体的にindustry_codeとは次のように結合されているindustry_nameいくつかの値があるがindustry_code列の単一の値(理由は不明)。各industry_codeは4桁の数字であることを考えると、分割され、修正するために、私のアプローチは次のとおりです。
for (i in 1:nrow(hs.industry)) {
if (isTRUE(nchar(hs.industry$industry_code[i]) > 4)) {
hs.industry$industry_name[i] <- gsub("[[:digit:]]","",hs.industry$industry_code[i])
hs.industry$industry_code[i] <- gsub("[^0-9]", "",hs.industry$industry_code[i])
}
}
私はこれがひどくinnificentであると感じ、私は良いだろうどのようなアプローチはよく分かりません。
ありがとうございます!
ありがとう!あなたは崩壊の必要性を説明できますか? – Michael
'' text '引数で 'read.table'を使用する場合、テキストは文字列のリストではなく、単一の文字列でなければなりません。このようにして、文字列のリスト(各項目は元のテキストの1行を表す)を改行文字で折りたたみます。 – jdobres