2
Suppose I have the following date.:
print(DADOS)
CODIGO QTDE MÊS
001 4 1
001 1 1
001 3 2
001 2 3
001 3 3
001 4 3
001 2 4
001 2 4
001 1 5
001 5 6
001 2 6
But I need to turn the values of the variable MONTH into columnar. That would be the data.frame this way:
print(DADOS_TRANSFORMADOS)
CODIGO QTDE MÊS QTDE MÊS QTDE MÊS QTDE MÊS QTDE MÊS QTDE MÊS
001 4 1 3 2 2 3 2 4 1 5 5 6
001 1 1 NA 2 3 3 2 4 NA 5 2 6
001 NA 1 NA 2 4 3 NA 4 NA 5 NA 6
I tried to split my data.frame into 6 parts filtering for each month and then use the function join
to join month to month, but it did not work.
How can I transform the values of my data.frame variable into columns?
thank you for the answer I will test.
– Izak Mandrak
Neves, if in my case the database is much larger, for example if in my field 'size' was larger than 100 thousand lines, as could, mount the vector 'mes' without having to write each line?
– Izak Mandrak
What do you mean "no need to write each line"?
– neves
Is that in the example you wrote the variables in the vector,
mes = c(1, 1, 2, 3, 3, 3, 4, 4, 5, 6, 6)
, but after some test I understood that I really did not need and selected with the group_by function the column MONTH directly.– Izak Mandrak