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

how can I write this nesting code probably?

$
0
0
Social_class <- ifelse(test = so_cla==("Lw"),
                       yes = sample(x = c("LwL","LwR"), size = 2, prob = c(0.64,0.36)),
                       ifelse(test = so_cla==("Uw"),
                              yes = sample(x = c("UwL","UwR"), size = 2, prob = c(0.64,0.36)),
                              ifelse(test = so_cla==("Lm"),
                                     yes = sample(x = c("LmL","LmR"), size = 2, prob = c(0.49,0.51)),
                                     ifelse(test = so_cla==("Um")  ,
                                            yes = sample(x = c("UmL","UmR"), size = 2, prob = c(0.43,0.57)),
                                            no = 0))))

Hi guys, when I'm trying to write this code, only R gives me either of them such as UwL OR UwR like this

table(Social_class)
Social_class
 LmL  LwL  UmR  UwL 
3093 3092 3092 3092

but I need both of them with the probability in the equation as it should be all of them


Viewing all articles
Browse latest Browse all 201839

Trending Articles



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