Dear all,
I have a file and I am using a code-
df=read.table("Case2.pileup",fill=T,sep="\t",colClasses =
"character")
to create a data frame that is df.
now in 4th column I have ASCII values which I want to convert in decimal
values.the data frame is like this-
V1 V2 V3 V4
9 2 ., a\
9 2 .$, a`
13 1 , a
13 1 , a
13 1 , a
13 1 , a
13 1 , `
13 1 , ^
13 1 , a
13 1 ,$ a
I am using this code to convert it-
as.numeric(charToRaw(df[,4]))
it is showing this error-
Warning message:
In charToRaw(df[, 4]) : argument should be a character vector of length 1
all but the first element will be ignored
and it is converting only the value in first row.How can I do this for all rows
in my data frame.
Please help me.I am new user for R.I will be very thankful to you.
Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
You can do:
as.numeric(charToRaw(paste(df[,4], collapse="")))
If you somehow want each row to be its own sequence of integers, you
could do something like:
lapply(df[,4], function(c) as.numeric(charToRaw(c)));
~Matthew Maycock
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Bansal, Vikas
Sent: Friday, July 08, 2011 4:42 PM
To: r-help at r-project.org
Subject: [R] ASCII values to Decimal
Dear all,
I have a file and I am using a code-
df=read.table("Case2.pileup",fill=T,sep="\t",colClasses =
"character")
to create a data frame that is df.
now in 4th column I have ASCII values which I want to convert in decimal
values.the data frame is like this-
V1 V2 V3 V4
9 2 ., a\
9 2 .$, a`
13 1 , a
13 1 , a
13 1 , a
13 1 , a
13 1 , `
13 1 , ^
13 1 , a
13 1 ,$ a
I am using this code to convert it-
as.numeric(charToRaw(df[,4]))
it is showing this error-
Warning message:
In charToRaw(df[, 4]) : argument should be a character vector of length
1
all but the first element will be ignored
and it is converting only the value in first row.How can I do this for
all rows in my data frame.
Please help me.I am new user for R.I will be very thankful to you.
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.
Dear all, I have a data frame which is like- V1 V2 V3 V4 9 2 ., a\ 9 2 .$, a` 13 1 , a 13 1 , a 13 1 , a 13 1 , a 13 1 , ` 13 1 , ^ 13 1 , a 13 1 ,$ a Column V4 contains ASCII values.I want to convert them into decimal.I am using- df$V4=lapply(df[,4], function(c) as.numeric(charToRaw(c))) I want to ask that,is this the right way to convert these values into decimal? Thanking you, Warm Regards Vikas Bansal Msc Bioinformatics Kings College London
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>