私はデータフレームdf
があるとします。各疾患のエントリは、各エントリの最初の文字を除いてすべて小文字になるようにR:データフレームの列にセミコロンで区切られた各単語の最初の文字を大文字にするにはどうすればいいですか?
> df <- data.frame(Disease = c('Disease Entry1; disease Entry2', 'disease Entry4','disease Entry5; disease entry6'), ID = c(1,2,3))
> df
Disease ID
1 Disease Entry1; disease Entry2 1
2 disease Entry4 2
3 disease Entry5; disease entry6 3
どのように私はそれを操作することができますか?すなわち
> df
Disease ID
1 Disease entry1; Disease entry2 1
2 Disease entry4 2
3 Disease entry5; Disease entry6 3
私は何とかtolower
機能の使用を取るだろうと仮定しますが、どのようにセミコロンを考慮に入れますか?
は、それは常にです大文字で始まるはずの単語「病気」?あるいは言葉が変わることはありますか?そうでない場合は、 'tolower()'を使用し、 'gsub(" disease "、" Disease "、df $ Disease)を使用することをお勧めします。 –
@KenSをもっと明確にする必要があります。この例で使用します。それは実際に変化する。 –
'stringr :: str_to_title'を使ってすべての単語を大文字で始めることができます –