categorizing data in R

后端 未结 3 970
逝去的感伤
逝去的感伤 2021-01-24 14:32

Im trying to categorising my data into different group based on type of data. My data and code is as follow:

bank    ROE
bank1   0.73
bank2   0.94
bank3   0.62
b         


        
3条回答
  •  长情又很酷
    2021-01-24 15:16

    You could also try:

    lst1 <- list(sob, fob, jov)
    test$type <- setNames(rep(seq_along(lst1),sapply(lst1,length)),unlist(lst1))[test$bank]
    test$type[is.na(test$type) ] <- 4
    
    test$type
    #[1] 1 1 1 2 2 2 3 3 3 3 3 4
    

提交回复
热议问题