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

How to use the Spread function using only one value of the target column?

$
0
0

We have the following data frame a with something like this:

> a
    google_prod      Value
1     categoria          ML
2        google         120
3       youtube          24
4     categoria          AO
5        google           2
6       youtube           0
7     categoria          ML
8        google          27
9       youtube           0
10    categoria          AO
11       google           5
12      youtube           0

We would like to get this:

    categoria google_prod    Value
1          ML   google        120
2          ML   youtube        24
3          AO   google          2
4          AO   youtube         0      
5          ML   google         27
6          ML   youtube         0    
7          AO   google          5
8          AO    youtube        0    

In other words, perform a type of application of the Spread or similar function, where only one value is taken from the google_prod column to apply it, in this case it would be the 'categoria' value.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



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