Entering edit mode
7.7 years ago
zizigolu
★
4.3k
Hi,
I have a file like below
> head(data[,1:4])
ID GSM943243 GSM943244 GSM943245
1 EEF1A1 14.517466 14.591990 14.582881
2 GAPDH 11.925736 11.820686 11.719080
3 LOC643334 7.505173 7.494044 7.365844
4 SLC35E2 7.720945 7.642623 7.727642
5 DUSP22 7.348523 7.345953 7.385760
6 LOC642820 7.538024 7.582380 7.501941
> # watching the dimension of matrix
> dim(data)
[1] 25217 203
>
I have a list of accession numbers (for example GSM943243
) corresponding control samples, how I can extract controls from my file???
https://dzone.com/articles/learn-r-how-extract-rows
http://stats.stackexchange.com/questions/10225/extracting-multiple-columns-from-a-matrix-in-r
thank you, inspired by the second link I did like so
first of all you need to
read.table
it into an object withrownames=1
then that dataframe can be subsetted with the columns of your choice. Do you know the indexes of the columns that are controls? then it is faily simple. In that case your rownames will be intact. Doing manually rownames is not a good approach. When you are doing programmtically add everything the same way.in my another file
and a list of samples names in another files
>
I want to extract only these samples from my expression data file
I did like so
but telling
Error in
[.data.frame
(data1, , c(data2)) : undefined columns selectedI could not figure out what happened that not working as previous case
to be honest this is a nominal thing to do both in
swk,sed
or inR
. The thing which i see here is the header name of data1 is not same as that in data2. You have to give some example of columns which you show indata[,1:4]
, in your data2 as well. I do not see that. Also the names are amazingly long strings which lot of attributes that makes me think they are actually not same. Lets have you have 10 columns in a dataframex
and you want to subset only 6 which are columns you know you want to extract. lets say you know the column indexes. So they are 2,4, 7 through 10.I would like to suggest editing the question title to include that you are trying to do this in R. For example: "Extracting several columns from a file using R." This will help other people looking for similar answers via search engines. As stated, the answer could be as simple as
man cut
.