叼花硬汉 2012-04-10 02:24 采纳率: 0%
浏览 3296
已采纳

从数据框中提取特定列

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条回答 默认 最新

  • 斗士狗 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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置