1

I have this following data (see df)

data=data.frame(v1=c("traf","hayr", "poaz", "adfv", "srta"))
dup=rep(2,nrow(data))
id=rep(1:nrow(data), dup)
dupdf=data[id,]
dupdf2=as.data.frame(dupdf)
df=dupdf2 %>%
   mutate(col1 = if_else(row_number() %% 2 == 0, paste(dupdf, "_var"), dupdf)) %>%select(-dupdf)

> df
        col1
1       traf
2  traf _var
3       hayr
4  hayr _var
5       poaz
6  poaz _var
7       adfv
8  adfv _var
9       srta
10 srta _var
 

I would like to create a Python equivalent dictionary in R that would look like this in Python

{'traf':1,
 'traf _var':1,
 'hayr':2,
 'hayr _var'=2,
 'poaz'=3,
 'poaz _var'=3,
 'adfv'=4,
 'adfv _var'=4,
 'srta'=5,
 'srta _var'=5}

I have seen that the best way would be to use the lists but I don't know how to proceed.

Please note that in my real data, I have 130 different lines (65 different values).

Any help is appreciated

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Patrick Parts
  • 203
  • 2
  • 9
  • Yes I have read these responses, and I have seen that I could use lists to do that, but I don't know how to create automatically a list with my values instead of doing it "by hands". – Patrick Parts Sep 09 '21 at 15:42
  • 1
    How does your expected output (as list) based on your input look like? – Martin Gal Sep 09 '21 at 15:52

0 Answers0