[R] Fwd: transpose ?
Dennis Murphy
djmuser at gmail.com
Wed May 25 20:23:30 CEST 2011
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)
> mm
[[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:
> Dear All,
> Sorry for the previous mail,suppose this data.frame
> D
>
>
> V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22
> 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
>
>
>
>
>
> I would translate D as follow ( just for the first line)
>
> C C T G A C G C
> C C T G A C G C
> (V8 under V7) (V9 under V10) ...
>
> Any help would be appreciated
>
> Regards
> M
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list