Skip to content

transpose ?

3 messages · Mohamed Lajnef, Jeff Newmiller, Dennis Murphy

#
Hi:

Does this work?

dd <- read.table(textConnection("
C  C  C   C   T   T   G   G   A   A   C   C   G   G   C   C
G  G  T   T   A   A   A   A   T   A   T   T   C   C   G   G
C  C  C   C   T   T   G   G   A   A   C   C   G   G   C   C
"), stringsAsFactors = FALSE)

# Convert the data frame to a character matrix
# To do this, you need to make sure that the variables in
# your data frame are character rather than factor
dm <- as.matrix(dd)
dm        # elements should be quoted if character

# Create an empty list of nrow(dm) components
mm <- vector('list', nrow(dm))

# Create a two-row matrix from each row of dm
for(i in seq_len(nrow(dm))) mm[[i]] <- matrix(dm[i, ], nrow = 2)
[[1]]
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] "C"  "C"  "T"  "G"  "A"  "C"  "G"  "C"
[2,] "C"  "C"  "T"  "G"  "A"  "C"  "G"  "C"

[[2]]
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] "G"  "T"  "A"  "A"  "T"  "T"  "C"  "G"
[2,] "G"  "T"  "A"  "A"  "A"  "T"  "C"  "G"

[[3]]
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] "C"  "C"  "T"  "G"  "A"  "C"  "G"  "C"
[2,] "C"  "C"  "T"  "G"  "A"  "C"  "G"  "C"

HTH,
Dennis

On Wed, May 25, 2011 at 7:19 AM, Mohamed Lajnef
<Mohamed.lajnef at inserm.fr> wrote: