Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Get column name of each row which is closest to 0

$
0
0

Thanks, I tried the first option and work fine now I want to built a dataframe like df2 from df1, looking always for the closets value to 0: Where clossets_1 - closer value to 0 of the columns x,y and z. clossets_2 - closer value to 0 of the columns x and a, because x is the most received value in clossets_1. clossets_3 - closer value to 0 of the columns a and b, because a is the most received value in clossets_2.

df1
x y z a b
1 2 3 4 3
2 3 4 1 2
3 2 4 2 1
4 3 2 3 6


df2
x  y  z clossets_1 a clossets_2 b clossets_3
1  2  3      x     4      x     3     b
2  3  4      x     1      a     2     a
3  2  4      y     2      a     1     b
4  3  2      z     3      a     2     b 


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>