2021年1月8日金曜日

Rの基本操作コマンド

概要

Rで基本的なコマンドをメモしようと思います。

コマンド

①コンソール出力
> print("hoge")
hoge

②コメントアウト
> # 頭に「#」をつける

③コマンドのヘルプの確認方法

> # ヘルプを表示したいコマンドの頭に「?」を付ける
> ?read.xlsx
read.xlsx {openxlsx}	R Documentation
Read from an Excel file or Workbook object
Description
Read data from an Excel file or Workbook object into a data.frame
Usage
read.xlsx(
  xlsxFile,
  sheet = 1,
  startRow = 1,
  colNames = TRUE,
  rowNames = FALSE,
  detectDates = FALSE,
  skipEmptyRows = TRUE,
  skipEmptyCols = TRUE,
  rows = NULL,
  cols = NULL,
  check.names = FALSE,
  sep.names = ".",
  namedRegion = NULL,
  na.strings = "NA",
  fillMergedCells = FALSE
)
Arguments
xlsxFile	An xlsx file, Workbook object or URL to xlsx file.
sheet	The name or index of the sheet to read data from.
startRow	first row to begin looking for data. Empty rows at the top of a file are always skipped, regardless of the value of startRow.
colNames	If TRUE, the first row of data will be used as column names.
rowNames	If TRUE, first column of data will be used as row names.
detectDates	If TRUE, attempt to recognise dates and perform conversion.
skipEmptyRows	If TRUE, empty rows are skipped else empty rows after the first row containing data will return a row of NAs.
skipEmptyCols	If TRUE, empty columns are skipped.
rows	A numeric vector specifying which rows in the Excel file to read. If NULL, all rows are read.
cols	A numeric vector specifying which columns in the Excel file to read. If NULL, all columns are read.
check.names	logical. If TRUE then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names
sep.names	One character which substitutes blanks in column names. By default, "."
namedRegion	A named region in the Workbook. If not NULL startRow, rows and cols parameters are ignored.
na.strings	A character vector of strings which are to be interpreted as NA. Blank cells will be returned as NA.
fillMergedCells	If TRUE, the value in a merged cell is given to all cells within the merge.
Details
Formulae written using writeFormula to a Workbook object will not get picked up by read.xlsx(). This is because only the formula is written and left to be evaluated when the file is opened in Excel. Opening, saving and closing the file with Excel will resolve this.
Value
data.frame
Author(s)
Alexander Walker
See Also
getNamedRegions
Examples
xlsxFile <- system.file("extdata", "readTest.xlsx", package = "openxlsx")
df1 <- read.xlsx(xlsxFile = xlsxFile, sheet = 1, skipEmptyRows = FALSE)
sapply(df1, class)
df2 <- read.xlsx(xlsxFile = xlsxFile, sheet = 3, skipEmptyRows = TRUE)
df2$Date <- convertToDate(df2$Date)
sapply(df2, class)
head(df2)
df2 <- read.xlsx(
  xlsxFile = xlsxFile, sheet = 3, skipEmptyRows = TRUE,
  detectDates = TRUE
)
sapply(df2, class)
head(df2)
wb <- loadWorkbook(system.file("extdata", "readTest.xlsx", package = "openxlsx"))
df3 <- read.xlsx(wb, sheet = 2, skipEmptyRows = FALSE, colNames = TRUE)
df4 <- read.xlsx(xlsxFile, sheet = 2, skipEmptyRows = FALSE, colNames = TRUE)
all.equal(df3, df4)
wb <- loadWorkbook(system.file("extdata", "readTest.xlsx", package = "openxlsx"))
df3 <- read.xlsx(wb,
  sheet = 2, skipEmptyRows = FALSE,
  cols = c(1, 4), rows = c(1, 3, 4)
)
## URL
##
## Not run: 
xlsxFile <- "https://github.com/awalker89/openxlsx/raw/master/inst/readTest.xlsx"
head(read.xlsx(xlsxFile))
## End(Not run)
[Package openxlsx version 4.2.3 Index]

本日はここまでで。

0 件のコメント:

コメントを投稿

FX自動トレード_2021年6月実績

      概要 2021年6月が終わり、FX自動トレードによる収益実績を取り纏めましたので振り返ってみたいと思います。 2021年6月結果 2021年6月の実績は、実利利益額:\66,761、実績利益率は1.42%でした。 今月もボラが全く出ず。利益率の連続過去最低記録更新は免...