3

I have the below values in one of the column in a dataframe

231204.66666666666 376.0 346593.5 802.0 346594.5 801.0 346595.5 800.0 null 0.0 

I just want the absolute value in this column. How can I do that in SparkR?

I found abs and round from SparkR which can do this job. But unfortunately it is not exported. Getting the below exception when I use Spark::abs(df$col)```

Error: 'abs' is not an exported object from 'namespace:SparkR'

I am getting the same error for SparkR::round as well.

I tried the below, but the column value not changed.

df$col <- abs(df$col) 

How can I get the absolute value in the column?

3
  • the sample you gave does not change under abs(). try round(abs(df$col),0) Commented Apr 6, 2016 at 8:06
  • @ZahiroMor - Thanks a lot. That does the trick. Could you please add that as answer? Commented Apr 6, 2016 at 9:23
  • 1
    fyi, round(abs(df$col)) also works. No need for ,0 Commented Apr 6, 2016 at 9:35

1 Answer 1

2

The sample you gave does not change under abs(). abs has to be combined with round. Like, round(abs(df$col))

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.