0

I would like to create a loop that can loop through (sub1[1,] ... sub1[1200,]) ... (sub10[1,] ... sub10[1200,])

for (j in 1:10){

        entries=1:1200
        for (i in 1:1200){
    entries[i]=max(table(sort(unlist(paste("sub",j,sep="")[i,]))-1:3)) > 2
}
        nam=paste("newsub",j,sep="")
        assign(nam, paste("sub",j,sep="")[!entries,])

}

however, I keep getting the error "Error in paste("sub", j, sep = "")[i, ] : incorrect number of dimensions".

I think I have apply a function to a string, but I have already used the paste() function; how can I fix this?

*edit: I expect to have sub1[i,]...sub10[i,], where j=1:10

  • `unlist(paste("sub",j,sep="")` will return a vector, a vector does not have dimension you would might need `unlist(paste("sub",j,sep="")[i]`. But do you actually need `unlist` here? Can you give a reproducible example and show expected output? – markus Mar 09 '19 at 19:27
  • @markus Hi, I basically want to do the same thing as what shown in this website https://www.reddit.com/r/Rlanguage/comments/axv7c2/remove_combinations_that_have_series_of_numbers/ the only difference is that I have 10 groups and 1200 rows. (so I adapt the codes from there) – Mathygroupy Mar 09 '19 at 21:12
  • What are `sub1` and `sub10`? Please include a minimal working example and show the expected output. See [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for a guidance. – markus Mar 09 '19 at 21:29
  • @markus Oh, sub[j] is just a data.frame of ( row=1200, col=7 ) of random combinations. For example, sub1 = 1 2 3 4 6 89 321 I will try to include a working example later, thanks! – Mathygroupy Mar 09 '19 at 21:57
  • The error message says it all. I don't think the `paste( ...) [ , ]` makes sense. There's no defined dimensioned value returned for `paste` so indexing it seems "just wrong". Close vote for no [MCVE] – IRTFM Mar 09 '19 at 23:18

0 Answers0