楼主: 遥一
11509 2

[问答] 新人求教R语言问题:names和vector不匹配问题。 [推广有奖]

  • 0关注
  • 0粉丝

学前班

80%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
33 点
帖子
2
精华
0
在线时间
3 小时
注册时间
2014-6-5
最后登录
2014-6-24

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
最近在学习Machine Learning for Hackers这本书。

在学习第四章。

我利用head截取了priority.train前六个来说明问题
   > head(priority.train)


                           Date             From.EMail                                      Subject
1003 2002-01-31 22:44:14  robinderbains@shaw.ca     please help a newbie compile mplayer :-)
1004 2002-02-01 00:53:41 lance_tt@bellsouth.net re: please help a newbie compile mplayer :-)
1005 2002-02-01 02:01:44  robinderbains@shaw.ca re: please help a newbie compile mplayer :-)
1006 2002-02-01 10:29:23      matthias@egwn.net re: please help a newbie compile mplayer :-)
1012 2002-02-01 12:42:02     bfrench@ematic.com                   prob. w/ install/uninstall
1014 2002-02-01 13:39:31     bfrench@ematic.com               re: prob. w/ install/uninstall



有priority.train数据集三个列Date,From.EMail, Subject.
然后我想做的是在在From.Email列中找到所有包含地址的行,并统计其数量
from.weight <- ddply(head(priority.train), .(From.EMail),summarise, Freq = length(Subject))
这个代码没问题。。。
然后它出现错误是,Error: 'names' attribute [11] must be the same length as the vector [2]
但names属性就3个。怎么来[11]


下面是我查看names
> names(head(priority.train))
[1] "Date"       "From.EMail" "Subject"   
> length(head(priority.train))
[1] 3



这个错误一直无法解决。。。。

二维码

扫码加我 拉你入群

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

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

关键词:Vector R语言问题 Names 新人求教 name please names

沙发
遥一 发表于 2014-6-6 10:49:10 |只看作者 |坛友微信交流群
自己顶。。。。。。。没人解决吗

使用道具

藤椅
麦兜vinci 发表于 2014-8-25 11:18:08 |只看作者 |坛友微信交流群

Problem solved

The problem is with the Date field, which is at this point a list that contains 9 fields (sec, min, hour, mday, mon, year, wday, yday, isdst). To solve the problem I've simply converted the dates into character vectors, used ddply then converted the dates back to Date:

> tmp <- priority.train$Date> priority.train$Date <- as.character(priority.train$Date)> from.weight <- ddply(priority.train, .(From.EMail), summarise, Freq = length(Subject))> priority.train$Date <- tmp> rm(tmp)

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-9-19 12:12