[R] reshape() not dropping varaibles
Bob O'Hara
rn|@boh @end|ng |rom gm@||@com
Sun Dec 10 11:38:02 CET 2023
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]]
More information about the R-help
mailing list