[R] How to merge two files
Joshua Wiley
jwiley.psych at gmail.com
Mon Jul 4 20:45:23 CEST 2011
Dear Albert,
Here is one way:
tmp.scores <- readLines("~/scores.txt")
tmp.seq <- readLines("~/seq.txt")
tmp.seq <- strsplit(gsub("N", "", tmp.seq), "")[[1]]
genedat <- data.frame(Sequence = tmp.seq, Scores = as.numeric(tmp.scores))
## Yields
> genedat
Sequence Scores
1 A 0.80
2 T 0.70
3 T 0.30
4 A 0.50
5 A 0.60
6 A 0.50
7 G 0.01
8 G 0.90
9 G 0.30
10 C 0.80
Hope this helps,
Josh
2011/7/4 albert coster <albertcoster2010 at gmail.com>:
> Dear all,
>
> I have two files :
>
> seq.txt: NNNNNNNNNNATTAAAGGGC
>
> scores.txt :
>
> 0.8
> 0.7
> 0.3
> 0.5
> 0.6
> 0.5
> 0.01
> 0.9
> 0.3
> 0.8
>
> I want output as following
>
> A 0.8
> T 0.7
> T 0.3
> A 0.5
> A 0.6
> A 0.5
> G 0.01
> G 0.9
> G 0.3
> C 0.8
>
> Where N are deleted and only A/T/G/C are appearing in a column.
>
> Thanks
>
> Albert
>
> ______________________________________________
> R-help at 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.
>
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list