Hi, I am trying to process genomics data and the presence of both characters and integers in an array is giving issues. The following is an example: > a<-array(c(2,2,"X",1:3,2:4),dim=c(3,3)) > b<-cbind(a[,1],a[,2]) With the output being: [,1] [,2] [1,] "2" "1" [2,] "2" "2" [3,] "X" "3" Is there any way for me to remove the quotation marks from every integer/character in the new array? Or, is there a way to create the new array without getting the quotation marks? Regards, Josh [[alternative HTML version deleted]]
Hi. Try: as.data.frame(cbind(a[,1],a[,2])) Andrija On Wed, Jun 6, 2012 at 9:51 PM, Joshua Budman <josh.budman@gmail.com> wrote:> Hi, > I am trying to process genomics data and the presence of both > characters and integers in an array is giving issues. The following is > an example: > > a<-array(c(2,2,"X",1:3,2:4),dim=c(3,3)) > > b<-cbind(a[,1],a[,2]) > With the output being: > [,1] [,2] > [1,] "2" "1" > [2,] "2" "2" > [3,] "X" "3" > > Is there any way for me to remove the quotation marks from every > integer/character in the new array? Or, is there a way to create the > new array without getting the quotation marks? > > Regards, > Josh > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
On Jun 6, 2012, at 3:51 PM, Joshua Budman wrote:> Hi, > I am trying to process genomics data and the presence of both > characters and integers in an array is giving issues.That is probably because you do not understand that it there is even one character in an array, then that is what ALL the rest of the items are.> The following is > an example: >> a<-array(c(2,2,"X",1:3,2:4),dim=c(3,3)) >> b<-cbind(a[,1],a[,2]) > With the output being: > [,1] [,2] > [1,] "2" "1" > [2,] "2" "2" > [3,] "X" "3" > > Is there any way for me to remove the quotation marks from every > integer/character in the new array? Or, is there a way to create the > new array without getting the quotation marks?It depend on what you mean by "not getting" or "removing the quotation marks". What is your goal? There is no way to have a mixture of character and numeric class items in a matrix. (There is also no way of have a column in a data.frame which is a mixture of different atomic classes.) The printed representation of a character class dataframe will not produce quotes on the console, admittedly a different behavior, but the internal representations will be the same. > data.frame(x=letters[1:3])$x == matrix(letters[1:3], 1)[1,] [1] TRUE TRUE TRUE > data.frame(x=letters[1:3])$x [1] a b c Levels: a b c > matrix(letters[1:3], 1)[1,] [1] "a" "b" "c" You can have a matrix of lists and I think you can have items in a column of a dataframe which are lists. Those are some uncommonly used methods which would allow (with some added overhead) storing items of different classes in a data structure that you could access with what might be called dimensional indexing. > matrix(c(list(1), list(2), list("a")), 1) [,1] [,2] [,3] [1,] 1 2 "a" > str(matrix(c(list(1), list(2), list("a")), 1)[1,3]) List of 1 $ : chr "a" > str(matrix(c(list(1), list(2), list("a")), 1)[1,2]) List of 1 $ : num 2>-- David Winsemius, MD West Hartford, CT
Arrays must all be the same type. Data frame columns may be of differing types. Try to avoid creating a matrix and converting it to a data frame. a<- data.frame(name=c(2,2,"X"), value=c(,1:3,2:4), as.is=TRUE) str(a) --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Joshua Budman <josh.budman at gmail.com> wrote:>Hi, >I am trying to process genomics data and the presence of both >characters and integers in an array is giving issues. The following is > >an example: > > a<-array(c(2,2,"X",1:3,2:4),dim=c(3,3)) > > b<-cbind(a[,1],a[,2]) >With the output being: > [,1] [,2] >[1,] "2" "1" >[2,] "2" "2" >[3,] "X" "3" > >Is there any way for me to remove the quotation marks from every >integer/character in the new array? Or, is there a way to create the >new array without getting the quotation marks? > >Regards, >Josh > [[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.