Dear all; I need to run heatmap. Because my first column in my data is alphanumeric, I can not run as.matrix(scale(my_data)). So I need to make my data readable as in data(mtcars). In *mtcars *data the first column is alphanumeric and has no name. Thanks, Greg [[alternative HTML version deleted]]
Clarification needed. Are your data in a data frame or an alphanumeric matrix? What does it look like? A small reproducible example would be very useful here I think! [1] http://stackoverflow.com/questions/5963269/how-to-make-a- great-r-reproducible-example [2] http://adv-r.had.co.nz/Reproducibility.html Also, is this relevant:> d <- matrix(1:12,ncol = 4) > d[,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12> dd <- d[,c(3,1,2,4)] > dd[,1] [,2] [,3] [,4] [1,] 7 1 4 10 [2,] 8 2 5 11 [3,] 9 3 6 12 Perhaps you neeed to spend time with an R tutorial that covers indexing of data frames and matrices, an absolutely basic R operation? (I am not clear from your question if this is your problem). Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, May 10, 2018 at 2:36 PM, greg holly <mak.hholly at gmail.com> wrote:> Dear all; > > I need to run heatmap. Because my first column in my data is alphanumeric, > I can not run as.matrix(scale(my_data)). So I need to make my data readable > as in data(mtcars). In *mtcars *data the first column is alphanumeric and > has no name. > > Thanks, > > Greg > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
I think you are confusing row names with the first column. The first column in mtcars is not alphanumeric:> class(mtcars)[1] "data.frame"> class(mtcars[,1])[1] "numeric"> rownames(mtcars)[1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Hornet 4 Drive" "Hornet Sportabout" "Valiant" (etc) Perhaps you should make a copy of my_data that includes only the numeric columns? -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 ?On 5/10/18, 2:36 PM, "R-help on behalf of greg holly" <r-help-bounces at r-project.org on behalf of mak.hholly at gmail.com> wrote: Dear all; I need to run heatmap. Because my first column in my data is alphanumeric, I can not run as.matrix(scale(my_data)). So I need to make my data readable as in data(mtcars). In *mtcars *data the first column is alphanumeric and has no name. Thanks, Greg [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
And more helpful, probably, would have been the str() function:> str(mtcars)'data.frame': 32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... $ disp: num 160 160 108 258 360 ... $ hp : num 110 110 93 110 175 105 245 62 95 123 ... $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ... $ wt : num 2.62 2.88 2.32 3.21 3.44 ... $ qsec: num 16.5 17 18.6 19.4 17 ... $ vs : num 0 0 1 1 0 1 0 1 1 1 ... $ am : num 1 1 1 0 0 0 0 0 0 0 ... $ gear: num 4 4 4 3 3 3 3 4 4 4 ... $ carb: num 4 4 1 1 2 1 4 2 2 4 ... Try it on your data. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 ?On 5/10/18, 2:36 PM, "R-help on behalf of greg holly" <r-help-bounces at r-project.org on behalf of mak.hholly at gmail.com> wrote: Dear all; I need to run heatmap. Because my first column in my data is alphanumeric, I can not run as.matrix(scale(my_data)). So I need to make my data readable as in data(mtcars). In *mtcars *data the first column is alphanumeric and has no name. Thanks, Greg [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
1. My name is Bert, not Brent; 2. I am not your private consultant -- always cc the list unless you have good reason not to. I have done that here. It looks like this is what you want; if so, you really need to go through an R tutorial or two to learn the basics: d <- structure(list(region = structure(c(1L, 1L, 1L, 1L), .Label = "zilan", class = "factor"), Fe_ppmtp = c(8.36, 8.78, 16.52, 42.22), Zn.ppmtp = c(0.44, 0.58, 2.28, 14.22), Mn_tp = c(6.9, 21.16, 27.58, 34.7), Cu_tp = c(0.5, 0.24, 0.8, 31.9)), class = "data.frame", row.names = c(NA, -4L))> md <- as.matrix(d[,-1]) ## knowledge of indexing is essential in R ! > mdFe_ppmtp Zn.ppmtp Mn_tp Cu_tp [1,] 8.36 0.44 6.90 0.50 [2,] 8.78 0.58 21.16 0.24 [3,] 16.52 2.28 27.58 0.80 [4,] 42.22 14.22 34.70 31.90> is.numeric(md)[1] TRUE ## to get rid of the column names:> dimnames(md)[[2]] <- NULL > md[,1] [,2] [,3] [,4] [1,] 8.36 0.44 6.90 0.50 [2,] 8.78 0.58 21.16 0.24 [3,] 16.52 2.28 27.58 0.80 [4,] 42.22 14.22 34.70 31.90 Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, May 10, 2018 at 3:13 PM, greg holly <mak.hholly at gmail.com> wrote:> Brent; > > I am sorry. Her is the reproducible data > > structure(list(region = structure(c(1L, 1L, 1L, 1L), .Label = "zilan", > class = "factor"), > Fe_ppmtp = c(8.36, 8.78, 16.52, 42.22), Zn.ppmtp = c(0.44, > 0.58, 2.28, 14.22), Mn_tp = c(6.9, 21.16, 27.58, 34.7), Cu_tp = c(0.5, > 0.24, 0.8, 31.9)), class = "data.frame", row.names = c(NA, > -4L)) > > > On Fri, May 11, 2018 at 1:10 AM, greg holly <mak.hholly at gmail.com> wrote: > >> Hi Brent; >> >> Thanks so much, fore writing. It is much appreciated. Here is a small >> example from my data >> >> Bolge Fe_ppmtp Zn ppmtp Mn_tp Cu_tp >> zilan >> zilan 8.36 0.44 6.9 0.5 >> zilan 8.78 0.58 21.16 0.24 >> zilan 16.52 2.28 27.58 0.8 >> zilan 42.22 14.22 34.7 31.9 >> >> On Fri, May 11, 2018 at 12:55 AM, Bert Gunter <bgunter.4567 at gmail.com> >> wrote: >> >>> Clarification needed. >>> >>> Are your data in a data frame or an alphanumeric matrix? What does it >>> look like? >>> >>> A small reproducible example would be very useful here I think! >>> >>> >>> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-gre >>> at-r-reproducible-example >>> [2] http://adv-r.had.co.nz/Reproducibility.html >>> >>> Also, is this relevant: >>> >>> > d <- matrix(1:12,ncol = 4) >>> > d >>> [,1] [,2] [,3] [,4] >>> [1,] 1 4 7 10 >>> [2,] 2 5 8 11 >>> [3,] 3 6 9 12 >>> > dd <- d[,c(3,1,2,4)] >>> > dd >>> [,1] [,2] [,3] [,4] >>> [1,] 7 1 4 10 >>> [2,] 8 2 5 11 >>> [3,] 9 3 6 12 >>> >>> Perhaps you neeed to spend time with an R tutorial that covers indexing >>> of data frames and matrices, an absolutely basic R operation? (I am not >>> clear from your question if this is your problem). >>> >>> >>> Cheers, >>> Bert >>> >>> >>> >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> On Thu, May 10, 2018 at 2:36 PM, greg holly <mak.hholly at gmail.com> >>> wrote: >>> >>>> Dear all; >>>> >>>> I need to run heatmap. Because my first column in my data is >>>> alphanumeric, >>>> I can not run as.matrix(scale(my_data)). So I need to make my data >>>> readable >>>> as in data(mtcars). In *mtcars *data the first column is alphanumeric >>>> and >>>> has no name. >>>> >>>> Thanks, >>>> >>>> Greg >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide http://www.R-project.org/posti >>>> ng-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>> >>> >> >[[alternative HTML version deleted]]