[R] clustering analysis is certainly possible with R.
See the article Cluster in R Task Views http://cran.at.r-project.org/src/contrib/Views/Cluster.html It lists names of packages for clustering analysis, which you can install. Or, go to choose another CRAN mirror closest to you from the R web site, then click on 'Task views' in the left frame. To install packages use the install.packages() function or the menu item in the GUI in you are on Windows. Maura E Monville wrote: I have 316 files storing a number of cycles of the respiratory signal from 316 different patients. Each file record is made up of the following data: [skipped data description] The goal is to perform clustering analysis on such data, that is to group togther those which have common characteristics. Which characteristics and how many groups ... ??? ... well this is to be found out. Is R a good tool for analysing many data and find patterns common to data subsets ? Which other tool do you advice ? Thank you very much, -- Maura E.M -- View this message in context: http://www.nabble.com/is-clustering-analysis-possible-with-R---tf4417188.html#a12602423 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] About = in command line in windows.
It seems, I don't understand something, or there is a bug in R. I have made some experiments after my yesterday post about using = with -e switch to the Rscript. Now, I've found: (1) C:\users\wl\trainings\rrscript --verbose -e mean(x=1:3) running 'C:\Program Files\R\bin\Rterm.exe --slave --no-restore -e mean(x=1:3)' Error in -args : invalid argument to unary operator Execution halted (2) C:\users\wl\trainings\rRterm --slave --no-restore -e mean(x=1:3) Nothing is printed on the console, but the window appears, saying R for Windows terminal front-end has encountered a problem and needs to close. We are sorry for the inconvenience. (3) C:\users\wl\trainings\rrscript --verbose -e mean(1:3) running 'C:\Program Files\R\bin\Rterm.exe --slave --no-restore -e mean(1:3)' [1] 2 (4) C:\users\wl\trainings\rRterm.exe --slave --no-restore -e mean(1:3) [1] 2 (5) C:\users\wl\trainings\rRterm.exe --slave --no-restore -e 'mean(1:3)' [1] mean(1:3) Points (1) and (2) don't seem normal to me, however, I don't see, what I am doing wrong. I use windowsXP Pro, my colleague uses windows 2000 and reports the same problems. My sessionInfo(): sessionInfo() R version 2.5.1 Patched (2007-08-19 r42614) i386-pc-mingw32 locale: LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base -- View this message in context: http://www.nabble.com/About-%22%3D%22-in-command-line-in-windows.-tf4360278.html#a12426839 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] bug in DEoptim package
(the same mail was sent to the author) When I called the function DEoptim with control=list(strategy=1) or control=list(strategy=2) I got the error: Error in mui[rtd + 1, i] : incorrect number of dimensions Analysis of the source code of the DEoptim reveals the following fragment if (con$strategy 5) st - con$strategy - 5 ## binomial crossover else { st - con$strategy ## exponential crossover mui - sort(t(mui)) ## transpose, collect 1's in each column for (i in 1:NP) { n - floor(runif(1) * d) if (n 0) { rtd - (rotd + n) %% d mui[,i] - mui[rtd + 1,i] ## rotate column i by n } } mui - t(mui) ## transpose back } sort returns a 1-dimensional vector, this causes the error in the following indexing operators. This also shows, that any strategy value from 1 through 5 will cause this error, while values from 1 through 10 are possible. Package's DESCRIPTION file contains the following: Version: 1.1-8 Date: 2007-01-29 My sessionInfo(): sessionInfo() R version 2.5.1 Patched (2007-08-19 r42614) i386-pc-mingw32 locale: LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russian_Russia.1251 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: debug mvbutils DEoptim 1.1.0 1.1.1 1.1-8 Unfortunately I haven't submerged deep enough to the algorithm details to propose the bug fix. -- View this message in context: http://www.nabble.com/bug-in-DEoptim-package-tf4353533.html#a12405068 Sent from the R help mailing list archive at Nabble.com. __ 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] R CMD BATCH: cat does not print
Use rscript Rscript myscript.R or Rscript -e 'cat(Hello!\n)' will show Hello! on the console. R CMD BATCH writes its output to the file myscript.Rout Paul Smith wrote: Dear All, I am trying to write my first R script. The code is simply cat(Hello!\n) However, when I run $ R CMD BATCH myscript.R I do not see Hello! on the console. I am using Fedora 7 (Linux) and R-2.5.1. Any ideas? Thanks in advance, Paul -- View this message in context: http://www.nabble.com/R-CMD-BATCH%3A-cat-does-not-print-tf4353572.html#a12405494 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] How to mask or escape =
-- View this message in context: http://www.nabble.com/How-to-mask-or-escape-%22%3D%22-tf4354174.html#a12406926 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] How to mask or escape = in Windows command prompt?
I have defined a function with several arguments and have it stored in the .RData file. The 'function head' is defined as follows EstimALIConc -function(sdname,SZ,W,farea,watri,biomodel,start.part=1,nparts=20,method=c(optim,DEoptim)) { [ blah-blah-blah ] (function body doesn't matter) } Then I call Rscript: e: rscript --restore -e EstimALIConc('17-aug',27.8,5,1,watri,biomodel,1,100,method='DEoptim');warnings(); 117-aug-log.txt 217-aug.err and get the error in the 17-aug.err: Error in -args : invalid argument to unary operator Execution halted If I remove method= from the function call, then everything works fine, and function executes. e: rscript --restore -e EstimALIConc('17-aug',27.8,5,1,watri,biomodel,1,100,'DEoptim');warnings(); 117-aug-log.txt 217-aug.err The problem seems to be that the equality sign acts as a separator. How to avoid this? This would allow skiping of the default arguments, for example start.part -- View this message in context: http://www.nabble.com/How-to-mask-or-escape-%22%3D%22-in-Windows-command-prompt--tf4354195.html#a12407015 Sent from the R help mailing list archive at Nabble.com. __ 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] How to signal the end of the table?
For example, fp-file(abc.csv,r) c.row-scan(file=fp,sep=,,nlines=1) # what argument is omitted for bevity as it doesn't matter rows-c.row while(length(c.row)0) { c.row-scan(file=fp,sep=;,nlines=1); rows-rbind(rows,c.row) } close(fp) If you want to read a file by parts, then you do something like the following (untested) But this looks like a C-style approach, not R-style fp-file(abc.csv,r) lines.skip-0 for(i in 1:nparts){ c.row-scan(file=fp,sep=,,nlines=1,skip=lines.skip) lines.read-1 rows-c.row while(length(c.row)0 lines.readpart.size) { c.row-scan(file=fp,sep=;,nlines=1); # nlines can be also 1 rows-rbind(rows,c.row) lines.read-lines.read+1 # if nlines above is 1 then +1 must be replaced with nlines value } lines.skip-lines.read # do operations with rows } close(fp) Yuchen Luo wrote: I am using a for loop to read a table row by row and I have to specify how many records are there in the table. I need to read row by row because the table is huge and the memory not large enough for the whole table.: number.of.records=100 fp=file(abc.csv,r) pos=seek(fp, rw=read) for (i in 1:number.of.record){ current.row=scan(file=fp, sep=',', what=list(count=1, cusip6=, idate=1, spread=1.1, vol252=1.1, vol1000=1.1, st_debt=1.1, lt_debt=1.1 , total_liab= 1.1, cr=1.1, shrout=1.1, prc=1.1, mkt_cap=1.1, rtng=1.1, sec=1.1, cr3m=1.1, cr5y=1.1, ust3m=1.1, ust5y=1.1), flush=TRUE, nlines=1,quiet=T) ... } I need to know the number of records in the table and put it in the variable named number.of.records. When I have a new table that I do not know how many records it has, I use excel to open the file to figure it out and put it in variable number.of.records. I often have many tables to try and every one of them has thousands of recordsit takes a lot of time and trouble to adjust the code every time I read a different table. I am wondering if I can change the for loop to a while loop: while (the end of the table has not been reached) { current.row=scan(file=fp, sep=',', what=list(count=1, cusip6=, idate=1, spread=1.1, vol252=1.1, vol1000=1.1, st_debt=1.1, lt_debt=1.1 , total_liab= 1.1, cr=1.1, shrout=1.1, prc=1.1, mkt_cap=1.1, rtng=1.1, sec=1.1, cr3m=1.1, cr5y=1.1, ust3m=1.1, ust5y=1.1), flush=TRUE, nlines=1,quiet=T) ... } The problem is how to articulate while (the end of the table has not been reached), or equivalently, how to signal the end of the table? Best Wishes Yuchen Luo -- View this message in context: http://www.nabble.com/How-to-signal-the-end-of-the-table--tf4353030.html#a12408586 Sent from the R help mailing list archive at Nabble.com. __ 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] Package installation
Vladimir Eremeev wrote: This is a source code package. Install Rtools (http://www.murdoch-sutherland.com/Rtools/), then you should be able to compile source packages from the Windows command prompt For example, c:\downloadsR CMD INSTALL biOps_0.1-1.tar.gz provided you have downloaded the file biOps_0.1-1.tar.gz to the directory c:\downloads on your hard drive. Sorry, I forgot to mention, this package could depend on 3rd party libraries, and your system must have them installed. Vladimir Eremeev wrote: Antje wrote: Hello, I'm running R with windows. Could anybody help me how to install the package biOps (http://cran.mirroring.de/src/contrib/Descriptions/biOps.html) ? I cannot find it at any mirror provided by the GUI; I just found it as tar.gz which cannot be installed with the installation method... Maybe, I simply do something wrong? Antje -- View this message in context: http://www.nabble.com/Package-installation-tf4322071.html#a12308092 Sent from the R help mailing list archive at Nabble.com. __ 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] Package installation
This is a source code package. Install Rtools (http://www.murdoch-sutherland.com/Rtools/), then you should be able to compile source packages from the Windows command prompt For example, c:\downloadsR CMD INSTALL biOps_0.1-1.tar.gz provided you have downloaded the file biOps_0.1-1.tar.gz to the directory c:\downloads on your hard drive. Antje wrote: Hello, I'm running R with windows. Could anybody help me how to install the package biOps (http://cran.mirroring.de/src/contrib/Descriptions/biOps.html) ? I cannot find it at any mirror provided by the GUI; I just found it as tar.gz which cannot be installed with the installation method... Maybe, I simply do something wrong? Thanks for any hint! Antje -- View this message in context: http://www.nabble.com/Package-installation-tf4322071.html#a12307927 Sent from the R help mailing list archive at Nabble.com. __ 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] prediction interval for multiple future observations
Vlad Skvortsov wrote: '?predict.lm' says that the prediction intervals returned by predict() are for single observation only. Is there a way to specify the desired number of observations to construct the interval for? You can generate the desired sequence of new values using seq or sequence and submit them to predict.lm in the newdata argument. -- View this message in context: http://www.nabble.com/prediction-interval-for-multiple-future-observations-tf4303243.html#a12249044 Sent from the R help mailing list archive at Nabble.com. __ 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] Partial comparison in string vector
Hi! seq(along=x) %in% grep(e,x) Steve Powell-4 wrote: I have a vector of strings x=c(w,ex,ee) And I want to get a logical vector showing the positions where my search string e matches the elements partially, i.e. is at least the left-hand part of the target strings, i.e. I want to get a vector FALSE TRUE TRUE. -- View this message in context: http://www.nabble.com/Partial-comparison-in-string-vector-tf4304145.html#a12251593 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Variable c and function c
I have found the error in my script which was semi-automatically translated from the other person's MATLAB code. The error is that c was assigned a value inside a function. That is the function body contained the following instructions c-nw*czr d-nw*cz rFren-0.5*(abs((cz-c)/(cz+c))^2+abs((d-czr)/(d+czr))^2) firstguess-c( 0,0,0,3,0.5, 0 , 0 , 0.01) I have already run this function and obtained the results, it was rather long process, therefore I don't want to rerun it. I was not given any warnings. How did the interpreter treat this? Will the result change, if I change the variable from c to, say, c. ? This variable is not used anywhere else in the function. -- View this message in context: http://www.nabble.com/Variable-c-and-function-c-tf4305781.html#a12256590 Sent from the R help mailing list archive at Nabble.com. __ 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] R on a flash drive
This is a FAQ. http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Can-I-run-R-from-a-CD-or-USB-drive_003f Erin Hodgess wrote: Dear R People: Has anyone run R from a flash drive, please? If so, how did it work, please? Thanks in advance! -- View this message in context: http://www.nabble.com/R-on-a-flash-drive-tf4299172.html#a12236850 Sent from the R help mailing list archive at Nabble.com. __ 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] Possible to import histograms in R?
Nick Chorley-3 wrote: I have a large amount of data that I would like to create a histogram of and plot and do things with in R. It is pretty much impossible to read the data into R, so I have written a program to bin the data and now have a list of counts in each bin. Is it possible to somehow import this into R and use hist(), so I can, for instance, plot the probability density? I have looked at the help page for hist(), but couldn't find anything related to this there. Hi! And why do you think, its impossible to import the data in R? It can handle rather large data volumes, especially in Linux. Just study help(Memory-limits). You can plot something looking like a histogram using barplot() or plot(... type=h). You can create the histogram class object manually. For example, [ import bin counts... probably, it is a table of 2 columns, defining bin borders and counts. let's store it in ncounts. ] hst-hist(rnorm(nrow(ncounts)),plot=FALSE) str(hst) # actually I called hist(rnorm(100)) List of 7 $ breaks : num [1:10] -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 $ counts : int [1:9] 3 6 12 9 24 19 14 9 4 $ intensities: num [1:9] 0.06 0.12 0.24 0.18 0.48 ... $ density: num [1:9] 0.06 0.12 0.24 0.18 0.48 ... $ mids : num [1:9] -2.25 -1.75 -1.25 -0.75 -0.25 0.25 0.75 1.25 1.75 $ xname : chr rnorm(100) $ equidist : logi TRUE - attr(*, class)= chr histogram hst$breaks - [ bsdfgsdghsdghdfgh ] hst$counts - [ asfd109,mnasdfkjhdsfl ] hst$intensities - Studying the hist.default() sources will help you to understand, how every list element is created. -- View this message in context: http://www.nabble.com/Possible-to-%22import%22-histograms-in-R--tf4271809.html#a12158586 Sent from the R help mailing list archive at Nabble.com. __ 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] Possible to import histograms in R?
Hello Nick, Wednesday, August 15, 2007, 1:18:34 PM, you wrote: NC On 15/08/07, Vladimir Eremeev [EMAIL PROTECTED] wrote: NC Nick Chorley-3 wrote: I have a large amount of data that I would like to create a histogram of and plot and do things with in R. It is pretty much impossible to read the data into R, so I have written a program to bin the data and now have a list of counts in each bin. Is it possible to somehow import this into R and use hist(), so I can, for instance, plot the probability density? I have looked at the help page for hist(), but couldn't find anything related to this there. NC Hi! And why do you think, its impossible to import the data in R? NC It can handle rather large data volumes, especially in Linux. Just study NC help(Memory-limits). NC My data file is 4.8 GB! NC You can plot something looking like a histogram using barplot() or plot(... NC type=h). NC The problem with those is that I can't plot the probability density. NC You can create the histogram class object manually. NC For example, NC [ import bin counts... probably, it is a table of 2 columns, defining bin NC borders and counts. NC let's store it in ncounts. ] NC Yes, that's what I have. hst-hist(rnorm(nrow(ncounts)),plot=FALSE) str(hst) # actually I called hist(rnorm(100)) List of 7 $ breaks : num [1:10] -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 $ counts : int [1:9] 3 6 12 9 24 19 14 9 4 $ intensities: num [1:9] 0.06 0.12 0.24 0.18 0.48 ... $ density: num [1:9] 0.06 0.12 0.24 0.18 0.48 ... $ mids : num [1:9] -2.25 -1.75 -1.25 -0.75 -0.25 0.25 0.75 1.25 1.75 $ xname : chr rnorm(100) $ equidist : logi TRUE - attr(*, class)= chr histogram hst$breaks - [ bsdfgsdghsdghdfgh ] hst$counts - [ asfd109,mnasdfkjhdsfl ] hst$intensities - NC My data isn't normally distributed, so I tried rexp() rather NC than rnorm(), but it's not looking like it should The call of the random generator doesn't matter, since it is used just to create a numeric vector for the hist(). And call to hist() just creates the dummy structure, which you must fill with your data. You then replace the returned result with yours. You can call hist(1:100) with the same success. And any other numeric vector can be used to call hist. If the result doesn't look like it should then you, probably, incorrectly or incompletely altered the list returned by hist(). Actually, you can create this structure from scratch: hst-list(breaks= [your breaks], counts= [your counts], intensities = [your intensities], density=[your density], mids= [your mids], xname= hist(of your data), equidist=TRUE [or FALSE] ) attr(hst,class)-histogram Studying the hist.default() sources will help you to understand, how every list element is created. Type hist.default (without parentheses) on the R prompt, and it will display you the sources of this function. You can also use dump(hist.default,file=hist_default.R) to save it to a text file. -- Best regards, Vladimirmailto:[EMAIL PROTECTED] --SevinMail-- __ 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] diffusing GIS data in maps
Hi. You will find some useful information in the http://r-spatial.sourceforge.net/ Particularly, Fig. 07 in the Graph gallery. Package spmaps can be used to extract desired boundaries from the mapdata and convert them to the format suitable for sp and others. Lawrence D. Brenninkmeyer wrote: Hi- I am trying to find a way to diffuse GIS data on a European map. I have a dataset consisting of particular locations scattered across Europe, along with magnitude and value information. I can plot these as discrete points with something like the following: geocode is a dataframe with four columns: LAT; LONG; MAGNITUDE;VALUE. library(maps) library(mapdata) map(worldHires, regions=c(Germany, Belgium, Netherlands)) points(geocode$LONG, geocode$LAT, cex=geocode$MAGNITUDE / 2500, col=rainbow(length(geocode$VALUE), start=0, end=.4)[rank(geocode$VALUE)]) This gives me a map of Europe with my datapoints highlighted in two ways: magnitude is represented by the size of the point, and value is represented by the color. However, what I would really like is for there to be some sort of diffusion, such that instead of discrete points, the European map is covered in color so I can see more clearly whether there are regional patterns (something that will presumably look like this contour chart: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=20 only on the European map). -- View this message in context: http://www.nabble.com/diffusing-GIS-data-in-maps-tf4265350.html#a12141809 Sent from the R help mailing list archive at Nabble.com. __ 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] Very new - beginners questions
Hi. You should study An Introduction to R manual. It is installed with R in PDF format and is accessible from the menu (Help - Manuals (in PDF) - ) There are several links in the R web site. Go to http://www.r-project.org/ and see links under the word Documentation in the left frame. There are some contributed documents: http://cran.r-project.org/other-docs.html Array manipulations are described in the chapter 5 of the Introduction. The plot window has its own menu allowing using of the Windows clipboard (you didn't describe your system, but Word for Windows suggests you're on Windows). Richard Price-4 wrote: Dear all, I have 4 sites and want to determine how different they are from each other. For this I have decided to use R though it seems a bit daunting to learn. I have read data in from a CSV the structure is : Species1 Species2 Species3 Site1 4 4 7 Site2 3 1 0 Site3 0 99 6 Site4 75 3 33 There are many more species than shown above this is just an example. Here are the questions. How do I read one row of data so as to load site2 into a variable called site2? Once I plot a graph using ordiplot how do I extract it from R so that I can put it into a Word for Windows document? Once I have the data in varables I hope to use designdist and Sørensen to discover diversity indices. I had a crack at this once but because I had sites as the columns it didn't work. Now that I think I have the data correct I can proceed. x Input data (this will be the whole data set that I read into my variable 'allSites' from a CSV.)? The variables for Sørensen will contain terms J for shared quantity, A and B for totals, N for the number of rows (sites) and P for the number of columns (species) and 'Binary' as the term. How do I get the shared number of species for each row? Probably very beginner type questions but I want to get on an haven't yet found the answers in my trawl throgh the help. Is there a book that I can buy to learn R? All the best, Richard Price MSc student University Birmingham. -- View this message in context: http://www.nabble.com/Very-new---beginners-questions-tf4260866.html#a12125845 Sent from the R help mailing list archive at Nabble.com. __ 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] vertically oriented color key in heatmaps
colorbar() from the package matlab. nightly.py wrote: Hi, I have some data which I was plotting using image(). I wanted to add a vertical color key to the plot and I found that heatmap.2 in gplots does let me add a color key. However, I was thinking of a vertical bar with the color range rather than the style that gplots provides. Is there any package (or code snippet) that would let me add a vertical color key to an image() or heatmap plot? -- View this message in context: http://www.nabble.com/vertically-oriented-color-key-in-heatmaps-tf4263271.html#a12138673 Sent from the R help mailing list archive at Nabble.com. __ 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] substrings
Is this what you want? a-c(a b c,1 2 3,q - 5) a [1] a b c 1 2 3 q - 5 sapply(strsplit(a,[[:blank:]]),function(x)x[1]) [1] a 1 q Edna Bell wrote: I have a set of character results. If one of the characters is a blank space, followed by other characters, I want to end at the blank space. I tried strsplit, but it picks up again after the blank. Any help would be much appreciated. -- View this message in context: http://www.nabble.com/substrings-tf4241506.html#a12069209 Sent from the R help mailing list archive at Nabble.com. __ 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] substrings
one more, shorter, solution. a [1] a b c 1 2 3 q- 5 gsub(\\s.+,,a) [1] a 1 q- Edna Bell wrote: I have a set of character results. If one of the characters is a blank space, followed by other characters, I want to end at the blank space. I tried strsplit, but it picks up again after the blank. Any help would be much appreciated. -- View this message in context: http://www.nabble.com/substrings-tf4241506.html#a12069488 Sent from the R help mailing list archive at Nabble.com. __ 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] About grep
Shao wrote: Hi,everyone. I have a problem when using the grep. for example: a - c(aa,aba,abac) b- c(ab,aba) I want to match the whole word,so grep(^aba$,a) it returns 2 but when I used it a more useful way: grep(^b[2]$,a), it doesn't work at all, it can't find it, returning integer(0). How can I chang the format in the second way? Thanks. The regexp ^b[2]$ matches only two words: b2 and b (in your present grep call with defaults extended = TRUE, perl = FALSE, fixed = FALSE). They don't present in a, that's why grep returns integer(0). If you want to find the word b[2] (the expression similar to an array indexing operator), either use fixed=TRUE and remove any regexp markup (^ and $) a- c(aa,aba,abac,b[2]) grep(b[2],a,fixed=TRUE) [1] 4 , or use escapes grep(^b\\[2\\]$,a) [1] 4 -- View this message in context: http://www.nabble.com/About-grep-tf4228021.html#a12029243 Sent from the R help mailing list archive at Nabble.com. __ 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] Finding multiple characters in the same string
gregexpr([0-9],this1is2a3test) [[1]] [1] 5 8 10 attr(,match.length) [1] 1 1 1 unlist(gregexpr([0-9],this1is2a3test)) [1] 5 8 10 Tom.O wrote: I have this problem where I need to find if there is any numbers in a string, this is no problem if theres only one number per string. I would then simply use the regexpr() funtion togheter with the substring function to extract the number. But regexpr only picks one number per string either from the beginning or the end, but not multiple. Can this be done? And how for example My string - this1is2a3test The result I want is an vector of c(1,2,3) -- View this message in context: http://www.nabble.com/Finding-multiple-characters-in-the-same-string-tf4205206.html#a11962341 Sent from the R help mailing list archive at Nabble.com. __ 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] Finding multiple characters in the same string
grep([0-9],unlist(strsplit(this1is2a3test,)),value=TRUE) Tom.O wrote: I have this problem where I need to find if there is any numbers in a string, this is no problem if theres only one number per string. I would then simply use the regexpr() funtion togheter with the substring function to extract the number. But regexpr only picks one number per string either from the beginning or the end, but not multiple. Can this be done? And how for example My string - this1is2a3test The result I want is an vector of c(1,2,3) -- View this message in context: http://www.nabble.com/Finding-multiple-characters-in-the-same-string-tf4205206.html#a11962578 Sent from the R help mailing list archive at Nabble.com. __ 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] Call R program from C++ code
Hi Feng, You cannot compile R scripts as a shared library. You can compile the R engine itself (interpreter and some basic functions) as .dll (or .so), dynamically load it during run time of your application and call its low level functions. All details are in the Writing R extensions manual, installed with R (%R_HOME%/doc/R-exts.pdf). Searching Google with embedding R gives the following (outdated) link http://developer.r-project.org/embedded.html This says basic things and references the Writing R Extensions manual. You can see the Rgnome sources for example. Monday, July 30, 2007, 10:25:16 PM, you wrote: K Hi Vladimir: K Thank you very much! I'm very interested in this sentence: R can K be compiled as a shared library object, that you can dynamically load from K your application and use its functions. That's would be great if R programs K can be compiled as shared library object(.lib? or .dll ? ) Can you please K give more details about that? K Best, K Feng K -Original Message- K From: [EMAIL PROTECTED] K [mailto:[EMAIL PROTECTED] On Behalf Of Vladimir Eremeev K Sent: 2007年7月30日 5:16 K To: r-help@stat.math.ethz.ch K Subject: Re: [R] Call R program from C++ code K Writing R Extensions manual contains chapters dedicated to parsing and K evaluating of the R extensions from C. K Also, I vaguely remember I've seen something like Embedding R somewhere in K manuals. K R can be compiled as a shared library object, that you can dynamically load K from your application and use its functions. K R doesn't have a compiler, it's the interpreted language. K However, it can parse a character string representing an expresstion and K transform it into the internal form, ready for evaluation. K Feng Qiu wrote: Hi All: I'm developing an application program using C++. From my C++ code, I would call some R program I have written. I' wondering if R provide some compiler that can compile R program into executable program. I searched R-help, there are a lot of posts talking about writing C++ code in R program, but few about calling R from C++. I might be wrong that R doesn't have complier. What I'm trying to do is to call R program from C++ code. Any help is highly appreciated! -- Best regards, Vladimirmailto:[EMAIL PROTECTED] __ 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] Prompt comes too late
You can use choose.files(caption=Choose data file please!,multi=FALSE,filters=Filters[All]) This will show the prompt in the file selection dialog and also allows you to restrict the list of possible choises with a filter. Ralf Finne wrote: I am trying to make a program to ask the user to choose data file: print(Choose data file please !) matr=read.table(file.choose(),dec=.,header=TRUE) The problem is that the prompt Choose data file please ! comes after I have chosen the file. -- View this message in context: http://www.nabble.com/Prompt-comes-too-late-tf4178913.html#a11919327 Sent from the R help mailing list archive at Nabble.com. __ 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] remove NA rows and columns
testmatrix [,1] [,2] [,3] [,4] [1,] NA NA NA NA [2,] NA11 NA [3,] NA22 NA [4,] NA11 NA [5,] NA22 NA [6,] NA NA NA NA tm1-testmatrix[,-which(apply(testmatrix,2,function(x)all(is.na(x] tm1 [,1] [,2] [1,] NA NA [2,]11 [3,]22 [4,]11 [5,]22 [6,] NA NA tm2-tm1[-which(apply(testmatrix,1,function(x)all(is.na(x,] tm2 [,1] [,2] [1,]11 [2,]22 [3,]11 [4,]22 Antje wrote: I guess, it's a rather simple thing but I cannot find a short way to reduce a matrix, removing all rows and columns having just NA elements. testmatrix - matrix(nrow=6, ncol=4) testmatrix[2:5,2:3] - seq(2) testmatrix [,1] [,2] [,3] [,4] [1,] NA NA NA NA [2,] NA11 NA [3,] NA22 NA [4,] NA11 NA [5,] NA22 NA [6,] NA NA NA NA the new matrix should look like this (by the way, I don't know which rows and columns are the one to be deleted... testmatrix [,1] [,2] [1,] 11 [2,] 22 [3,] 11 [4,] 22 -- View this message in context: http://www.nabble.com/remove-NA-rows-and-columns-tf4192605.html#a11923002 Sent from the R help mailing list archive at Nabble.com. __ 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] remove NA rows and columns
Or, these operations can be called in one command: testmatrix[-which(apply(testmatrix,1,function(x)all(is.na(x,-which(apply(testmatrix,2,function(x)all(is.na(x] [,1] [,2] [1,]11 [2,]22 [3,]11 [4,]22 Vladimir Eremeev wrote: testmatrix [,1] [,2] [,3] [,4] [1,] NA NA NA NA [2,] NA11 NA [3,] NA22 NA [4,] NA11 NA [5,] NA22 NA [6,] NA NA NA NA tm1-testmatrix[,-which(apply(testmatrix,2,function(x)all(is.na(x] tm1 [,1] [,2] [1,] NA NA [2,]11 [3,]22 [4,]11 [5,]22 [6,] NA NA tm2-tm1[-which(apply(testmatrix,1,function(x)all(is.na(x,] tm2 [,1] [,2] [1,]11 [2,]22 [3,]11 [4,]22 Antje wrote: I guess, it's a rather simple thing but I cannot find a short way to reduce a matrix, removing all rows and columns having just NA elements. testmatrix - matrix(nrow=6, ncol=4) testmatrix[2:5,2:3] - seq(2) testmatrix [,1] [,2] [,3] [,4] [1,] NA NA NA NA [2,] NA11 NA [3,] NA22 NA [4,] NA11 NA [5,] NA22 NA [6,] NA NA NA NA the new matrix should look like this (by the way, I don't know which rows and columns are the one to be deleted... testmatrix [,1] [,2] [1,] 11 [2,] 22 [3,] 11 [4,] 22 -- View this message in context: http://www.nabble.com/remove-NA-rows-and-columns-tf4192605.html#a11923066 Sent from the R help mailing list archive at Nabble.com. __ 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] Call R program from C++ code
Writing R Extensions manual contains chapters dedicated to parsing and evaluating of the R extensions from C. Also, I vaguely remember I've seen something like Embedding R somewhere in manuals. R can be compiled as a shared library object, that you can dynamically load from your application and use its functions. R doesn't have a compiler, it's the interpreted language. However, it can parse a character string representing an expresstion and transform it into the internal form, ready for evaluation. Feng Qiu wrote: Hi All: I'm developing an application program using C++. From my C++ code, I would call some R program I have written. I' wondering if R provide some compiler that can compile R program into executable program. I searched R-help, there are a lot of posts talking about writing C++ code in R program, but few about calling R from C++. I might be wrong that R doesn't have complier. What I'm trying to do is to call R program from C++ code. Any help is highly appreciated! -- View this message in context: http://www.nabble.com/Call-R-program-from-C%2B%2B-code-tf4167083.html#a11860280 Sent from the R help mailing list archive at Nabble.com. __ 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] regular expressions : extracting numbers
GOUACHE David wrote: Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the numbers. A quick example - extract of the original vector : lema, rb 2% rb 2% rb 3% rb 4% rb 3% rb 2%,mineuse rb rb rb 12 rb rj 30% rb rb rb 25% rb rb rb rj, rb and the type of thing I wish to end up with : 2 2 3 4 3 2 12 30 25 or, instead of , NA would be acceptable (actually it would almost be better for me) chv-scan(what=character,sep= ) #then copy the text from your message to the clipboard and paste it to the R console chv [1] lema, rb 2% rb 2% rb 3% rb 4% [5] rb 3% rb 2%,mineuse rbrb [9] rb 12 rbrj 30%rb [13] rbrb 25%rbrb [17] rbrj, rb # actual replacements : # replace non-digits with nothing chv.digits-gsub([^0-9],,chv) chv.digits [1] 2 2 3 4 3 21230 25 [16] # replace empty strings with NA chv.digits[chv.digits==]-NA chv.digits [1] 2 2 3 4 3 2 NA NA 12 NA 30 NA NA 25 NA [16] NA NA NA -- View this message in context: http://www.nabble.com/regular-expressions-%3A-extracting-numbers-tf4169660.html#a11862597 Sent from the R help mailing list archive at Nabble.com. __ 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] exporting character vector to text files
Use get() instead of eval(). And, probably, some arguments are missing in call to paste(). Maybe, extension? That is, for(i in test) write.table(get(i),file=paste(i,txt,sep=.),row.names=FALSE,sep=\t) If you want file names matching exactly names of your matrices, and being without extension, you don't need to call paste() at all: for(i in test) write.table(get(i),file=i,row.names=FALSE,sep=\t) Luis Ridao Cruz wrote: R-help, I have a character vector whose elements are the names of matrixes. Something like this: test - ls(pattern=Oki) [1] aaOkiaOki bOki c1Okic2Okic3Oki cOki dOki eOki fOki gprsOki hOki iOki [14] jOki kOki lOki mOki .. An example: aaOki xy [1,] -6.33 61.41667 [2,] -4.83 61.41667 [3,] -4.83 61.25000 [4,] -5.00 61.25000 [5,] -5.00 61.16667 [6,] -5.17 61.16667 [7,] -5.17 61.0 [8,] -5.33 61.0 [9,] -5.33 60.91667 [10,] -5.50 60.91667 [11,] -5.50 60.8 [12,] -5.67 60.8 [13,] -5.67 60.75000 [14,] -5.83 60.75000 [15,] -5.83 60.7 [16,] -6.00 60.7 [17,] -6.00 60.5 [18,] -6.17 60.5 [19,] -6.17 61.0 [20,] -6.33 61.0 [21,] -6.33 61.41667 .. .. .. What I want to do is to export these objects to text files by doing: for(i in test) write.table(eval(i),file=paste(i),row.names=FALSE,sep=\t) but it doesn't work. -- View this message in context: http://www.nabble.com/exporting-character-vector-to-text-files-tf4157676.html#a11829294 Sent from the R help mailing list archive at Nabble.com. __ 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] Download multiple stock quotes in a loop
Owe Jessen wrote: Hi all, this should be a simple question, but I haven't been able to do it right. I am trying to download multiple stock quotes in a loop, so that every timeseries is safed with the symbol of the stock. Can anybody help me out? Here's the code: require(tseries) startd - 2000-06-01 stocks - c(bmw.de, vow.de, dte.de) for(stock in stocks) stock - as.timeSeries(get.hist.quote(instrument=stock, start=startd, quote=Close, compress=d)) } Thanks in advance, Owe The variable stock is assigned values twice in the cycle. First, it gets the value of bmw.de, and immediately after that it is assigned with the result returned by as.timeSeries( ... ) If you replace the interior of the loop with the assign(paste(stock.,stock,sep=), as.timeSeries(get.hist.quote [etc])) you will get three variables, namely, stock.bmw.de, stock.vow.de and stock.dte.de. -- View this message in context: http://www.nabble.com/Download-multiple-stock-quotes-in-a-loop-tf4150838.html#a11808177 Sent from the R help mailing list archive at Nabble.com. __ 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] plots
amna khan wrote: I did not find any function of graph which plot one variable on x-axis and 2 or more than 2 variables on y-axis. You can use xyplot() from the package lattice. library(lattice) xyplot(y1+y2+y3~x) I suspect, the problem is, that plot() erases everything that was plotted earlier and establishes a new coordinate system in the plotting window. In case of basic graphics, you can set par(new=TRUE) and call plot() several times. points(), lines() and other functions from the basic graphics will add new curves to the existing plot. Initially, you must set axis ranges large enough to fit everything you want to plot. -- View this message in context: http://www.nabble.com/plots-tf4141246.html#a11780013 Sent from the R help mailing list archive at Nabble.com. __ 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] problem with sub !
Try Sys.setlocale(). marco.R.help marco.R.help wrote: I am trying to use sub to replace patterns in a character array that contains german names with german special characters. I have the following problem: sub(\\xdf,ss,Wei\xdferitzkreis) Error in sub(pattern, replacement, x, ignore.case, extended, fixed, useBytes) : input string 1 is invalid in this locale sub(\xdf,ss,Wei\xdferitzkreis) Error in sub(pattern, replacement, x, ignore.case, extended, fixed, useBytes) : 'pattern' is invalid in this locale Does anybody know how to tackle this problem ? -- View this message in context: http://www.nabble.com/problem-with-sub-%21-tf4141431.html#a11781512 Sent from the R help mailing list archive at Nabble.com. __ 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] Redirecting print output
Stan Hopkins wrote: I see a rich set of graphic device functions to redirect that output. Are there commands to redirect text as well. I have a set of functions that execute many linear regression tests serially and I want to capture this in a file for printing. Thanks, Stan Hopkins Yes, there are. ?sink You could also run your functions from a batch mode: R your_script.R output.txt or Rscript your_script.R output.txt This, however, will give you a single file, while sink() allows creation of multiple files. capture.output can store the output in an array of character strings. -- View this message in context: http://www.nabble.com/Redirecting-print-output-tf4134131.html#a11758652 Sent from the R help mailing list archive at Nabble.com. __ 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] values from a linear model
Manuele Pesenti wrote: Dear R users, how can I extrapolate values listed in the summary of an lm model but not directly available between object values such as the the standard errors of the calculated parameters? for example I got a model: mod - lm(Crd ~ 1 + Week, data=data) and its summary: summary(mod) Call: lm(formula = Crd ~ 1 + Week, data = data, model = TRUE, y = TRUE) Residuals: Min 1Q Median 3QMax -4.299e-03 -1.653e-03 2.628e-05 1.291e-03 5.130e-03 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.000e+01 3.962e-04 25238.73 2e-16 *** Week5.038e-04 6.812e-0673.96 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.001966 on 98 degrees of freedom Multiple R-Squared: 0.9824, Adjusted R-squared: 0.9822 F-statistic: 5469 on 1 and 98 DF, p-value: 2.2e-16 I'm interested in values of Std. Error of coefficients... thank you very much If you want to assign these values to some other variables, try assigning the result of the summary() to a variable and working with its components (the result is a list, use $ or [[]] to get its members) mod.sum-summary(mod) then coef(mod.sum)[,2] or mod.sum$coefficients[,2] will give you those Std. Errors -- View this message in context: http://www.nabble.com/values-from-a-linear-model-tf4134911.html#a11760459 Sent from the R help mailing list archive at Nabble.com. __ 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] Formatted Data File Question for Clustering -Quickie Project
The R Data Import/Export guide was mentioned already, it contains everything you should know about data exchange between R and other software. In case it says nothing about dates, try as.Date() and strftime(). For your example below, as.Date(1/31/1994,format=%m/%d/%Y) works. ngottlieb wrote: I am trying to learn how to format Ascii data files for scan or read into R. Precisely for a quickie project, I found some code (at end of this email) to do exactly what I need: To cluster and graph a dendrogram from package (stats). I am stuck on how to format a text file to run the script. I looked at the dataset USArrests (which would be replaced by my data and labels) using UltraEdit. That data appears to be in binary format and I would simply like a readable ASCII text file. How can I: A) format this data to a file for the script below? B) I would like to use squared Euclidean distance, can hclust support this? Thanks, Neil Gottlieb Here is sub-set example of my data set, return series to cluster: 13 cases by 36 observations): Month Convertible Arbitrage Dedicated Short BiasEmerging Markets 1/31/1994 0.004 -0.016 0.105 2/28/1994 0.002 0.020 -0.011 3/31/1994 -0.010 0.072 -0.046 [skip] -- View this message in context: http://www.nabble.com/Formatted-Data-File-Question-for-Clustering--Quickie-Project-tf3915926.html#a5436 Sent from the R help mailing list archive at Nabble.com. __ 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] test if files in current folder
runner wrote: I want to test if the files are already in my current folder before I download or copy from somewhere else. What's in my mind is to check if a file is open-able in current folder. Is there a way to do this, like in Perl: if (open()) { do sth}? To put it another way, how to extract all file names in a folder to an array or list? ?files ?dir BTW, Perl has nice -X functions, which allow file testing without explicit opening: http://perldoc.perl.org/functions/-X.html -- View this message in context: http://www.nabble.com/test-if-files-in-current-folder-tf3919587.html#a8347 Sent from the R help mailing list archive at Nabble.com. __ 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] Read Windows-like .INI files into R data structure?
One more question, inspired by this one, just to increase my R skill level. Earl F. Glynn wrote: I need to process some datasets where the configuration information was stored in .INI-like files, i.e., text files with sections like this: [Section1] var1=value1 var2=value2 [Section2] A=value3 B=value4 var1=value1, A=value3 is almost pure R code. Is it possible to use this feature to solve the problem? That is, something like eval(as.expression(A=value3)) and assign (store) the result in lst$Section2 environment. lst is a newly created list, containing the contents of the file being processed. -- View this message in context: http://www.nabble.com/Read-Windows-like-.INI-files-into-R-data-structure--tf3908740.html#a11094865 Sent from the R help mailing list archive at Nabble.com. __ 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] Read Windows-like .INI files into R data structure?
Christophe Pallier wrote: var1=value1, A=value3 is almost pure R code. Is it possible to use this feature to solve the problem? Along the same lines: you may write a short script that converts the ini file into R code that can be sourced. From your example, you can generate the following R code: Section1 - list() Section1['var1'] - value1 Section1['var2'] - value2 Section2 - list() Section2['A'] - value3 Section2['B'] - value4 with the following awk script (using awk -F'=' -f conv.awk example.ini example.R) ### conv.awk $1 ~ /\[/ { gsub(/[\[\]]/,); # remove the brackets listname = $1; print $1 - list(); next } { print listname [' $1 '] - $2 } (I know, it looks cryptic... so I am shooting myself in the foot after claiming that awk scripts are typically quite readable ;-) Christophe Pallier (http://www.pallier.org) It's sufficiently readable, but using something besides R is not sporty. ;) -- View this message in context: http://www.nabble.com/Read-Windows-like-.INI-files-into-R-data-structure--tf3908740.html#a11095800 Sent from the R help mailing list archive at Nabble.com. __ 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] selecting characters from a line of text
Tim Holland wrote: Is there a way in R to select certain characters from a line of text? I have some data that is presently in a large number of text files, and I would like to be able to select elements of each text file (elements are always on the same line, in the same position) and organize them into a table. Is there a tool to select text in this way in R? Use substr() or substring() to select characters from a a text string, nchar() will give you its length, scan() can also help in reading data from text files, grep() can be used for search and selecting character strings in an array, having certain patterns. If your files are formatted in some way, consider read.table(), read.csv(), read.fwf() and friends. You should also read the Data import/export manual from the R documentation. Its pdf version was, probably, installed on your hard drive with R, and html is here: http://cran.r-project.org/doc/manuals/R-data.html pdf version is also here: http://cran.r-project.org/doc/manuals/R-data.pdf -- View this message in context: http://www.nabble.com/selecting-characters-from-a-line-of-text-tf3904063.html#a11074650 Sent from the R help mailing list archive at Nabble.com. __ 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] dyn.load( ) problem
Ian McCarthy wrote: I am trying to access a dll with dyn.load, but I get an error message box titled R Console: Rgui.exe - Unable to Locate Component. The error message itself states this application has failed to start because libifcoremdd.dll was not found. Re-installing the application may fix this problem. I have reinstalled the program (with full installation) but still get the same error. I received the dll from a colleague who never had this issue on his computer, so I don't think it is problem with a compiler or the source code. And where is the file libifcoremdd.dll? Looks like you have to install the Intel Fortran compiler, as this DLL is its component (Intel-specific Fortran I/O intrinsic support library when compiled with /MDd, http://www.intel.com/support/performancetools/fortran/windows/sb/cs-007847.htm), or, at least all DLLs, your DLL depends on. Try using Dependency Walker to resolve these (http://www.dependencywalker.com/). -- View this message in context: http://www.nabble.com/dyn.load%28-%29-problem-tf3908956.html#a11084157 Sent from the R help mailing list archive at Nabble.com. __ 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] Selecting all values smaller than X in a dataframe
Christoph Scherber-2 wrote: Dear R users, I have a correlation matrix for a dataframe called synth, for which I now want to select only those cells that have correlations larger than +/-0.6: synth=data.frame(x=rnorm(10,1),y=rnorm(10,2),z=rnorm(10,0.5)) w=cor(synth,use=pairwise.complete.obs) w=as.data.frame(w) w[,sapply(w,abs(w),,0.6)] The problem is that using sapply with or doesn´t seem to work. How could I solve this problem? If you want to extract correlations with absolute value 0.6, then simply use w[abs(w)0.6] Please, reread the help(sapply). You give some extra arguments to this function. The first goes the vector, the second goes the function, and then - additional arguments to the function. Probably, you wanted w[sapply(abs(w),,0.6)] This gives the same result. -- View this message in context: http://www.nabble.com/Selecting-all-values-smaller-than-X-in-a-dataframe-tf3901238.html#a11059804 Sent from the R help mailing list archive at Nabble.com. __ 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] Neural Net. in R
I have written some bindings from the SNNS (Stuttgart Neural Network Simulator) to R. However, this work is not finished since the lack of interest to it and lack of time. At the moment, I use the mixture of scripts for R, cmd.exe, bash, and SNNS' batchman (latter two under cygwin) in my work. SNNS by itself is rather feature rich and well documented. Unfortunately its development has stopped many years ago, and it contains bugs, which I still failed to find and eliminate. Ehsan Rasa wrote: Hi everyone, I'm a graduate student of engineering, lately introduced with R. and using R for my project and thesis. I'm trying to use R for implementing a neural network regression model and apply it to my database. I found three R packages (AMORE , grnnR , neural) in R website, but their manuals are not really user-friendly in my idea. I was wondering if anyone has a written code in R using any of these packages for a feed-forward back-propagation neural network in R that I can use it. That'll be a remedy for my nightmare which already took quite time from me. I would really appreciate it. Sincerely, Jason. -- View this message in context: http://www.nabble.com/Neural-Net.-in-R-tf3877741.html#a10991934 Sent from the R help mailing list archive at Nabble.com. __ 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] Why is the R mailing list so hard to figure out?
irishhacker wrote: Why does the R mailing list need such an unusual and customized user interface? There was a discussion of this some time ago on the list. I believe, RSiteSearch(r-help mailing list forum) or some other similar keywords will find it. irishhacker wrote: What's the best way to view and read discussions in this group for recent days? Can I view the postings for the current day via Google Groups? GMANE was mentioned already. I use the Nabble interface (http://www.nabble.com/R-f13819.html), it seems more convenient to me, but it collects less lists than Gmane. -- View this message in context: http://www.nabble.com/Why-is-the-R-mailing-list-so-hard-to-figure-out--tf3868661.html#a10965539 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Where is CRAN mirror address stored?
When I update.packages(), R shows the dialog window, listing CRAN mirrors and asks to choose the CRAN mirror to use in this session. Then, R uses this address and never asks again until quit. Is there any way to make R ask for the CRAN mirror again, except restarting it? I am just trying to save typing, because sometimes my internet connection with CRAN becomes too slow, and mirrors disappear. -- View this message in context: http://www.nabble.com/Where-is-CRAN-mirror-address-stored--tf3845953.html#a10891857 Sent from the R help mailing list archive at Nabble.com. __ 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] Accessing plots in Trellis graphics
I used similar empty space to place the legend, by specifying the placement coordinates to the key argument of xyplot. This was rather long time ago, and I had to explicitly form the list, used as the key argument for this function. Lattice has evolved since that, some automation has appeared. Try also using panel.identify, trellis.focus and other functions, listed on the help page together with these two. Sigbert Klinke wrote: I used xyplot to create conditional scatterplots. My layout is 5x3 plots, but my data contains only 14 subgroups. So I would like to use the empty plot to display additional information about the data. How can I access the plot? -- View this message in context: http://www.nabble.com/Accessing-plots-in-Trellis-graphics-tf3845949.html#a10892051 Sent from the R help mailing list archive at Nabble.com. __ 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] determining a parent function name
Does tail(capture.output(traceback()),n=1) do what you want? that is error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) parent-tail(capture.output(traceback()),n=1) parent-gsub([0-9]: ,,parent) # deleting 1: from the captured string tkinsert(tkmsg, end, sprintf(Error in %s: %s, parent , msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } Sundar Dorai-Raj wrote: Hi, All, I'm writing a wrapper for stop that produces a popup window using tcltk. Something like: error - function(...) { msg - paste(..., sep = ) if(!length(msg)) msg - if(require(tcltk, quiet = TRUE)) { tt - tktoplevel() tkwm.title(tt, Error) tkmsg - tktext(tt, bg = white) tkinsert(tkmsg, end, sprintf(Error in %s: %s, ???, msg)) tkconfigure(tkmsg, state = disabled, font = Tahoma 12, width = 50, height = 3) tkpack(tkmsg, side = bottom, fill = y) } stop(msg) } But, I would like to know from which function error() is called. For example, if I have foo - function() stop() bar - function() error() foo() Error in foo() : bar() Error in error() : and in the tk window I get Error in ???: I need the output of bar (in the tk window only) to be Error in bar(): then it's clear where error is called. I'm not worried about the output bar() produces on the console. Hope this makes sense. Thanks, -- View this message in context: http://www.nabble.com/determining-a-parent-function-name-tf3843262.html#a10892459 Sent from the R help mailing list archive at Nabble.com. __ 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] determining a parent function name
Vladimir Eremeev wrote: Does tail(capture.output(traceback()),n=1) do what you want? that is Hmmm... Seems, no... Having the earlier error() definition and bar-function() error(asdasdf) ft-function() bar() ft() I get in the tcl/tk window: Error in bar(): asdasdf bar() I get in the tcl/tk window: Error in ft(): asdasdf I get in the tcl/tk window: Error in bar(): asdasdf Some kind of the stack flushing is needed. .Traceback-NULL did not help -- View this message in context: http://www.nabble.com/determining-a-parent-function-name-tf3843262.html#a10892608 Sent from the R help mailing list archive at Nabble.com. __ 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] search path question
Yes, it is. The original is here http://finzi.psych.upenn.edu/R/Rhelp02a/archive/92829.html However, it requires some modifications. Here they are. Sorry, I can test it only in Windows. search.source - function(file, path=Sys.getenv(PATH), ...) { for(p in strsplit(path,.Platform$path.sep)[[1]]) { fp - file.path(p, f) if(file.exists(fp)) return(source(fp, ...)) } stop(file , sQuote(file), not found) } Try also looking here. http://finzi.psych.upenn.edu/R/Rhelp02a/archive/92821.html Zhiliang Ma wrote: Is there a simple function that can add a folder into current R search path? For example, suppose my current work directory is D:\work, but my input files are stored in folder C:\inFiles\, I know I can change work directory or add C:\inFiles\ before files name when I scan them, but I don't want to do that. I want to find a function that can simply add C:\inFiles\ into R's search path, so that we I scan a file R will go to all the search paths to find it. In matlab, path(path,C:\inFiles) will do this job, I'm just wondering if there is a similar function in R can do this job. -- View this message in context: http://www.nabble.com/search-path-question-tf3833821.html#a10855885 Sent from the R help mailing list archive at Nabble.com. __ 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] creating txt file from data.frame
apply(dfr,1,FUN=function(x){ cat(c(x[1], ifelse(x[2]==x[3],x[2],paste(x[2],x[3],sep=-)),\n), file=filename.txt) }) This code assumes the data frame with at least 3 columns, errors will occur if there will be less than 3 columns. Taka Matzmoto wrote: R-users I need to create a txt file as input for another program using data.frame values Variable_name Start End [1,] a 1 1 [2,] bbb 2 2 [3,] c 3 6 [4,] ddd 7 10 [5,] eee 11 16 the text file should look like below, if the start and the end is the same, only put the start one in the txt file. a 1 bbb 2 c 3-6 ddd 7-10 eee 11-16 -- View this message in context: http://www.nabble.com/creating-txt-file-from-data.frame-tf3825900.html#a10833782 Sent from the R help mailing list archive at Nabble.com. __ 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] how to mimic plot=F for truehist?
By defining your own function. You can get the function body by typing its name in the R command line and pressing Enter. Copy-paste the function body in ascii file (source R code), redefine it as you like, for example, by adding desired argument and code for processing it, then source that file and use your customized function. Johannes Graumann-2 wrote: Dear Rologists, In order to combine plots I need to get access to the some pars specific to my plot prior to replot it with modified parameters. I have not found any option like plot=F associated with truehist and would like to know whether someone can point out how to overcome this problem. -- View this message in context: http://www.nabble.com/how-to-mimic-plot%3DF-for-truehist--tf3815196.html#a10800310 Sent from the R help mailing list archive at Nabble.com. __ 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] about lex/yacc
These are not functions. These are separate products (one more is bison), aimed to help in creating programming language interpreters. You should know the C programming language and be familiar with the algorithm theory, the finite state machine theory and with the LALR grammatics, in order to successfuly use these products. elyakhlifi mustapha wrote: hello, what about these functions lex/yacc which can parse and recognize a syntax? thanks -- View this message in context: http://www.nabble.com/about-lex-yacc-tf3802443.html#a10759642 Sent from the R help mailing list archive at Nabble.com. __ 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] Please, remind a function name
Great! I was thinking about adding such a feature in the future. Gabor Grothendieck wrote: Note that a significant difference between the two solutions is that the OO solution allows new methods corresponding to method= to be added without changing the function holding the statements. My solution (after a cup of coffee :) ): model.formula-switch(model.type,S=[s-model formula],HK=[hk-model formula]) model-lm(model.formula) Gabor Grothendieck wrote: You could use the class dispatching mechanism: mymodel - function(a, b, method = S) { .Class - method NextMethod(mymodel) } mymodel.S - function(a, b, method = S) cat(S:, a, b, method, \n) mymodel.HK - function(a, b, method = S) cat(HK:, a, b, method, \n) mymodel(1:3, 1:4) mymodel(1:3, 1:4, S) mymodel(1:3, 1:4, HK) -- View this message in context: http://www.nabble.com/Please%2C-remind-a-function-name-tf3797444.html#a10759959 Sent from the R help mailing list archive at Nabble.com. __ 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] Legend outside plotting area
RSiteSearch(legend outside plot) will bring you many links to the discussions of this question. layout perfectly allows everything. typical sequence looks like this This divides the device region by two parts one below another: layout(matrix(c(1,2),byrow=TRUE), heights=[blah-blah-blah], [some other arguments]) Then we plot on the first part: plot( ... ) lines ( ... ) points ( ... ) grid( ... ) [ whatever you want on the plotting area] Then we finish plotting on the first part of the layout matrix and come to the next, legend part. The only thing to do is placing the legend in the top left corner. plot.new(); plot.window(c(0,1), c(0,1)); legend(0,1, [ legend text ] ) Judith Flores wrote: Hi, I have been trying many of the suggested options to place a legend outside plotting area, including something like this: par(xpd=T, oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) But the aspect of the four plots gets compromised when I change the margin settings. I cannot use mtext because I need to use colors for the text. I tried layout, but wouldn't let me include the legend, only plots. I would appreciate very much some more help. Regards, J -- View this message in context: http://www.nabble.com/Legend-outside-plotting-area-tf3794564.html#a10735956 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Please, remind a function name
Sorry, I'm stuck. :) I am writing a function, which would fit either one linear model or another one, depending on its argument model.type. And I don't want to use several if's, because R allows doing it with much more beauty. That is I am looking for prettier alternative to the following AB2C-function(a,b,model.type=S) { # or HK, and return NULL if this argument has any other value [ do some stuff] if(model.type==S) model-lm( [s.model formula] ) else if (model.type == HK) model-lm([hk.model formula]) else model-NULL return(model) } I was looking at switch, but didn't come to solution. Sorry :) -- View this message in context: http://www.nabble.com/Please%2C-remind-a-function-name-tf3797444.html#a10741597 Sent from the R help mailing list archive at Nabble.com. __ 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] Parallel processes
snow still exists, and there is one more package snowFT on CRAN (FT stands for Fault Tolerant) Probably, you didn't find it because of typing its name in capitals. hodgess wrote: According to the R-help, at one time there was a package called SNOW. It doesn't seem to exist anymore. -- View this message in context: http://www.nabble.com/Parallel-processes-tf3798421.html#a10750966 Sent from the R help mailing list archive at Nabble.com. __ 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] Parallel processes
There are R interfaces to MPI and PVM on CRAN, which are Rmpi and RPVM, respectively. hodgess wrote: I was wondering if there were any packages for parallel programming in R. According to the R-help, at one time there was a package called SNOW. It doesn't seem to exist anymore. -- View this message in context: http://www.nabble.com/Parallel-processes-tf3798421.html#a10750815 Sent from the R help mailing list archive at Nabble.com. __ 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] Please, remind a function name
My solution (after a cup of coffee :) ): model.formula-switch(model.type,S=[s-model formula],HK=[hk-model formula]) model-lm(model.formula) Gabor Grothendieck wrote: You could use the class dispatching mechanism: mymodel - function(a, b, method = S) { .Class - method NextMethod(mymodel) } mymodel.S - function(a, b, method = S) cat(S:, a, b, method, \n) mymodel.HK - function(a, b, method = S) cat(HK:, a, b, method, \n) mymodel(1:3, 1:4) mymodel(1:3, 1:4, S) mymodel(1:3, 1:4, HK) On 5/22/07, Vladimir Eremeev [EMAIL PROTECTED] wrote: Sorry, I'm stuck. :) I am writing a function, which would fit either one linear model or another one, depending on its argument model.type. And I don't want to use several if's, because R allows doing it with much more beauty. That is I am looking for prettier alternative to the following AB2C-function(a,b,model.type=S) { # or HK, and return NULL if this argument has any other value [ do some stuff] if(model.type==S) model-lm( [s.model formula] ) else if (model.type == HK) model-lm([hk.model formula]) else model-NULL return(model) } I was looking at switch, but didn't come to solution. Sorry :) -- View this message in context: http://www.nabble.com/Please%2C-remind-a-function-name-tf3797444.html#a10750855 Sent from the R help mailing list archive at Nabble.com. __ 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] using lm() with variable formula
I was solving similar problem some time ago. Here is my script. I had a data frame, containing a response and several other variables, which were assumed predictors. I was trying to choose the best linear approximation. This approach now seems to me useless, please, don't blame me for that. However, the script might be useful to you. code library(forward) # dfr is a data.frame, that contains everything. # The response variable is named med5x # The following lines construct linear models for all possibe formulas # of the form # med5x~T+a+height # med5x~a+height+RH # T, a, RH, etc are the names of possible predictors inputs-names(dfr)[c(10:30,1)] # dfr was a very large data frame, containing lot of variables. # here we have chosen only a subset of them. for(nc in 11:length(inputs)){ # the linear models were assumed to have at least 11 terms # now we are generating character vectors containing formulas. formulas-paste(med5x,sep=~, fwd.combn(inputs,nc,fun=function(x){paste(x,collapse=+)})) # and then, are trying to fit every for(f in formulas){ lms-lm(eval(parse(text=f)),data=dfr) cat(file=linear_models.txt,f,sum(residuals(lms)^2),\n,sep=\t,append=TRUE) } } /code Hmm, looking back, I see that this is rather inefficient script. For example, the inner cycle can easily be replaced with the apply function. Chris Elsaesser wrote: New to R; please excuse me if this is a dumb question. I tried to RTFM; didn't help. I want to do a series of regressions over the columns in a data.frame, systematically varying the response variable and the the terms; and not necessarily including all the non-response columns. In my case, the columns are time series. I don't know if that makes a difference; it does mean I have to call lag() to offset non-response terms. I can not assume a specific number of columns in the data.frame; might be 3, might be 20. My central problem is that the formula given to lm() is different each time. For example, say a data.frame had columns with the following headings: height, weight, BP (blood pressure), and Cals (calorie intake per time frame). In that case, I'd need something like the following: lm(height ~ weight + BP + Cals) lm(height ~ weight + BP) lm(height ~ weight + Cals) lm(height ~ BP + Cals) lm(weight ~ height + BP) lm(weight ~ height + Cals) etc. In general, I'll have to read the header to get the argument labels. Do I have to write several functions, each taking a different number of arguments? I'd like to construct a string or list representing the varialbes in the formula and apply lm(), so to say [I'm mainly a Lisp programmer where that part would be very simple. Anyone have a Lisp API for R? :-}] -- View this message in context: http://www.nabble.com/using-lm%28%29-with-variable-formula-tf3772540.html#a10716815 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] ... and 5 cents more.
Vladimir Eremeev wrote: I was solving similar problem some time ago. Here is my script. I had a data frame, containing a response and several other variables, which were assumed predictors. I was trying to choose the best linear approximation. This approach now seems to me useless, please, don't blame me for that. However, the script might be useful to you. code library(forward) # dfr is a data.frame, that contains everything. # The response variable is named med5x # The following lines construct linear models for all possibe formulas # of the form # med5x~T+a+height # med5x~a+height+RH # T, a, RH, etc are the names of possible predictors inputs-names(dfr)[c(10:30,1)] # dfr was a very large data frame, containing lot of variables. # here we have chosen only a subset of them. for(nc in 11:length(inputs)){ # the linear models were assumed to have at least 11 terms # now we are generating character vectors containing formulas. formulas-paste(med5x,sep=~, fwd.combn(inputs,nc,fun=function(x){paste(x,collapse=+)})) # and then, are trying to fit every for(f in formulas){ lms-lm(eval(parse(text=f)),data=dfr) cat(file=linear_models.txt,f,sum(residuals(lms)^2),\n,sep=\t,append=TRUE) } } /code Hmm, looking back, I see that this is rather inefficient script. For example, the inner cycle can easily be replaced with the apply function. lm(as.formula(f),data=dfr) do.call(lm,list(formula=f,data=dfr)) also should work in the inner cycle. -- View this message in context: http://www.nabble.com/using-lm%28%29-with-variable-formula-tf3772540.html#a10717354 Sent from the R help mailing list archive at Nabble.com. __ 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] rJava problem
mister_bluesman wrote: Basically, I’m trying to install rJava on my windows XP machine. I think I have succeeded in doing so as it appears in the list when i type library() in R. However, when i type ‘library(rJava)’ I get an error dialog box saying: 'This application has failed to start because jvm.dll was not found. Re-installing the application may fix this problem' When I press 'OK' on the dialog box, I get the following in the R console: Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to load shared library 'C:/PROGRA~1/R/R-25~1.0/library/rJava/libs/rJava.dll': LoadLibrary failure: The specified module could not be found. Error : .onLoad failed in 'loadNamespace' for 'rJava' Error: package/namespace load failed for 'rJava' Do you have any ideas how I can fix this? I really would appreciate any help you could give me? I have tried reinstalling it and I continue to get the same problem. I am using java's jdk1.6.0_01 Thanks Dynamic library jvm.dll must be in the PATH. -- View this message in context: http://www.nabble.com/rJava-problem-tf3771205.html#a10661933 Sent from the R help mailing list archive at Nabble.com. __ 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] rJava problem
mister_bluesman wrote: Ah thanks for that. That seems to have done the trick. But I'm not sure whether I have copied the right jvm.dll file into the path. I have 3 places where a jvm.dll file can be found: ~\Java\jre1.6.0_01\bin\client -this is the one i copied ~\Java\jdk1.6.0_01\jre\bin\client ~\Java\jdk1.6.0_01\jre\bin\server Did I copy the right one? or do the all have exactly the same file but just placed in different directories? The first one works for me (from the JRE), since I don't have the Development Kit, only Runtime Environment. Try using comp from the system command prompt and compare files to see if they are same. -- View this message in context: http://www.nabble.com/rJava-problem-tf3771205.html#a10662482 Sent from the R help mailing list archive at Nabble.com. __ 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] drop a letter
elyakhlifi mustapha wrote: hello, how can I do to drop C from this character C325 ? 1. if C is always single and always first: substring(C325,2) 2. more generic solution, drops all letters sp-unlist(strsplit(C325,split=[A-Z])) sp-sp[nchar(sp)0] sp -- View this message in context: http://www.nabble.com/drop-a-letter-tf3763392.html#a10638376 Sent from the R help mailing list archive at Nabble.com. __ 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] Running R function as a Batch process
d. sarthi maheshwari wrote: Hi, I am struggling with using R CMD BATCH command. Kindly suggest solution to the following problem. I have a function named CinC with accept two input parameters. This can be shown as: CinC - function(start, end) where start and end both are character strings. Please suggest me how can I run this function using command R CMD BATCH. Currently I am trying to do like this - R CMD BATCH c:/tt/CinC.r c:/tt/h.Rout -20070416 08:41 -20070416 10:33 What is wrong/incorrect with it? You should use the function commandArgs in your code to retrieve supplied arguments from the command line. Look at ?commandArgs ?Startup Your R invokation should look like this C:\ R CMD BATCH c:/tt/CinC.r c:/tt/h.Rout --args 20070416 08:41 20070416 10:33 And you should add something like this in your R code command.args-commandArgs(trailingOnly=TRUE) CinC(command.args[1],command.args[2]) -- View this message in context: http://www.nabble.com/Running-R-function-as-a-Batch-process-tf3764048.html#a10640433 Sent from the R help mailing list archive at Nabble.com. __ 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] space in R
elyakhlifi mustapha wrote: hello, can you help me I need to seperate words and symbol in a mathematics formula as follow C744=(C627*C177)/100 How could I do please? If you need to simply split a character vector, use strsplit. This and previous your posts suggest you need to create a parser. parse can do that. However, R doesn't seem to me an appropriate tool for the lexical analysis. bison and yacc could be the right choise. -- View this message in context: http://www.nabble.com/space-in-R-tf3757462.html#a10620039 Sent from the R help mailing list archive at Nabble.com. __ 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] qr.solve and lm (addition)
Vladimir Eremeev wrote: Dear R experts, I have a Matlab code which I am translating to R in order to examine and enhance it. First of all, I need to reproduce in R the results which were already obtained in Matlab (to make sure that everything is correct). There are some matrix manipulations and '\' operation among them in the code. I have the following data frame ABS.df Prosyn unk Chl Y NhV1 1 0.056524968 0.04387755 -0.073925372 0.026477146 0.083527021 0.0031950622 0.02164793 2 0.066456284 0.05992579 -0.094609497 0.031772575 0.054881164 0.0022078221 0.01358594 3 0.036383887 0.04601113 -0.061213302 0.021181717 0.026713530 0.0011716424 0.00824816 4 0.020419528 0.03803340 -0.044517584 0.013935340 0.019204991 0.0008763467 0.00577604 5 0.010209764 0.02968460 -0.030418334 0.009476031 0.013806924 0.0006554761 0.00376991 6 0.006033043 0.02666976 -0.025735131 0.006967670 0.009778344 0.0004838437 0.00441753 7 0.004733618 0.01168831 -0.009732966 0.006688963 0.002351775 0.0001380701 0.00403229 8 0.0 0. 0.0 0.0 0.0 0.00 -0.00060456 9 0.0 0. 0.0 0.0 0.0 0.00 -0.0003 11 0.241505077 0.45843930 -0.611308847 0.0 0.0 0.0584138174 0.07397018 21 0.226065730 0.41703452 -0.558270870 0.0 0.0 0.0516895121 0.07460447 31 0.211956969 0.37139373 -0.495174662 0.0 0.0 0.0426347324 0.07189945 41 0.206558807 0.35022863 -0.466337208 0.0 0.0 0.0392775042 0.06943217 51 0.197535970 0.33100673 -0.441656561 0.0 0.0 0.0363102112 0.06912282 61 0.186798904 0.31656506 -0.416287992 0.0 0.0 0.0335613531 0.06595377 71 0.156005203 0.24868275 -0.329660100 0.0 0.0 0.0250152915 0.06399879 81 0.153751864 0.23900952 -0.324902567 0.0 0.0 0.0232553862 0.05981515 91 0.144414605 0.22782217 -0.297243170 0.0 0.0 0.0209515025 0.05981442 qr.solve(ABS.df[,1:6],ABS.df[,7]) ProsynunkChl Y Nh 0.3877544 0.4282277 0.2221960 -0.8668715 0.2821082 -1.3696411 This reproduces the Matlab's numbers However, I used to lm, its syntax seems to me more clear. ?lm says that it uses QR decomposition to fit the model. Trying it: coef(lm(V1~Pro+syn+unk+Chl+Y+Nh,data=ABS.df)) (Intercept) Pro syn unk Chl Y Nh 0.001640184 0.417253116 0.351472810 0.196977369 -0.899729874 0.265585292 -1.181526491 Numbers differ. Obviously, I don't understand something. Please, could you clarify, what? Thank you. Moreover, coef(lm.fit(x=as.matrix(ABS.df[,1:6]),y=as.matrix(ABS.df[,7]))) ProsynunkChl Y Nh 0.3877544 0.4282277 0.2221960 -0.8668715 0.2821082 -1.3696411 -- View this message in context: http://www.nabble.com/qr.solve-and-lm-tf3757650.html#a10620477 Sent from the R help mailing list archive at Nabble.com. __ 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] qr.solve and lm (SOLVED)
Vladimir Eremeev wrote: Dear R experts, I have a Matlab code which I am translating to R in order to examine and enhance it. First of all, I need to reproduce in R the results which were already obtained in Matlab (to make sure that everything is correct). There are some matrix manipulations and '\' operation among them in the code. I have the following data frame ABS.df Prosyn unk Chl Y NhV1 [skip] qr.solve(ABS.df[,1:6],ABS.df[,7]) ProsynunkChl Y Nh 0.3877544 0.4282277 0.2221960 -0.8668715 0.2821082 -1.3696411 This reproduces the Matlab's numbers However, I used to lm, its syntax seems to me more clear. ?lm says that it uses QR decomposition to fit the model. Trying it: coef(lm(V1~Pro+syn+unk+Chl+Y+Nh,data=ABS.df)) (Intercept) Pro syn unk Chl Y Nh 0.001640184 0.417253116 0.351472810 0.196977369 -0.899729874 0.265585292 -1.181526491 Numbers differ. Obviously, I don't understand something. Please, could you clarify, what? Thank you. This was because of implied intercept term. lm(V1~Pro+syn+unk+Chl+Y+Nh+0,data=ABS.df) Call: lm(formula = V1 ~ Pro + syn + unk + Chl + Y + Nh + 0, data = ABS.df) Coefficients: Pro syn unk ChlY Nh 0.3878 0.4282 0. -0.8669 0.2821 -1.3696 That is, reproduces earlier results. -- View this message in context: http://www.nabble.com/qr.solve-and-lm-tf3757650.html#a10620691 Sent from the R help mailing list archive at Nabble.com. __ 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] Batch
elyakhlifi mustapha wrote: I saw the R-help to run some R programs in batch I used it like this R CMD BATCH C:/Documents and Settings/melyakhlifi/Bureau/calcara.r Erreur : erreur de syntaxe dans R CMD but without success!!!I don't work on linux but on windows IS it the same command ? Yes, it is. You need to set up paths to R executables. -- View this message in context: http://www.nabble.com/Batch-tf3753072.html#a10606289 Sent from the R help mailing list archive at Nabble.com. __ 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] Piecewise cubic Hermite interpolation [FOUND]
'pchip' from the 'signal' package seems to do the desirable operations. Vladimir Eremeev wrote: Which function implements the piecewise cubic Hermite interpolation? I am looking for equivalent of matlab's interp1 with the method = 'pchip' Here is the reference http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/interp1.html; -- View this message in context: http://www.nabble.com/Piecewise-cubic-Hermite-interpolation-tf3708765.html#a10409872 Sent from the R help mailing list archive at Nabble.com. __ 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] how to control the sampling to make each sample unique
Urania Sun wrote: I have a dataset of 1 records which I want to use to compare two prediction models. I split the records into test dataset (size = ntest) and training dataset (size = ntrain). Then I run the two models. Now I want to shuffle the data and rerun the models. I want many shuffles. I know that the following command sample ((1:1), ntrain) can pick ntrain numbers from 1 to 1. Then I just use these rows as the training dataset. But how can I make sure each run of sample produce different results? I want the data output be unique each time. I tested sample(). and found it usually produce different combinations. But can I control it some how? Is there a better way to write this? Thank you, You could have numbers, not picked yet, in a vector, use this vector with sample and remove picked numbers from it iteratively. Something like the following (not fully tested) index-1:1 for( blah-blah-blah ) { train.index-sample(index,ntrain) index-index[!index %in% train.index] test.index-sample(index,ntest) index-index[!index %in% test.index] } -- View this message in context: http://www.nabble.com/how-to-control-the-sampling-to-make-each-sample-unique-tf3719058.html#a10410229 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Piecewise cubic Hermite interpolation
Which function implements the piecewise cubic Hermite interpolation? I am looking for equivalent of matlab's interp1 with the method = 'pchip' Here is the reference http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/interp1.html; -- View this message in context: http://www.nabble.com/Piecewise-cubic-Hermite-interpolation-tf3708765.html#a10373214 Sent from the R help mailing list archive at Nabble.com. __ 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] trouble with help
Did you try manually opening the file mentioned in the browser (Z:\Software\R\R-2.5.0\doc\html\index.html) ? Does this file exist? Was the html help installed? Schmitt, Corinna wrote: Hallo, I just updated to the new version of R by installing everything new. Now I have a problem with the help command: help.start() updating HTML package listing updating HTML search index If nothing happens, you should open 'Z:\Software\R\R-2.5.0\doc\html\index.html' yourself The browser was started but nothing was displayes. Can anyone help me, Corinna -- View this message in context: http://www.nabble.com/trouble-with-help-tf3708685.html#a10373271 Sent from the R help mailing list archive at Nabble.com. __ 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] trouble with help
You should select it in the list of components to install, when the installer asks. It happens after you 3rd time press Next in the installation wizard window. Choose Custom installation and select all you need. Schmitt, Corinna wrote: How can I install the html help? Corinna -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Vladimir Eremeev Gesendet: Dienstag, 8. Mai 2007 12:22 An: r-help@stat.math.ethz.ch Betreff: Re: [R] trouble with help Did you try manually opening the file mentioned in the browser (Z:\Software\R\R-2.5.0\doc\html\index.html) ? Does this file exist? Was the html help installed? -- View this message in context: http://www.nabble.com/trouble-with-help-tf3708685.html#a10374007 Sent from the R help mailing list archive at Nabble.com. __ 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] minimum of each row in a matrix
Looks like you are reading manuals and these mailings insufficiently carefully. ?apply says that if its second argument is 1, it gives you what you want. Gabor Csardi has also written you this. If you have several vectors, not a single matrix, you can use pmin: pmin(a[1,],a[2,],a[3,],a[4,],a[5,]) However, this variant is inefficient in this particular case (lots of typing, and hardcoded). Schmitt, Corinna wrote: Hallo, I just followed the discussion of the title: minimum from matrix. I have a similar problem. a=matrix(c(0,2, 0, 0, 1, 3, 0, 3, 2, 0, 3, 5, 0, 4, 0, 0),ncol=4) a=rbind(a,1:4) a [,1] [,2] [,3] [,4] [1,]0120 [2,]2304 [3,]0030 [4,]0350 [5,]1234 minOfColumns=apply(a, 2, function(x) min(x[x!=0]) ) minOfColumns [1] 1 1 2 4 maxOfColumns=apply(a, 2, function(x) max(x) ) maxOfColumns [1] 2 3 5 4 How looks like the command for the minimum of the rows? I tried several possibilities with apply but did not get the wanted result. The result should be minOfRows = 0 0 0 0 1 -- View this message in context: http://www.nabble.com/minimum-of-each-row-in-a-matrix-tf3709616.html#a10375966 Sent from the R help mailing list archive at Nabble.com. __ 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] creating a new column
To create 6th column in the matrix m, you should use the cbind function. To calculate the vector of pairwise min or max values, you should use the pmin and pmax functions: act.surv.time-pmin(m[,censoringTime],m[,survivalTime]) m-cbind(m,act.surv.time) raymond chiruka wrote: hie l would like to create a 6th column actual surv time from the following data the condition being if censoringTimesurvivaltime then actual survtime =survival time else actual survtime =censoring time the code l used to create the data is s=2 while(s!=0){ n=20 m-matrix(nrow=n,ncol=4) colnames(m)=c(treatmentgrp,strata,censoringTime,survivalTime) for(i in 1:20) m[i,]-c(sample(c(1,2),1,replace=TRUE),sample(c(1,2),1,replace=TRUE),rexp(1,.007),rexp(1,.002)) m-cbind(m,0) m[m[,3]m[,4],5]-1 colnames(m)[5]-censoring print(m) s=s-1 treatmentgrp strata censoringTime survivalTime censoring [1,] 1 1 1.0121591137.80922 0 [2,] 2 2 32.971439 247.21786 0 [3,] 2 1 85.758253 797.04949 0 [4,] 1 1 16.999171 78.92309 0 [5,] 2 1 272.909896 298.21483 0 [6,] 1 2 138.230629 935.96765 0 [7,] 2 2 91.529859 141.08405 0 l keep getting an error message when i try to create the 6th column - __ 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. -- View this message in context: http://www.nabble.com/creating-a-new-column-tf3704043.html#a10358728 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] looking for equivalent of matlab's medfilt1 function
Dear all, I have several files with Matlab code, which I am translating to R. For the zero-level approach, I took the very old shell script from R-help archives, which has made some obvious leg-work such as replacement of = with -. Now I am translating indexing, matrix operations and function call using this table http://37mm.no/mpy/octave-r.html The problem is, I cannot find the R equivalent of the matlab's function medfilt1, performing 1-dimensional median filtering of a vector. Its summary is here http://www-ccs.ucsd.edu/matlab/toolbox/signal/medfilt1.html -- View this message in context: http://www.nabble.com/looking-for-equivalent-of-matlab%27s-medfilt1-function-tf3704211.html#a10358868 Sent from the R help mailing list archive at Nabble.com. __ 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] Error in if (!length(fname) || !any(fname == zname)) { :
For me, the simplest way to find, what is wrong, would be tracing the R code: library(debug) mtrace(cph) cph(Surv(time.sur, status.sur)~ strat(colon[,13])+colon[,18] +colon[,20]+colon[,9], surv=TRUE) ... then find the place of the error and analyze how to adjust the function call arguments to avoid the error and get the desired result. hongyuan cao wrote: I tried to fit a cox proportional hazard model to get estimation of stratified survival probability. my R code is as follows: cph(Surv(time.sur, status.sur)~ strat(colon[,13])+colon[,18] +colon[,20]+colon[,9], surv=TRUE) Error in if (!length(fname) || !any(fname == zname)) { : missing value where TRUE/FALSE needed Here colon[,13] is the one that I want to stratify and the others are all coefficients. How can I solve this problem? Thanks a lot! Grace -- View this message in context: http://www.nabble.com/Error-in-if-%28%21length%28fname%29-%7C%7C-%21any%28fname-%3D%3D-zname%29%29-%7B-%3A-tf3691016.html#a10319988 Sent from the R help mailing list archive at Nabble.com. __ 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] Library Package for Tobit regression
Here is some information on this regression in R http://tolstoy.newcastle.edu.au/R/help/06/02/21153.html Abdus Sattar wrote: I am want to use tobit regression for left censored panel/longitudinal data. Could you please provide me the name of library and/or package that will give me option of fitting tobit regression model for longitudinal data? Library differs from package in R. Roughly: package is a collection of functions and data implementing certain functionality. library is a collection of packages. -- View this message in context: http://www.nabble.com/Library---Package-for-Tobit-regression-tf3689927.html#a10320070 Sent from the R help mailing list archive at Nabble.com. __ 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] Error in if (!length(fname) || !any(fname == zname)) { :
Vladimir Eremeev wrote: For me, the simplest way to find, what is wrong, would be tracing the R code: library(debug) mtrace(cph) cph(Surv(time.sur, status.sur)~ strat(colon[,13])+colon[,18] +colon[,20]+colon[,9], surv=TRUE) ... then find the place of the error and analyze how to adjust the function call arguments to avoid the error and get the desired result. and then, switch off the tracing mtrace(cph,FALSE) or mtrace.off() -- View this message in context: http://www.nabble.com/Error-in-if-%28%21length%28fname%29-%7C%7C-%21any%28fname-%3D%3D-zname%29%29-%7B-%3A-tf3691016.html#a10320118 Sent from the R help mailing list archive at Nabble.com. __ 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] searching for special variables
ls(pattern=.*777.*) Schmitt, Corinna wrote: Dear R-Experts, in my program I have a big workspace. Now I want to look for all variables which have the letters 777 in their name (e.g. ask777first) and afterwards I need to delete those variables. How can I reach this aim? -- View this message in context: http://www.nabble.com/searching-for-special-variables-tf3685103.html#a10300943 Sent from the R help mailing list archive at Nabble.com. __ 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] searching for special variables
sorry, forgot to delete objects. rm(list=ls(pattern=.*777.*)) Vladimir Eremeev wrote: ls(pattern=.*777.*) Schmitt, Corinna wrote: in my program I have a big workspace. Now I want to look for all variables which have the letters 777 in their name (e.g. ask777first) and afterwards I need to delete those variables. How can I reach this aim? -- View this message in context: http://www.nabble.com/searching-for-special-variables-tf3685103.html#a10302565 Sent from the R help mailing list archive at Nabble.com. __ 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] adding a column to a matrix
Hello, Please, consider the functions pmin and pmax. Tuesday, May 1, 2007, 3:29:54 PM, you wrote: rc thanks for the previous advice it seems to have worked what about the following rc l have the following dataset and would like to calculate the actual survival time by rc if censoring time survival time then actual survival time rc =survival time else its= censoring time. rc treatmentgrp strata censoringTime survivalTime censoring actualsurvivaltim rc [1,] 1 1 1.012159 1137.80922 0 rc [2,] 2 2 32.971439 247.21786 0 rc [3,] 2 1 85.758253 797.04949 0 rc [4,] 1 1 16.999171 78.92309 0 rc l used matrix to genarate the data rc thanks in advance rc Vladimir Eremeev [EMAIL PROTECTED] wrote: rc m-cbind(m,0) m[m[,3]m[,4],5]-1 rc colnames(m)[5]-censoring rc raymond chiruka wrote: i would like to add a variable to an existing matrix by manipulating 2 previous variables eg for the data m treat strata censti survTime [1,] 1 2 284.684074 690.4961005 [2,] 1 1 172.764515 32.3990335 [3,] 1 1 2393.195400 24.6145279 [4,] 2 1 30.3647718.0272267 [5,] 1 1 523.182282 554.7659501 l would want to add a new column censoring by comparing ( if censti survtime then censoring=1) how do l go about it thanks the code l used to generate the data is n=100 m=matrix(nrow=n,ncol=4) colnames(m)=c(treat, strata, censti, survTime) for(i in 1:100) m[i,]=c(sample(c(1,2),1,replace=TRUE),sample(c(1,2),1,replace=TRUE),rexp(1,.002),rexp(1,.005)) m l know its ugly but it seems to work any suggestions l still new at this thanks -- Best regards, Vladimirmailto:[EMAIL PROTECTED] --SevinMail-- __ 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] convert text to exprission good for lm arguments
Vadim Ogranovich wrote: Hi, I ran into a problem of converting a text representation of an expression into parsed expression to be further evaluated inside lm (). n - 100 data - data.frame(x= rnorm (n), y= rnorm (n)) data. lm - lm (y ~ x, data=data) ## this works update(data. lm , subset=x0) Call: lm (formula = y ~ x, data = data, subset = x 0) Coefficients: (Intercept) x -0.07864094193322170023 -0.14596982635007796358 ## this doesn't work ## text representation of subset subset - x0 update(data. lm , subset=parse(text=subset)) Error in `[.data.frame`(list(y = c(-0.601925958140825, -0.111931189071517, : invalid subscript type What is the correct way to convert x0 into a valid subset argument? update(data.lm,subset=eval(parse(text=subset))) -- View this message in context: http://www.nabble.com/convert-text-to-exprission-good-for-lm-arguments-tf3686309.html#a10304608 Sent from the R help mailing list archive at Nabble.com. __ 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] upgrade to 2.5
I usually install a new version over the old one (in the same directory). I did this since R 1.xx, using windows 2000 and then windows XP. No bugs were found, everything always works fine. Iasonas Lamprianou wrote: Hi I am using R version 2.4.1. How can I upgrade to version 2.5 without having to install all the packages again? Thanks Jason -- View this message in context: http://www.nabble.com/upgrade-to-2.5-tf3681336.html#a10304613 Sent from the R help mailing list archive at Nabble.com. __ 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] adding a column to a matrix
m-cbind(m,0) m[m[,3]m[,4],5]-1 colnames(m)[5]-censoring raymond chiruka wrote: i would like to add a variable to an existing matrix by manipulating 2 previous variables eg for the data m treat strata censti survTime [1,] 1 2 284.684074 690.4961005 [2,] 1 1 172.764515 32.3990335 [3,] 1 1 2393.195400 24.6145279 [4,] 2 1 30.3647718.0272267 [5,] 1 1 523.182282 554.7659501 l would want to add a new column censoring by comparing ( if censti survtime then censoring=1) how do l go about it thanks the code l used to generate the data is n=100 m=matrix(nrow=n,ncol=4) colnames(m)=c(treat, strata, censti, survTime) for(i in 1:100) m[i,]=c(sample(c(1,2),1,replace=TRUE),sample(c(1,2),1,replace=TRUE),rexp(1,.002),rexp(1,.005)) m l know its ugly but it seems to work any suggestions l still new at this thanks -- View this message in context: http://www.nabble.com/adding-a-column-to-a-matrix-tf3650601.html#a10197380 Sent from the R help mailing list archive at Nabble.com. __ 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] automating merging operations from multiple dataframes
Consider sapply and get. There might be something like the following (untested) fn-function(l){ # l is supposed to be a letter. Errors will occur otherwise. #constructing names dfr.name-paste(toupper(l),INDSLIM,sep=) column.name-paste(tolower(l),region,sep=) #retrieving data from the environment this.reg-get(dfr.name)[,c(pid,column.name)] #merging data frames. #please, note -. This assigns the value to the variable in this function environment's parent frame PidRegion-merge(PidRegion,this.reg,by=pid,all=TRUE) # this should help avoiding too much output invisible(PidRegion) } PidRegion - data.frame(pid=XWAVEID$pid) sapply(letters[1:14],FUN=fn) Jon Minton wrote: Hi, I have a set of dataframes names AINDSLIM, BINDSLIM, CINDSLIM ... NINDSLIM In each dataframe I want to extract two variables, pid and {w}region, where {w} means a, b, c, ...n At the moment my code looks like: PidRegion - data.frame(pid=XWAVEID$pid) this.region - AINDSLIM[,c(pid, aregion)] PidRegion - merge(PidRegion, this.region, by=pid, all=T) this.region - BINDSLIM[,c(pid, bregion)] PidRegion - merge(PidRegion, this.region, by=pid, all=T) this.region - CINDSLIM[,c(pid, cregion)] ... this.region - NINDSLIM[,c(pid, nregion)] PidRegion - merge(PidRegion, this.region, by=pid, all=T) But surely theres a way to automate this? Any suggestions? Jon Minton -- View this message in context: http://www.nabble.com/automating-merging-operations-from-multiple-dataframes-tf3630723.html#a10139026 Sent from the R help mailing list archive at Nabble.com. __ 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] Random Number Generator of Park and Miller
gracezhang wrote: Hi, I failed to search for R package providing random number generator of Park and Miller. Anyone know any R package supporting this kind of function? I failed too. However, here is the source code http://www.firstpr.com.au/dsp/rand31/ which can be either easily rewritten to R or compiled to the shared library, providing functions, callable from R -- View this message in context: http://www.nabble.com/Random-Number-Generator-of-Park-and-Miller-tf3636502.html#a10154560 Sent from the R help mailing list archive at Nabble.com. __ 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] Random Number Generator of Park and Miller
By the way, AFAIK, R uses the Mersenne-Twister random number generator, which has a much better reputation for producing numbers than any linear congruential PRNG (the same url, http://www.firstpr.com.au/dsp/rand31/) gracezhang wrote: I failed to search for R package providing random number generator of Park and Miller. Anyone know any R package supporting this kind of function? -- View this message in context: http://www.nabble.com/Random-Number-Generator-of-Park-and-Miller-tf3636502.html#a10154562 Sent from the R help mailing list archive at Nabble.com. __ 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] A structured output from for(i...)?
Try using cat, paste(c(c(,paste (. .. .. collapse=,),))), format, formatC and others francogrex wrote: Hello I am using the for (i...) and a sink() into a file. But the output I am having is not arranged in either a vector or any other good structure. I would like to have the output in a file directly as a vector so that I do not have to edit the [1] and [6] etc and that the values are comma separated. Is there a way? Thanks. Example data: x=read.table(file=pw.power.txt) for(i in 1:26){sink(pw.predict.txt,append=TRUE) print((x$V1[i]*x$V2[1:26])) sink() } The output is like that [1] 3.355638e-11 4.172354e-10 2.716469e-09 1.232176e-08 4.371243e-08 [6] 1.286392e-07 3.261277e-07 7.301315e-07 1.468560e-06 2.686579e-06 [11] 4.509928e-06 6.990915e-06 1.004944e-05 1.343056e-05 1.670355e-05 [16] 1.932102e-05 2.073859e-05 2.057033e-05 1.873071e-05 1.550436e-05 [21] 1.149907e-05 7.478074e-06 4.122808e-06 1.820828e-06 5.777628e-07 [26] 9.981781e-08 [1] 2.256961e-10 2.806274e-09 1.827063e-08 8.287463e-08 2.940043e-07 [6] 8.652112e-07 2.193495e-06 4.910773e-06 9.877352e-06 1.806960e-05 [11] 3.033321e-05 4.702002e-05 6.759127e-05 9.033228e-05 1.123460e-04 [16] 1.299508e-04 1.394852e-04 1.383535e-04 1.259804e-04 1.042804e-04 [21] 7.734131e-05 5.029659e-05 2.772949e-05 1.224666e-05 3.885961e-06 [26] 6.713622e-07...etc What I would like to have is that it is arranged into a structure (vector, data.frame...) x=c(3.355638e-11, 4.172354e-10, 2.716469e-09, etc... ) -- View this message in context: http://www.nabble.com/A-structured-output-from-for%28i...%29--tf3605354.html#a10074167 Sent from the R help mailing list archive at Nabble.com. __ 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] Export multiple data files from R
You didn't describe the exact format of the .gpr files. There are 32 heading lines in each file, which are now hidden from R community. You 'skip' 31 of them in read.table, and one more plays header ('header=T'). Since you are using read.table, your files are usual ascii files. You shoud use 'cat' and/or 'write.table' R functions to accomplish your task. There are some more functions exist. Using them, you should explicitly write those 32 lines, and then write the rest contents of the resulting data frame. Jenny persson wrote: Dear R-users, I have 10 data files in gpr format (dat1.gpr,...,dat10.gpr). I want to read in these files one by one in R and then add one extra column (called log) to each data file as below data.file=sort(dir(path ='C:/Documents and Settings/ Mina dokument/data1, pattern = .gpr$,full.names = TRUE)) num.data.files- length(data.file) num.data.files i=1 ### read one data file data-read.table(file = data.file[i],skip=31,header=T,sep='\t',na.strings=NA) ### Define the log ratio using values in column 2 resp 8 log=as.matrix(log((data[,2])/(data[,8]))) ### append column called log to data frame data, for the reading data file data=cbind(data,log) ### Read remaining data files for (i in 2:num.data.files) { data-read.table(file=data.file[i],header=T,skip=31,sep='\t',na.strings=NA) log=as.matrix(log((data[,2])/(data[,8]))) data=cbind(data,log) } Now I want to export these files (with an extra column in each) as gpr-files in a folder called data2 but don't know exactly how to do it, can you help me out ? Thanks for your help, Jenny -- View this message in context: http://www.nabble.com/Export-multiple-data-files-from-R-tf3587093.html#a10036489 Sent from the R help mailing list archive at Nabble.com. __ 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] using install.packages via proxy
What operating system do you use? If you use Windows, than open the Control Panel, double click on the System icon, go to Advanced tab, press Environment variables button, then press New to create one more new variable, enter http_proxy as the Name of variable, and http://address.of.your.proxy:port; as its value. In unix you should consult with your shell manual for the proper command and proper startup script file (in bash, this would be export and ~/.bash_profile) You also could use Sys.putenv R function Erbe, Nicole wrote: I'm trying to install rJava to use JRI in a Java program as JRI is a part of rJava. There should be the option to install this package via install.packages(rJava). Unfortunately I'm connected to the internet via a proxy. I have no idea how to tell R to connect via the proxy. The R-help tells me something about environment variables like http_proxy. But I have no idea how and where to set these variable as I'm new to R. I don't know whether this is the right way to solve my problem. Is there anyone out there who knows how to solve this problem? Any help is appreciated. -- View this message in context: http://www.nabble.com/using-install.packages-via-proxy-tf3564991.html#a9958606 Sent from the R help mailing list archive at Nabble.com. __ [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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to image.plot a XY grid file into a lat-lon map
Hello Linda, Friday, April 6, 2007, 2:47:43 AM, you wrote: LS On 4/5/07, Vladimir Eremeev [EMAIL PROTECTED] wrote: VE If your country or state borders are polygons or polylines, you could convert VE them to desired projection using VE the function project from the package rgdal. VE Latitude-longitude grid also could be added by generating desired polylines VE in lat-lon and converting them to the desired projection using project. LS Linda Smith wrote: LS I have a netcdf gridded file with LCC projection. I can easily use LS image.plot to visualize it. However, as the axises are in X,Y, not Lat and LS Lon, I could not add state or country maps onto it (or lat lon LS information). LS I do have a grid2d file that describes the lat and lon for each (X,Y) LS grid, LS but the lat and lon are not regularly spaced, so I could not use LS image.plot. LS LS Does anyone know how to plot this type of gridded data so that country or LS state borders can be easily added? Thanks a lot! LS VE What do you mean by grid2d file that describes the lat and lon for each VE (X,Y) grid? VE If this are two rasters of the same size having corresponding latitude and VE longitude values in each raster cell, then you could use contourLines to get VE lat-lon grid. However, you, probably, will want to smooth it. LS Yes, they are. I could add lat and lon info that way, but LS still I could not use map() function to overlay state borders onto LS my image plot because this image is not in lat and lon LS coordinates. I presume you are using the function map() from the maps package. ?map says that it returns a list with x, y, range, and names components. You could do something like following, for example (UNTESTED). state.borders.ll-map(state,plot=FALSE) state.borders-project(cbind(state.borders.ll$x,state.borders.ll$y),proj=+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100) lines(state.borders) -- Best regards, Vladimirmailto:[EMAIL PROTECTED] --SevinMail-- __ 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.
[R] how to exclude some packages from help.search() ?
I have installed RGTk2 to satisfy other package requirements. I am not planning to use it in my own work. Occasionally I search through the R help using the help.search() function, and every time it returns me lots of references to the functions in the RGtk2 package, which I don't need. I would like to avoid them. At present, I have renamed the file hsearch.rds in the RGtk2 directory. This worked, however, help.search now gives a warning, that it didn't find that file. Is there any other way to avoid extraneous information, returned by help.search, which is not such crude as mine? -- View this message in context: http://www.nabble.com/how-to-exclude-some-packages-from-help.search%28%29---tf3535954.html#a9869861 Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] or, you could consider R-spatial.
http://r-spatial.sourceforge.net Linda Smith wrote: I have a netcdf gridded file with LCC projection. I can easily use image.plot to visualize it. However, as the axises are in X,Y, not Lat and Lon, I could not add state or country maps onto it (or lat lon information). I do have a grid2d file that describes the lat and lon for each (X,Y) grid, but the lat and lon are not regularly spaced, so I could not use image.plot. Does anyone know how to plot this type of gridded data so that country or state borders can be easily added? Thanks a lot! Linda -- View this message in context: http://www.nabble.com/how-to-image.plot-a-XY-grid-file-into-a-lat-lon-map-tf3528721.html#a9852804 Sent from the R help mailing list archive at Nabble.com. __ 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] reading of a matrix
Schmitt, Corinna wrote: I still have problems with the reading of a matrix. Input: matrixData6.txt A-Paar B-Paar C-Paar D-Paar E-Paar A 1 3 5 7 9 B 2 4 6 8 10 R-commands: y=read.table(file=Z:/Software/R-Programme/matrixData6.txt) y Result: A.Paar B.Paar C.Paar D.Paar E.Paar A 1 3 5 7 9 B 2 4 6 8 10 If you look into the txt-file you can recognize that the column names are not the same. Why? Using _ in variable names was illegal earlier (now this rule seems to be relaxed). read.table has converted names. You could try to change them back (UNTESTED) names(y) - gsub(., _, names(y)), Schmitt, Corinna wrote: If I add in the txt-file the line MyData: infront of all followed by a newline. The R-command as above response an error. How can I read the modified input and get the following result: MyData: A.Paar B.Paar C.Paar D.Paar E.Paar A 1 3 5 7 9 B 2 4 6 8 10 You could name your variable MyData: MyData-read.table( ) MyData Schmitt, Corinna wrote: Another stupid question might be hows can I change the column and row names after I made read.table? I want to have the following result, for example: MyData: G H I J K M 1 3 5 7 9 N 2 4 6 8 10 I studied all manuals I could find and the help but could not understand the examples or interpret it right for my case. Thanks for help, Corinna names(MyData)-c(G,H,I,J,K) row.names(MyData)-c(M,N) -- View this message in context: http://www.nabble.com/reading-of-a-matrix-tf3530874.html#a9854003 Sent from the R help mailing list archive at Nabble.com. __ 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] how to image.plot a XY grid file into a lat-lon map
If your country or state borders are polygons or polylines, you could convert them to desired projection using the function project from the package rgdal. Latitude-longitude grid also could be added by generating desired polylines in lat-lon and converting them to the desired projection using project. Linda Smith wrote: I have a netcdf gridded file with LCC projection. I can easily use image.plot to visualize it. However, as the axises are in X,Y, not Lat and Lon, I could not add state or country maps onto it (or lat lon information). I do have a grid2d file that describes the lat and lon for each (X,Y) grid, but the lat and lon are not regularly spaced, so I could not use image.plot. Does anyone know how to plot this type of gridded data so that country or state borders can be easily added? Thanks a lot! What do you mean by grid2d file that describes the lat and lon for each (X,Y) grid? If this are two rasters of the same size having corresponding latitude and longitude values in each raster cell, then you could use contourLines to get lat-lon grid. However, you, probably, will want to smooth it. -- View this message in context: http://www.nabble.com/how-to-image.plot-a-XY-grid-file-into-a-lat-lon-map-tf3528721.html#a9852612 Sent from the R help mailing list archive at Nabble.com. __ 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] Help neural network in R
Here is the list of NN related packages http://cran.r-project.org/src/contrib/Views/MachineLearning.html I also have written some bindings from R to the SNNS (Stuttgart neural network simulator), however, they are still not on the release stage. vinod gullu wrote: I am interested in Neural network models in R. Is there any reference material/tutorial which i can use. Regards, -- View this message in context: http://www.nabble.com/Help-neural-network-in-R-tf3215374.html#a8941445 Sent from the R help mailing list archive at Nabble.com. __ 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] path for source()
Here is the discussion about the function search.path() http://finzi.psych.upenn.edu/R/Rhelp02a/archive/34411.html which searches the PATH variable for your script and returns the full path. You also can put your script contents in functions, then create a package and load it with library(). package.skeleton() can help you. Anyway, source()'ing every time does not seem to be a good idea, because every time you do this you obtain one more copy of your functions and variables in the newly created workspace. If you don't want to create a package, you can save your functions in a file with the .Rdata extension and attach that file. Try going here https://www.stat.math.ethz.ch/pipermail/r-help/2004-July/thread.html and searching source() in the page (i.e. in message headers). I believe, discussions could provide you with several more good ideas. colliera wrote: i have a couple of .R files distributed about my file system. i commonly source() these from other files, but i have to include the full file path. this is not always convenient if you move files around. is there a way of setting the search path for source()? -- View this message in context: http://www.nabble.com/-R--path-for-source%28%29-tf3191709.html#a8861457 Sent from the R help mailing list archive at Nabble.com. __ 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] Convert Class numeric to class lm
Simon P. Kempf wrote: Background: I have five multiple imputed datasets. For each datasets I have run a regression analysis and combined the regression coefficients according to Rubin (1987) rule. So, now you have two numeric values: slope and offset. Right? Simon P. Kempf wrote: Now I want to use these combined regression coefficients on a different dataset (with the same variable names but different values) and check how good they can predict my dependent variable. Normally, it would use the predict.lm function which requires an object of class lm. But my combined regression coefficients are an object of class numeric. Therefore, I need to know how to convert an object of class numeric to a class lm. Given numeric values above, I would use multiplication and addition operations on them and new data. Try to explore the structure of instances of these classes with str(). You will see that an object of class lm is a list with several components (12 afair). One of them is coefficients. You can also construct this object manually from scratch and use predict.lm(), however, you must correctly create all list elements used by this function. Typing predict.lm in R console will show you the body of this function. Don't forget to assign the attribute class. RSiteSearch(construct lm) will take you here: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/32782.html -- View this message in context: http://www.nabble.com/-R--Convert-Class-%22numeric%22-to-class-%22lm-tf3185677.html#a8842534 Sent from the R help mailing list archive at Nabble.com. __ 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] heatmap from xyz data
You can use plot(y~x,col=color.index.in.palette.defined.from(z),pch=20,type=p) where color.index.in.palette.defined.from(z) is a function or an expression, returning either a color index in a predefined palette or any other color representation, suitable for R. This is described in ?par. I have successfuly used col=z*10 with your sample data. type=p specifies, that points will be plotted. pch=20 says to plot them as small filled circles, sometimes I needed smaller circles, and pch=183 worked for me. The package fields and several other packages related to the spatial statistics are able to plot irregularly distributed point data and interpolate them to a regular grid (produce a 'contiguous' map). Here are some links: http://sal.uiuc.edu/csiss/Rgeo/ http://r-spatial.sourceforge.net/ You can also try RSiteSearch(spatial) or help.search(spatial) from the R console Trevor Graham wrote: I've got some data in a data frame arranged like this: x y z othervariables 0.1 0.2 1.7 0.01 0.2 0.2 1.3 0.23 0.2 0.3 1.1 0.43 etc I'd like to plot a heatmap of this data, with x and y as the (x,y) coords and z defining the colour at each point. I'm having difficulty finding the correct functions to use. Can anyone make any recommendations? It seems straightforward to make the plot using the image function if the data is in matrix form, but I'm not sure how to transform my xyz data into matrix form. -- View this message in context: http://www.nabble.com/-R--heatmap-from-xyz-data-tf3180966.html#a8827597 Sent from the R help mailing list archive at Nabble.com. __ 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.