简体   繁体   中英

How to select columns in RStudio Viewer?

I have a dataframe and would like to inspect and compare several columns. How can I select two or more columns with the data Viewer? I do not want to create a subsample for those columns each time. Is there another way?

data(mtcars)
View(mtcars$mpg)
View(mtcars$mpg, mtcars$mpg) # not working
View(c(mtcars$mpg, mtcars$cyl)) # shows 2 columns underneath each other

I usually use this code to do this

library(dplyr)

mtcars%>%
  select(mpg,cyl)%>%
  View

It uses the dplyr package and the pipe %>% . It works in a way that you first give it your data, then you manipulate it (in your case just selecting the rows) and then throw in View, head() , str() or any other function.

View() will only take a dataframe, not 2 seperate vectors

With base R you could do something like

View(mtcars[c("mpg", "cyl")])

您可以在View使用data.frame而不是c ,即

View(data.frame(mtcars$mpg, mtcars$cyl))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM