Hi Milu, I may have the wrong idea, but is this what you want? temp$ID<-paste(temp$iso3,temp$lon,temp$lat,sep="") library(prettyR) newtemp<-stretch_df(temp,"month","precip")[,c(5,7,8)] names(newtemp)<-c("month",unique(temp$ID))
Jim On Tue, Dec 13, 2016 at 4:10 AM, Miluji Sb <miluj...@gmail.com> wrote: > Dear all, > > I have the following monthly data by coordinates: > > I would like to reshape this data to wide format so that each column is a > coordinate and each row is a month, > > coordinate1 coordinate2 coordinate3... > Month 1 > Month 2 > > Is the best option to concatenate the iso3, lon, and lat variables to > create an ID variable? I realize that this question might be very basic but > I'm slightly baffled. Thank you. > > temp <- dput(head(precip_2000,20)) > structure(list(iso3 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("AFG", > "AGO", "ALB", "ARE", "ARG", "ARM", "AUS", "AUT", "AZE", "BDI", > "BEL", "BEN", "BFA", "BGD", "BGR", "BHS", "BIH", "BLR", "BLZ", > "BOL", "BRA", "BRN", "BTN", "BWA", "CAF", "CAN", "CHE", "CHL", > "CHN", "CIV", "CMR", "COD", "COG", "COL", "CRI", "CUB", "CYP", > "CZE", "DEU", "DJI", "DNK", "DOM", "DZA", "ECU", "EGY", "ERI", > "ESH", "ESP", "EST", "ETH", "FIN", "FJI", "FLK", "FRA", "GAB", > "GBR", "GEO", "GHA", "GIN", "GNB", "GNQ", "GRC", "GRL", "GTM", > "GUF", "GUY", "HND", "HRV", "HTI", "HUN", "IDN", "IND", "IRL", > "IRN", "IRQ", "ISL", "ISR", "ITA", "JAM", "JOR", "JPN", "KAZ", > "KEN", "KGZ", "KHM", "KIR", "KOR", "KWT", "LAO", "LBN", "LBR", > "LBY", "LCA", "LKA", "LSO", "LTU", "LUX", "LVA", "MAR", "MDA", > "MDG", "MEX", "MKD", "MLI", "MMR", "MNE", "MNG", "MOZ", "MRT", > "MWI", "MYS", "NAM", "NCL", "NER", "NGA", "NIC", "NLD", "NOR", > "NPL", "NZL", "OMN", "PAK", "PAN", "PER", "PHL", "PNG", "POL", > "PRI", "PRK", "PRT", "PRY", "QAT", "ROU", "RUS", "RWA", "SAU", > "SDN", "SEN", "SJM", "SLB", "SLE", "SLV", "SOM", "SRB", "SUR", > "SVK", "SVN", "SWE", "SWZ", "SYR", "TCD", "TGO", "THA", "TJK", > "TKM", "TLS", "TUN", "TUR", "TWN", "TZA", "UGA", "UKR", "URY", > "USA", "UZB", "VEN", "VNM", "VUT", "YEM", "ZAF", "ZMB", "ZWE" > ), class = "factor"), lon = c(61L, 61L, 61L, 61L, 61L, 61L, 61L, > 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L > ), lat = c(32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, > 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L), dm = structure(c(1L, > 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 1L, 5L, 6L, 7L, > 8L, 9L, 10L, 11L), .Label = c("2000m1", "2000m10", "2000m11", > "2000m12", "2000m2", "2000m3", "2000m4", "2000m5", "2000m6", > "2000m7", "2000m8", "2000m9"), class = "factor"), month = c(1L, > 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, > 5L, 6L, 7L, 8L), precip = c(0.996665806451613, 0.156711724137931, > 0.242477419354839, 0, 0, 0, 0, 0, 0, 0, 0.121536, 0.38866064516129, > 1.13312903225806, 0.355208275862069, 0.307277419354839, 0.008316, > 0, 0, 0, 0.0008361290322581)), .Names = c("iso3", "lon", "lat", > "dm", "month", "precip"), row.names = c(NA, 20L), class = "data.frame") > > Sincerely, > > Milu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.