Reputation: 375
I have 10 objects eg1, eg2, eg3....eg10 that I want to see using the View() function in R. I have a feeling that I can write a simple code that would run View(egi) with i from 1 to 10, but I'm not sure how I could write this in R. Can anyone give me some advice?
Upvotes: 2
Views: 741
Reputation: 193517
I would suggest Map
, like this:
eg1 <- eg2 <- eg3 <- data.frame(matrix(1:4, ncol = 2))
egs <- mget(ls(pattern = "^eg"))
Map(View, egs, names(egs))
Wrap it in invisible
before running it if you don't want all those pesky NULL
s in your console.
Proof :-)
Upvotes: 7
Reputation: 23788
This should work:
names <- paste0("eg",seq(1:10))
sapply(1:1O, function(x) View(eval(parse(text=names[x]))))
Upvotes: 3
Reputation: 66819
Keep your stuff in a list
egs <- mget(ls(pattern="^eg"))
and loop:
for (i in seq_along(egs)) View(egs[[i]],title=names(egs)[i])
Upvotes: 6
Reputation: 819
Here is a silly example, first put all your object in a list:
my.list<-list(data.frame(V1=1:10),data.frame(V1=11:20),data.frame(V1=21:30) )
then do
lapply(my.list,View)
Upvotes: 4