How to extract specific columns from a dataframe in R?

0 votes

Hi Guys,

I am new in R. I have one data frame in R. I want to extract some specific columns from that data frame. How can I do that?

Aug 7 in Data Analytics by akhtar
• 25,450 points
87 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use the select method to extract any columns from a data frame. I have attached one example below for your reference.

> df
  IND snp1 snp2 snp3 snp4 snp5
1   1  A/G  T/T  T/C  G/C  G/G
2   2  A/A  C/C  G/G  G/G  A/A
3   3  T/T  G/G  C/C  C/C  T/T

This is a data frame that has six columns. Now to extract particular columns we can use the select method.

> select(df, snp1,snp3,snp4)
  snp1 snp3 snp4
1  A/G  T/C  G/C
2  A/A  G/G  G/G
3  T/T  C/C  C/C
answered Aug 7 by MD
• 57,680 points

Related Questions In Data Analytics

0 votes
1 answer

How to extract specific columns from a DataFrame ?

Yes there are so many ways: df[,c(V2,V4)] and another ...READ MORE

answered Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,720 points
4,458 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 13, 2018 in Data Analytics by Sahiti
• 6,320 points
942 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
425 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
280 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
397 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 32,490 points
418 views
0 votes
1 answer
0 votes
1 answer

How to select columns containing specific text in R?

Hi, You can use the select method to extract ...READ MORE

answered Aug 7 in Data Analytics by MD
• 57,680 points
126 views