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

Enumeration of a variable using R [duplicate]

$
0
0

I want to add a numeric column "ID" each each unique 'cat' value.. In other teams, enumerate "cat"

    cat        val  
1  aaa 0.05638315  
2  aaa 0.25767250  
3  aaa 0.30776611  
4  aaa 0.46854928  
5  aaa 0.55232243  
6  bbb 0.17026205  
7  bbb 0.37032054  
8  bbb 0.48377074  
9  bbb 0.54655860  
10 bbb 0.81240262  
11 ccc 0.28035384  
12 ccc 0.39848790  
13 ccc 0.62499648  
14 ccc 0.76255108  
15 ccc 0.88216552 

Intended output with a numeric ID column

df  
   cat        val    ID
1  aaa 0.05638315    1
2  aaa 0.25767250    1
3  aaa 0.30776611    1
4  aaa 0.46854928    1
5  aaa 0.55232243    1
6  bbb 0.17026205    2
7  bbb 0.37032054    2
8  bbb 0.48377074    2
9  bbb 0.54655860    2
10 bbb 0.81240262    2
11 ccc 0.28035384    3
12 ccc 0.39848790    3
13 ccc 0.62499648    3
14 ccc 0.76255108    3
15 ccc 0.88216552    3

Viewing all articles
Browse latest Browse all 201919

Trending Articles



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