I'm trying to run Micropower using weighted unifrac distance matrices following the outline found here: https://gist.githubusercontent.com/brendankelly/6673e8596d3cde3fac7d493d7747aa80/raw/59ee6a6be3db8bd751817cdd7c31c7bd12d4d5f8/micropower_simulation_example.R
For the following command,
sd_wu_df <- data.frame(otu_number=round(as.numeric(gsub(".txt","",gsub("otu","",sapply(strsplit(names(sd_wu),"_"),FUN=function(x){x[[4]]})), fixed = TRUE))),sd=sapply(sd_wu, FUN=function(x){sd(as.dist(x))}))
I get this: Error in x[[4]] : subscript out of bounds
The script will only run if I sub 1 in for 4 as follows:
sd_wu_df <- data.frame(otu_number=round(as.numeric(gsub(".txt","",gsub("otu","",sapply(strsplit(names(sd_wu),"_"),FUN=function(x){x[[1]]})), fixed = TRUE))),sd=sapply(sd_wu, FUN=function(x){sd(as.dist(x))}))
But then I get this:
Warning message:
In data.frame(otu_number = round(as.numeric(gsub(".txt", "", gsub("otu", :
NAs introduced by coercion
That causes my table to have NA for otu_number, meaning I can't do the next steps in the script. Screen shot below. What is the problem with the script?