1

データフレームに要素が表示される順序を変更するにはどうすればよいですか?

オーストラリアの州名のサンプルを使用したデータの例:

location <- c("new_south_wales", "victoria", "queensland")

victoria最後に出てもらいたいって言って!

#this doesn't work
factor(location, levels = c("new_south_wales", "queensland", "victoria")

#neither does this
ordered(location, levels = c("new_south_wales", "queensland", "victoria")

試してみforcats::fct_relevelましたが、レベルを変更することはできますが、要因が表示される順序には影響しません。

4

1 に答える 1