在R中的dataframe中选择多少列?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (546)

我想从dataframe中选择3117列,我尝试按列名选择它们:

dataframe %>% 
  select(
    'AAACCTGAGCACGCCT-1',
    'AAACCTGAGCGCTTAT-1',
    'AAACCTGAGCGTTGCC-1',
    ......,
    'TTGGAACCACGGACAA-1'
  )

firstpickupnames <- ('AAACCTGAGCACGCCT-1','AAACCTGAGCGCTTAT-1','AAACCTGAGCGTTGCC-1',......,'TTGGAACCACGGACAA-1')

这两种方式,R控制台输出

'AAACCTGAGCACGCCT-1','AAACCTGAGCGCTTAT-1','AAACCTGAGCGTTGCC-
1',......,'TTGGAACCACGGACAA-1'
+ )
+

这是什么意思?在R中选择的列数会有限制吗?

提问于
用户回答回答于
library(dplyr)

# this reorders the column names, but keeps everything without having to name the columns specifically:
mtcars %>% 
  select(carb, gear, everything()) 

# from a list of column names:
keep_columns <- c('cyl','disp','hp')
mtcars %>% 
  select(one_of(keep_columns)) 

# specific names, and a range of names:
mtcars %>% 
  select(hp, qsec:gear) 

#You could also use  `contains()`, `starts_with()`, `ends_with()`, or `matches()`. Note that calling all of the following at once will give you no results:
mtcars %>% 
  select(contains('t')) %>%
  select(starts_with('a')) %>% 
  select(ends_with('b')) %>% 
  select(matches('^m.+g$')) 

扫码关注云+社区

领取腾讯云代金券