楼主: fuyizhou
18432 22

[问答] integer(0)如何转换成数字0,急求!!! [推广有奖]

11
yywan0913 在职认证  发表于 2015-1-5 15:48:45
fuyizhou 发表于 2015-1-5 15:43
> x
[1] 101 102
sum(grep(x,recommendation[recommendation$user==2,]$item),)
pattern长度大于1  就不要用grep了,用which(recom大断%in%x)

12
fuyizhou 发表于 2015-1-5 15:55:53
yywan0913 发表于 2015-1-5 15:48
pattern长度大于1  就不要用grep了,用which(recom大断%in%x)
> recommendation
   user item  val
1     1  104 30.5
2     1  105 12.5
3     1  106  7.5
4     2  105 13.0
5     2  106  9.0
6     3  103 24.5
7     3  106 10.5
8     3  102  8.0
9     4  105 22.0
10    4  102 20.5
11    4  106 12.5
12    5  102 16.0
> testing
   user item pref
11    3  107    5
15    4  106    4
17    5  102    3
如何书写testing比如4 106这一项recommendation中user=4的排序
(答案是3)

实在新手,求助,感激不尽!

13
yywan0913 在职认证  发表于 2015-1-5 16:09:34
fuyizhou 发表于 2015-1-5 15:55
> recommendation
   user item  val
1     1  104 30.5
  1. attach(recommendation)
  2. with(subset(recommendation[user==4,]),which(item==106))
复制代码

14
fuyizhou 发表于 2015-1-6 16:52:45
yywan0913 发表于 2015-1-5 16:09
我的程序中有这一句话:
each_xulie=sapply(unique(m[,1]),function(x) sum(with(subset(recommendation[user==x,]),which(item==(subset(m,m[,1]==x&m[,2]==m[,4])$item.x))))/sum(recommendation[,1]==x))
然后有时候(subset(recommendation[user==x,]),which(item==(subset(m,m[,1]==x&m[,2]==m[,4])$item.x))中的后面item的值可能有两个或者更多,这样r中默认就算了一个,请问如何处理呢?

15
fuyizhou 发表于 2015-1-6 17:14:44
yywan0913 发表于 2015-1-5 16:09
如果item中的值是一个集合,要一个个验证集合呢?

16
yywan0913 在职认证  发表于 2015-1-6 17:21:30
fuyizhou 发表于 2015-1-6 17:14
如果item中的值是一个集合,要一个个验证集合呢?
不用一个一个来
举个例子?

17
fuyizhou 发表于 2015-1-6 17:24:00
yywan0913 发表于 2015-1-6 17:21
不用一个一个来
举个例子?
attach(recommendation)
with(subset(recommendation[user==4,]),which(item==a))

比如这个哈,a如果只是一个数就可以计算,那如果a是一个集合呢?
感谢!

18
yywan0913 在职认证  发表于 2015-1-6 17:26:02
fuyizhou 发表于 2015-1-6 17:24
attach(recommendation)
with(subset(recommendation),which(item==a))
with(subset(recommendation[user==4,]),which(a%in%item))

19
fuyizhou 发表于 2015-1-6 17:30:18
yywan0913 发表于 2015-1-6 17:26
with(subset(recommendation),which(a%in%item))
太棒了!大作业完成了!非常感谢!!!

20
fuyizhou 发表于 2015-1-6 17:48:07
yywan0913 发表于 2015-1-6 17:26
with(subset(recommendation),which(a%in%item))
不对 大神 又有问题了

b<-subset(m,m[,1]==1&m[,2]==m[,4])$item.x

b

with(subset(recommendation[user==1,]),which(item==102))

with(subset(recommendation[user==1,]),which(b%in%item))


> b<-subset(m,m[,1]==1&m[,2]==m[,4])$item.x
> b
[1] 101 102
> with(subset(recommendation[user==1,]),which(item==102))
[1] 3
> with(subset(recommendation[user==1,]),which(b%in%item))
[1] 1 2

应该输出1和3呀怎么是2

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-27 08:15