查看两个 SparkR 列中有多少个值匹配
Seeing how many values in two SparkR columns match
我在名为 df
的 SparkR
DataFrame
中有两个整数列(x1
和 x2
),它们彼此非常相似。我想计算有多少值匹配并将其与列的总长度进行比较。我怎样才能做到这一点?我尝试了以下方法,这两种方法都会导致错误。
agg(df, sum(df$x1==df$x2))
collect(sum(df$x1==df$x2))
您可以使用 withColumn 生成新列,填充值使 x1
和 x2
列相等。
并且您可以使用 count 来 count
新列中的值。
具体来说,这是答案的代码:
df <- withColumn(df, 'x', df$x1==df$x2)
head(agg(groupBy(df, 'x'), x="count"))
我在名为 df
的 SparkR
DataFrame
中有两个整数列(x1
和 x2
),它们彼此非常相似。我想计算有多少值匹配并将其与列的总长度进行比较。我怎样才能做到这一点?我尝试了以下方法,这两种方法都会导致错误。
agg(df, sum(df$x1==df$x2))
collect(sum(df$x1==df$x2))
您可以使用 withColumn 生成新列,填充值使 x1
和 x2
列相等。
并且您可以使用 count 来 count
新列中的值。
具体来说,这是答案的代码:
df <- withColumn(df, 'x', df$x1==df$x2)
head(agg(groupBy(df, 'x'), x="count"))