On 13-01-26 3:00 PM, Christofer Bogaso wrote:
Hello again,

I generally use Clipboard to load data into R from Excel using the
read.delim() function. In most cases, my data after loading looks like
below:

myData <- structure(list(V1 = structure(c(3L, 2L, 1L, 1L, 2L), .Label = c("",
"2", "a"), class = "factor"), V2 = structure(c(4L, 3L, 1L, 2L,
1L), .Label = c("", "34", "4", "b"), class = "factor"), V3 = structure(c(3L,
1L, 1L, 1L, 2L), .Label = c("", "4", "c"), class = "factor"),
     V4 = structure(c(3L, 1L, 1L, 2L, 1L), .Label = c("", "4",
     "d"), class = "factor"), V5 = structure(c(4L, 3L, 1L, 1L,
     2L), .Label = c("", "4", "7", "f"), class = "factor")), .Names = c("V1",
"V2", "V3", "V4", "V5"), class = "data.frame", row.names = c(NA,
-5L))


myData
   V1 V2 V3 V4 V5
1  a  b  c  d  f
2  2  4        7
3
4    34     4
5  2     4     4


Now I want to put this data in a Matrix class with all elements are
character. So tried this :

as.character(myData)
[1] "c(3, 2, 1, 1, 2)" "c(4, 3, 1, 2, 1)" "c(3, 1, 1, 1, 2)" "c(3, 1,
1, 2, 1)" "c(4, 3, 1, 1, 2)"


This looks funny and does not conform the original data. Can somebody
point me what would be right way to put it into Matrix?

Use as.matrix(myData).

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to