【发布时间】:2018-09-30 10:24:47
【问题描述】:
我想在不使用第三方包的情况下使用 R 在数据框中拆分以分号分隔的文本。
我有以下数据。
> #To view the first 6 rows of the data
> head(bank1)
age.job.marital.education.default.housing.loan.contact.month.day_of_week.duration.campaign.pdays.previous.poutcome.emp.var.rate.cons.price.idx.cons.conf.idx.euribor3m.nr.employed.y
1 56;housemaid;married;basic.4y;no;no;no;telephone;may;mon;261;1;999;0;nonexistent;1.1;93.994;-36.4;4.857;5191;no
2 57;services;married;high.school;unknown;no;no;telephone;may;mon;149;1;999;0;nonexistent;1.1;93.994;-36.4;4.857;5191;no
3 37;services;married;high.school;no;yes;no;telephone;may;mon;226;1;999;0;nonexistent;1.1;93.994;-36.4;4.857;5191;no
4 40;admin.;married;basic.6y;no;no;no;telephone;may;mon;151;1;999;0;nonexistent;1.1;93.994;-36.4;4.857;5191;no
5 56;services;married;high.school;no;no;yes;telephone;may;mon;307;1;999;0;nonexistent;1.1;93.994;-36.4;4.857;5191;no
6 45;services;married;basic.9y;unknown;no;no;telephone;may;mon;198;1;999;0;nonexistent;1.1;93.994;-36.4;4.857;5191;no
请帮助我根据标题中的列名将数据分成不同的列。
提前致谢。
【问题讨论】:
-
导入数据时,指定
;为字段分隔符。这是一个选择吗? -
欢迎来到 SO!您如何在 r 中导入数据?
read.csv?其他?如果您无法处理输入端口,您能否发布dput(head(bank1))的结果而不是head(bank1)?这将使您更容易在 R 中复制和粘贴数据。 -
@markus 我试过这样做。但是,标题由 . 分隔。而数据由 ; 分隔
-
@s_t 但是,我有近 45000 行。我很难复制粘贴每个数据,对吧?
-
@AradhyaMudigonda,你是对的,这就是为什么我建议你将
head()嵌套在dput()函数中。
标签: r dataframe split delimiter