this question has answer here:
i know basic r i'm stuck dataframe handling. need able use package or base function in r transoform dataframe this.
id value variable 1 25.5 max_temp 1 16.4 min_temp 2 23.1 max_temp 3 12.1 min_temp
into this:
id max_temp min_temp 1 25.5 16.4 2 23.1 na 3 na 12.1
check na example observations have missing measurements. can fix directly in excel file i'm trying preprocessing less manually.
thanks.
what want reshape data. there lot of ways this. here's one:
reshape(x, direction='wide', idvar='id', timevar='variable') id value.max_temp value.min_temp 1 1 25.5 16.4 3 2 23.1 na 4 3 na 12.1
reshape2::dcast
has nicer syntax:
> dcast(x, id ~ variable) id max_temp min_temp 1 1 25.5 16.4 2 2 23.1 na 3 3 na 12.1
Comments
Post a Comment