[R] cbind question
Gabor Grothendieck
ggrothendieck at myway.com
Sun Mar 28 04:34:57 CEST 2004
Suppose you have these two variables:
x1 <- matrix(list("a","b","c"),3,1)
x2 <- matrix(list(1,2,3),3,1)
You can unlist them and then create a data frame out of them:
data.frame(x1=unlist(x1),x2=unlist(x2))
Aside from the above solution, you might want to question why your
variables are lists in the first place.
Han, Hillary <Hillary_Han <at> brown.edu> writes:
:
: Thanks very much. I used c, and got the two lists merged fine. I would like
to write the results into a file. So used
:
: > write.table(try, file = "try.txt")
: Error in cbind(...) : cannot create a matrix from these types
:
: Got into the same cbind error... Any suggestions? Thanks in advance.
:
: code:
: > > class(ll)
: > [1] "list"
: > > class(sym)
: > [1] "list"
: > > dim(sym)
: > [1] 508 1
: > > dim(ll)
: > [1] 508 1
: > try <- c(sym[1:5], ll[1:5])
: > dim(try)
: NULL
: > dim(try)<- c(5, 2)
: > try
: [,1] [,2]
: [1,] "Slc40a1" 53945
: [2,] "Rassf5" 54354
: [3,] "Igfbp4" 16010
: [4,] "Hmox1" 15368
: [5,] "Cxcr4" 12767
: > write.table(try, file = "try.txt")
: Error in cbind(...) : cannot create a matrix from these types
:
:
: -----Original Message-----
: From: Prof Brian Ripley [mailto:ripley <at> stats.ox.ac.uk]
: Sent: Sat 3/27/2004 3:30 PM
: To: Han, Hillary
: Cc: r-help <at> stat.math.ethz.ch
: Subject: Re: [R] cbind question
: cbind on vectors/matrices which are not atomic is unsupported: we had a
: bug report on that within the last 24 hours (but it seems to be
: intentional).
:
: You can just concatenate the lists and add a suitable dimension:
:
: res <- c(ll, sym)
: dim(res) <- c(508,2)
:
: if I understand your intentions.
:
: I think. However, *why* do you want to do this? A list of lists would
: seem to make more sense, and can be indexed in a similar way.
:
: On Sat, 27 Mar 2004, Han, Hillary wrote:
:
: > Just wonder if there is any suggestions in how to get around this cbind
: > error. I created two character lists with identical length. First tried
:
: What is a `character list'?
:
: > combine the lists together with cbind, then convert the lists to matrix,
: > and tried again. Both faied. Any fix to merge the two lists/matrices?
:
: Merge? That's what c() does.
:
: > ll<- multiget(ftID, hgu95av2LOCUSID)
: > > class(ll)
: > [1] "list"
: > > sym <- multiget(ftID, hgu95av2SYMBOL)
: > > class(sym)
: > [1] "list"
: > > cbind(sym, ll)
: > Error in cbind(...) : cannot create a matrix from these types
: > > sym <- as.matrix(multiget(ftID, hgu95av2SYMBOL))
: > > ll<- as.matrix(multiget(ftID, hgu95av2LOCUSID))
: > > dim(sym)
: > [1] 508 1
: > > dim(ll)
: > [1] 508 1
: > > class(sym)
: > [1] "matrix"
: > > class(ll)
: > [1] "matrix"
: > > cbind(sym,ll)
: > Error in cbind(...) : cannot create a matrix from these types
:
More information about the R-help
mailing list