Province ElecDistName Candidate Votes Majority Vper MajPer
<chr> <chr> <chr> <int> <int> <dbl> <dbl>
1 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est Nick Whalen Liberal 20974 646 46.7 1.4
2 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est Jack Harris ** NDP-New Democratic Party 20328 NA 45.3 NA
3 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est Deanne Stapleton Conservative 2938 NA 6.5 NA
4 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est David Anthony Peters Green Party 500 NA 1.1 NA
5 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est Sean Burton Communist 140 NA 0.3 NA
6 New Brunswick/Nouveau-Brunswick Fundy Royal Alaina Lockhart Liberal 19136 1775 40.9 3.8
素人質問をパターンマッチングによる文字列は、私は他の党を含む、名前を含む二つの1つに候補列を分割しようとしています。私はここに掲載された別の機能のいくつかを試しました:
しかし、これは多くの観測を欠場するようです。 3つの名前を持つ候補者の場合、問題は明らかですが、完全に欠けているようなものもあります(1つのアスタリスクは不可能なアスタリスクを持つ候補者です)。
Liberal、Conservative、NDP、Greenなどの最も一般的なパーティー名を識別するgreplと機能を組み合わせて、Party nameという名前のPartyという新しい列を作成することを考えました。試してみるたびにエラーメッセージが継続的に表示されます。
誰かがこの列をどのように分割できるか考えている人は、大きな助けになるでしょう。
ありがとうございました!ここで
はdputを使用してコードである:ここでは
structure(list(Province = c("Newfoundland and Labrador/Terre-Neuve-et-Labrador",
"Newfoundland and Labrador/Terre-Neuve-et-Labrador", "Newfoundland and Labrador/Terre-Neuve-et-Labrador",
"Newfoundland and Labrador/Terre-Neuve-et-Labrador", "Newfoundland and Labrador/Terre-Neuve-et-Labrador",
"New Brunswick/Nouveau-Brunswick"), ElecDistName = c("St. John's East/St. John's-Est",
"St. John's East/St. John's-Est", "St. John's East/St. John's-Est",
"St. John's East/St. John's-Est", "St. John's East/St. John's-Est",
"Fundy Royal"), Candidate = c("Nick Whalen Liberal", "Jack Harris ** NDP-New Democratic Party",
"Deanne Stapleton Conservative", "David Anthony Peters Green Party",
"Sean Burton Communist", "Alaina Lockhart Liberal"), Votes = c(20974L,
20328L, 2938L, 500L, 140L, 19136L), Majority = c(646L, NA, NA,
NA, NA, 1775L), Vper = c(46.7, 45.3, 6.5, 1.1, 0.3, 40.9), MajPer = c(1.4,
NA, NA, NA, NA, 3.8)), .Names = c("Province", "ElecDistName",
"Candidate", "Votes", "Majority", "Vper", "MajPer"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
データオブジェクトがどのように見えるか分かりません。 – ssp3nc3r
申し訳ありませんが、今コードを投稿しました – lazslo93
あなたはいくつのパーティを持っていますか? – Val