[R] Conversion of matrix in r to integer
David Carlson
dcarlson at tamu.edu
Thu Aug 1 19:46:24 CEST 2013
Assuming you have created a data.frame from the text file you
sent that is called RP:
> str(RP)
# 'data.frame': 28597 obs. of 8 variables:
# $ gene : chr "XLOC_000001" "XLOC_000002" "XLOC_000003"
"XLOC_000004" ...
# $ ZPT.1: num 3516 342 2000 143 0 ...
# $ ZPT.0: num 626 82 361 30 0 0 0 0 0 1 ...
# $ ZPT.2: num 1277 185 867 67 0 ...
# $ ZPT.3: num 770 72 438 37 0 0 0 0 0 3 ...
# $ PGR.1: num 2603 304 195 66 0 ...
# $ PGR.0: num 1534 175 80 49 0 ...
# $ PGR.2: num 1764 208 109 54 0 ...
> RP[,-1] <- sapply(round(RP[,-1], 0), as.integer)
> str(RP)
# 'data.frame': 28597 obs. of 8 variables:
# $ gene : chr "XLOC_000001" "XLOC_000002" "XLOC_000003"
"XLOC_000004" ...
# $ ZPT.1: int 3516 342 2000 143 0 0 0 0 0 7 ...
# $ ZPT.0: int 626 82 361 30 0 0 0 0 0 1 ...
# $ ZPT.2: int 1277 185 867 67 0 0 0 0 0 5 ...
# $ ZPT.3: int 770 72 438 37 0 0 0 0 0 3 ...
# $ PGR.1: int 2603 304 195 66 0 1 0 0 0 0 ...
# $ PGR.0: int 1534 175 80 49 0 0 1 0 0 0 ...
# $ PGR.2: int 1764 208 109 54 0 0 1 0 0 1 ...
-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Vivek Das
Sent: Thursday, August 1, 2013 10:49 AM
To: arun; R help
Subject: [R] Conversion of matrix in r to integer
Hi,
I have a matrix which which I need for some analysis and that
package in R
only works on integer values. My data.frame is not integer
value . I want
to convert the values to the nearest integer values for my
matrix. Can you
tell me how to do it in r. I am sending you the matrix where
you can see a
lot of decimal point numbers and all of them needs to be
converted to
integer values
----------------------------------------------------------
Vivek Das
PhD Student in Computational Biology
Giuseppe Testa's Lab
European School of Molecular Medicine
IFOM-IEO Campus
Via Adamello, 16
Milan, Italy
emails: vivek.das at ieo.eu
vchris_05 at yahoo.co.in
vd4mmind at gmail.com
More information about the R-help
mailing list