由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - R data.frame
相关主题
包子答谢,一个txt file 转换成sas的问题怎么在EXCEL里把一个column的A/B分到两个column里?
一个用R 进行data preparation的问题请教个 SAS 读数据的问题
sas helpR问题
问个r问题请问我们平时在SAS里头那种data叫什么format的data呀?
R question Help.请教一道 R 的题目, 谢谢
求教 SAS base 123 Q 16大侠们:How to solve this EXPORT in SAS
Another SAS perl question请教一个关于R的问题
A SAS infile problem如何read multiple lines into one record in sas
相关话题的讨论汇总
话题: abcde话题: v1话题: delimiters话题: what话题: length
进入Statistics版参与讨论
1 (共1页)
f******9
发帖数: 267
1
When I input a file containing:
ABCDE
ABCDE
ABCDE
the row length is 1 from the R output.
Actually, there are 5 columns, so the row length should be 5. What should I
do to let R know the dimension of
this data.frame is (3,5) instead of (3,1)?
s*****n
发帖数: 2174
2
are there any field delimiters?
If there are no delimiters, R will treat these as string naturally.
f******9
发帖数: 267
3

There are not any field delimiters. How to let R treat them individually
instead of string?

【在 s*****n 的大作中提到】
: are there any field delimiters?
: If there are no delimiters, R will treat these as string naturally.

s*****n
发帖数: 2174
4
what you can do is to read them as a string into R, and then split the
string into each characters.
strsplit("ABCDE", split = "")
[[1]]
[1] "A" "B" "C" "D" "E"
f******9
发帖数: 267
5
If I use this command, all the rows will be connected together.
My file contains more than 100 such rows and how can I keep each row the
same length as the original. If [[1]]
doesn't exist in the output, that will be much easier.
Thanks!

【在 s*****n 的大作中提到】
: what you can do is to read them as a string into R, and then split the
: string into each characters.
: strsplit("ABCDE", split = "")
: [[1]]
: [1] "A" "B" "C" "D" "E"

s*****n
发帖数: 2174
6
I just give you a hint, of course you need to modify it to fit what you need
. for example
> data
V1
1 ABCDE
2 ABCDE
3 ABCDE
> t(sapply(1:dim(data)[1], function(i) unlist(strsplit(data$V1[i], split = "
"))))
[,1] [,2] [,3] [,4] [,5]
[1,] "A" "B" "C" "D" "E"
[2,] "A" "B" "C" "D" "E"
[3,] "A" "B" "C" "D" "E"
f******9
发帖数: 267
7
Thanks a lot!

need
"

【在 s*****n 的大作中提到】
: I just give you a hint, of course you need to modify it to fit what you need
: . for example
: > data
: V1
: 1 ABCDE
: 2 ABCDE
: 3 ABCDE
: > t(sapply(1:dim(data)[1], function(i) unlist(strsplit(data$V1[i], split = "
: "))))
: [,1] [,2] [,3] [,4] [,5]

t**i
发帖数: 688
8
read.table(...,sep="")

I

【在 f******9 的大作中提到】
: When I input a file containing:
: ABCDE
: ABCDE
: ABCDE
: the row length is 1 from the R output.
: Actually, there are 5 columns, so the row length should be 5. What should I
: do to let R know the dimension of
: this data.frame is (3,5) instead of (3,1)?

s*****n
发帖数: 2174
9
this doesn't work.
sep = "" 本来就是默认选项了.

【在 t**i 的大作中提到】
: read.table(...,sep="")
:
: I

c*****m
发帖数: 4817
10
if the width is fixed, then you can use read.fwf, for example
> data1 = read.fwf("M:/test.txt", widths=c(1,1,1,1,1))
> data1

V1 V2 V3 V4 V5
1 A B C D E
2 A B C D E
3 A B C D E

I

【在 f******9 的大作中提到】
: When I input a file containing:
: ABCDE
: ABCDE
: ABCDE
: the row length is 1 from the R output.
: Actually, there are 5 columns, so the row length should be 5. What should I
: do to let R know the dimension of
: this data.frame is (3,5) instead of (3,1)?

s*****n
发帖数: 2174
11
this is really nice. I didn't know this before.

【在 c*****m 的大作中提到】
: if the width is fixed, then you can use read.fwf, for example
: > data1 = read.fwf("M:/test.txt", widths=c(1,1,1,1,1))
: > data1
:
: V1 V2 V3 V4 V5
: 1 A B C D E
: 2 A B C D E
: 3 A B C D E
:
: I

1 (共1页)
进入Statistics版参与讨论
相关主题
如何read multiple lines into one record in sasR question Help.
问一下R的读取数据问题求教 SAS base 123 Q 16
请教一个R 的编程问题Another SAS perl question
[合集] excel并行一问,急~~~A SAS infile problem
包子答谢,一个txt file 转换成sas的问题怎么在EXCEL里把一个column的A/B分到两个column里?
一个用R 进行data preparation的问题请教个 SAS 读数据的问题
sas helpR问题
问个r问题请问我们平时在SAS里头那种data叫什么format的data呀?
相关话题的讨论汇总
话题: abcde话题: v1话题: delimiters话题: what话题: length