Didn"t forge 2012-04-10 02:24 采纳率: 25%
浏览 1281
已采纳

从数据框中提取特定列

I have an R data frame with 6 columns, and I want to create a new dataframe that only has three of the columns.

Assuming my data frame is df, and I want to extract columns A, B, and E, this is the only command I can figure out:

 data.frame(df$A,df$B,df$E)

Is there a more compact way of doing this?

转载于:https://stackoverflow.com/questions/10085806/extracting-specific-columns-from-a-data-frame

  • 写回答

8条回答 默认 最新

  • lrony* 2015-04-19 21:19
    关注

    Using the dplyr package, if your data.frame is called df1:

    library(dplyr)
    
    df1 %>%
      select(A, B, E)
    

    This can also be written without the %>% pipe as:

    select(df1, A, B, E)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥100 如何修改别人网站内的数字,各位接单的私我
  • ¥15 poi怎么在指定位置之后生成多个表格
  • ¥15 nginx在location设置了client_max_body_size依旧报错413
  • ¥15 C#添加WCF服务引用客户端调用方法没有反应
  • ¥15 stm32f103c8t6与esp8266
  • ¥15 使用Hadoop的MapReduce program
  • ¥15 Python发生IndexError错误如何解决?
  • ¥15 如何用matlab搭建激光器
  • ¥15 51单片机两路互补SPWM输出全桥逆变
  • ¥15 outlook左边用户名下拉为啥打不开了