0

I am attempting to loop a name vector within a command multiple times in R. The traditional command looks like the following:

ps_10B <- prune_taxa(colmax>100 &         colMeans(data.frame(ps_10B@otu_table@.Data)>0)>2/nsamples(ps_10B),   ps_10B)

This is the list I am trying to loop through:

groups <- c("10B","10D", "11D", "12D", "13D", "14D", "15D",   "16D","17B","17D", "18B", "18D", "19B", "19D", "1B", "1D", "20D", "21B","21D", "22D", "23B", "23D", "24B", "24D", "25D", "26D", "27B","27D", "28B", "28D", "29B", "29D", "2B", "2D", "30B", "31B", "32B", "33B", "34B", "35B", "36B", "37B", "38B", "39B", "3B", "3D", "43B", "47B", "4D", "5B", "5D", "6B", "6D", "7D", "8B","8D", "9D")

I am working with phyloseq objects and the only difference for each command would be the number followed by the letter (ex: 10B, 11B, 12B, ect.)

I have tried using the following command and it worked up to the point of naming the objects, but provides an error when asking for the second loop.

Error in h(simpleError(msg, call)) : error in evaluating the argument 'samples' in selecting a method for function 'prune_samples': sam_data slot is empty.

for(i in groups) {
  name <- paste("ps_", i, sep = "")
  assign(name, prune_samples(sample_data(for(i in groups) {
    paste(i)})$Prefix==(for(i in groups) {
      paste(i)}),ps))}
}

Thanks in advance!

for(i in groups) {
  name <- paste("ps_", i, sep = "")
  assign(name, prune_samples(sample_data(for(i in groups) {
    paste(i)})$Prefix==(for(i in groups) {
      paste(i)}),ps))}
}

I expected the command to produce individual phyloseq objects for each element in the list.

0 Answers0