楼主: googlegood
5829 13

[问答] read.fwf() [推广有奖]

  • 3关注
  • 1粉丝

本科生

96%

还不是VIP/贵宾

-

威望
0
论坛币
15 个
通用积分
0
学术水平
0 点
热心指数
4 点
信用等级
0 点
经验
1212 点
帖子
109
精华
0
在线时间
69 小时
注册时间
2011-8-24
最后登录
2012-8-11

楼主
googlegood 发表于 2012-4-18 10:48:46 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
>mydata<-read.fwf("data.txt",widths=c(1,4,3))
警告信息:
In readLines(file, n = thisblock) : 读'data.txt'时最后一行未遂
The file data.txt exist in the directory which I set . I run this code , but error information appear. Who can tell me what's wrong with the code.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:READ EAD Data

沙发
googlegood 发表于 2012-4-18 10:49:37
The code comes from the book R for beginngers (Chinese Edition) .

藤椅
qoiqpwqr 发表于 2012-4-18 11:04:16
把数据data.txt附上来看看。

板凳
googlegood 发表于 2012-4-18 11:13:32
A1.501.2
A1.551.3
B1.601.4
B1.651.5
C1.701.6
C1.751.7
This is the data.txt.

报纸
qoiqpwqr 发表于 2012-4-18 11:15:38
googlegood 发表于 2012-4-18 11:13
This is the data.txt.
我用的一切正常
> mydata<-read.fwf("data.txt",widths=c(1,4,3))
> mydata
  V1   V2  V3
1  A 1.50 1.2
2  A 1.55 1.3
3  B 1.60 1.4
4  B 1.65 1.5
5  C 1.70 1.6
6  C 1.75 1.7

地板
googlegood 发表于 2012-4-18 11:27:08
qoiqpwqr 发表于 2012-4-18 11:15
我用的一切正常
> mydata mydata
  V1   V2  V3
I restart my R and try again , my R still tell me the error.
> mydata<-read.fwf("data.txt",widths=c(1,4,3))
警告信息:
In readLines(file, n = thisblock) : 读'data.txt'时最后一行未遂

7
googlegood 发表于 2012-4-18 11:49:23
qoiqpwqr 发表于 2012-4-18 11:15
我用的一切正常
> mydata mydata
  V1   V2  V3
111222333
111222555
000111333
555888999
I use another dat.txt file to try again , and succeed.
>  mydata<-read.fwf("dat.txt",widths=c(3,3,3))
> mydata
   V1  V2  V3
1 111 222 333
2 111 222 555
3   0 111 333
4 555 888 999
>  mydata<-read.fwf("dat.txt",widths=c(2,3,4))
> mydata
  V1  V2   V3
1 11 122 2333
2 11 122 2555
3  0  11 1333
4 55 588 8999

8
googlegood 发表于 2012-4-18 11:55:03
But I still don't understand the error when read the data.txt file.

9
qoiqpwqr 发表于 2012-4-18 11:59:08
googlegood 发表于 2012-4-18 11:55
But I still don't understand the error when read the data.txt file.
在最后一行加上一个回车试试看。
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
youngvitas + 1 + 1 + 1 热心帮助其他会员
yahoocom + 20 热心帮助其他会员

总评分: 论坛币 + 20  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

10
googlegood 发表于 2012-4-18 12:03:01
qoiqpwqr 发表于 2012-4-18 11:59
在最后一行加上一个回车试试看。
I succeed this time . Thanks ! You are a cowman !
>  mydata<-read.fwf("data.txt",widths=c(1,4,3))
> mydata
  V1   V2  V3
1  A 1.50 1.2
2  A 1.55 1.3
3  B 1.60 1.4
4  B 1.65 1.5
5  C 1.70 1.6
6  C 1.75 1.0

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-2 21:09