Thanks, that seems to work.
On Fri, Nov 15, 2013 at 10:26 PM, arun kirshna [via R] <
ml-node+s789695n4680556h45@n4.nabble.com> wrote:
> Hi,
>
> Try:
> var1 <- load("reshape_data.frame.RData")
> ##It is better not to name the objects with function names.
> dat1 <- data
> reshape1 <- reshape
> names(dat1)[grep("X\\d+",names(dat1))] <-
>
gsub("[[:alpha:]]","X_",names(dat1)[grep("X\\d+",names(dat1))])
> res1 <-
reshape(dat1,direction="long",varying=7:ncol(dat1),sep="_")
> res2 <- res1[with(res1,order(Yr,Seas,Flt.Svy,Gender,Part,NSAMP)),-9]
> row.names(res2) <- 1:nrow(res2)
> colnames(res2) <- colnames(reshape1)
> all.equal(res2,reshape1)
> #[1] TRUE
>
> A.K.
>
>
> Some advice on transforming my data would be appreciated. Attached is
> an .Rdata image with my examples (reshape_data.frame.Rdata). Within the
> image are 2 objects:
>
> 1) The "data" object contains an example of my original data
> format. The columns "X20" : "X50" are histogram bins,
and the rows
> beneath are the number of observations (ie. counts) within those bins.
> The other columns; "Yr", "Seas", "Flt.Svy",
"Gender", "Part", "NSAMP"
> are observation associated with each bin count.
>
> 2) The "reshape" object is the format I need to transform the
"data"
> object into.
>
> I think the reshape() function is designed for this, and my
> "data" object is in wide format, and my "resphape"
object would be in
> long format. If indeed reshape() is the best way to do this, I'm
> looking for help in calling the function to transform my data.
>
> Many thanks,
>
> Tim
>
> ______________________________________________
> [hidden email]
<http://user/SendEmail.jtp?type=node&node=4680556&i=0>mailing list
> 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.
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://r.789695.n4.nabble.com/reshape-data-frame-tp4680539p4680556.html
> To unsubscribe from reshape data frame, click
here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4680539&code=dHNpcHBlbEBnbWFpbC5jb218NDY4MDUzOXwxMTExOTI5MjI=>
> .
>
NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context:
http://r.789695.n4.nabble.com/reshape-data-frame-tp4680539p4680707.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]