Assigning Objects To A Variable
1
0
Entering edit mode
12.0 years ago
Avoks ▴ 40

Hi all,

This is perhaps very basic to the R pros, but I was wondering how I could assign a variable, say "control" to a string of sorts. For example:

"musclenormal15494"
"musclenormal15497"
"musclenormal15501"

My interest is in the muscle_normal part and since it's quite a list, it will be quite hectic to assign each one individually.

Any suggestions will be greatly appreciated.

Thanks.

-Avoks

r • 1.4k views
ADD COMMENT
0
Entering edit mode

Hi, Sorry its unclear to me, do you have list with strings given above stored in it, and you want to filter the ones starting with muscle_normal and store it in other list!!

ADD REPLY
0
Entering edit mode

Hi Sukhdeep. These are gse18732 data I extracted from GEO using getGEO. I'm running a limma analysis and trying to assign the different cases to the 3 test levels, T2D, IGT and Control(normal) so that I can create an appropriate cont. matrix. I usually use a different "channel" but for this particular study the channels are quite confusing and the "title" seemed to be the most straightforward but it comes with the numbers, hence my question.

ADD REPLY
1
Entering edit mode
12.0 years ago

I guess what you want is:

x=c("muscle_normal_15494","muscle_normal_15497","muscle_normal_15501","the_other_string_1","the_other_string_2")
myfactors=rep(NA,length(x))
myfactors[grep("muscle_normal",x)]="control"
myfactors[grep("the_other_string",x)]="other"
myfactors=as.factor(myfactors)
ADD COMMENT
0
Entering edit mode

Thanks Leonor. But that's not really what I want, I think, because this code involves manually inputting each one to create a list...that's what I'm trying to avoid.

ADD REPLY
0
Entering edit mode

This is just an example, you absolutely should not need to enter these by hand! If this is stored in a file, you can of course read the file with x=read.table("myfile"), if it is a list, you just have to unlist() it first. How is your data stored?

ADD REPLY
0
Entering edit mode

Actually now I read through again, I kind of get it. I however got the info I wanted by sorting and extracting by numbers:

groups = pData(phenoData(gsexxxxxdat[[1]]))$title

groups=as.character(groups)

groups=sort(groups)

groups[c(1:45)]="T2D"

groups[c(46:71)]="IGT"

groups[c(72:118)]="control"

f = factor(groups, levels=c("control","T2D","IGT"))

Perhaps not the most intuitive way but I got what I wanted:).

Thanks again.

ADD REPLY

Login before adding your answer.

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