1

Column one (x[, 1]) has the original signal. Column 2 (x[, 2]) has the improved signal. I want to have them now as a single column for the following line. Code for single column reference in x[, 1]

# http://stackoverflow.com/a/40329062/54964
M <- cor(sapply(files, function(x) x[, 1]))

Pseudocode x[, 1:2] for taking both columns in a long column - second column after the first one

M_both <- cor(sapply(files, function(x) x[, 1:2]))

I think this can be done by many measures, maybe concatenating also in R. I have about 100x2 cases so the matrix sizes are 100x100 x2.

c(x[,1],x[,2]) is not making a big column.

Structure of files by str(files)

List of 2
 $ :'data.frame':   541650 obs. of  2 variables:
  ..$ V1: num [1:541650] -0.13 -0.165 -0.17 -0.135 -0.12 -0.11 -0.12 -0.135 -0.155 -0.145 ...
  ..$ V2: num [1:541650] -0.535 -0.515 -0.505 -0.505 -0.505 -0.5 -0.495 -0.49 -0.48 -0.48 ...
 $ :'data.frame':   541650 obs. of  2 variables:
  ..$ V1: num [1:541650] -0.2 -0.195 -0.185 -0.18 -0.17 -0.16 -0.16 -0.16 -0.155 -0.145 ...
  ..$ V2: num [1:541650] -0.43 -0.38 -0.375 -0.515 -0.605 -0.575 -0.525 -0.505 -0.495 -0.49 ...

Output of Luke1018's answer

I do

M_both <- cor(sapply(files, function(x) c(x[, 1],x[, 2]) ))
makeMatrixPlot(M_both, ids)

Fig. 1 Initial output on left with single columns, while output of two columns at the right-hand side

enter image description here

OS: Debian 8.5
R: 3.1.1

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 3
    I dont really understand what you're asking. If you want to put two columns together, you can just do `c(x[,1],x[,2])` or `rbind` or `reshape2::melt` if it helps... – Jan Sila Oct 30 '16 at 21:55
  • Can you provide the structure of "files"? Is it a list of two matrices? So for the first line, are you trying to find the correlation between the first column of file1 and the first column of file2? I don't understand what you meant by "taking both columns in a long column" either. Please clarify. – acylam Oct 30 '16 at 21:56
  • @JanSila Please, see the body. – Léo Léopold Hertz 준영 Oct 30 '16 at 22:05
  • you got a list of two data frames. do you want to put V1,V2 and V1,V2 after each other? – Jan Sila Oct 30 '16 at 22:08
  • 1
    You want all the data frames to become a single column or a each one of them to become a single column and keep the list structure? I guess you could just do `unlist(files)` or `lapply(files, unlist)` - depending on your desired output. You can also specify `, use.names = FALSE` within `unlist` if you don't want a named vector – David Arenburg Oct 30 '16 at 22:12

1 Answers1

2

data.frame(c(x[, 1], x[, 2])) will create your "one big column". However, your function is not reassigning any new value to files - so naturally the structure will not have changed.

seasmith
  • 889
  • 9
  • 16