全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
812 3
2019-03-20
> d <- data.table(a,b,c)
> d[a=="f" &  b>4, c:=-1*c]
Warning message:
In `[.data.table`(d, a == "f" & b > 4, `:=`(c, -1 * c)) :
  Coerced double RHS to integer to match the type of the target column (column 3 named 'c'). The RHS values contain no fractions so would be more efficiently created as integer. Consider using R's 'L' postfix (typeof(0L) vs typeof(0)) to create constants as integer and avoid this warning. Wrapping the RHS with as.integer() will avoid this warning too but it's better if possible to create the RHS as integer in the first place so that the cost of the coercion can be avoided.
> d
   a b   c
1: t 1  11
2: t 2  12
3: f 3  13
4: t 4  14
5: f 5 -15
6: t 6  16
7: t 7  17
8: f 8 -18
9: t 9  19

请教:为什么结果正确,但是报错呢?
           我的目的是,c列符合a列取f且b列大于4的元素乘以-1

二维码

扫码加我 拉你入群

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

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

全部回复
2019-3-21 06:41:40
没有报错,只是警告信息而已。可能是你的数据类型有问题,你能给出你的数据的前五行吗?
二维码

扫码加我 拉你入群

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

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

2019-3-21 07:15:33
caimiao0714 发表于 2019-3-21 06:41
没有报错,只是警告信息而已。可能是你的数据类型有问题,你能给出你的数据的前五行吗?
谢谢您的回复,下面的d就是数据,里面的负数是-1×c得来的,正常数就是b=c(1:9),c=c(11:19).不知表达的是否清楚。
二维码

扫码加我 拉你入群

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

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

2019-3-21 07:20:22
菩提镜 发表于 2019-3-21 07:15
谢谢您的回复,下面的d就是数据,里面的负数是-1×c得来的,正常数就是b=c(1:9),c=c(11:19).不知表达的是 ...
你试试运行这个:

d[a=="f" &  b>4, ][,c:=-1*c]
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群