
エクセルで管理しているデータをR/Rstudioで解析するときに、データをR/Rstudioにインポートする必要があります。
今回は、エクセルファイルのデータをR/Rstudioにインポートする2つの方法を解説します。
方法1:read_excel()を使用
この方法でエクセルファイルをRにインポートするには、readxlライブラリーからread_excel()を呼び出してインポートします。
library(readlx)
sample_data = read_excel("sample_data.xlsx")
という感じです。
例:cs30_age_fallという名前のエクセルファイルをインポートする場合、
library(readxl)
cs30_age_fall <- read_excel("cs30_age_fall.xlsx")
cs30_age_fall
とすると、cs30_age_fallにデータがインポートされます。
方法2:Rstudioにビルトインされているメニューを使用
Rstudioにビルトインされているメニューを使ってファイルをインポートする方法は、Consoleペインに入力する必要もないので、もっと簡単です。
Step 1:
Environmentタブ下の”Import Dataset”を選択

Step 2:
”Import Dataset”の選択オプションから”From excel”を選択。

Step 3:
”Import Excel Data”ウインドウが開くので、”Browse”ボタンをクリックして、インポートするエクセルファイルを選択してください。

Step 4:
インポートするエクセルファイルを選択すれば、無事にデータがインポートされ、”Data Preview”に表示されます。OKなら、”Import Excel Data”ウインド右下の”Import”ボタンをクリックして終了です。

以上の2方法がRstudioにエクセルファイルをインポートする方法です。
とっても簡単でしょう!

コメント