Reshaping data.frame with a by-group where id variable repeats [duplicate]
问题 This question already has answers here : How to reshape data from long to wide format (11 answers) Closed 21 days ago . I want to reshape/ rearrange a dataset, that is stored as a data.frame with 2 columns: id (non-unique, i.e. can repeat over several rows) --> stored as character value --> stored as numeric value (range 1:3) Sample data: id <- as.character(1001:1003) val_list <- data.frame(sample(1:3, size=12, replace=TRUE)) have <- data.frame(cbind(rep(id, 4), val_list)) colnames(have) <- c