【Rデータ整理】文字列や数値の抽出:str_extract/str_extract_all/readr::parse_number 更新日:2024年12月23日 公開日:2023年12月15日 R 文字列の抽出には、stringrパッケージのstr_extract()やstr_extract_all()を使う。 また、数値の抽出には、readrパッケージのparse_number()も使える。 3つの関数のざっくり […] 続きを読む
【Rデータ整理】マッチするかどうかを返す:str_detect/grepl 更新日:2024年12月15日 公開日:2023年12月15日 R 特定の条件にマッチするかどうかを判定する関数には、str_detect() と grepl()を使うことができる。 str_detect() は stringr パッケージの関数で、grepl() はRの標準パッケージ( […] 続きを読む
【Rデータ整理】文字列のマッチする箇所の数を返す:str_count 更新日:2024年12月15日 公開日:2023年12月15日 R str_count(string, pattern) は、文字列内に正規表現pattern がいくつ出現するかをカウントする関数。 この関数は、stringr パッケージに含まれているので、まずは、library(str […] 続きを読む
【Rデータ整理】文字列を繰り返し複製する:str_dup/strrep 更新日:2024年12月15日 公開日:2023年12月15日 R 文字列を繰り返し複製する時には、str_dup() と strrep()などを使う。 str_dup():stringrパッケージの関数で、ベクトル化が簡単、使い方が直感的。 strrep():base R (標準関数) […] 続きを読む
【Rデータ整理】文字列のフォーマットを変更する:str_to_upper/str_to_lower/str_to_title/str_to_sentence 更新日:2024年12月16日 公開日:2023年12月15日 R 文字列のフォーマットを変更する時には、stringrパッケージに含まれているstr_to_upper(), str_to_lower(), str_to_title(), str_to_sentence()等を使う。 こ […] 続きを読む