如果另一列中的值>创建具有逻辑值的新列。 0 [英] creating a new column with logical values if value in another column > 0

查看:141
本文介绍了如果另一列中的值>创建具有逻辑值的新列。 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R的新手,请耐心等待。我有一个值为的数据框

New to R, so bear with me. I have a dataframe with values

x y
1 2
4 4
5 3
6 0 

我想创建第三列,指示TRUE或FALSE是否为值在y列中为0。

I want to create a third column that indicates with TRUE or FALSE whether a value in column y is 0.

x y z
1 2 TRUE
0 4 TRUE
5 3 TRUE
6 0 FALSE


推荐答案

> 比较lhs和rhs以获得逻辑向量。通过将输出指定为新列('z'),我们在原始数据集'df1'中创建新列。

The > compares the lhs and rhs to get a logical vector. By assigning the output as a new column ('z'), we create the new column in the original dataset 'df1'.

df1$z <- df1$y > 0

这篇关于如果另一列中的值&gt;创建具有逻辑值的新列。 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆