Create Vector Of Affy Ids
1
0
Entering edit mode
11.5 years ago
Nitin ▴ 170

Hello,

I have list of 50000 affy ids in text file can any body tell me how to create vector in R?

Cheers, Ni

r • 2.1k views
ADD COMMENT
1
Entering edit mode

As it stands, this is a basic R programming question, rather than a bioinformatics research problem. I would normally suggest you ask such questions at StackOverflow but in this case, they would close it and tell you to read the manual and/or search the Web, since this is a common question that has been answered many times.

In brief: the function you want is scan(). Try "?scan" in R for more information. Also read http://cran.r-project.org/doc/manuals/R-data.html.

ADD REPLY
0
Entering edit mode

Do you have expression data in tabular (TSV or CSV) format?

ADD REPLY
0
Entering edit mode

If you are working with affy in R you most likely want to load the appropriate bioconductor annotation package in stead of importing probe ids from a text file

ADD REPLY
2
Entering edit mode
11.5 years ago
seidel 11k

If your data is in any kind of tabular form, a common way to read data into R from files is to use a function called read.table(). Assuming your file simply contains one column of ids, you could read it in as follows:

# read in data
x <- read.table(file="yourfile.txt", as.is=T)

# x is a 1 column table, take the 1st column to a new variable
# the result should be a vector
affy_ids <- x[,1]

In most cases this function is used to read in tables of data delimited in some way (i.e. tab or comma), thus you would specify what the delimiter is: delimiter="\t" for tab. The as.is=T parameter tells R not to treat any of the data as a factor (a way to group data). The T is a shortcut for TRUE.

Here's a shorter way to do the same thing:

affy_ids <- read.table(file="yourfile.txt", as.is=T)[,1]

There is a more robust function which does the same thing called read.delim(). Sometimes read.table fails if the data is complicated or has any irregularities (i.e. after exporting from excel) whereas read.delim seems to survive more insults. There are many ways to read data into R. It didn't occur to me to use scan() for a file of ids. I think you could figure out the above scenario if you looked at the documentation for 5 minutes, but I sympathize because even after using R for more than a decade, most of the time I can't understand the documentation myself.

ADD COMMENT
0
Entering edit mode

I chose scan() because the questioner stated that they wanted a vector. First line of scan() documentation: "Read data into a vector or list from the console or file." However, a 1-column data frame using read.table() works just as well and is perhaps easier to understand. And of course, that column is a vector :)

ADD REPLY

Login before adding your answer.

Traffic: 2452 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