ファイルを読み込む tips 集(暫定版)
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
SIZE(18){COLOR(red){R にファイルを読み込む tips 集(暫定版...
~
~
R にファイルを読み込むのに苦労されるケースが多いようです...
サイズ・書式が様々なこと、OS、ユーザインタフェイスの違い...
~
一度にまとめるのも大変とおもわれますから、以下には主に r-...
~
#contents
~
#article
** sas7bdat ファイルを読み込む、2011.08.22 [#d9d559f1]
-[[Really useful R package: sas7bdat:http://sas-and-r.blo...
** 複数のファイルを読み込み、コード中で生成したオブジェク...
ファイル X00Y00.txt, X01Y00.txt, X00Y01.txt, X01Y01.txt (...
> for (i in 0:1) {
if (i < 10) I <- paste("0",i,sep="") else I <- as.c...
for (j in 0:1) {
if (j < 10) J <- paste("0",j,sep="") else J <- a...
oname <- paste("X",I,"Y",J, sep="") # 文字列 "X00...
fname <- paste(oname, ".txt", sep="") # ファイル...
x <- read.table(fname) # ファイルを読み込み
colnames(x) <- c(paste("X_",oname,sep=""), paste(...
assign(oname, x) # 文字列 oname を名前に持ち、中...
}
}
> 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) # 文字列 "X00Y0...
x <- read.table(sprintf("%s.txt", oname)) # ファイル...
colnames(x) <- c(sprintf("X_%s",oname), sprintf("I_%...
assign(oname, x) # 文字列 oname を名前に持ち、中身が...
}
}
** 現在の作業環境をファイルにセーブし、それを次回に復元す...
R を q() 関数で終了する際、yes と答えると現在の作業環境(i...
save.image(file = ".RData", version = NULL, ascii = FALSE,
compress = FALSE, safe = TRUE)
オプションでアスキーセーブ、圧縮ファイルにすることもでき...
'save.image()' は単に 'save(list = ls(all=TRUE), file = "...
save.image(file=".Rdata.20050127")
等とする。次回の R セッションをちょうどこの環境で始めたけ...
R --no-restore
と開始し(詳しくは help(Startup) 参照)、次に命令
load(".Rdata.20050127")
を実行する。
** R オブジェクトを Excel ファイルに落し、それを Excel で...
私は MSW を使いませんから、実際に試してはいません。 R オ...
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?OFF...
tmpfilename ), wait=FALSE);
# Excel がファイルを開く前に、R が一時ファイル名オブ...
Sys.sleep(5);
unlink(tmpfilename) # 一時ファイル名オブジェクトを消す
}
** 複数のファイルを一括してデータフレームのリストに読み込...
次のような内容のデータファイル 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
}
} else {
function (s) gsub("([][)(}{'?";&! ?t?n])", "????...
}
wc <- function (s) {
r <- scan(pipe(paste("wc <", for.system(s)), open="r...
names(r) <- c("lines", "words", "chars")
r
}
> wc("Foo Bar") # ファイル名中に空白がある例
lines words chars # 集計結果
3 6 12
> wc("Drunkard's Walk")["chars"] # ファイル名中の特殊文字
chars
3633
- 「for.system の定義構文はびっくり、こんなのあり?」って...
a <- if (logical) 1 else 2 # なんてのと同じですから。
b <- (if (logical2) sin else cos)(1.23) # なんてのもあり...
**データのセーブとロード [#w6d7bf9f]
>[[MKR]] (2004-11-29 (月) 17:15:41)~
~
データをファイルにセーブする save() 関数は既定では "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,...
[1] 62.62 0.62 63.27 0.00 0.00~
[1] TRUE
> rm(xxx); gc(); system.time(load("x.xdr")); identical(x...
[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%、アスキーファ...
//
#comment
**アドオンパッケージ foreign を使って外部システムファイル...
>[[MKR]] (2004-11-20 (土) 06:46:35)~
~
他頁より転載。アドオンパッケージ foreign には他システムの...
~
COLOR(red){foreign}(Minitab, S, SAS, SPSS, Stata, ... で...
~
|項目| 説明 |
|lookup.xport| SAS XPORT 形式ライブラリーのルック...
|S3 read functions | S3 バイナリ・ファイルの読み込み|
|read.dta| Stata バイナリ・ファイルの読み...
|read.epiinfo| Epi Info データ・ファイルの読み...
|read.mtp| Minitab ポータブル・ワークシー...
|read.spss | SPSS データ・ファイルの読み込み|
|read.ssd| SAS permanent dataset, via read...
|read.xport| SAS XPORT 形式ライブラリーの読...
|write.dta| Stata バイナリ形式ファイルへの...
//
#comment
**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 im...
tabular form. In the sense, direct usage of read.table...
>>Thanks
Hi Gauri:
There are several ways of doing that. Easiest in my opin...
SPSS data into "txt", or "csv" file and read it directly...
read.table() function to read the txt or csv data. See ?...
information, or read the data input output section of th...
second way is to use library(foreign) and then read the ...
read.spss. For more information, do library(foreign) and...
Hope this helps,
Arin Basu
//
-後半に書かれている方法を勧めます。普通に保存したファイル...
> library(foreign)
> d <- read.spss("spss-data.sav", use.value.labels=TRUE,...
> d
Sex X1 Class
1 1 2.1 a
2 2 3.4 b
3 1 4.2 c
4 2 1.5 b
5 1 4.2 c
6 1 5.4 c
7 1 5.7 b
8 2 6.5 c
9 1 2.3 a
10 2 4.1 c
ほかのソフトとのインポート・エクスポートは[[foreign(Minit...
[[S-plus/R Function Finder:http://biostat.mc.vanderbilt.e...
#comment
** Excel からコピーしたセル範囲を R に読み込む (何でも掲...
エクセルのセル範囲を R に読み込むために,今まではわざわざ...
from.excel <- function(nc)
{
matrix(scan(""), byrow=TRUE, nc=nc)
}
エクセルで必要な部分をコピーします。
x <- from.excel(2)
などとして,プロンプトが出たらペーストします。
入力の終わりはMacintoshだとcommand+.
汎用関数にする価値もないのでこのまま。
- ?scan によれば Linux だと CTRL+D, MS Windows では CTRL+...
- Windows だと,入力元として"clipboard"が使えると,中澤さ...
- 船尾さんの http://cwoweb2.bai.ne.jp/%7ejgb11101/files/I...
ヘッダーを含めて範囲を指定してコピーし,コンソールに以下...
> x <- read.delim(stdin(), header=TRUE) # 入力元に stdin...
0: x y z 0: が表示されたらペースト
1: 1 1 1
2: 2 1.414213562 4
3: 3 1.732050808 9
4: 4 2 16
5: 5 2.236067977 25
6: 入力が尽きたら,リター...
> x
x y z データフレームの出来上...
1 1 1.000000 1
2 2 1.414214 4
3 3 1.732051 9
4 4 2.000000 16
5 5 2.236068 25
- Linux でも同様の方法が使えるかと試してみましたが、どう...
> x <- read.table(file("clipboard"), header=TRUE) # cli...
> x # 勝...
R1 R2 R3
C1 A 1 1.2
C2 B 2 2.5
C3 C 3 -0.9
> y <- read.table(file("stdin"), header=TRUE) # pas...
> y
R1 R2 R3
C1 A 1 1.2
C2 B 2 2.5
C3 C 3 -0.9
> matrix(scan(file("stdin")), 3,3, byrow=TRUE)
1 1.2 0
2 2.5 1
3 -0.9 1 # pas...
Read 9 items
[,1] [,2] [,3]
[1,] 1 1.2 0
[2,] 2 2.5 1
[3,] 3 -0.9 1
> matrix(scan(file("clipboard")), 3,3, byrow=TRUE) # cli...
Read 9 items
[,1] [,2] [,3]
[1,] 1 1.2 0
[2,] 2 2.5 1
[3,] 3 -0.9 1
- Mac OS X だと read.table(pipe("pbpaste")) でいいんで...
#comment
**上(下)三角行列としてファイルを読み込む (from r-help, 20...
> (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 ...
> x <- scan("data.txt")
Read 45 items
> x
[1] 1.000 0.591 1.000 0.356 0.350 1.000 -0.098 0...
[11] 0.573 0.408 0.382 0.062 1.000 0.156 0.232 0...
[21] 1.000 0.400 0.414 0.611 0.320 0.401 0.479 1...
[31] 0.512 0.346 0.308 0.463 0.605 1.000 0.519 0...
[41] 0.455 0.311 0.574 0.557 1.000
> y <- data.matrix(read.table("data.txt", fill = TRUE, c...
> 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,d...
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [...
[1,] 1 0.591 0.356 -0.098 0.573 0.156 0.400 0.282 0....
[2,] 0 1.000 0.350 0.072 0.408 0.232 0.414 0.375 0....
[3,] 0 0.000 1.000 0.380 0.382 0.517 0.611 0.512 0....
[4,] 0 0.000 0.000 1.000 0.062 0.424 0.320 0.346 0....
[5,] 0 0.000 0.000 0.000 1.000 0.303 0.401 0.308 0....
[6,] 0 0.000 0.000 0.000 0.000 1.000 0.479 0.463 0....
[7,] 0 0.000 0.000 0.000 0.000 0.000 1.000 0.605 0....
[8,] 0 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0....
[9,] 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1....
> m <- t(m) # 下三角行列にするには転置する
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [...
[1,] 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ...
[2,] 0.591 1.000 0.000 0.000 0.000 0.000 0.000 0.000 ...
[3,] 0.356 0.350 1.000 0.000 0.000 0.000 0.000 0.000 ...
[4,] -0.098 0.072 0.380 1.000 0.000 0.000 0.000 0.000 ...
[5,] 0.573 0.408 0.382 0.062 1.000 0.000 0.000 0.000 ...
[6,] 0.156 0.232 0.517 0.424 0.303 1.000 0.000 0.000 ...
[7,] 0.400 0.414 0.611 0.320 0.401 0.479 1.000 0.000 ...
[8,] 0.282 0.375 0.512 0.346 0.308 0.463 0.605 1.000 ...
[9,] 0.519 0.484 0.467 0.167 0.455 0.311 0.574 0.557 ...
> m[upper.tri(m,diag=TRUE)] <- x # 対称行列が欲しければ...
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] ...
[1,] 1.000 0.591 0.356 -0.098 0.573 0.156 0.400 0.282 ...
[2,] 0.591 1.000 0.350 0.072 0.408 0.232 0.414 0.375 ...
[3,] 0.356 0.350 1.000 0.380 0.382 0.517 0.611 0.512 ...
[4,] -0.098 0.072 0.380 1.000 0.062 0.424 0.320 0.346 ...
[5,] 0.573 0.408 0.382 0.062 1.000 0.303 0.401 0.308 ...
[6,] 0.156 0.232 0.517 0.424 0.303 1.000 0.479 0.463 ...
[7,] 0.400 0.414 0.611 0.320 0.401 0.479 1.000 0.605 ...
[8,] 0.282 0.375 0.512 0.346 0.308 0.463 0.605 1.000 ...
[9,] 0.519 0.484 0.467 0.167 0.455 0.311 0.574 0.557 ...
//
- 読み込みだけならread.table("data.txt",sep=" ",fill=T)で...
#comment
**read.fwf() 関数の skip が変(R2.0.0 のバグ。R2.0.1 で fi...
>[[なぜ?]] (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 = ...
no lines available in input
どうも、skip で指定した数の2倍にあたる行数を読み飛ばして...
日本語版 R2.0.0 を使っています。Win XP と Win ME で同じ症...
//
-気づくのが遅くなりましたが、元記事は R 1.9 で確認したも...
-read.fwfの最後(テンポラリから取込)のread.tableのskip=ski...
-どうも n 引数を与えるとエンドレスループに入ってしまうよ...
-さっきバグレポートしたと思ったら、すでに r-help に R 教...
-「元記事者」って私のこと?ひぇぇ!英作文、どうしよう!?...
-R 2.0.1 でフィックスされる(もしくはすでにフィックスされ...
-おいしい所を奪われた模様ですよ>なぜ?さん:-) -- [[なか...
r31818 | ripley | 2004-11-08 17:36:54 +0900 (Mon, 08 Nov...
Changed paths:
M /branches/R-2-0-patches/NEWS
M /branches/R-2-0-patches/src/library/utils/R/read.fw...
M /branches/R-2-0-patches/tests/reg-tests-2.R
M /branches/R-2-0-patches/tests/reg-tests-2.Rout.save
port r31817 (fix PR#7350) from trunk
--------------------------------------------------------...
r31817 | ripley | 2004-11-08 17:34:29 +0900 (Mon, 08 Nov...
Changed paths:
M /trunk/NEWS
M /trunk/src/library/utils/R/read.fwf.R
M /trunk/tests/reg-tests-2.R
M /trunk/tests/reg-tests-2.Rout.save
fix PR#7350
formatting issues in read.fwf
-う〜ん、残念!などと言ってみたりして。早速 fix されるよ...
-[[日本産バグレポート:http://r-bugs.biostat.ku.dk/cgi-bin...
-本当ですね。ここにもスパムメールがたくさん届いているよう...
-いまごろ気づきましたが、私のところに外国から大量のスパム...
-spamは今年の春くらいから爆発的に増えたようです.ウイルス,...
#comment
**一行の各欄の桁数を指定して読み込む、 read.fwf() 関数 (2...
~
read.fwf (Read Fixed Width Format Files) 関数はファイルの...
テスト用テキストファイル test.txt (最初と最後にコメント行...
# comment 1
1234567 # comment 2
1 234567 # comment 3
12345 67 # comment 4
# comment 5
~
冒頭の一行を無視し、総計 4 (1+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
//
#comment
**xls 形式のファイルをデータフレームとして読み込む (gregm...
> (2004-10-13 (水) 16:21:00)~
~
gregmisc パッケージ中の read.xls() 関数は MS Excel の xls...
> library(gregmisc) # gregmisc パッケージを読み込...
> library(help=gregmisc) # gregmisc パッケージ中のオブ...
> ?read.xls # read.xls() 関数のヘルプ表示
read.xls package:gregmisc R Do...
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 whic...
be read
verbose: logical flag idicating whether details should b...
the file is processed.
...: additional arguments to read.table. The default...
are used.
Details:
This function works translating the named Microsoft ...
into a temporary .csv file, using Greg Warnes' xls2c...
(installed as part of the gregmisc package).
Note that, in the conversion to csv, strings will be...
is a problem if you are trying to use the 'comment.c...
'read.table' since the first character of all lines ...
comment lines) will be "?"" after conversion.
Value:
a data frame
> example(read.xls) # その実行例
rd.xls> xlsfile <- file.path(.path.package("gregmisc"), ...
"iris.xls") # 例示用 xls ファイル "iris.x...
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 Spec...
1 1 5.1 3.5 1.4 ...
2 2 4.9 3.0 1.4 ...
3 3 4.7 3.2 1.3 ...
4 4 4.6 3.1 1.5 ...
5 5 5.0 3.6 1.4 ...
6 6 5.4 3.9 1.7 ...
//
-FmtJapan2を使えるようにすれば日本語ExcelもUnix上で直接読...
-パッケージ RODBC を使っても読めるらしい-- &new{2004-10-...
> library(RODBC)
> z <- odbcConnectExcel("c:??mydata.xls")
> myframe <- sqlFetch(z, "mysheet1")
> close(z)
#comment
~
**ワーキングディレクトリ中のファイルを、ファイル名を指定...
読み込むべきファイルのパス付きの正確な名前を知ることが困...
~
John Fox <jfox <at> mcmaster.ca> writes:~
>> You got several useful suggestions for what you may h...
>> find that it's easier to use read.table(file.choose()...
>> the file in the resulting dialog than to type the pat...
Related to this, you could issue the command exactly as ...
any arguments at all:~
file.choose()
from the R console, navigate to the correct file and it ...
correct text representation of the filename to use in yo...
For example, below I navigated to the AUTHORS file in th...
R distribution:~
R> file.choose()
[1] "C:??Program Files??R??rw1091??AUTHORS"
This should help you decipher whether you got the path w...
wrong, etc.~
//
#comment
~
~
**欄数が行毎に不揃いなファイルを読み込む read.delim() [#j...
read.table() 関数の変種の read.delim() 関数は(既定では)...
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 differen...
>> using x<- read.table("filename", header = true) comma...
>> program refuses to read the table. Could you tell me ...
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 exp...
dwarf climbs out from your computer and says he will not...
your data. Or is he?
?read.table
gives you more details about how to read some data.
#comment
終了行:
SIZE(18){COLOR(red){R にファイルを読み込む tips 集(暫定版...
~
~
R にファイルを読み込むのに苦労されるケースが多いようです...
サイズ・書式が様々なこと、OS、ユーザインタフェイスの違い...
~
一度にまとめるのも大変とおもわれますから、以下には主に r-...
~
#contents
~
#article
** sas7bdat ファイルを読み込む、2011.08.22 [#d9d559f1]
-[[Really useful R package: sas7bdat:http://sas-and-r.blo...
** 複数のファイルを読み込み、コード中で生成したオブジェク...
ファイル X00Y00.txt, X01Y00.txt, X00Y01.txt, X01Y01.txt (...
> for (i in 0:1) {
if (i < 10) I <- paste("0",i,sep="") else I <- as.c...
for (j in 0:1) {
if (j < 10) J <- paste("0",j,sep="") else J <- a...
oname <- paste("X",I,"Y",J, sep="") # 文字列 "X00...
fname <- paste(oname, ".txt", sep="") # ファイル...
x <- read.table(fname) # ファイルを読み込み
colnames(x) <- c(paste("X_",oname,sep=""), paste(...
assign(oname, x) # 文字列 oname を名前に持ち、中...
}
}
> 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) # 文字列 "X00Y0...
x <- read.table(sprintf("%s.txt", oname)) # ファイル...
colnames(x) <- c(sprintf("X_%s",oname), sprintf("I_%...
assign(oname, x) # 文字列 oname を名前に持ち、中身が...
}
}
** 現在の作業環境をファイルにセーブし、それを次回に復元す...
R を q() 関数で終了する際、yes と答えると現在の作業環境(i...
save.image(file = ".RData", version = NULL, ascii = FALSE,
compress = FALSE, safe = TRUE)
オプションでアスキーセーブ、圧縮ファイルにすることもでき...
'save.image()' は単に 'save(list = ls(all=TRUE), file = "...
save.image(file=".Rdata.20050127")
等とする。次回の R セッションをちょうどこの環境で始めたけ...
R --no-restore
と開始し(詳しくは help(Startup) 参照)、次に命令
load(".Rdata.20050127")
を実行する。
** R オブジェクトを Excel ファイルに落し、それを Excel で...
私は MSW を使いませんから、実際に試してはいません。 R オ...
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?OFF...
tmpfilename ), wait=FALSE);
# Excel がファイルを開く前に、R が一時ファイル名オブ...
Sys.sleep(5);
unlink(tmpfilename) # 一時ファイル名オブジェクトを消す
}
** 複数のファイルを一括してデータフレームのリストに読み込...
次のような内容のデータファイル 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
}
} else {
function (s) gsub("([][)(}{'?";&! ?t?n])", "????...
}
wc <- function (s) {
r <- scan(pipe(paste("wc <", for.system(s)), open="r...
names(r) <- c("lines", "words", "chars")
r
}
> wc("Foo Bar") # ファイル名中に空白がある例
lines words chars # 集計結果
3 6 12
> wc("Drunkard's Walk")["chars"] # ファイル名中の特殊文字
chars
3633
- 「for.system の定義構文はびっくり、こんなのあり?」って...
a <- if (logical) 1 else 2 # なんてのと同じですから。
b <- (if (logical2) sin else cos)(1.23) # なんてのもあり...
**データのセーブとロード [#w6d7bf9f]
>[[MKR]] (2004-11-29 (月) 17:15:41)~
~
データをファイルにセーブする save() 関数は既定では "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,...
[1] 62.62 0.62 63.27 0.00 0.00~
[1] TRUE
> rm(xxx); gc(); system.time(load("x.xdr")); identical(x...
[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%、アスキーファ...
//
#comment
**アドオンパッケージ foreign を使って外部システムファイル...
>[[MKR]] (2004-11-20 (土) 06:46:35)~
~
他頁より転載。アドオンパッケージ foreign には他システムの...
~
COLOR(red){foreign}(Minitab, S, SAS, SPSS, Stata, ... で...
~
|項目| 説明 |
|lookup.xport| SAS XPORT 形式ライブラリーのルック...
|S3 read functions | S3 バイナリ・ファイルの読み込み|
|read.dta| Stata バイナリ・ファイルの読み...
|read.epiinfo| Epi Info データ・ファイルの読み...
|read.mtp| Minitab ポータブル・ワークシー...
|read.spss | SPSS データ・ファイルの読み込み|
|read.ssd| SAS permanent dataset, via read...
|read.xport| SAS XPORT 形式ライブラリーの読...
|write.dta| Stata バイナリ形式ファイルへの...
//
#comment
**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 im...
tabular form. In the sense, direct usage of read.table...
>>Thanks
Hi Gauri:
There are several ways of doing that. Easiest in my opin...
SPSS data into "txt", or "csv" file and read it directly...
read.table() function to read the txt or csv data. See ?...
information, or read the data input output section of th...
second way is to use library(foreign) and then read the ...
read.spss. For more information, do library(foreign) and...
Hope this helps,
Arin Basu
//
-後半に書かれている方法を勧めます。普通に保存したファイル...
> library(foreign)
> d <- read.spss("spss-data.sav", use.value.labels=TRUE,...
> d
Sex X1 Class
1 1 2.1 a
2 2 3.4 b
3 1 4.2 c
4 2 1.5 b
5 1 4.2 c
6 1 5.4 c
7 1 5.7 b
8 2 6.5 c
9 1 2.3 a
10 2 4.1 c
ほかのソフトとのインポート・エクスポートは[[foreign(Minit...
[[S-plus/R Function Finder:http://biostat.mc.vanderbilt.e...
#comment
** Excel からコピーしたセル範囲を R に読み込む (何でも掲...
エクセルのセル範囲を R に読み込むために,今まではわざわざ...
from.excel <- function(nc)
{
matrix(scan(""), byrow=TRUE, nc=nc)
}
エクセルで必要な部分をコピーします。
x <- from.excel(2)
などとして,プロンプトが出たらペーストします。
入力の終わりはMacintoshだとcommand+.
汎用関数にする価値もないのでこのまま。
- ?scan によれば Linux だと CTRL+D, MS Windows では CTRL+...
- Windows だと,入力元として"clipboard"が使えると,中澤さ...
- 船尾さんの http://cwoweb2.bai.ne.jp/%7ejgb11101/files/I...
ヘッダーを含めて範囲を指定してコピーし,コンソールに以下...
> x <- read.delim(stdin(), header=TRUE) # 入力元に stdin...
0: x y z 0: が表示されたらペースト
1: 1 1 1
2: 2 1.414213562 4
3: 3 1.732050808 9
4: 4 2 16
5: 5 2.236067977 25
6: 入力が尽きたら,リター...
> x
x y z データフレームの出来上...
1 1 1.000000 1
2 2 1.414214 4
3 3 1.732051 9
4 4 2.000000 16
5 5 2.236068 25
- Linux でも同様の方法が使えるかと試してみましたが、どう...
> x <- read.table(file("clipboard"), header=TRUE) # cli...
> x # 勝...
R1 R2 R3
C1 A 1 1.2
C2 B 2 2.5
C3 C 3 -0.9
> y <- read.table(file("stdin"), header=TRUE) # pas...
> y
R1 R2 R3
C1 A 1 1.2
C2 B 2 2.5
C3 C 3 -0.9
> matrix(scan(file("stdin")), 3,3, byrow=TRUE)
1 1.2 0
2 2.5 1
3 -0.9 1 # pas...
Read 9 items
[,1] [,2] [,3]
[1,] 1 1.2 0
[2,] 2 2.5 1
[3,] 3 -0.9 1
> matrix(scan(file("clipboard")), 3,3, byrow=TRUE) # cli...
Read 9 items
[,1] [,2] [,3]
[1,] 1 1.2 0
[2,] 2 2.5 1
[3,] 3 -0.9 1
- Mac OS X だと read.table(pipe("pbpaste")) でいいんで...
#comment
**上(下)三角行列としてファイルを読み込む (from r-help, 20...
> (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 ...
> x <- scan("data.txt")
Read 45 items
> x
[1] 1.000 0.591 1.000 0.356 0.350 1.000 -0.098 0...
[11] 0.573 0.408 0.382 0.062 1.000 0.156 0.232 0...
[21] 1.000 0.400 0.414 0.611 0.320 0.401 0.479 1...
[31] 0.512 0.346 0.308 0.463 0.605 1.000 0.519 0...
[41] 0.455 0.311 0.574 0.557 1.000
> y <- data.matrix(read.table("data.txt", fill = TRUE, c...
> 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,d...
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [...
[1,] 1 0.591 0.356 -0.098 0.573 0.156 0.400 0.282 0....
[2,] 0 1.000 0.350 0.072 0.408 0.232 0.414 0.375 0....
[3,] 0 0.000 1.000 0.380 0.382 0.517 0.611 0.512 0....
[4,] 0 0.000 0.000 1.000 0.062 0.424 0.320 0.346 0....
[5,] 0 0.000 0.000 0.000 1.000 0.303 0.401 0.308 0....
[6,] 0 0.000 0.000 0.000 0.000 1.000 0.479 0.463 0....
[7,] 0 0.000 0.000 0.000 0.000 0.000 1.000 0.605 0....
[8,] 0 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0....
[9,] 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1....
> m <- t(m) # 下三角行列にするには転置する
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [...
[1,] 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ...
[2,] 0.591 1.000 0.000 0.000 0.000 0.000 0.000 0.000 ...
[3,] 0.356 0.350 1.000 0.000 0.000 0.000 0.000 0.000 ...
[4,] -0.098 0.072 0.380 1.000 0.000 0.000 0.000 0.000 ...
[5,] 0.573 0.408 0.382 0.062 1.000 0.000 0.000 0.000 ...
[6,] 0.156 0.232 0.517 0.424 0.303 1.000 0.000 0.000 ...
[7,] 0.400 0.414 0.611 0.320 0.401 0.479 1.000 0.000 ...
[8,] 0.282 0.375 0.512 0.346 0.308 0.463 0.605 1.000 ...
[9,] 0.519 0.484 0.467 0.167 0.455 0.311 0.574 0.557 ...
> m[upper.tri(m,diag=TRUE)] <- x # 対称行列が欲しければ...
> m
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] ...
[1,] 1.000 0.591 0.356 -0.098 0.573 0.156 0.400 0.282 ...
[2,] 0.591 1.000 0.350 0.072 0.408 0.232 0.414 0.375 ...
[3,] 0.356 0.350 1.000 0.380 0.382 0.517 0.611 0.512 ...
[4,] -0.098 0.072 0.380 1.000 0.062 0.424 0.320 0.346 ...
[5,] 0.573 0.408 0.382 0.062 1.000 0.303 0.401 0.308 ...
[6,] 0.156 0.232 0.517 0.424 0.303 1.000 0.479 0.463 ...
[7,] 0.400 0.414 0.611 0.320 0.401 0.479 1.000 0.605 ...
[8,] 0.282 0.375 0.512 0.346 0.308 0.463 0.605 1.000 ...
[9,] 0.519 0.484 0.467 0.167 0.455 0.311 0.574 0.557 ...
//
- 読み込みだけならread.table("data.txt",sep=" ",fill=T)で...
#comment
**read.fwf() 関数の skip が変(R2.0.0 のバグ。R2.0.1 で fi...
>[[なぜ?]] (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 = ...
no lines available in input
どうも、skip で指定した数の2倍にあたる行数を読み飛ばして...
日本語版 R2.0.0 を使っています。Win XP と Win ME で同じ症...
//
-気づくのが遅くなりましたが、元記事は R 1.9 で確認したも...
-read.fwfの最後(テンポラリから取込)のread.tableのskip=ski...
-どうも n 引数を与えるとエンドレスループに入ってしまうよ...
-さっきバグレポートしたと思ったら、すでに r-help に R 教...
-「元記事者」って私のこと?ひぇぇ!英作文、どうしよう!?...
-R 2.0.1 でフィックスされる(もしくはすでにフィックスされ...
-おいしい所を奪われた模様ですよ>なぜ?さん:-) -- [[なか...
r31818 | ripley | 2004-11-08 17:36:54 +0900 (Mon, 08 Nov...
Changed paths:
M /branches/R-2-0-patches/NEWS
M /branches/R-2-0-patches/src/library/utils/R/read.fw...
M /branches/R-2-0-patches/tests/reg-tests-2.R
M /branches/R-2-0-patches/tests/reg-tests-2.Rout.save
port r31817 (fix PR#7350) from trunk
--------------------------------------------------------...
r31817 | ripley | 2004-11-08 17:34:29 +0900 (Mon, 08 Nov...
Changed paths:
M /trunk/NEWS
M /trunk/src/library/utils/R/read.fwf.R
M /trunk/tests/reg-tests-2.R
M /trunk/tests/reg-tests-2.Rout.save
fix PR#7350
formatting issues in read.fwf
-う〜ん、残念!などと言ってみたりして。早速 fix されるよ...
-[[日本産バグレポート:http://r-bugs.biostat.ku.dk/cgi-bin...
-本当ですね。ここにもスパムメールがたくさん届いているよう...
-いまごろ気づきましたが、私のところに外国から大量のスパム...
-spamは今年の春くらいから爆発的に増えたようです.ウイルス,...
#comment
**一行の各欄の桁数を指定して読み込む、 read.fwf() 関数 (2...
~
read.fwf (Read Fixed Width Format Files) 関数はファイルの...
テスト用テキストファイル test.txt (最初と最後にコメント行...
# comment 1
1234567 # comment 2
1 234567 # comment 3
12345 67 # comment 4
# comment 5
~
冒頭の一行を無視し、総計 4 (1+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
//
#comment
**xls 形式のファイルをデータフレームとして読み込む (gregm...
> (2004-10-13 (水) 16:21:00)~
~
gregmisc パッケージ中の read.xls() 関数は MS Excel の xls...
> library(gregmisc) # gregmisc パッケージを読み込...
> library(help=gregmisc) # gregmisc パッケージ中のオブ...
> ?read.xls # read.xls() 関数のヘルプ表示
read.xls package:gregmisc R Do...
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 whic...
be read
verbose: logical flag idicating whether details should b...
the file is processed.
...: additional arguments to read.table. The default...
are used.
Details:
This function works translating the named Microsoft ...
into a temporary .csv file, using Greg Warnes' xls2c...
(installed as part of the gregmisc package).
Note that, in the conversion to csv, strings will be...
is a problem if you are trying to use the 'comment.c...
'read.table' since the first character of all lines ...
comment lines) will be "?"" after conversion.
Value:
a data frame
> example(read.xls) # その実行例
rd.xls> xlsfile <- file.path(.path.package("gregmisc"), ...
"iris.xls") # 例示用 xls ファイル "iris.x...
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 Spec...
1 1 5.1 3.5 1.4 ...
2 2 4.9 3.0 1.4 ...
3 3 4.7 3.2 1.3 ...
4 4 4.6 3.1 1.5 ...
5 5 5.0 3.6 1.4 ...
6 6 5.4 3.9 1.7 ...
//
-FmtJapan2を使えるようにすれば日本語ExcelもUnix上で直接読...
-パッケージ RODBC を使っても読めるらしい-- &new{2004-10-...
> library(RODBC)
> z <- odbcConnectExcel("c:??mydata.xls")
> myframe <- sqlFetch(z, "mysheet1")
> close(z)
#comment
~
**ワーキングディレクトリ中のファイルを、ファイル名を指定...
読み込むべきファイルのパス付きの正確な名前を知ることが困...
~
John Fox <jfox <at> mcmaster.ca> writes:~
>> You got several useful suggestions for what you may h...
>> find that it's easier to use read.table(file.choose()...
>> the file in the resulting dialog than to type the pat...
Related to this, you could issue the command exactly as ...
any arguments at all:~
file.choose()
from the R console, navigate to the correct file and it ...
correct text representation of the filename to use in yo...
For example, below I navigated to the AUTHORS file in th...
R distribution:~
R> file.choose()
[1] "C:??Program Files??R??rw1091??AUTHORS"
This should help you decipher whether you got the path w...
wrong, etc.~
//
#comment
~
~
**欄数が行毎に不揃いなファイルを読み込む read.delim() [#j...
read.table() 関数の変種の read.delim() 関数は(既定では)...
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 differen...
>> using x<- read.table("filename", header = true) comma...
>> program refuses to read the table. Could you tell me ...
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 exp...
dwarf climbs out from your computer and says he will not...
your data. Or is he?
?read.table
gives you more details about how to read some data.
#comment
ページ名: