R にファイルを読み込む tips 集(暫定版)

R にファイルを読み込むのに苦労されるケースが多いようです。もとのファイルの サイズ・書式が様々なこと、OS、ユーザインタフェイスの違いから、一筋縄ではいかないようですが、基本をまとめてみたらいかがでしょうか。なお一覧表 Rがインポート・エクスポートできるデータ形式 をまず参考にして下さい。
一度にまとめるのも大変とおもわれますから、以下には主に r-help への投稿記事から参考になりそうなものを順次メモしておきます。ある程度溜ったら別頁に清書しましょう。





sas7bdat ファイルを読み込む、2011.08.22

複数のファイルを読み込み、コード中で生成したオブジェクトに付値する(初級者 Q&A 記事より転載)、2005.01.27

ファイル X00Y00.txt, X01Y00.txt, X00Y01.txt, X01Y01.txt (実体は同じ)があると仮定する。それらを X00Y00, X01Y00, X01Y00, X01Y01 という名前のオブジェクトに読み込む。オブジェクト名を表す文字列を paste, sprintf 関数で作り、それを名前に持つオブジェクトを assign 関数で作成・付値するのがキーポイント。

> for (i in 0:1) {
    if (i < 10) I <- paste("0",i,sep="")  else I <- as.character(i)
    for (j in 0:1) {
       if (j < 10) J <- paste("0",j,sep="")  else J <- as.character(j)
       oname <- paste("X",I,"Y",J, sep="") # 文字列 "X00Y00" 等を作る
       fname <- paste(oname, ".txt", sep="") # ファイル名文字列 "X00Y00.txt" 等を作る
       x <- read.table(fname) # ファイルを読み込み
       colnames(x) <- c(paste("X_",oname,sep=""), paste("I_",oname,sep=""))
       assign(oname, x) # 文字列 oname を名前に持ち、中身が x のオブジェクトを作る
    }
 }
> X00Y00
   X_X00Y00 I_X00Y00
1         1        2
2         2        4
3         3        6
4         4        8
5         5       10
6         6       12
7         7       14
8         8       16
9         9       18
10       10       20
> X01Y01
   X_X01Y01 I_X01Y01
1         1        2
2         2        4
3         3        6
4         4        8
5         5       10
6         6       12
7         7       14
8         8       16
9         9       18
10       10       20
===== 別の記述方法
for (i in 0:1) {
  for (j in 0:1) {
    oname <- sprintf("X%02iY%02i", i, j) # 文字列 "X00Y01" 等を作る
    x <- read.table(sprintf("%s.txt", oname)) # ファイルを読み込み
    colnames(x) <- c(sprintf("X_%s",oname), sprintf("I_%s",oname))
    assign(oname, x) # 文字列 oname を名前に持ち、中身が x のオブジェクトを作る
  }
}

現在の作業環境をファイルにセーブし、それを次回に復元する方法。save.image 関数 -- 2005.01.27

R を q() 関数で終了する際、yes と答えると現在の作業環境(ie. 現在のワークスペース中のすべてのオブジェクト)は起動ディレクトリの XDR というバイナリ書式ファイル .Rdata に保存され、次回 R を起動するとそれが自動的に読み込まれる。もし作業途中の環境を独自に保存したければ save.image 関数を使う。

save.image(file = ".RData", version = NULL, ascii = FALSE,
           compress = FALSE, safe = TRUE)

オプションでアスキーセーブ、圧縮ファイルにすることもできる。 'save.image()' は単に 'save(list = ls(all=TRUE), file = ".RData")' と同値で、'q("yes")' としたのと同じ(但し R を終了しない)となる。もし作業途中の環境を独自に保存したければ、例えば

save.image(file=".Rdata.20050127") 

等とする。次回の R セッションをちょうどこの環境で始めたければ、R をオプション付き(.Rdata を自動読み込みしない)で

R --no-restore

と開始し(詳しくは help(Startup) 参照)、次に命令

load(".Rdata.20050127")

を実行する。

R オブジェクトを Excel ファイルに落し、それを Excel で開く関数 -- from r-help, 2005.01.02

私は MSW を使いませんから、実際に試してはいません。 R オブジェクトを Excel ファイルに落し、それを R の中から Excel で開く関数のようです。by Eugene MeMelamud

excel <- function(x) {
 
   # Excel の一時的ファイル名のオブジェクトを作る
   tmpfilename <-paste(tempfile(c("abs")),".csv",sep="");

   # 引数 x で指定されたオブジェクトをコンマで区切ったテーブルに変換 
   write.table(x, file=tmpfilename, sep=",")

   # Excel をバックグラウンドで起動(Excel 関数の所在パスを変更する必要があるかも知れない)
   system( paste('"C:?PROGRAM FILES?MICROSOFT OFFICE?OFFICE?EXCEL.EXE"',
                 tmpfilename ), wait=FALSE);

   # Excel がファイルを開く前に、R が一時ファイル名オブジェクトを消しさらないように 5 秒休む
   Sys.sleep(5);
   unlink(tmpfilename) # 一時ファイル名オブジェクトを消す
}

複数のファイルを一括してデータフレームのリストに読み込む -- from r-help, 2004.12.29

次のような内容のデータファイル file1.txt, file2.txt があるとする。

   A B C
X1 1 2 3 
X2 4 5 6
    D  E  F
Y1  7  8  9
Y2 10 11 12

これを一括してデータファイルのリストとして読み込む

> filenames <- c("file1.txt", "file2.txt")      # 読み込むべきファイル名の文字ベクトル
> listoftables <- lapply(filenames, read.table)
> names(listoftables) <- filenames              # ファイル名を成分名にする
> listoftables
$file1.txt
   A B C
X1 1 2 3
X2 4 5 6
$file2.txt
    D  E  F
Y1  7  8  9
Y2 10 11 12
> listoftables[[1]]     # listoftables[["file1.txt"]] でも良い
   A B C
X1 1 2 3
X2 4 5 6
> listoftables[[2]]     # listoftables[["file2.txt"]] でも良い
    D  E  F
Y1  7  8  9
Y2 10 11 12

ファイル中の行数、ワード数、文字数を(ファイル全体を読み込むこと無しに)数える関数

(by R. A. O'Keefe, form r-help, 2004.12.09)

OS による違いとファイル名中の空白・特殊文字の扱いが結構難しいらしい。
(ついでにいうと、次の関数 for.system の定義構文はびっくり、こんなのあり?)

for.system <-
    if (.Platform$OS.type == "windows") {
        function (s) {
            i <- grep("[^-_:.A-Za-z0-9/????]", s)
            s[i] <- sapply(s[i], function (s) paste("?"", s, "?"", sep=""))
            s
        }
    } else {
        function (s) gsub("([][)(}{'?";&! ?t?n])", "??????1", s)
    }
wc <- function (s) {
    r <- scan(pipe(paste("wc <", for.system(s)), open="r"), n=3, quiet=TRUE)
    names(r) <- c("lines", "words", "chars")
    r
}
> wc("Foo Bar")  # ファイル名中に空白がある例
 
lines words chars  # 集計結果
    3     6    12 
 
> wc("Drunkard's Walk")["chars"]  # ファイル名中の特殊文字
 
chars 
 3633 

データのセーブとロード

MKR (2004-11-29 (月) 17:15:41)

データをファイルにセーブする save() 関数は既定では "XDR" というバイナリー書式でセーブする。これはバイナリファイルになりエディターでは編集できないが、書き込み、読み込み、ファイルサイズともに相当短縮され、OS によらず読み込みができる。一方 ASCII 書式でセーブすると書き込み、読み込み、ファイルサイズが相当大きくなる。頻繁に使う巨大データファイルは一旦 R に読み込み、 "XDR" 書式でセーブするのが得。

> xxx <- xx <- x <- rnorm(10e6) # 百万個の実数データ
# 書き込み速度は 11.5:1 
> gc(); system.time(save(xx, file="x.txt", ascii=TRUE)) # アスキー書式でセーブ
[1] 23.68  2.34 26.45  0.00  0.00
> gc(); system.time(save(xxx, file="x.xdr")) # XDR 書式でセーブ(拡張子は実は任意)
[1] 2.06 0.74 2.96 0.00 0.00
# 読み込み速度は 21.7:1
> rm(xx); gc(); system.time(load("x.txt")); identical(x, xx) # 読み込み
[1] 62.62  0.62 63.27  0.00  0.00~
[1] TRUE
> rm(xxx); gc(); system.time(load("x.xdr")); identical(x, xxx) # 読み込み
[1] 2.88 0.29 3.66 0.00 0.00
[1] TRUE

ちなみにファイルサイズは 2.4:1

 80000050 2004-11-29 17:12 x.xdr
191603179 2004-11-29 17:12 x.txt

さらに save() 関数をオプション compress=TRUE で実行するとファイルは圧縮されて保存されるが、当然読み書き速度は遅くなるが、それでも読み込みならアスキーファイルよりはるかに早い。

> gc(); system.time(save(x, file="x.cxdr", compress=TRUE))
[1] 39.75  0.94 40.97  0.00  0.00
> gc(); system.time(load("x.cxdr"))
[1] 7.20 0.34 7.75 0.00 0.00

ファイルサイズは 6853838 で非圧縮時の 8.6%、アスキーファイルに比べると 3.6%。


アドオンパッケージ foreign を使って外部システムファイルを読み込む

MKR (2004-11-20 (土) 06:46:35)

他頁より転載。アドオンパッケージ foreign には他システムのファイルを R に読み込むための関数がいくつも定義されています。

foreign(Minitab, S, SAS, SPSS, Stata, ... で保存されたデータを読み込む)パッケージ中のオブジェクト一覧

項目説明
lookup.xportSAS XPORT 形式ライブラリーのルックアップ情報
S3 read functionsS3 バイナリ・ファイルの読み込み
read.dtaStata バイナリ・ファイルの読み込み
read.epiinfoEpi Info データ・ファイルの読み込み
read.mtpMinitab ポータブル・ワークシートの読み込み
read.spssSPSS データ・ファイルの読み込み
read.ssdSAS permanent dataset, via read.xport経由で SAS permanent データセットよりデータフレームを取得
read.xportSAS XPORT 形式ライブラリーの読み込み
write.dtaStata バイナリ形式ファイルへの書き出し

SPSS のファイルを R に読み込む (from r-help, 2004.11.18)

MKR (2004-11-18 (木) 17:30:11)

SPSS のデータファイルを R に読み込む方法

>>Date: Tue, 16 Nov 2004 09:49:45 -0800 (PST)
>> From: gauri <gdsr15@yahoo.com>
>>Hi,
>>I was wondering as to how I could convert SPSS data imported to R into 
  tabular form. In the sense, direct usage of read.table( ) doesnt help. 
>>Thanks

Hi Gauri:

There are several ways of doing that. Easiest in my opinion is to save the 
SPSS data into "txt", or "csv" file and read it directly into R using
read.table() function to read the txt or csv data. See ?read.table for more
information, or read the data input output section of the user manual. The
second way is to use library(foreign) and then read the data directly using
read.spss. For more information, do library(foreign) and then ?read.spss

Hope this helps,
Arin Basu

Excel からコピーしたセル範囲を R に読み込む (何でも掲示版の青木繁伸さんの記事を転載)

エクセルのセル範囲を R に読み込むために,今まではわざわざファイルに書き出してやっていましたが,面倒なので,簡単なラッパーを作ってみました。

from.excel <- function(nc)
{
       matrix(scan(""), byrow=TRUE, nc=nc)
}

エクセルで必要な部分をコピーします。

x <- from.excel(2)

などとして,プロンプトが出たらペーストします。 入力の終わりはMacintoshだとcommand+. 汎用関数にする価値もないのでこのまま。


上(下)三角行列としてファイルを読み込む (from r-help, 2004.11.07)

(2004-11-07 (日) 19:43:49)

次のようなデータファイル "data.txt" を下三角行列として読み込む

 1.000
 0.591  1.000
 0.356  0.350  1.000
-0.098  0.072  0.380  1.000
 0.573  0.408  0.382  0.062  1.000
 0.156  0.232  0.517  0.424  0.303  1.000
 0.400  0.414  0.611  0.320  0.401  0.479  1.000
 0.282  0.375  0.512  0.346  0.308  0.463  0.605  1.000
 0.519  0.484  0.467  0.167  0.455  0.311  0.574  0.557  1.000
> x <- scan("data.txt")
Read 45 items
> x
 [1]  1.000  0.591  1.000  0.356  0.350  1.000 -0.098  0.072  0.380  1.000
[11]  0.573  0.408  0.382  0.062  1.000  0.156  0.232  0.517  0.424  0.303
[21]  1.000  0.400  0.414  0.611  0.320  0.401  0.479  1.000  0.282  0.375
[31]  0.512  0.346  0.308  0.463  0.605  1.000  0.519  0.484  0.467  0.167
[41]  0.455  0.311  0.574  0.557  1.000
> y <- data.matrix(read.table("data.txt", fill = TRUE, col.names = 1:9))
> y
      X1    X2    X3    X4    X5    X6    X7    X8 X9
1  1.000    NA    NA    NA    NA    NA    NA    NA NA
2  0.591 1.000    NA    NA    NA    NA    NA    NA NA
3  0.356 0.350 1.000    NA    NA    NA    NA    NA NA
4 -0.098 0.072 0.380 1.000    NA    NA    NA    NA NA
5  0.573 0.408 0.382 0.062 1.000    NA    NA    NA NA
6  0.156 0.232 0.517 0.424 0.303 1.000    NA    NA NA
7  0.400 0.414 0.611 0.320 0.401 0.479 1.000    NA NA
8  0.282 0.375 0.512 0.346 0.308 0.463 0.605 1.000 NA
9  0.519 0.484 0.467 0.167 0.455 0.311 0.574 0.557  1
> is.matrix(y) # read.table 関数経由のため行・列ラベルがついているが行列である
[1] TRUE

別法

> m <- matrix(0,9,9)
> m[upper.tri(m,diag=TRUE)] <- x  # 直接 m[lower.tri(m,diag=TRUE)] 適用は何故か失敗
> m
      [,1]  [,2]  [,3]   [,4]  [,5]  [,6]  [,7]  [,8]  [,9]
 [1,]    1 0.591 0.356 -0.098 0.573 0.156 0.400 0.282 0.519
 [2,]    0 1.000 0.350  0.072 0.408 0.232 0.414 0.375 0.484
 [3,]    0 0.000 1.000  0.380 0.382 0.517 0.611 0.512 0.467
 [4,]    0 0.000 0.000  1.000 0.062 0.424 0.320 0.346 0.167
 [5,]    0 0.000 0.000  0.000 1.000 0.303 0.401 0.308 0.455
 [6,]    0 0.000 0.000  0.000 0.000 1.000 0.479 0.463 0.311
 [7,]    0 0.000 0.000  0.000 0.000 0.000 1.000 0.605 0.574
 [8,]    0 0.000 0.000  0.000 0.000 0.000 0.000 1.000 0.557
 [9,]    0 0.000 0.000  0.000 0.000 0.000 0.000 0.000 1.000
> m <- t(m)     # 下三角行列にするには転置する
> m
        [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8] [,9]
 [1,]  1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000    0
 [2,]  0.591 1.000 0.000 0.000 0.000 0.000 0.000 0.000    0
 [3,]  0.356 0.350 1.000 0.000 0.000 0.000 0.000 0.000    0
 [4,] -0.098 0.072 0.380 1.000 0.000 0.000 0.000 0.000    0
 [5,]  0.573 0.408 0.382 0.062 1.000 0.000 0.000 0.000    0
 [6,]  0.156 0.232 0.517 0.424 0.303 1.000 0.000 0.000    0
 [7,]  0.400 0.414 0.611 0.320 0.401 0.479 1.000 0.000    0
 [8,]  0.282 0.375 0.512 0.346 0.308 0.463 0.605 1.000    0
 [9,]  0.519 0.484 0.467 0.167 0.455 0.311 0.574 0.557    1
> m[upper.tri(m,diag=TRUE)] <- x  # 対称行列が欲しければ更に
> m
        [,1]  [,2]  [,3]   [,4]  [,5]  [,6]  [,7]  [,8]  [,9]
 [1,]  1.000 0.591 0.356 -0.098 0.573 0.156 0.400 0.282 0.519
 [2,]  0.591 1.000 0.350  0.072 0.408 0.232 0.414 0.375 0.484
 [3,]  0.356 0.350 1.000  0.380 0.382 0.517 0.611 0.512 0.467
 [4,] -0.098 0.072 0.380  1.000 0.062 0.424 0.320 0.346 0.167
 [5,]  0.573 0.408 0.382  0.062 1.000 0.303 0.401 0.308 0.455
 [6,]  0.156 0.232 0.517  0.424 0.303 1.000 0.479 0.463 0.311
 [7,]  0.400 0.414 0.611  0.320 0.401 0.479 1.000 0.605 0.574
 [8,]  0.282 0.375 0.512  0.346 0.308 0.463 0.605 1.000 0.557
 [9,]  0.519 0.484 0.467  0.167 0.455 0.311 0.574 0.557 1.000

read.fwf() 関数の skip が変(R2.0.0 のバグ。R2.0.1 で fix の予定)

なぜ? (2004-11-04 (木) 10:02:50)

「一行の各欄の桁数を指定して読み込む、 read.fwf() 関数」の通りにやってみたんですが、

> x <- read.fwf("test.txt", width=c(2,2,3), skip=1, n=4)

だと反応が返ってきません。

> x <- read.fwf("test.txt", width=c(2,2,3), skip=1)

とすると、x の内容は

> x
  V1 V2  V3
1  1 23 456
2 12 34   5

です。コメント行を無視してさらに1行読み飛ばしているので、これはこれでいいような気もしますが、

> x <- read.fwf("test.txt", width=c(2,2,3), skip=2)

だと、下のようなエラーが返ってきてしまいます。

Error in read.table(file = FILE, header = header, sep = sep, as.is = as.is,  : 
       no lines available in input

どうも、skip で指定した数の2倍にあたる行数を読み飛ばしているようなんですが、バグなんでしょうか?

日本語版 R2.0.0 を使っています。Win XP と Win ME で同じ症状でした。


一行の各欄の桁数を指定して読み込む、 read.fwf() 関数 (2004-10-25 (月) 09:32:21)


read.fwf (Read Fixed Width Format Files) 関数はファイルの各行の数値の桁数を指定してデータフレームとして読み込む。総桁数以上は無視されるので、例えば行末にコメントを置いておくこともできる。指定桁数が 0 だったり、該当欄がすべて半角空白だと NA 値が置かれる。

テスト用テキストファイル test.txt (最初と最後にコメント行、各行の最後にコメント)

# comment 1
1234567   # comment 2
1 234567  # comment 3
12345  67 # comment 4
# comment 5


冒頭の一行を無視し、総計 4 (1+3) 行を読み込む。欄の桁数は 2,2,3 とする。

> x <- read.fwf("test.txt", width=c(2,2,3), skip=1, n=4)
> x
  V1 V2  V3
1 12 34 567
2  1 23 456
3 12 34   5

該当する欄が半角空白のみの時は NA とされる

> x <- read.fwf("test.txt", width=c(2,1,2,2), skip=1, n=4)
> x
  V1 V2 V3 V4
1 12  3 45 67
2  1  2 34 56
3 12  3 45 NA

欄桁数 0 は NA 値とされる

> x <- read.fwf("test.txt", width=c(2,0,2,2), skip=1, n=4)
> x
  V1 V2 V3 V4
1 12 NA 34 56
2  1 NA 23 45
3 12 NA 34  5

行名、列名ラベルを付ける例

> x <- read.fwf("test.txt", width=c(2,2,3), skip=1, n=4, 
                row.names=c("case1","case2","case3"))
> x
      V1 V2  V3
case1 12 34 567
case2  1 23 456
case3 12 34   5
> x <- read.fwf("test.txt", width=c(2,2,3), skip=1, n=4,
                row.names=c("case1","case2","case3"),
                col.names=c("A","B","C"))
> x
       A  B   C
case1 12 34 567
case2  1 23 456
case3 12 34   5

数値以外の文字が入っていても良いが、文字ではなく、因子と解釈される

# comment 1
AB123456  # comment 2
HI1 23456 # comment 3
ab 987654 # comment 4
# comment 5
> x <- read.fwf("test.txt", width=c(2,2,2), skip=1, n=4)
> x
  V1 V2 V3
1 AB 12 34
2 HI  1 23
3 ab  9 87
> str(x)
`data.frame':   3 obs. of  3 variables:
 $ V1: Factor w/ 3 levels "AB","HI","ab": 1 2 3
 $ V2: num  12 1 9
 $ V3: int  34 23 87

xls 形式のファイルをデータフレームとして読み込む (gregmisc パッケージ中の read.xls() 関数)

(2004-10-13 (水) 16:21:00)

gregmisc パッケージ中の read.xls() 関数は MS Excel の xls ファイルをデータフレームとして読み込む。file.path() 関数の使用例にも注意。

> library(gregmisc)        # gregmisc パッケージを読み込む 
> library(help=gregmisc)   # gregmisc パッケージ中のオブジェクト一覧
> ?read.xls                # read.xls() 関数のヘルプ表示
read.xls              package:gregmisc              R Documentation
Read Excel files
Description:
    Reads a Microsoft Excel file into a data frame
Usage:
    read.xls(xls, sheet=1, verbose=FALSE, ...)
Arguments:
    xls: name of the Microsoft Excel file
  sheet: number of sheet within the Excel file from which data are to
         be read
verbose: logical flag idicating whether details should be printed as
         the file is processed.
    ...: additional arguments to read.table. The defaults of read.csv
         are used.
Details:
    This function works translating the named Microsoft Excel file
    into a temporary .csv file, using Greg Warnes' xls2csv perl script
    (installed as part of the gregmisc package).
    Note that, in the conversion to csv, strings will be quoted. This
    is a problem if you are trying to use the 'comment.char' option of
    'read.table' since the first character of all lines (including
    comment lines) will be "?"" after conversion.
Value:
    a data frame
> example(read.xls)        # その実行例

rd.xls> xlsfile <- file.path(.path.package("gregmisc"), "xls", 
   "iris.xls")             # 例示用 xls ファイル "iris.xls" のパス検索
rd.xls> xlsfile            # 結果
[1] "/usr/local/lib/R/site-library/gregmisc/xls/iris.xls"
rd.xls> iris <- read.xls(xlsfile)  # iris.xls ファイルを読み込む
rd.xls> head(iris)         # データフレームの先頭 6 行を表示 
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species       X
1            1         5.1          3.5         1.4     0.2 setosa 
2            2         4.9          3.0         1.4     0.2 setosa 
3            3         4.7          3.2         1.3     0.2 setosa 
4            4         4.6          3.1         1.5     0.2 setosa 
5            5         5.0          3.6         1.4     0.2 setosa 
6            6         5.4          3.9         1.7     0.4 setosa 
> library(RODBC)         
> z <- odbcConnectExcel("c:??mydata.xls")   
> myframe <- sqlFetch(z, "mysheet1")   
> close(z)  


ワーキングディレクトリ中のファイルを、ファイル名を指定して確認 file.choose()

読み込むべきファイルのパス付きの正確な名前を知ることが困難な場合がある(特に MS Windows?) 。file.choose() 関数はファイル名を入力し、パス付きのファイル名をインタラクティブに得る関数である。一括して列挙するには list.files() 関数を使う。source(file.choose()) といった使い方もできますね。-- (2004-10-12 (火) 18:37:06)

John Fox <jfox <at> mcmaster.ca> writes:~ 
>> You got several useful suggestions for what you may have done wrong. I often~
>> find that it's easier to use read.table(file.choose()) and to navigate to~
>> the file in the resulting dialog than to type the path to the file.~

Related to this, you could issue the command exactly as shown without~
any arguments at all:~

 file.choose()

from the R console, navigate to the correct file and it will return the~
correct text representation of the filename to use in your read.table.~
For example, below I navigated to the AUTHORS file in the rw1091~
R distribution:~

  R> file.choose()
  [1] "C:??Program Files??R??rw1091??AUTHORS"

This should help you decipher whether you got the path wrong, the filename~
wrong, etc.~



欄数が行毎に不揃いなファイルを読み込む read.delim()

read.table() 関数の変種の read.delim() 関数は(既定では)タブで区切られた、欄が行毎に不揃いのファイルを適正に読み込むのに使える。該当欄が欠損している時は、NA 値が補われる。

r-help, Petr Pikal, 2004.10.12
~
On 11 Oct 2004 at 11:45, wfang wrote:
>> Hi,
>>    I tried to read some unbalance data (with different number if rows)
>> using x<- read.table("filename", header = true) command, but the
>> program refuses to read the table. Could you tell me why this is

Hallo
Your OS, your R version is missing, but having this:

a	b	d	e   
1	1	1	1
2	2	2	2
3		3	3
4		4	
5		5	
		6	

read.delim("clipboard")

produces

> mydata<-read.delim("clipboard")

   a  b d  e
1  1  1 1  1
2  2  2 2  2
3  3 NA 3  3
4  4 NA 4 NA
5  5 NA 5 NA
6 NA NA 6 NA

so it ***do not refuse*** to read the data. I do not expect some 
dwarf climbs out from your computer and says he will not read 
your data. Or is he? 

?read.table 

gives you more details about how to read some data.


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-03-25 (土) 11:19:17