Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in R Programming by (50.2k points)

From the two or more dataframes, df1, df2, df3, df4, I want to know what all data structure can we used such that it is possible to iterate through the dataframes and do something with each.

for(df in 'what?') {

  print(colnames(df))

}

1 Answer

0 votes
by (107k points)

Generally, it is sufficient to have data in a list instead of having separate data frames in the global environment. Keeping data in the list is more manageable.

list_df <- mget(ls(pattern = 'df\\d+'))

After that, you can use lapply to do something on each one of them.

lapply(list_df, function(x) names(x))

If you are interested in certification of R, then do check out the R programming certification

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...