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

Can't convert from long to wide

$
0
0

I am trying to convert data from long format to wide format using spread function in R, it works but not correctly and transforms dataset wrongly.

dbv_fc1<-read.csv("dbtest_forum.csv",header = TRUE,na.strings=0)
data_new <- dbv_fc1 %>% spread(test, value)

My dataset contains four columns

original data

But when it does the transforming into wide format on the basis of just two columns, it moved values of tests with same dates into new rows rather than same row but in respective columns as shown below.

After transformation

It shows that in ID A6 where dates are same it moves values into next row of corresponding column which I don't want.


Viewing all articles
Browse latest Browse all 206653

Trending Articles



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