Error111: incorrect number of dimensions

Hi, I'm trying to use this code. However the problem is when I tried to create means and min. I got this error

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'mean': incorrect number of dimensions

df_list <- split(Pdat1, as.factor(Pdat1$ID_P))
names(df_list)

distlo<-list()

for (i in names(df_list)){
  
  dist_df<-df_list[[i]]
  coordinates(dist_df)<-c("x","y")
  dm<-spDists(dist_df)
  rownames(dm)<-dist_df$ID
  colnames(dm)<-dist_df$ID
  dm<-dm[,1]
  distlo[[i]]<-dm
  
}

means<-lapply(distlo, function(x) mean(x[,2][2:nrow(x)]))

Some of the data is attached here

Can someone help me with that?
Thank you so much
[details="Summary"]
This text will be hidden
[/details]

If the error comes at this line

means<-lapply(distlo, function(x) mean(x[,2][2:nrow(x)]))

then please post the output of

dput(distlo)
1 Like

The elements of distlo are numeric vectors. Perhaps this gives you the information you want.

class(distlo[[1]])
[1] "numeric"
means<-lapply(distlo, function(x) mean(x[2:length(x)]))
means
$Aragon
[1] 9.280352

$End
[1] 12.59237

$Falbala
[1] 10.02451

$Lucario
[1] 9.493018
2 Likes

This topic was automatically closed 7 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.