0 votes
1 view
in R Programming by (42k points)

Is there a smart way to generate the below tibble (without having to repeat each variable's values manually)?

data.frame(First=rep(c('A', 'B'), each=2),

       Second=rep(c(1, 2), each=4),

       Third=rep(c('true', 'false')),

       Unique=1:8, stringsAsFactors = F) %>% as.tibble()

output:

<table><tbody><tr><th>First</th><th> Second</th><th> Third</th><th> Unique</th></tr><tr><td><chr>  </td><td><int> </td><td><chr>  </td><td><dbl></td></tr><tr><td>A</td><td>1 </td><td>true</td><td>1</td></tr><tr><td>A</td><td>1 </td><td>false</td><td>2</td></tr><tr><td>B</td><td>1 </td><td>true</td><td>3</td></tr><tr><td>B</td><td>1 </td><td>false</td><td>4</td></tr><tr><td>A</td><td>2 </td><td>true</td><td>5</td></tr><tr><td>A</td><td>2</td><td>false</td><td>6</td></tr><tr><td>B</td><td>2 </td><td>true</td><td>7</td></tr><tr><td>B</td><td>2</td><td>false</td><td>8</td></tr></tbody></table>

Please log in or register to answer this question.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...