R studio Help Statistics

I am trying to find the column mean and std for my new data set results from my bootstrap, I was trying to use mean(results$V1) but it isnt working as its a vector. Not too sure where to go from here but hopefully the fix isnt hard. The Bootstrap had no issues and ran fine, it created the new data set results and I just need to find the mean and std for those individual columns

nBoot = 1000
> results = array(NA, dim = c(nBoot, length(unique(DATAWAR$Name))))
> J = 1
> for (name in unique(DATAWAR$Name)) {
+   tempdata = DATAWAR[DATAWAR$Name == name,"CustomWAR"]
+   n = length(tempdata)
+   for(i in 1:nBoot){
+     dat = sample(tempdata, n, replace = T)
+     results[i, J]= sum(dat)
+   }
+   J = J+1
+ }
> mean(results$V1)
Error in results$V1 : $ operator is invalid for atomic vectors

It might be helpful for you to know how to properly format code and console output that you post here. Using proper code formatting makes the site easier to read, prevents confusion (unformatted code can get garbled by the forum software :anguished:), and is generally considered the polite thing to do. Check out this FAQ to find out how — it's as easy as the click of a button! :grinning::

$ syntax i good for data.frames and lists, but not arrays/matrices/vectors.


m1 <- matrix(1:4,nrow = 2)
colnames(m1) <- c("a","b")

# Error in m1$a : $ operator is invalid for atomic vectors
# [1] 1 2

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.