Rstudio not displaying matrix data

I am currently working on an assignment for a population dynamics class. I input the data and code to generate a matrix but every time I run the chunk it displays all the matrix data as NA. I'm just not sure what to change

frog_mat <- matrix(data=NA, nrow=100, ncol=2)
frog_mat[.1] <- 1:100
frog_mat[1.2] <- P

for (xx in 1:99){
  frog_mat[xx+1,2] <- frog_mat[xx,2]*(1+d_patches)
}
frog_mat[,2] < 5

Might be this?

Error in d_patches : object 'd_patches' not found

1 Like

Sorry i didn't include the full data set, I thought the problem might be just in the part where I code for the matrix. Here is the full data set:
thanks for your help btw

swampfrog <- read.csv("~/Fall 2021 class work/Population dynamics/swampfrog.csv")
E <- .06
C <- .04 
d_patches <- C-E 
# Frog population is decreasing 

p0 <- 12 
dpdt <- C-E
P <- p0*(1+dpdt)
curr_occ <- 12 

frog_mat <- matrix(data=NA, nrow=100, ncol=2)
frog_mat[.1] <- 1:100
frog_mat[1.2] <- P

for (xx in 1:99){
  frog_mat[xx+1,2] <- frog_mat[xx,2] * (1+d_patches)
}
frog_mat[,2] < 5
```{r}
1 Like

This worked for me (replaced the dots with commas):

frog_mat <- matrix(data=NA, nrow=100, ncol=2)
frog_mat[,1] <- 1:100 # here 
frog_mat[1,2] <- P # and here

for (xx in 1:99){
  frog_mat[xx+1,2] <- frog_mat[xx,2] * (1+d_patches)
}
frog_mat[,2] < 5
2 Likes

oh my gosh thank you so much. That was such a stupid error on my part

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.