Re: [R] multiple return
one way -- somma - function (a, b) { c - a+b return (list(a=a, b=a, c=c)) } Mahbub. On 6/22/07, Manuele Pesenti [EMAIL PROTECTED] wrote: Dear User, what's the correct way to obtain a multiple return from a function? for example creating the simple function: somma - function (a, b) { c - a+b return (a, b, c) } when I call it, it runs but returns the following output: somma(5, 7) $a [1] 5 $b [1] 7 $c [1] 12 Warning message: return multi-argomento sono deprecati in: return(a, b, c) i.e. multi-return is deprecated... thanks a lot best regards Manuele -- Manuele Pesenti [EMAIL PROTECTED] [EMAIL PROTECTED] http://mpesenti.polito.it __ R-help@stat.math.ethz.ch 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. -- A H M Mahbub Latif, PhD Assistant Professor Applied Statistics Institute of Statistical Research and Training University of Dhaka, Dhaka 1000, Bangladesh web : http://www.isrt.ac.bd/mlatif Computers are like airconditioners: They stop working properly if you open windows. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
Re: [R] make apply() return a list
How about this... x = matrix(1:27, ncol=9, byrow=T) nr= nrow(x) lapply(1:nr, function(i) matrix(x[i,], nrow=3, byrow=T)) Mahbub. On Mon, 1 Nov 2004 19:37:08 +0100, Arne Henningsen [EMAIL PROTECTED] wrote: Hi, I have a dataframe (say myData) and want to get a list (say myList) that contains a matrix for each row of the dataframe myData. These matrices are calculated based on the corresponding row of myData. Using a for()-loop to do this is very slow. Thus, I tried to use apply(). However, afaik apply() does only return a list if the matrices have different dimensions, while my matrices have all the same dimension. To get a list I could change the dimension of one matrix artificially and restore it after apply(): This a (very much) simplified example of what I did: myData - data.frame( a = c( 1,2,3 ), b = c( 4,5,6 ) ) myFunction - function( values ) { +myMatrix - matrix( values, 2, 2 ) +if( all( values == myData[ 1, ] ) ) { + myMatrix - cbind( myMatrix, rep( 0, 2 ) ) +} +return( myMatrix ) + } myList - apply( myData, 1, myFunction ) myList[[ 1 ]] - myList[[ 1 ]][ 1:2, 1:2 ] myList $1 [,1] [,2] [1,]11 [2,]44 $2 [,1] [,2] [1,]22 [2,]55 $3 [,1] [,2] [1,]33 [2,]66 This exactly does what I want and really speeds up the calculation, but I wonder if there is an easier way to make apply() return a list. Thanks for your help, Arne -- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 [EMAIL PROTECTED] http://www.uni-kiel.de/agrarpol/ahenningsen/ __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- A.H.M. Mahbub-ul Latif PhD Student Department of Medical Statistics University of Goettingen Germany __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (no subject)
?density On Sat, 30 Oct 2004 13:03:11 -0400 (EDT), Yulei He [EMAIL PROTECTED] wrote: Hi, there. Does anybody know how to plot a smooth density plot for some data simulated from certain distribution? Thanks. Yulei $$$ Yulei He 1586 Murfin Ave. Apt 37 Ann Arbor, MI 48105-3135 [EMAIL PROTECTED] 734-647-0305(H) 734-763-0421(O) 734-763-0427(O) 734-764-8263(fax) $$ __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- -- A.H.M. Mahbub-ul Latif PhD Student Department of Medical Statistics, Goettingen Germany __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Imputing missing values
Try this: newPrice = unlist(sapply(Price, Crop:Season, function(x){ x[is.na(x)]=mean(x,na.rm=T); return(x); })) --- Jan Smit [EMAIL PROTECTED] wrote: Dear all, Apologies for this beginner's question. I have a variable Price, which is associated with factors Season and Crop, each of which have several levels. The Price variable contains missing values (NA), which I want to substitute by the mean of the remaining (non-NA) Price values of the same Season-Crop combination of levels. Price CropSeason 10RiceSummer 12RiceSummer NARiceSummer 8 RiceWinter 9 WheatSummer Price[is.na(Price)] gives me the missing values, and by(Price, list(Crop, Season), mean, na.rm = T) the values I want to impute. What I've not been able to figure out, by looking at by and the various incarnations of apply, is how to do the actual substitution. Any help would be much appreciated. Jan Smit __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] off topic: C/C++ codes for pseudo inverse
Hi, I am looking for C/C++ codes for computing generalized inverse of a matrix. Can anyone help me in this regard? Thanks, Mahbub. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] RODBC installation in debian
Hello List, I am trying to install RODBC package in a debian linux box but getting the following message. Can anyone help me to find what I am doing wrong here: $ R CMD INSTALL RODBC_1.0-4.tar.gz ### * Installing *source* package 'RODBC' ... checking for gcc... gcc checking for C compiler default output... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking for library containing SQLTables... no configure: error: no ODBC driver manager found ERROR: configuration failed for package 'RODBC' ** Removing '/usr/local/lib/R/site-library/RODBC' R version platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major1 minor9.0 year 2004 month04 day 12 language R Thanks, Mahbub. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] large fonts on plots
see ?par Mahbub. --- Piet van Remortel [EMAIL PROTECTED] wrote: Hi all, I need to enlarge te fonts used oo R-plots (plots, histograms, ...) in labels and titles etc. I seem to be unable to figure out how to do it. The problem is that the titles of the plots are simply unreadable when I insert them into my LaTeX text, since they are relatively small compared to the entire plot. I am sure it is pretty simple, can anybody give me a hint ? Please reply to: [EMAIL PROTECTED] Thanks, Piet -- Piet van Remortel PhD Student [EMAIL PROTECTED] http://como.vub.ac.be/Members/Piet.htm __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] lattice (qqmath) question
Hi, In lattice, is it possible to get qqplot for t distribution in different panels with different dfs. For example, # in panel 1 qqmath(~x, distribution=function(p) qt(p, df=3)) # in panel 2 qqmath(~x, distribution=function(p) qt(p, df=5)) etc... Thanks, Mahbub. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] lattice question--- different ylim
Hi there, I have four panels in a lattice bwplot. I want to have two different ylim for the panels, for example panels [1,1] and [1,2] with ylim=c(0,200) and panels [2,1] and [2,2] with ylim=c(0,100). Thanks for help in advance. Mahbub. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] anova(lme object)
Hi, I use lme to fit models like R res1 - lme(y~A+B, data=mydata, random=~1|subject) R res2 - lme(y~B+A, data=mydata, random=~1|subject) (only difference between these two models are the sequence in which the indep variables are written in formula) where y is continuous and A, B, and subject are factors. To get ANOVA table I used R anova(res1) R anova(res2) and found ANOVA tables corresponding to these two models are different. Is there any way I can get similar ANOVA tables from lme objects of this type? __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] greek in main title
Hi, change the name of function argument theta to something else say thta and then use the following heading - expression(paste(Exp w/ , theta, =, thta, , n = , n[i])) Hope it will help... Mahbub. --- [EMAIL PROTECTED] wrote: Hello, I have written a function that demonstrates the CLT by generating samples following the exponential distribution, calculating the means, plotting the histogram, and drawing the limiting normal curve as an overlay. I have the title of each histogram state the sample size and rate (1/theta) for the exponential (the output is actually 4 histograms), but I can't get the greek letter theta to appear in the heading. Is this possible? I can get nontext for the xlab and ylab pretty easily. Thanks, Jason Below is my code. Currently it just writes out theta. function (theta) { layout(matrix(c(1:4),2,2,byrow=TRUE)) par(bg = cornsilk) n - c(1,10,25,50) for(i in 1:4) { xbar - rep(0, 1000) for (j in 1:1000) xbar[j] - mean(rexp(n[i], rate = 1/theta)) heading - paste(Exp w/ theta =, theta, , n = , n[i]) hist(xbar, prob = TRUE, breaks = FD, main = title(heading, font.main = 6), col = lightgray, xlab = expression(bar(x))) xbar - sort(xbar) points(xbar, dnorm(xbar, mean = theta, sd = theta/sqrt(n[i])), type = l, col = 2) } } __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ Yahoo! SiteBuilder - Free, easy-to-use web site design software __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] bold AND italic as font in text()
use text(, , expression(bold(what you want to write))) Mahbub. --- Tord Snall [EMAIL PROTECTED] wrote: Dear all, Is it possible to somshow plot text as italic AND bold. I tried font=c(2,3) in text(), but it doesn't work. It seems like the latter value is used. Thanks in advance! Sincerely, Tord --- Tord Snäll Avd. f växtekologi, Evolutionsbiologiskt centrum, Uppsala universitet Dept. of Plant Ecology, Evolutionary Biology Centre, Uppsala University Villavägen 14 SE-752 36 Uppsala, Sweden Tel: 018-471 28 82 (int +46 18 471 28 82) (work) Tel: 018-25 71 33 (int +46 18 25 71 33) (home) Fax: 018-55 34 19 (int +46 18 55 34 19) (work) E-mail: [EMAIL PROTECTED] Check this: http://www.vaxtbio.uu.se/resfold/snall.htm! __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] installing XML in linux
Hi, I was trying to install XML package in a linux (dabian) machine and got the following error message. I am not sure whether there is any error in my linux installion. I appreciate suggestions to install XML properly in this machine. Thanks in advance. Mahbub. ##Errors $ R CMD INSTALL -l /usr/local/lib/R/library/ XML_0.93-4.tar.gz * Installing *source* package 'XML' ... creating cache ./config.cache checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking how to run the C preprocessor... gcc -E checking for xml-config... no checking for libxml/parser.h... no checking for gnome-xml/parser.h... no checking for libxml/parser.h... (cached) no checking for gnome-xml/parser.h... (cached) no checking for libxml/parser.h... (cached) no Cannot find parser.h. Set the value of the environment variable LIBXML_INCDIR to point to where it can be found. ERROR: configuration failed for package 'XML' version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major1 minor7.0 year 2003 month04 day 16 language R __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Re: [BioC] installing XML in linux
Thanks a lot Prof Bates. One more thing... What Debian packages should I install to install R packages Rgraphviz and rhdf5? Mahbub. --- Douglas Bates [EMAIL PROTECTED] wrote: You will need to install the Debian package libxml-dev before you can install the R XML package. Mahbub Latif [EMAIL PROTECTED] writes: I was trying to install XML package in a linux (dabian) machine and got the following error message. I am not sure whether there is any error in my linux installion. I appreciate suggestions to install XML properly in this machine. Thanks in advance. Mahbub. ##Errors $ R CMD INSTALL -l /usr/local/lib/R/library/ XML_0.93-4.tar.gz * Installing *source* package 'XML' ... creating cache ./config.cache checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking how to run the C preprocessor... gcc -E checking for xml-config... no checking for libxml/parser.h... no checking for gnome-xml/parser.h... no checking for libxml/parser.h... (cached) no checking for gnome-xml/parser.h... (cached) no checking for libxml/parser.h... (cached) no Cannot find parser.h. Set the value of the environment variable LIBXML_INCDIR to point to where it can be found. ERROR: configuration failed for package 'XML' __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Re: [BioC] installing XML in linux
apt-get install libhdf5-serial-dev To install libhdf5 what I am getting $ apt-get install libhdf5-serial-dev libhdf5-serial-dev: Depends: libhdf5-serial (= 1.4.5-2) but it is not going to be installed then I try... $ apt-get install libhdf5-serial libhdf5-serial: Depends: libc6 (= 2.3.1-1) but 2.2.5-11.5 is to be installed That means I need libc6 2.3.1-1 or higher. How can I get that? Mahbub. unless you really want the MPI or PVM versions. best, -tony -- A.J. Rossini / [EMAIL PROTECTED] / [EMAIL PROTECTED] Biomedical/Health Informatics and Biostatistics, University of Washington. Biostatistics, HVTN/SCHARP, Fred Hutchinson Cancer Research Center. FHCRC: 206-667-7025 (fax=4812)|Voicemail is pretty sketchy/use Email CONFIDENTIALITY NOTICE: This e-mail message and any attachments may be confidential and privileged. If you received this message in error, please destroy it and notify the sender. Thank you. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] trellis plot
Hi there, I need some help about trellis plot. I have the following plot. x - c(rep(LETTERS[1:4],13), rep(LETTERS[4:1],12)) y - rnorm(100)z - rep(1:2,50)bwplot(y~factor(x)|z,layout=c(2,1), panel=function(x,y) panel.bwplot(x,y,horizontal=F)) Now I want to place "*" on the positions (1,-1.5) in the first panel and (2,-2.5) in the second panel. I need help on this. Thanks. Mahbub. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help