user3755880
user3755880

Reputation: 375

R: Viewing multiple objects using View function

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

Answers (4)

A5C1D2H2I1M1N2O1R2T1
A5C1D2H2I1M1N2O1R2T1

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 NULLs in your console.

Proof :-)

enter image description here

Upvotes: 7

RHertel
RHertel

Reputation: 23788

This should work:

names <- paste0("eg",seq(1:10))
sapply(1:1O, function(x) View(eval(parse(text=names[x]))))

Upvotes: 3

Frank
Frank

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

Andrelrms
Andrelrms

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

Related Questions