4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

コマンドラインで R を使って要約統計量を算出するワンライナー

Last updated at Posted at 2022-03-27

入力用数列生成 (例)

  • 一様乱数

    $ Rscript -e 'cat(runif(10), sep="\n")' > runif10.txt
    

統計量算出

  • 算術平均や中央値等の要約 (Min., 1st Qu., Median, Mean, 3rd Qu., Max.)

    $ Rscript -e 'summary(as.numeric(readLines("stdin")))' < runif10.txt
    
  • 標準偏差

    $ Rscript -e 'sd(as.numeric(readLines("stdin")))' < runif10.txt
    
  • 分位点

    $ Rscript -e 'quantile(as.numeric(readLines("stdin")))' < runif10.txt
    

CSV 出力

readrreadr::format_csv() (TSV なら readr::format_tsv()) を使う.

  • 要約

    $ Rscript -e 'cat(readr::format_csv(tibble::enframe(summary(as.numeric(readLines("stdin")))), col_names = F))' < runif10.txt
    
  • 分位点

    $ Rscript -e 'cat(readr::format_csv(tibble::enframe(quantile(as.numeric(readLines("stdin")))), col_names = F))' < runif10.txt
    
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?