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

How to reduce factor levels depending on other attribute?

$
0
0

I have a dataframe of two columns id and result, and I want to assign factor levels to result depending on id. So that for id "1", result c("a","b","c","d") will have factor levels 1,2,3,4. For id "2", result c("22","23","24") will have factor levels 1,2,3.

id <- c(1,1,1,1,2,2,2)
result <- c("a","b","c","d","22","23","24")

I tried to group them by split, but they will be converted to a list instead of a data frame, which causes a length problem for modeling. Can you help please?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



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