converting a matrix to array

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

converting a matrix to array

Effat Habibi
Dear Sir/ Madam,

I have a problem with converting a matrix (247 rows, 16 columns) to an array in R.

Would you please help me in this regard.

Thank you,
E. Habibi
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: converting a matrix to array

Jim Lemon
On Sun, 18 May 2014 08:18:18 PM Effat Habibi wrote:
> Dear Sir/ Madam,
>
> I have a problem with converting a matrix (247 rows, 16 columns) to
an array
> in R.
>
> Would you please help me in this regard.
>
Hi Effat,

"A two-dimensional array is the same thing as a matrix."

>From the help page for "array".

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: converting a matrix to array

arun kirshna
In reply to this post by Effat Habibi


Hi,


If you meant to convert the matrix to a 3D array, check this link:

http://stackoverflow.com/questions/9572656/how-to-convert-matrix-into-array

A.K.



On Monday, May 19, 2014 2:18 AM, Effat Habibi <[hidden email]> wrote:
Dear Sir/ Madam,

I have a problem with converting a matrix (247 rows, 16 columns) to an array in R.

Would you please help me in this regard.

Thank you,
E. Habibi
______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: converting a matrix to array

arun kirshna

Hi,
Try:
mat <- as.matrix(read.csv("R.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t",row.names=1))
pdf("Hist_colwise.pdf")
lst1 <- lapply(seq_len(ncol(mat)),function(i) {x<- mat[,i,drop=FALSE]; hist(x, main=paste("Histogram of", colnames(x)))})
dev.off()

##or may be this would be another way to look at the data
library(reshape2)
library(ggplot2)
 dat <- melt(mat)


pdf("Hist_all.pdf", width=14)
ggplot(dat, aes(x=Var2, y=value, fill=Var1))+geom_histogram(stat="identity",position="dodge")+
 theme(legend.position = "none")+
 xlab("") +
 theme(axis.line = element_line(colour = "black"),
 panel.grid.major = element_blank(),
 panel.grid.minor = element_blank(),
 panel.border = element_blank(),
 panel.background = element_blank())
dev.off()



A.K.


On Thursday, May 22, 2014 10:48 AM, Effat Habibi <[hidden email]> wrote:



Thanks. I think columnwise histogram should be fine. Can you please help me with the commands for making that?
On May 22, 2014 2:21 AM, "arun" <[hidden email]> wrote:

Hi Effat,

>
>Sorry, I was a bit busy.  I did read the data. 
>
>
>mat <- as.matrix(read.csv("R.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t",row.names=1))
> is.matrix(mat)
>#[1] TRUE
>
> head(mat,2)
>          COG0001H COG0002E COG0003P COG0004P COG0005F COG0006E COG0007H
>NC_014218       NA       NA       NA       NA      274      502       NA
>NC_013501      437      345       NA      458      284      364      271
>          COG0008J COG0009J COG0010E COG0011S COG0012J COG0013J COG0014E
>NC_014218      427      212       NA      103      365      890       NA
>NC_013501      500      317      316       NA      366      953       NA
>          COG0015F
>NC_014218      479
>NC_013501      431
>
>
>
>I am not sure I understand what you really wanted.  In the matrix example I showed, I did the table for all the elements of the matrix.  Do you want a columnwise histogram or a rowwise histogram??
>
>A.K.
>
>
>
>On Tuesday, May 20, 2014 1:29 PM, Effat Habibi <[hidden email]> wrote:
>
>
>
>Thanks, it works. But this histogram doesn't show any information about my data,
>I want to make an informative histogram of my data which tells about length of different COGs across 
>the genome. 
>
>
>
>
>

______________________________________________
[hidden email] 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.