extracting several columns from a file
1
0
Entering edit mode
Angel ▴ 40
@angel-7981
Last seen 7.1 years ago
Berlin

hi I have two files

 

> head(data1[,1:4])
          GSE35974_Biomat_17___BioAssayImplId.212266Name.DE37_111809_rep5
LINC01128                                                        8.789351
SAMD11                                                           7.059227
KLHL17                                                           7.453778
PLEKHN1                                                          7.546892
ISG15                                                            7.091302
AGRN                                                             7.505454
          GSE35974_Biomat_139___BioAssayImplId.212294Name.AC99_111809
LINC01128                                                    8.733914
SAMD11                                                       7.120576
KLHL17                                                       7.503455
PLEKHN1                                                      7.425533
ISG15                                                        6.788893
AGRN                                                         7.269030
          GSE35974_Biomat_137___BioAssayImplId.212295Name.AC96_111809
LINC01128                                                    8.914045
SAMD11                                                       7.232991
KLHL17                                                       7.472246
PLEKHN1                                                      7.352260
ISG15                                                        7.017254
AGRN                                                         7.436749
          GSE35974_Biomat_136___BioAssayImplId.212296Name.AC95_111809
LINC01128                                                    8.977482
SAMD11                                                       7.087887
KLHL17                                                       7.436269
PLEKHN1                                                      7.321820
ISG15                                                        6.922916
AGRN                                                         7.470006
 

> and a list of samples names in another files

> head(data2[,1])
[1] GSE35974_Biomat_69___BioAssayImplId=212347Name=AC45_111109
[2] GSE35974_Biomat_67___BioAssayImplId=212345Name=AC47_111109
[3] GSE35974_Biomat_64___BioAssayImplId=212344Name=AC49_102309
[4] GSE35974_Biomat_74___BioAssayImplId=212351Name=AC41_111809
[5] GSE35974_Biomat_73___BioAssayImplId=212349Name=AC43_102309
[6] GSE35974_Biomat_68___BioAssayImplId=212348Name=AC44_111809
94 Levels: GSE35974_Biomat_10___BioAssayImplId=212273Name=DE35_102309 ...
 

>

I want to extract only these samples from my expression data file

 

I did like so

list of samples=t(data2)
>extraction=data1[,c(data2)]

 

but telling

 

Error in `[.data.frame`(data1, , c(data2)) : 
  undefined columns selected

 

then how can I do that please???

software error • 629 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 6 minutes ago
United States

This is a basic R question, not really pertinent to Bioconductor. In the future you should probably ask this sort of thing on the R-help listserv (r-help@r-project.org). Or better yet, just google it. You could just paste that error into Google's search bar and you would almost surely get an answer.

Another alternative is to look at the error and try to determine what it is telling you. These things are intended to be useful, rather than cryptic, so whomever wrote that error message intended that it would be self-explanatory. And really, it is. It says 'undefined columns selected'. You are trying to select columns from data1 based on whatever is in data2. If data2 contains anything that doesn't exactly match one of the columns in data1, you will get that error:

> data1 <- data.frame(a = 1:4, b = 2:5, c = 3:6)
> data2 <- data.frame(whatevs = letters[1:3])
> data2[,1]
[1] a b c
Levels: a b c
> data1[,data2[,1]]
  a b c
1 1 2 3
2 2 3 4
3 3 4 5
4 4 5 6
> data2 <- data.frame(whatevs = letters[1:4])
> data1[,data2[,1]]
Error in `[.data.frame`(data1, , data2[, 1]) : undefined columns selected

 

ADD COMMENT

Login before adding your answer.

Traffic: 967 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6