Dear all,
I have a file that is summary.txt(I have attached it) .we can read
this file using-
dfa=read.table("summar.txt",fill=T,colClasses = "character",header=T)
In V10 column I have ASCII values which I want to convert into decimal
numbers -
my data frame(dfa) which is like-
V7 V8 V9 V10
1 0 1 G `
2 0 1 T a
3 0 1 C a
4 0 1 A a
5 0 1 G _
6 0 1 G Z
7 0 1 C ^
8 0 1 C \\
9 0 1 A Z
10 0 1 T a
11 0 1 g ^
12 0 1 A \\
13 0 1 C _
14 0 1 G a
15 0 1 C X
16 0 1 C `
17 0 1 G a
18 0 1 G _
Column V10 contains ASCII values.I want to convert them into decimal.
Can you please help me.
Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: summary.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110709/5132ce66/attachment.txt>
ASCII values to Decimal
4 messages · jim holtman, Brian Ripley, Bansal, Vikas
Try this:
str(x)
'data.frame': 111 obs. of 5 variables: $ V7 : int 0 0 0 0 0 0 0 0 0 0 ... $ V8 : int 1 1 1 1 1 1 1 1 1 1 ... $ V9 : chr "G" "T" "C" "A" ... $ V10 : chr "`" "a" "a" "a" ... $ value: chr "96" "97" "97" "97" ...
x$value <- sapply(x$V10, function(a) paste(as.integer(charToRaw(a)), collapse = ' ')) head(x, 40)
V7 V8 V9 V10 value 1 0 1 G ` 96 2 0 1 T a 97 3 0 1 C a 97 4 0 1 A a 97 5 0 1 G _ 95 6 0 1 G Z 90 7 0 1 C ^ 94 8 0 1 C \\ 92 9 0 1 A Z 90 10 0 1 T a 97 11 0 1 g ^ 94 12 0 1 A \\ 92 13 0 1 C _ 95 14 0 1 G a 97 15 0 1 C X 88 16 0 1 C ` 96 17 0 1 G a 97 18 0 1 G _ 95 19 0 1 G a 97 20 0 1 G a 97 21 0 1 A a 97 22 0 1 G a 97 23 0 1 G a 97 24 0 1 C a 97 25 0 1 A a 97 26 0 1 C _ 95 27 0 1 A X 88 28 0 1 g ` 96 29 0 2 GG \\\\ 92 92 30 0 2 GG [^ 91 94 31 0 2 AA Y^ 89 94 32 0 2 GG `] 96 93 33 0 2 AA a^ 97 94 34 0 2 GG ]^ 93 94 35 0 2 AA a\\ 97 92 36 0 2 GG a] 97 93 37 0 2 GG Z] 90 93 38 0 2 GG ]^ 93 94 39 0 2 CC W\\ 87 92 40 0 2 CC a] 97 93
2011/7/9 Bansal, Vikas <vikas.bansal at kcl.ac.uk>:
Dear all,
I have a file that is summary.txt(I have attached it) .we can read
?this file using-
?dfa=read.table("summar.txt",fill=T,colClasses = "character",header=T)
?In V10 column I have ?ASCII values which I want to convert into decimal
?numbers -
my ?data frame(dfa) which is like-
? ? V7 V8 ?V9 ?V10
1 ? ?0 ?1 ? G ? ?`
2 ? ?0 ?1 ? T ? ?a
3 ? ?0 ?1 ? C ? ?a
4 ? ?0 ?1 ? A ? ?a
5 ? ?0 ?1 ? G ? ?_
6 ? ?0 ?1 ? G ? ?Z
7 ? ?0 ?1 ? C ? ?^
8 ? ?0 ?1 ? C ? \\
9 ? ?0 ?1 ? A ? ?Z
10 ? 0 ?1 ? T ? ?a
11 ? 0 ?1 ? g ? ?^
12 ? 0 ?1 ? A ? \\
13 ? 0 ?1 ? C ? ?_
14 ? 0 ?1 ? G ? ?a
15 ? 0 ?1 ? C ? ?X
16 ? 0 ?1 ? C ? ?`
17 ? 0 ?1 ? G ? ?a
18 ? 0 ?1 ? G ? ?_
Column V10 contains ASCII values.I want to convert them into decimal.
Can you please help me.
Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
______________________________________________ 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.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
And what is the mapping from ascii characters to decimal numbers that you seek? One possible answer is to use utf8ToInt, but it is only one answer.
sapply(c('`', 'a', '_', 'Z', '^', '\\'), utf8ToInt)
` a _ Z ^ \\ 96 97 95 90 94 92
On Sat, 9 Jul 2011, Bansal, Vikas wrote:
Dear all,
I have a file that is summary.txt(I have attached it) .we can read
this file using-
dfa=read.table("summar.txt",fill=T,colClasses = "character",header=T)
In V10 column I have ASCII values which I want to convert into decimal
numbers -
my data frame(dfa) which is like-
V7 V8 V9 V10
1 0 1 G `
2 0 1 T a
3 0 1 C a
4 0 1 A a
5 0 1 G _
6 0 1 G Z
7 0 1 C ^
8 0 1 C \\
9 0 1 A Z
10 0 1 T a
11 0 1 g ^
12 0 1 A \\
13 0 1 C _
14 0 1 G a
15 0 1 C X
16 0 1 C `
17 0 1 G a
18 0 1 G _
Column V10 contains ASCII values.I want to convert them into decimal.
Can you please help me.
Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
I used this code by Jim Holtman (Thanks to him)and it is working perfectly. dfa$value <- sapply(dfa$V10, function(a) paste(as.integer(charToRaw(a)), collapse = ' ')) Thanking you, Warm Regards Vikas Bansal Msc Bioinformatics Kings College London
From: Prof Brian Ripley [ripley at stats.ox.ac.uk]
Sent: Saturday, July 09, 2011 6:44 PM
To: Bansal, Vikas
Cc: r-help at r-project.org
Subject: Re: [R] ASCII values to Decimal
Sent: Saturday, July 09, 2011 6:44 PM
To: Bansal, Vikas
Cc: r-help at r-project.org
Subject: Re: [R] ASCII values to Decimal
And what is the mapping from ascii characters to decimal numbers that
you seek?
One possible answer is to use utf8ToInt, but it is only one answer.
> sapply(c('`', 'a', '_', 'Z', '^', '\\'), utf8ToInt)
` a _ Z ^ \\
96 97 95 90 94 92
On Sat, 9 Jul 2011, Bansal, Vikas wrote:
> Dear all,
>
> I have a file that is summary.txt(I have attached it) .we can read
> this file using-
>
> dfa=read.table("summar.txt",fill=T,colClasses = "character",header=T)
>
> In V10 column I have ASCII values which I want to convert into decimal
> numbers -
>
> my data frame(dfa) which is like-
>
> V7 V8 V9 V10
> 1 0 1 G `
> 2 0 1 T a
> 3 0 1 C a
> 4 0 1 A a
> 5 0 1 G _
> 6 0 1 G Z
> 7 0 1 C ^
> 8 0 1 C \\
> 9 0 1 A Z
> 10 0 1 T a
> 11 0 1 g ^
> 12 0 1 A \\
> 13 0 1 C _
> 14 0 1 G a
> 15 0 1 C X
> 16 0 1 C `
> 17 0 1 G a
> 18 0 1 G _
>
>
> Column V10 contains ASCII values.I want to convert them into decimal.
>
> Can you please help me.
>
>
> Thanking you,
> Warm Regards
> Vikas Bansal
> Msc Bioinformatics
> Kings College London
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595