ファイルを読み取るとき、read.table
関数は を使用type.convert
して、論理列、整数列、数値列、複素数列、または因子列を区別し、それに応じて格納します。
日付を含む列が自動的に認識され、オブジェクトに解析されるように、日付をミックスに追加したいと思いDate
ます。いくつかの日付形式のみが認識される必要があります。
date.formats <- c("%m/%d/%Y", "%Y/%m/%d")
次に例を示します。
fh <- textConnection(
"num char date-format1 date-format2 not-all-dates not-same-formats
10 a 1/1/2013 2013/01/01 2013/01/01 1/1/2013
20 b 2/1/2013 2013/02/01 a 2013/02/01
30 c 3/1/2013 NA b 3/1/2013"
)
そして、の出力
dat <- my.read.table(fh, header = TRUE, stringsAsFactors = FALSE,
date.formats = date.formats)
sapply(dat, class)
与えるでしょう:
num => numeric
char => character
date-format1 => Date
date-format2 => Date
not-all-dates => character
not-same-formats => character # not a typo: date format must be consistent
最初から実装する前に、このようなものはパッケージで既に利用可能ですか? あるいは、誰かがすでにクラックを与えて (またはそうするつもりで)、彼のコードをここで共有してくれるのでしょうか? ありがとうございました。