1

次のようなデータを含む csv ファイルがあります。

"Date","Time","Open","High","Low","Close","Up","Down","Sell","Buy","Stop1","Stop2","Stop3","Target1","Target2","Target3"
04/18/2012,1335,1365.25,1366.00,1365.00,1366.00,2855,1153,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
04/18/2012,1340,1366.00,1366.25,1365.50,1366.00,450,607,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
04/18/2012,1345,1366.00,1366.00,1365.75,1365.75,300,263,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00

このコマンドを使用してファイルを読み取ると、文字マトリックスが得られます。

RawData = as.matrix(read.table(PathName,sep=",",header=TRUE))

typeof(RawData)
[1] "character"

これは、日付列が原因であることがわかります。

これを数値配列にする必要があります。上記で使用している read.table コマンドの代わりになるものは何ですか?

4

1 に答える 1

4
RawData.df <- read.table(PathName,sep=",",header=TRUE)
RawData <- as.matrix(RawData.df[,-1])

あなたのデータについて:

> RawData.df <- read.table(sep = ",", header = TRUE, text =
+ '"Date","Time","Open","High","Low","Close","Up","Down","Sell","Buy","Stop1","Stop2","Stop3","Target1","Target2","Target3"
+ 04/18/2012,1335,1365.25,1366.00,1365.00,1366.00,2855,1153,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
+ 04/18/2012,1340,1366.00,1366.25,1365.50,1366.00,450,607,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
+ 04/18/2012,1345,1366.00,1366.00,1365.75,1365.75,300,263,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00')
> str(RawData.df)
'data.frame':   3 obs. of  16 variables:
 $ Date   : Factor w/ 1 level "04/18/2012": 1 1 1
 $ Time   : int  1335 1340 1345
 $ Open   : num  1365 1366 1366
 $ High   : num  1366 1366 1366
 $ Low    : num  1365 1366 1366
 $ Close  : num  1366 1366 1366
 $ Up     : int  2855 450 300
 $ Down   : int  1153 607 263
 $ Sell   : num  0 0 0
 $ Buy    : num  0 0 0
 $ Stop1  : num  0 0 0
 $ Stop2  : num  0 0 0
 $ Stop3  : num  0 0 0
 $ Target1: num  0 0 0
 $ Target2: num  0 0 0
 $ Target3: num  0 0 0
> RawData <- as.matrix(RawData.df[,-1])
> str(RawData)
 num [1:3, 1:15] 1335 1340 1345 1365 1366 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:15] "Time" "Open" "High" "Low" ...
于 2012-10-30T19:37:48.397 に答える