[R] Error in names(data)[ix] : only 0's may be mixed with negative subscripts
rennerie
rennerie at uwec.edu
Wed May 29 18:31:11 CEST 2013
I am getting the error "Error in names(data)[ix] : only 0's may be mixed with
negative subscripts" and cannot quite figure out how to resolve this. Any
ideas?
> attempt <- read.csv("attempt.csv")
> str(attempt)
'data.frame': 9424 obs. of 9 variables:
$ cgPlaId : int 647 647 647 647 647 647 647 647 647 647 ...
$ measureYr: int 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 ...
$ pop : Factor w/ 14 levels "aa","alf","btg",..: 12 12 12 12 12 12 12
12 12 12 ...
$ row : int 36 36 36 36 36 36 36 36 36 36 ...
$ pos : int 975 975 975 975 975 975 975 975 975 975 ...
$ ld : int 1 1 1 1 1 1 0 0 0 0 ...
$ fl : int 0 0 0 0 0 0 0 0 0 0 ...
$ hdCt : int NA NA NA NA NA NA NA NA NA NA ...
$ achCt : int NA NA NA NA NA NA NA NA NA NA ...
> head(attempt)
cgPlaId measureYr pop row pos ld fl hdCt achCt
1 647 1997 spp 36 975 1 0 NA NA
2 647 1998 spp 36 975 1 0 NA NA
3 647 1999 spp 36 975 1 0 NA NA
4 647 2000 spp 36 975 1 0 NA NA
5 647 2001 spp 36 975 1 0 NA NA
6 647 2002 spp 36 975 1 0 NA NA
>
> ##to deal with NA values##
>
> table(attempt$hdCt, useNA = "always")
0 1 2 3 4 5 6 7 9 10 12 13 <NA>
67 429 151 48 26 12 2 4 2 1 1 1 8680
> attempt$hdCt[is.na(attempt$hdCt)] <- 0
> table(attempt$hdCt, useNA = "always")
0 1 2 3 4 5 6 7 9 10 12 13 <NA>
8747 429 151 48 26 12 2 4 2 1 1 1 0
>
> attempt$achCt[is.na(attempt$achCt)] <- 0
>
> ww <- reshape(attempt, v.names = c("ld", "fl", "hdCt", "achCt"), idvar =
> "cgPlaId", timevar = "measureYr", direction = "wide")
> head(ww)
cgPlaId pop row pos ld.1997 fl.1997 hdCt.1997 achCt.1997 ld.1998 fl.1998
1 647 spp 36 975 1 0 0 0 1 0
17 648 spp 33 982 1 0 0 0 1 0
33 649 spp 14 973 1 0 0 0 1 0
49 650 spp 27 979 1 0 0 0 1 0
65 651 spp 16 971 1 0 0 0 1 0
81 652 spp 21 974 1 0 0 0 1 0
hdCt.1998 achCt.1998 ld.1999 fl.1999 hdCt.1999 achCt.1999 ld.2000 fl.2000
1 0 0 1 0 0 0 1 0
17 0 0 1 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 0 0 0 1 0
65 0 0 1 0 0 0 1 0
81 0 0 1 0 0 0 1 0
hdCt.2000 achCt.2000 ld.2001 fl.2001 hdCt.2001 achCt.2001 ld.2002 fl.2002
1 0 0 1 0 0 0 1 0
17 0 0 0 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 0 0 0 1 0
65 0 0 1 0 0 0 1 0
81 0 0 1 0 0 0 1 0
hdCt.2002 achCt.2002 ld.2003 fl.2003 hdCt.2003 achCt.2003 ld.2004 fl.2004
1 0 0 0 0 0 0 0 0
17 0 0 0 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 0 0 0 1 0
65 0 0 1 0 0 0 1 0
81 0 0 1 0 0 0 1 1
hdCt.2004 achCt.2004 ld.2005 fl.2005 hdCt.2005 achCt.2005 ld.2006 fl.2006
1 0 0 0 0 0 0 0 0
17 0 0 0 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 0 0 0 1 0
65 0 0 1 0 0 0 1 0
81 1 192 1 0 0 0 1 0
hdCt.2006 achCt.2006 ld.2007 fl.2007 hdCt.2007 achCt.2007 ld.2008 fl.2008
1 0 0 0 0 0 0 0 0
17 0 0 0 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 0 0 0 1 0
65 0 0 1 0 0 0 1 0
81 0 0 1 0 0 0 1 0
hdCt.2008 achCt.2008 ld.2009 fl.2009 hdCt.2009 achCt.2009 ld.2010 fl.2010
1 0 0 0 0 0 0 0 0
17 0 0 0 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 0 0 0 1 0
65 0 0 1 0 0 0 1 0
81 0 0 1 1 1 214 1 0
hdCt.2010 achCt.2010 ld.2011 fl.2011 hdCt.2011 achCt.2011 ld.2012 fl.2012
1 0 0 0 0 0 0 0 0
17 0 0 0 0 0 0 0 0
33 0 0 1 0 0 0 1 0
49 0 0 1 1 1 0 1 0
65 0 0 1 0 0 0 1 0
81 0 0 1 0 0 0 1 0
hdCt.2012 achCt.2012
1 0 0
17 0 0
33 0 0
49 0 0
65 0 0
81 0 0
> attach (ww)
> names(ww)
[1] "cgPlaId" "pop" "row" "pos" "ld.1997"
[6] "fl.1997" "hdCt.1997" "achCt.1997" "ld.1998" "fl.1998"
[11] "hdCt.1998" "achCt.1998" "ld.1999" "fl.1999" "hdCt.1999"
[16] "achCt.1999" "ld.2000" "fl.2000" "hdCt.2000" "achCt.2000"
[21] "ld.2001" "fl.2001" "hdCt.2001" "achCt.2001" "ld.2002"
[26] "fl.2002" "hdCt.2002" "achCt.2002" "ld.2003" "fl.2003"
[31] "hdCt.2003" "achCt.2003" "ld.2004" "fl.2004" "hdCt.2004"
[36] "achCt.2004" "ld.2005" "fl.2005" "hdCt.2005" "achCt.2005"
[41] "ld.2006" "fl.2006" "hdCt.2006" "achCt.2006" "ld.2007"
[46] "fl.2007" "hdCt.2007" "achCt.2007" "ld.2008" "fl.2008"
[51] "hdCt.2008" "achCt.2008" "ld.2009" "fl.2009" "hdCt.2009"
[56] "achCt.2009" "ld.2010" "fl.2010" "hdCt.2010" "achCt.2010"
[61] "ld.2011" "fl.2011" "hdCt.2011" "achCt.2011" "ld.2012"
[66] "fl.2012" "hdCt.2012" "achCt.2012"
> sapply(ww, class)
cgPlaId pop row pos ld.1997 fl.1997 hdCt.1997
"integer" "factor" "integer" "integer" "integer" "integer" "numeric"
achCt.1997 ld.1998 fl.1998 hdCt.1998 achCt.1998 ld.1999 fl.1999
"numeric" "integer" "integer" "numeric" "numeric" "integer" "integer"
hdCt.1999 achCt.1999 ld.2000 fl.2000 hdCt.2000 achCt.2000 ld.2001
"numeric" "numeric" "integer" "integer" "numeric" "numeric" "integer"
fl.2001 hdCt.2001 achCt.2001 ld.2002 fl.2002 hdCt.2002 achCt.2002
"integer" "numeric" "numeric" "integer" "integer" "numeric" "numeric"
ld.2003 fl.2003 hdCt.2003 achCt.2003 ld.2004 fl.2004 hdCt.2004
"integer" "integer" "numeric" "numeric" "integer" "integer" "numeric"
achCt.2004 ld.2005 fl.2005 hdCt.2005 achCt.2005 ld.2006 fl.2006
"numeric" "integer" "integer" "numeric" "numeric" "integer" "integer"
hdCt.2006 achCt.2006 ld.2007 fl.2007 hdCt.2007 achCt.2007 ld.2008
"numeric" "numeric" "integer" "integer" "numeric" "numeric" "integer"
fl.2008 hdCt.2008 achCt.2008 ld.2009 fl.2009 hdCt.2009 achCt.2009
"integer" "numeric" "numeric" "integer" "integer" "numeric" "numeric"
ld.2010 fl.2010 hdCt.2010 achCt.2010 ld.2011 fl.2011 hdCt.2011
"integer" "integer" "numeric" "numeric" "integer" "integer" "numeric"
achCt.2011 ld.2012 fl.2012 hdCt.2012 achCt.2012
"numeric" "integer" "integer" "numeric" "numeric"
> vars <- c(ld.1997, ld.1998, ld.1999, ld.2000, ld.2001, ld.2002, ld.2003,
> ld.2004, ld.2005, ld.2006, ld.2007, ld.2008, ld.2009, ld.2010, ld.2011,
> ld.2012, fl.1997, fl.1998, fl.1999, fl.2000, fl.2001, fl.2002, fl.2003,
> fl.2004, fl.2005, fl.2006, fl.2007, fl.2008, fl.2009, fl.2010, fl.2011,
> fl.2012, hdCt.1997, hdCt.1998, hdCt.1999, hdCt.2000, hdCt.2001, hdCt.2002,
> hdCt.2003, hdCt.2004, hdCt.2005, hdCt.2006, hdCt.2007, hdCt.2008,
> hdCt.2009, hdCt.2010, hdCt.2011, hdCt.2012, achCt.1997, achCt.1998,
> achCt.1999, achCt.2000, achCt.2001, achCt.2002, achCt.2003, achCt.2004,
> achCt.2005, achCt.2006, achCt.2007, achCt.2008, achCt.2009, achCt.2010,
> achCt.2011, achCt.2012)
> redata<-reshape(ww, varying=list(vars), direction="long", timevar="varb",
> times=as.factor(vars), v.names="resp")
Error in names(data)[ix] : only 0's may be mixed with negative subscripts
>
--
View this message in context: http://r.789695.n4.nabble.com/Error-in-names-data-ix-only-0-s-may-be-mixed-with-negative-subscripts-tp4668227.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list