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

Formatting a data.frame with binary values

$
0
0

I have a dataframe with 4 columns and 4 rows. For simplicity, I changed it to numeric format. The schema is as follows:

df <- structure(list(a = c(1,2,2,0),
                     b = c(2,1,2,2),
                     c = c(2,0,1,0),
                     d = c(0,2,1,1)),row.names=c(NA,-4L) ,class = "data.frame")
  a b c d
1 1 2 2 0
2 2 1 2 2
3 2 0 1 0
4 0 2 1 1

I would like to change this data frame and obtain the following:

   1     2
1  a     b/c
2  b     a/c/d
3  c     a
4  c/d   b

Is there a function or package I should look into? I have been doing lots of text processing in R recently. I'd appreciate your assistance!


Viewing all articles
Browse latest Browse all 204798

Trending Articles



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