[R] replacement has length zero

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Jul 7 15:30:21 CEST 2012


Your request fails the reproducibility requirement from the posting guide, because you have not supplied enough data to run the code and reproduce the error.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

fabiano <chimbioputo at gmail.com> wrote:

>I have been working on the following code but keep getting an err
>message. My
>current thinking is that the problem is on the indexing but do not know
>how
>to fix it. Any help please?
>
>ungulate <- read.csv("Ungulate.csv",row.names=1)
>ungulate <-
>as.matrix(ungulate);colnames(ungulate)<-NULL;rownames(ungulate)<-NULL
>habitat <- read.csv("Ungulate_vegetation.csv")
>habitat <- habitat[,3]
>site.data <- read.csv("Ungulate_site.csv")
>site <- site.data$SiteId
>visit <- site.data$Visit
>date <- site.data$Date
>date <- matrix(date,nrow=20,ncol=7,byrow=TRUE)
>S <- dim(ungulate)[1]
>m <- 14	# number of augmented species
>G <- read.csv("Ungulate_group.csv")
>G <- G[,2]
>g <- rep(NA,length=m)
>G <- c(G,g) # combined list with actual and augmented data set so in
>this
>case 6 + 14 
>g <- length(table(G))
># habitat id
>Hab <- cbind(seq(1,20),habitat) #habitat types for 20 sties run from 2
>to 4
>
>hab <- matrix(NA,nrow=2,ncol=7)    #creating placing values to be
>filled
>with values generated by the following loop
>for(i in 1:4){
>	hab[i,] <- Hab[habitat==i,1]   }   # want to use this loop to
>substitute NA
>by exact values as those found in the real data set which can be 2 to 4
>but
>keep getting an error message saying 
>
>Error in hab[i, ] <- Hab[habitat == i, 1] : replacement has length zero
>
>Any help. Thanks
>Error in hab[i, ] <- Hab[habitat == i, 1] : replacement has length zero
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/replacement-has-length-zero-tp4635700.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org 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.



More information about the R-help mailing list