Boy are you confused. This has nothing at all to do with substitution.
Instead do
test <- with(fc,ave.fc[match(diff_mirs_list,Probe)])
cheers,
Rolf Turner
On 7/11/2008, at 11:46 AM, Iain Gallagher wrote:
Hello list.
I have a vector of values:
eg
head(diff_mirs_list)
[1] "hsa-miR-26b" "hsa-miR-26b" "hsa-miR-23a" "hsa-miR-27b" "hsa-
miR-29a"
[6] "hsa-miR-29b"
and I would like to conditionally replace each value in this vector
with a number defined in a dataframe:
fc
Probe ave.fc
1 hsa-let-7a 1.28
2 hsa-miR-100 1.47
3 hsa-miR-125a-5p 1.31
4 hsa-miR-140-3p 1.28
5 hsa-miR-143 1.98
6 hsa-miR-193a-3p 1.37
7 hsa-miR-193b 1.48
8 hsa-miR-195 1.16
9 hsa-miR-214 1.22
10 hsa-miR-23a 1.21
11 hsa-miR-26b 1.13
12 hsa-miR-27b 1.37
13 hsa-miR-29a 1.24
14 hsa-miR-29b 1.69
15 hsa-miR-30b 1.16
16 hsa-miR-424 1.42
17 hsa-miR-768-3p 1.48
18 hsa-miR-886-3p 1.43
19 hsa-miR-933 1.23
ie every hsa-let-7a in the diff_mirs_list is replaced by 1.28, hsa-
miR-100 by 1.47 etc etc
I have tried to make a loop to use gsub eg
for (i in 1:nrow(fc)){
+ test<-gsub(fc[i,1], fc[i,2], diff_mirs_list)
}
but this obviously passes the unchanged vector to gsub each time
and so I get back my 'test' vector with only hsa-miR-933 changed.
Could someone help me out with this please.
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.