[R] reshape() not dropping varaibles

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Dec 10 16:35:17 CET 2023


Posting a few rows, say 5, of your data using dput() along with the result
that you would like to get for those rows would help get you a quicker and
more accurate response, I believe. This is as suggested by the posting
guide, linked below, which you should read if you have not already.

-- Bert



On Sun, Dec 10, 2023 at 2:38 AM Bob O'Hara <rni.boh using gmail.com> wrote:

> Hi all!
>
> I1m trying to re-format some data from long to wide format with reshape().
> Specifically, the data has SURVEYDATE, which I want to be in the rows, and
> COMMON_NAME which should be the columns. The entries should be TOTAL_CATCH.
> The data has a bunch of other variables, which can be ignored.
>
> When I run reshape(), it includes all of the variables, not just
> TOTAL_CATCH:
>
> Data <- read.csv("
>
> https://conservancy.umn.edu/bitstream/handle/11299/227105/fish_data_raw.csv?sequence=6&isAllowed=y
> ")
> Data.wide <- reshape(Data, direction = "wide",
>                 idvar = "SURVEYDATE", timevar = "COMMON_NAME",
>                 v.names = "TOTAL_CATCH")
> names(Data.wide)
>
> I tried with the example on the help page, which works fine:
>
> # this works
> Indometh$thing <- 1:nrow(Indometh)
> wide <- reshape(Indometh, direction = "wide", idvar = "Subject",
>                 timevar = "time", v.names = "conc", sep= "_")
> names(wide)
>
> There are some obvious work-arounds and alternatives, but it would be nice
> to have this sorted. Can anyone help?
>
> Bob
>
> Bob
>
> --
> Bob O'Hara
> Institutt for matematiske fag
> NTNU
> 7491 Trondheim
> Norway
>
> Mobile: +47 915 54 416
> Journal of Negative Results - EEB: www.jnr-eeb.org
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list