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

change data frame into another data frame with 1 and 0

$
0
0

I have data frame dat1 and I want to have data frame dat2. How convert this data frame dat1 to dat2 build 1 and 0.

s <- c("A","B","C","D","E")
h <- c("H1","H2","H1","H3","H4")
dat1 <- data.frame(s,h)

dat2:
  H1 H2 H3 H4
A 1  0  0  0
B 0  1  0  0
C 1  0  0  0
E 0  0  1  0
F 0  0  0  1

Viewing all articles
Browse latest Browse all 201867

Trending Articles



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