[R] summary with names
Hi, how can I tell 'summary' to print the name of the summarised variable? This is probably an awkward newbie question but I didn't find an answer in the Docus, the FAQ and maillist archive. I want a summary for about 250 variables and realise it the following way (I know, that I shouldn't use iterations that way in R; but at the moment it's the easiest way for me): for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} It works fine, but I don't know which summary corresponds to which variable, because the variable names are not printed. Can somebody give me a hint? TIA Regards, Christoph -- Christoph Bier, Dipl.Oecotroph., Email: [EMAIL PROTECTED] Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] summary with names
Christoph Bier wrote: Hi, how can I tell 'summary' to print the name of the summarised variable? This is probably an awkward newbie question but I didn't find an answer in the Docus, the FAQ and maillist archive. I want a summary for about 250 variables and realise it the following way (I know, that I shouldn't use iterations that way in R; but at the moment it's the easiest way for me): for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} Given fb.12.unt is a list or data.frame, lapply(fb.12.unt, summary, na.rm = TRUE) or sapply(fb.12.unt, summary, na.rm = TRUE) might do what you want. BTW: na.rm=t is wrong anyway ... Uwe Ligges It works fine, but I don't know which summary corresponds to which variable, because the variable names are not printed. Can somebody give me a hint? TIA Regards, Christoph __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] summary with names
Christoph Bier [EMAIL PROTECTED] wrote: how can I tell 'summary' to print the name of the summarised variable? This is probably an awkward newbie question but I didn't find an answer in the Docus, the FAQ and maillist archive. I want a summary for about 250 variables and realise it the following way (I know, that I shouldn't use iterations that way in R; but at the moment it's the easiest way for me): for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} It works fine, but I don't know which summary corresponds to This surprises me. which variable, because the variable names are not printed. Can somebody give me a hint? Can you give us an example of summary not giving variable names? df-data.frame(var1=c(1,2,3),var2=c(4,5,6),factor1=c('a','a','b')) summary(df) var1 var2 factor1 Min. :1.0 Min. :4.0 a:2 1st Qu.:1.5 1st Qu.:4.5 b:1 Median :2.0 Median :5.0 Mean :2.0 Mean :5.0 3rd Qu.:2.5 3rd Qu.:5.5 Max. :3.0 Max. :6.0 summary(df[1:2]) var1 var2 Min. :1.0 Min. :4.0 1st Qu.:1.5 1st Qu.:4.5 Median :2.0 Median :5.0 Mean :2.0 Mean :5.0 3rd Qu.:2.5 3rd Qu.:5.5 Max. :3.0 Max. :6.0 -- Philippe __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] summary with names
On Thu, 16 Oct 2003, Christoph Bier wrote: Hi, how can I tell 'summary' to print the name of the summarised variable? This is probably an awkward newbie question but I didn't find an answer in the Docus, the FAQ and maillist archive. I want a summary for about 250 variables and realise it the following way (I know, that I shouldn't use iterations that way in R; but at the moment it's the easiest way for me): for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} It works fine, but I don't know which summary corresponds to which variable, because the variable names are not printed. Can somebody give me a hint? In this context you will have to print the names yourself. summary() doesn't know the names, it only knows the contents of i. summary(a.data.frame) can print the names becuase the names are part of the data frame. As people have already pointed out there are some other strange things about the command. -thomas __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] summary with names
Philippe Glaziou schrieb: [...] Can you give us an example of summary not giving variable names? I could send you my data frame, but that's surely not what you want =). Your following example prints the value names on my machine, too. But my data frame does not. And the summary isn't printed among one another but abreast. Sorry, can't tell you why. But I will try to create a simple example. [example] Regards, Christoph -- Christoph Bier, Dipl.Oecotroph., Email: [EMAIL PROTECTED] Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] summary with names
Patrick Burns schrieb: I think you mean na.rm=T by the way. Yes, you're right! Is for(i in whatever) {cat(i, \n); print(summary(i, na.rm=TRUE))} what you want? No, it doesn't print the value names. I can't tell you why. Philippe wonders, too. In his example the value names are printed. But not with my data frame. Regards, Christoph -- Christoph Bier, Dipl.Oecotroph., Email: [EMAIL PROTECTED] Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] summary with names
Uwe Ligges schrieb: Christoph Bier wrote: Hi, how can I tell 'summary' to print the name of the summarised variable? This is probably an awkward newbie question but I didn't find an answer in the Docus, the FAQ and maillist archive. I want a summary for about 250 variables and realise it the following way (I know, that I shouldn't use iterations that way in R; but at the moment it's the easiest way for me): for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} Given fb.12.unt is a list or data.frame, lapply(fb.12.unt, summary, na.rm = TRUE) or sapply(fb.12.unt, summary, na.rm = TRUE) might do what you want. Yes, it does :-)! Thanks a lot. BTW: na.rm=t is wrong anyway ... Sure, actually I used na.rm=T -- but not TRUE. My alleged knowledge about this is based on a book about S and S-Plus. I'm still waiting for An Introductory in R as I wrote in a mail some days ago. I can not read Docus on a monitor, I need paper in my hand =). Best regards, Christoph -- Christoph Bier, Dipl.Oecotroph., Email: [EMAIL PROTECTED] Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] [Summary] Color names
Thanks to those who took time to respond. Based on the functions that were pointed out to me I have the following: # colors.hex and colors.name convert color names to hex and visa versa # note that each color has a unique hex code but each hex code may have # more than one color colors.hex - function( x=colors() ) { color.hex - function(x) do.call( rgb, as.list(col2rgb(x)/255) ) sapply( x, color.hex ) } colors.name - function( x ) { color.name - function( x ) colors()[ colors.hex() == x ] lapply( x, color.name ) } # For example, colors.hex( red ) colors.hex( colors()[1:5] ) colors.name( #FF ) colors.name( rainbow(3) ) colors.name( rainbow(7) ) # note: only first element has a name # LL partitions all color names into equivalence classes w same hex code # LL2 is similar but only has equivalence classes with more than one name LL - by( colors(), colors.hex(), as.vector ) LL2 - LL[ lapply( LL, length ) 1 ] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help