[R] Question
Hi Dear, I have a question, Thank you if you answer me. Can I use cure model to short-term(5years)of breast cancer? Thanks a lot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Low cost marriage service for you
Latino wives alone and try to chat her http://tinyurl.cz.cc/a5qu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] She is from Thailand and need to marry you
Latino Beauties are there http://qu.pe/ixG3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Please help with write.foreign(SPSS)
On 12/07/2010 09:45 AM, He wrote: Dear all, I get stuck when i try to export the data into SPSS format/file using write.foreign() Do you know how to do it exactly? What i have done is 1) First i type the following code in R: df-data.frame(id,year,res1) names(df)-c(idcode,year,resarrvl) write.foreign(df,z:/daten/res.dat,z:/daten/res.sps,package=SPSS) 2) Then I run res.sps in SPSS DATA LIST FILE= k:/res.dat free (,) / idcode year resarrvl . VARIABLE LABELS idcode idcode year year resarrvl resarrvl . VALUE LABELS / idcode 1 000CF7CC 2 000D0212 3 000D055F .. 1339 06996BC5 1340 069972BF . EXECUTE. 3) After running this file, there automatically appears a SPSS file. The variable name is correct, however, there is no data in that file. The character variable id has different values like 1.00 = 000CF7CC, where 000CF7CC should be in the tab of data view instead of variable view. 4) Try to open res.dat It comes out the window Text import wizard The first column which should be the vairable id, shows only the values of id, i.e. 1, 2 and so on. And no real variables names. Hi He, Your data list statement looks like it is trying to read in a non-SPSS file (maybe a CSV file). Are you sure you want to do this? Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dataframe from list of similar lists: not _a_ way, but _the best_ way
Hi All. I often find myself in this situation: . Based on some vector (or list) of values, I need to calculate a few new values for each of them, where some of the new values are numbers, but some are more of descriptive nature (so: character strings) . So I use e.g. sapply, passing a custom function that returns a list with all the calculated values . The result of this is: a list (=the return value of sapply) of lists, that all have the same kind of named values A silly example: list.of.lists-sapply(1:10, function(nr){list(org=nr, chr=as.character(nr))}) It seems rather obvious that the result would be better structured as a dataframe. Now I know a few ways to do this (using do.call), but I fear most of these are rather bad in performance: I suspect all the data is being repetitively copied which may be slow. So, my question to the specialists: . Is the above way of working reasonable for this kind of problem? Or would you suggest otherwise? . What would be the best (as in: quickest) way of transforming this list of lists to a dataframe? The answer to this is probably based upon knowledge of the inner workings of R? Or is there any way in which this depends on the specifics of my function (for nontrivial functions and list sizes)? Thanks! Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be/ http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tinn-R 2.3.7.0 released
Try installing the complements (configure permanent or temporary) El lun, 06-12-2010 a las 08:36 -0500, steve_fried...@nps.gov escribió: I am also finding the link between TINN - R (2.3.7.0) and R (2.12.0 2010 - 10 - 15) to be problematic. source(.trPaths[5], echo=TRUE, max.deparse.length=150) Error in source(.trPaths[5], echo = TRUE, max.deparse.length = 150) : object '.trPaths' not found Steve Friedman Ph. D. Ecologist / Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Frank Black frank.black.1988 @gmail.comTo Sent by: Jose Claudio Faria r-help-boun...@r- joseclaudio.fa...@gmail.com project.orgcc r-help@r-project.org Subject 12/02/2010 08:16 Re: [R] Tinn-R 2.3.7.0 released PM Nice, but I'm still finding the same bug when communicating between R and Tinn-R: source(.trPaths[5], echo=TRUE, max.deparse.length=150) So I still have to use the last version of Tinn-R which doesn't have that problem (Tinn-R 1.19.4.7). Emili 2010/11/22 Jose Claudio Faria joseclaudio.fa...@gmail.com Dears users, A new version of Tinn-R was released today. Below details: 2.3.7.0 (Nov/22/2010) * Bug(s) fixed: - A bug related with the intermittent loose of connection (or appear to freeze) with Rgui.exe was fixed. * The versions 2.3.6.4, 2.3.6.5, 2.3.6.6 and 2.3.6.7 restricted to pre-release testers. * The Application options interface was a bit changed: - The Application options/R/Rterm was split in two tabs: Error and Options. The tab Error has a new option: Try to find error in the editor. It enables the user to set Tinn-R in order to find errors in the editor when sending instructions to Rterm. * This version is full compatible with Windows 7 and R 2.12.0. * The component XPmenu was removed from the project. Windows XP users, perhaps, will find the Tinn-R appearance less attractive, but the applicative is now more stable. As soon as possible, the project will get a better option for skins. * Parts of the source code were optimized. All the best, -- ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\ Jose Claudio Faria Estatistica - prof. Titular UESC/DCET/Brasil joseclaudio.fa...@gmail.com ///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ELCOM/CAEDYM like simulation
Hi R users: I will like to know if there is any set of packages that work as the ELCOM/CAEDYM (Estuary and Lake Computer Model/Computational Aquatic Ecosystem Dynamics Model) works. It is an 3D hidrodynamic and ecology modelling simulation. Thank you for your help. Kenneth __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] GEE for three-level hierarchical data?
Dear, Are there R packages for Generalized Estimating Equations that provide the possibility to implement a three-level structure? My data consist of repeated measures of subjects (AutoRegressive correlation is expected) within different groups (I expect the behavior of individuals from one group to be correlated), with individuals not balanced over groups. So, I have observations at time t (level 1) nested within individuals (level 2) and individuals nested within groups (level 3). The implementation of a two-level structure is rather straightforward in for instance geepack. At first, I thought that by providing a user-defined correlation structure in “geepack”, I could create such a 3-level structure. However, after further investigation (i.e. the single hierarchy id-vector) it seems to me that this is not the way to go. Are there suggestions for how to implement such a three-level structure? Best regards, Bram -- Bram Van Moorter Centre for Conservation Biology (NTNU), Norwegian Institute for Nature Research (NINA) Trondheim (Norway) email: bram.van.moor...@gmail.com website: http://ase-research.org/moorter phone: +47 73596060 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Please help with write.foreign(SPSS)
On Dec 7, 2010, at 09:19 , Jim Lemon wrote: On 12/07/2010 09:45 AM, He wrote: Dear all, I get stuck when i try to export the data into SPSS format/file using write.foreign() Do you know how to do it exactly? What i have done is 1) First i type the following code in R: df-data.frame(id,year,res1) names(df)-c(idcode,year,resarrvl) write.foreign(df,z:/daten/res.dat,z:/daten/res.sps,package=SPSS) 2) Then I run res.sps in SPSS DATA LIST FILE= k:/res.dat free (,) / idcode year resarrvl . VARIABLE LABELS idcode idcode year year resarrvl resarrvl . VALUE LABELS / idcode 1 000CF7CC 2 000D0212 3 000D055F .. 1339 06996BC5 1340 069972BF . EXECUTE. 3) After running this file, there automatically appears a SPSS file. The variable name is correct, however, there is no data in that file. The character variable id has different values like 1.00 = 000CF7CC, where 000CF7CC should be in the tab of data view instead of variable view. 4) Try to open res.dat It comes out the window Text import wizard The first column which should be the vairable id, shows only the values of id, i.e. 1, 2 and so on. And no real variables names. Hi He, Your data list statement looks like it is trying to read in a non-SPSS file (maybe a CSV file). Are you sure you want to do this? Jim That makes OK sense to me, the object is to _write_ an spss file in the end. write.foreign writes a plain text .dat file plus an spss syntax file which supposedly should read the file and generate the spss file. What looks odd to me is that res.dat appears to be written t z:/daten/ but read from k:, so I wonder whether spss is actually finding the same file? It is not particularly odd that a direct import of res.dat comes out without variable names and value labels, because that information is contained in res.sps. A closer look at k:res.dat (as a plain text file) and any messages from running res.sps could be illuminating. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] less than full rank contrast methods
Greg and Frank, Thanks for the replies. I didn't express myself very well; I'm not interest in the model fitting aspect. I'd just like to get the full set of dummy variables (optimally from model.matrix) Max On Dec 6, 2010, at 10:29 PM, Frank Harrell f.harr...@vanderbilt.edu wrote: Given a non-singular fit, the contrast function in the rms package will allow you to request multi-dimensional contrasts some of which are redundant. These singular contrasts are automatically ignored. One use for this is to test for differences in longitudinal trends between two of three treatment groups, where the time trend is a multiple degree of freedom parameterization such as cubic splines. You don't have to stop and think about how many time points to test; just test as many as you'd like and get the right degrees of freedom according to the number of spline terms (main effects + interactions). Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/less-than-full-rank-contrast-methods-tp3074688p3075771.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] tikzDevice 0.5.3 released to CRAN
A new release of the tikzDevice was posted to CRAN today and will soon be available from mirrors worldwide. The tikzDevice package provides a graphics device that translates R graphics into TeX code suitable for seamless integration with LaTeX documents. Version 0.5.3 of the tikzDevice is a bugfix release that addresses clarity of warning/error messages and enhances the handling of characters that are special to LaTeX. Details are contained in the changelog at the end of this announcement. Barring the discovery of significant issues, the next release of the tikzDevice should be version 0.6.0. This release is planned to contain new functionality drawn from one or both of the following development efforts: - Support for UTF8 plot text when tikzDevice is used with the XeTeX engine. - Support for the raster and polypath additions to the R graphics engine. --- ### Version: 0.5.3 --- Bug Fixes - R 2.12.x now throws a warning message when shell commands run via `system()` have non-zero exit conditions. The metric calculation runs LaTeX on a file containing an \@@end command. This causes a non zero exit condition. The end result was that users were getting spammed by warning messages. These messages have been gagged for now and a better way to run LaTeX such that a non-zero condition can meaningfully indicate an error is being investigated. - The range of characters the default sanitizer looks for has been extended. It should now process all characters that are special to TeX with the exception of backslashes. Documentation has been improved. - Detection of failed string metric calculations has been strengthened and the resulting error message has been improved. Happy TeXing! -The tikzDevice team ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Please help with write.foreign(SPSS)
On 12/07/2010 09:42 PM, He wrote: Hi Jim, Thank you so much for your suggestion. I have tried .csv and .sav. .sav works better. I learned DAT file from the internet. There were some similar discussion about wirte.foreign() before. I don't really know how the transfermation of the files between R and SPSS works. When i got several files, I was a little lost. But I should emphasize my main problem which is the character variable is not read shown up in the file. I mean i want to see e.g., 000CF7CC in the data instead of its corresponding value 1 defined by SPSS automatically. Another problem is how to keep the variable names in the data file. Normally, when you write out a data file in SPSS format from R, it should correspond to an SPSS system or .SAV file. I would expect to see something like this: library(foreign) write.spss(df,file=k:/res.sav) Then in your SPSS file: GET /FILE=k:\res.sav. I don't think the .SAV extension is necessary, but I'm not sure. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to find out if a data frame has automatic row names?
Hi all, I just stumbled across the difference between explicit and 'automatic' row names for data frames. Is there a quick way to find out if a data frame has automatic row names or not? Of course I know this for data frames that I create myself, but what if a function needs to extract this information for an argument? The following example shows that this property is not easily visible: # data frame with automatic row names df - data.frame(a=1:2, b=3:4) # data frame with explicit row names df2 - data.frame(a=1:2, b=3:4, row.names=1:2) # printing does not reveal any difference df a b 1 1 3 2 2 4 df2 a b 1 1 3 2 2 4 # both are considered equal all.equal(df, df2) [1] TRUE identical(df, df2) [1] TRUE # calling rownames gives the same result rownames(df) [1] 1 2 rownames(df2) [1] 1 2 # when converting to a matrix, it makes a difference as.matrix(df) a b [1,] 1 3 [2,] 2 4 as.matrix(df2) a b 1 1 3 2 2 4 Thanks for any suggestion, Andreas -- Andreas Borg Medizinische Informatik UNIVERSITÄTSMEDIZIN der Johannes Gutenberg-Universität Institut für Medizinische Biometrie, Epidemiologie und Informatik Obere Zahlbacher Straße 69, 55131 Mainz www.imbei.uni-mainz.de Telefon +49 (0) 6131 175062 E-Mail: b...@imbei.uni-mainz.de Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail und der darin enthaltenen Informationen ist nicht gestattet. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Downloading a .csv through a .jsp url with variable parameters - R code or package?
Something like this should work, only Sept has 30 days, not 31: files - seq(as.Date('2008-09-30'), by = '1 day', length = 250) input - paste(.jsp?y= + , format(files, %Y) + , m= + , format(files, %m) + , d= + , format(files, %d) + , sep = + ) head(input) [1] .jsp?y=2008m=09d=30 .jsp?y=2008m=10d=01 [3] .jsp?y=2008m=10d=02 .jsp?y=2008m=10d=03 [5] .jsp?y=2008m=10d=04 .jsp?y=2008m=10d=05 On Mon, Dec 6, 2010 at 8:18 PM, Arsenio Staer arsenio.st...@gmail.com wrote: So i realized putting this raw.untr - as.data.frame(read.csv(file='...jsp?y=2008m=09d=30', header = TRUE, as.is = TRUE)) reads the file prefectly, so i was wondering how can i create a set of dataframes each with observations for one day (say for 3 years with 250 days of data each year = 750 datasets) ? And in each loop of a cycle the text string in the url would change to reflect the new date, say from y=2008m=09d=30 to y=2008m=09d=31? Any help would be great, i somewhat expected more of a reaction given how vibrant R community is, Arsenio -- View this message in context: http://r.789695.n4.nabble.com/Downloading-a-csv-through-a-jsp-url-with-variable-parameters-R-code-or-package-tp3070541p3075644.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] understanding output of tapply/by cumsum
Dear R-users, I have a dataset with categories and numbers. I would like to compute and add cumulative numbers to the dataset. I do not understand the structure of by(...) or tapply(...) output enough to handle it. Here a small example -- d-expand.grid(a=1:5,b=1:3,c=1:2) d$n = 10 * d$a + d$b +0.1* d$c Sn-by(d$n,list(d$a,d$c),cumsum) str(Sn) - List of 10 $ : num [1:3] 11.1 23.2 36.3 $ : num [1:3] 21.1 43.2 66.3 $ : num [1:3] 31.1 63.2 96.3 $ : num [1:3] 41.1 83.2 126.3 $ : num [1:3] 51.1 103.2 156.3 $ : num [1:3] 11.2 23.4 36.6 $ : num [1:3] 21.2 43.4 66.6 $ : num [1:3] 31.2 63.4 96.6 $ : num [1:3] 41.2 83.4 126.6 $ : num [1:3] 51.2 103.4 156.6 - attr(*, dim)= int [1:2] 5 2 - attr(*, dimnames)=List of 2 ..$ : chr [1:5] 1 2 3 4 ... ..$ : chr [1:2] 1 2 - attr(*, call)= language by.default(data = d$n, INDICES = list(d$a, d$c), FUN = cumsum) - attr(*, class)= chr by - # these give (a) lists of one numerical vector(a) Sn[5,2] Sn[cbind(d$a,d$c)] # how to access the individual cumsum values? # and assign them to d$Sn? -- Thanks, Gerrit. --- Gerrit Draisma Department of Public Health Erasmus MC, University Medical Center Rotterdam Room AE-235 P.O. Box 2040 3000 CA Rotterdam The Netherlands Phone: +31 10 7043787 Fax: +31 10 7038474 http://mgzlx4.erasmusmc.nl/pwp/?gdraisma __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Time out for a R Function
Date: Tue, 7 Dec 2010 16:11:42 +1100 From: michael.bedw...@gmail.com To: santosh.srini...@gmail.com; r-help@r-project.org Subject: Re: [R] Time out for a R Function Below is a toy function with one way of doing it. There are bound to be better ways :) This seems to just check total time on each iteration. Presumably for this you would be better off setting an ieration limit, not a timeout. A watchdog timer to insure that pretend task doesn't hang would need another thread and you would either need the target task to check a shared variable that you set from the watchdog or you just kill the target thread from watchdog but this may be hard to do in a way that lets you continue in any meaningful way. function(niter = 10, time.out = 3) { pretend.task - function() { Sys.sleep(0.5) } start - proc.time() for (iter in 1:niter) { pretend.task() cur - proc.time() - start if (cur[3] time.out) return(timed out) } return(completed) } On 7 December 2010 13:04, Santosh Srinivas wrote: Hello Group, I have an R-function that works fine for most part but sometime runs into a long loop! (I'm lazy and short on time to debug right now so want to do something easy) For my purpose, it is ok to make few errors is there a way I can put a timeout on a function and the r-process needes to move on to the next step? Thank you. S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] what is this averaging function called ?, has R a built in function for it ?
my input is from csv file: fname= 'test' csvdata = read.table(file=paste(fname,'.csv',sep=''),head=FALSE) x = csvdata$V1 y = csvdata$V2 I know that this group is not about php , but I managed to make function from above a lot faster, and I'm still cannot operate R at a sufficient level to recreate in in this language. Fit function in R that kinda resembles it is smooth.spline, but that function seems to go in a strange directions when data density becomes low But I think I would get desired behaviour in smooth.spline if for x axis I put matrix of simple 1,2,3 sequence here is revised php code: function smooth($in,$smooth=500) { if (count(current($in))!=2) exit('wrong array'); timer(); foreach($in as $v) { $v[0] = (string)$v[0]; if (!isset($y[$v[0]])) { $y[$v[0]] = 0; $z[$v[0]] = 0; } $y[$v[0]] += $v[1]; ++$z[$v[0]]; } unset($in); ksort($y, SORT_NUMERIC); ksort($z, SORT_NUMERIC); $x = array_keys($z); $y = array_values($y); $z = array_values($z); $count = count($z); echo n.$count.' : '; for ($k=0;$k$count;++$k) { if (!($k % 1000)) echo $k.' '; $u = $d = 0; $usum = $dsum = 0; $walk = 0; while (true) { ++$walk; if (isset($z[$k-$walk]) and $z[$k]+$z[$k-$walk]+$usum$smooth) { $usum += $z[$k-$walk]; $u += $y[$k-$walk]; } else break; } $walk = 0; while (true) { ++$walk; if (isset($z[$k+$walk]) and $z[$k]+$z[$k+$walk]+$dsum$smooth) { $dsum += $z[$k+$walk]; $d += $y[$k+$walk]; } else break; } $out[$k] = ($y[$k]+$u+$d)/($z[$k]+$usum+$dsum); } echo ' : '.timer().n; return array($x,$out); } -- View this message in context: http://r.789695.n4.nabble.com/what-is-this-averaging-function-called-has-R-a-built-in-function-for-it-tp3072826p3076215.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find out if a data frame has automatic row names?
If as.matrix distinguishes between the two options, then you could look at the code for that function and see how it's done. Sarah On Tue, Dec 7, 2010 at 6:34 AM, Andreas Borg andreas.b...@unimedizin-mainz.de wrote: Hi all, I just stumbled across the difference between explicit and 'automatic' row names for data frames. Is there a quick way to find out if a data frame has automatic row names or not? Of course I know this for data frames that I create myself, but what if a function needs to extract this information for an argument? The following example shows that this property is not easily visible: # data frame with automatic row names df - data.frame(a=1:2, b=3:4) # data frame with explicit row names df2 - data.frame(a=1:2, b=3:4, row.names=1:2) # printing does not reveal any difference df a b 1 1 3 2 2 4 df2 a b 1 1 3 2 2 4 # both are considered equal all.equal(df, df2) [1] TRUE identical(df, df2) [1] TRUE # calling rownames gives the same result rownames(df) [1] 1 2 rownames(df2) [1] 1 2 # when converting to a matrix, it makes a difference as.matrix(df) a b [1,] 1 3 [2,] 2 4 as.matrix(df2) a b 1 1 3 2 2 4 Thanks for any suggestion, Andreas -- Andreas Borg Medizinische Informatik -- Sarah Goslee\ http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How can I change the longitude scale on the plotMap() PBSmapping package
Dear R-helpers, I am using the package PBSmapping and I have a question on the fuction plotMap: How can I change the longitude scale on data(worldLLhigh)? I changed the coordinates of ylim () and xlim () on the function plotMap to plot my study area. I would like to plot the Brazilian coastline that goes from the latitude -26.0°S to -21.0°S and longitude from -48.0°W to -45.0°W. However how can I change the scale value of xlim ranging from 312.0 to 315.0 for the scale of longitude 48.0W-and-45.0W to the same area?. Can anyone help me? Thanks, -- Fabio Prior Caltabellotta, M.Sc. Doutorando em Zoologia - Campus Botucatu Universidade Estadual Paulista Júlio de Mesquita Filho - UNESP Laboratório de Pesquisa em Elasmobrânquios http://lattes.cnpq.br/2735351775616389 End: Praça Infante Dom Henrique s/n - Parque Bitarú 11330-150 - São Vicente-SP, Brasil Tel: +5511 81649946 :(_)))( `·.¸¸.·´¯`·.¸.· _:(_ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find out if a data frame has automatic row names?
On 2010-12-07 03:34, Andreas Borg wrote: Hi all, I just stumbled across the difference between explicit and 'automatic' row names for data frames. Is there a quick way to find out if a data frame has automatic row names or not? Of course I know this for data frames that I create myself, but what if a function needs to extract this information for an argument? The following example shows that this property is not easily visible: # data frame with automatic row names df- data.frame(a=1:2, b=3:4) # data frame with explicit row names df2- data.frame(a=1:2, b=3:4, row.names=1:2) # printing does not reveal any difference df a b 1 1 3 2 2 4 df2 a b 1 1 3 2 2 4 # both are considered equal all.equal(df, df2) [1] TRUE identical(df, df2) [1] TRUE # calling rownames gives the same result rownames(df) [1] 1 2 rownames(df2) [1] 1 2 # when converting to a matrix, it makes a difference as.matrix(df) a b [1,] 1 3 [2,] 2 4 as.matrix(df2) a b 1 1 3 2 2 4 Thanks for any suggestion, Check ?.row_names_info Peter Ehlers Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Encoding problem - I fails to read Hebrew text from online
Hello all, # I am trying to read the text in this URL: u - http://google.com/complete/search?output=toolbarq=%d7%a9%d7%9c%d7%95%d7%9d # By using this command: readLines(u) And no matter what variation I tried, I keep getting this output: [1] ?xml version=\1.0\?toplevelCompleteSuggestionsuggestion data=\#x5E9;#x5DC;#x5D5;#x5DD;\/ (etc...) Instead of this output: ?xml version=1.0?toplevelCompleteSuggestionsuggestion data=ש×××/num_queries int=1680//CompleteSuggestionCompleteSuggestionsuggestion data=ש××× ×× ××/num_queries int=232000//CompleteSuggestionCompleteSuggestionsuggestion data=ש××× ×¢××××/ (etc) I tried: readLines(u, encoding= latin1) readLines(u, encoding= UTF-8) And also changing Sys.setlocale: Sys.setlocale(LC_ALL, Hebrew) # must be done for Hebrew to work. Sys.setlocale(LC_ALL, English) # must be done for Hebrew to work. Are there any more options I could try to get this text properly encoded? Thanks! Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] understanding output of tapply/by cumsum
Maybe 'ave' is what you were looking for: d$cum - ave(d$n, d$a, d$c, FUN = cumsum) d a b cn cum 1 1 1 1 11.1 11.1 2 2 1 1 21.1 21.1 3 3 1 1 31.1 31.1 4 4 1 1 41.1 41.1 5 5 1 1 51.1 51.1 6 1 2 1 12.1 23.2 7 2 2 1 22.1 43.2 8 3 2 1 32.1 63.2 9 4 2 1 42.1 83.2 10 5 2 1 52.1 103.2 11 1 3 1 13.1 36.3 12 2 3 1 23.1 66.3 13 3 3 1 33.1 96.3 14 4 3 1 43.1 126.3 15 5 3 1 53.1 156.3 16 1 1 2 11.2 11.2 17 2 1 2 21.2 21.2 18 3 1 2 31.2 31.2 19 4 1 2 41.2 41.2 20 5 1 2 51.2 51.2 21 1 2 2 12.2 23.4 22 2 2 2 22.2 43.4 23 3 2 2 32.2 63.4 24 4 2 2 42.2 83.4 25 5 2 2 52.2 103.4 26 1 3 2 13.2 36.6 27 2 3 2 23.2 66.6 28 3 3 2 33.2 96.6 29 4 3 2 43.2 126.6 30 5 3 2 53.2 156.6 On Tue, Dec 7, 2010 at 6:39 AM, Gerrit Draisma gdrai...@xs4all.nl wrote: Dear R-users, I have a dataset with categories and numbers. I would like to compute and add cumulative numbers to the dataset. I do not understand the structure of by(...) or tapply(...) output enough to handle it. Here a small example -- d-expand.grid(a=1:5,b=1:3,c=1:2) d$n = 10 * d$a + d$b +0.1* d$c Sn-by(d$n,list(d$a,d$c),cumsum) str(Sn) - List of 10 $ : num [1:3] 11.1 23.2 36.3 $ : num [1:3] 21.1 43.2 66.3 $ : num [1:3] 31.1 63.2 96.3 $ : num [1:3] 41.1 83.2 126.3 $ : num [1:3] 51.1 103.2 156.3 $ : num [1:3] 11.2 23.4 36.6 $ : num [1:3] 21.2 43.4 66.6 $ : num [1:3] 31.2 63.4 96.6 $ : num [1:3] 41.2 83.4 126.6 $ : num [1:3] 51.2 103.4 156.6 - attr(*, dim)= int [1:2] 5 2 - attr(*, dimnames)=List of 2 ..$ : chr [1:5] 1 2 3 4 ... ..$ : chr [1:2] 1 2 - attr(*, call)= language by.default(data = d$n, INDICES = list(d$a, d$c), FUN = cumsum) - attr(*, class)= chr by - # these give (a) lists of one numerical vector(a) Sn[5,2] Sn[cbind(d$a,d$c)] # how to access the individual cumsum values? # and assign them to d$Sn? -- Thanks, Gerrit. --- Gerrit Draisma Department of Public Health Erasmus MC, University Medical Center Rotterdam Room AE-235 P.O. Box 2040 3000 CA Rotterdam The Netherlands Phone: +31 10 7043787 Fax: +31 10 7038474 http://mgzlx4.erasmusmc.nl/pwp/?gdraisma __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] understanding output of tapply/by cumsum
You can also use 'split' to separate each group: split(d, list(d$a, d$c)) $`1.1` a b cn cum 1 1 1 1 11.1 11.1 6 1 2 1 12.1 23.2 11 1 3 1 13.1 36.3 $`2.1` a b cn cum 2 2 1 1 21.1 21.1 7 2 2 1 22.1 43.2 12 2 3 1 23.1 66.3 $`3.1` a b cn cum 3 3 1 1 31.1 31.1 8 3 2 1 32.1 63.2 13 3 3 1 33.1 96.3 $`4.1` a b cn cum 4 4 1 1 41.1 41.1 9 4 2 1 42.1 83.2 14 4 3 1 43.1 126.3 $`5.1` a b cn cum 5 5 1 1 51.1 51.1 10 5 2 1 52.1 103.2 15 5 3 1 53.1 156.3 $`1.2` a b cn cum 16 1 1 2 11.2 11.2 21 1 2 2 12.2 23.4 26 1 3 2 13.2 36.6 $`2.2` a b cn cum 17 2 1 2 21.2 21.2 22 2 2 2 22.2 43.4 27 2 3 2 23.2 66.6 $`3.2` a b cn cum 18 3 1 2 31.2 31.2 23 3 2 2 32.2 63.4 28 3 3 2 33.2 96.6 $`4.2` a b cn cum 19 4 1 2 41.2 41.2 24 4 2 2 42.2 83.4 29 4 3 2 43.2 126.6 $`5.2` a b cn cum 20 5 1 2 51.2 51.2 25 5 2 2 52.2 103.4 30 5 3 2 53.2 156.6 On Tue, Dec 7, 2010 at 6:39 AM, Gerrit Draisma gdrai...@xs4all.nl wrote: Dear R-users, I have a dataset with categories and numbers. I would like to compute and add cumulative numbers to the dataset. I do not understand the structure of by(...) or tapply(...) output enough to handle it. Here a small example -- d-expand.grid(a=1:5,b=1:3,c=1:2) d$n = 10 * d$a + d$b +0.1* d$c Sn-by(d$n,list(d$a,d$c),cumsum) str(Sn) - List of 10 $ : num [1:3] 11.1 23.2 36.3 $ : num [1:3] 21.1 43.2 66.3 $ : num [1:3] 31.1 63.2 96.3 $ : num [1:3] 41.1 83.2 126.3 $ : num [1:3] 51.1 103.2 156.3 $ : num [1:3] 11.2 23.4 36.6 $ : num [1:3] 21.2 43.4 66.6 $ : num [1:3] 31.2 63.4 96.6 $ : num [1:3] 41.2 83.4 126.6 $ : num [1:3] 51.2 103.4 156.6 - attr(*, dim)= int [1:2] 5 2 - attr(*, dimnames)=List of 2 ..$ : chr [1:5] 1 2 3 4 ... ..$ : chr [1:2] 1 2 - attr(*, call)= language by.default(data = d$n, INDICES = list(d$a, d$c), FUN = cumsum) - attr(*, class)= chr by - # these give (a) lists of one numerical vector(a) Sn[5,2] Sn[cbind(d$a,d$c)] # how to access the individual cumsum values? # and assign them to d$Sn? -- Thanks, Gerrit. --- Gerrit Draisma Department of Public Health Erasmus MC, University Medical Center Rotterdam Room AE-235 P.O. Box 2040 3000 CA Rotterdam The Netherlands Phone: +31 10 7043787 Fax: +31 10 7038474 http://mgzlx4.erasmusmc.nl/pwp/?gdraisma __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Appearance of Forest Plot
Hi Josh, Thank you for your response. I have recreated my issue using the Olkin 95 data and subgrouping by year of study - I hope it shows where my problem lies: library(meta) data(Olkin95) metaeg-metabin(event.e, n.e, event.c, n.c, studlab = author, data=Olkin95, method=MH, sm=OR, MH.exact=FALSE, RR.cochrane=FALSE, comb.fixed=TRUE, comb.random=TRUE, title=, complab=, outclab=, label.e=Active, label.c=Control, print.CMH=FALSE, warn=FALSE) Olkin95$year-Olkin95$year metaeg$year-addvar(metaeg,Olkin95,year,by.y=author) as.data.frame(metaeg) print.meta(metaeg) forest (metaeg,byvar=year) Any ideas would be very much appreciated. Thanks again! -- View this message in context: http://r.789695.n4.nabble.com/Appearance-of-Forest-Plot-tp3075326p3076271.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting own function
Hello, I have a simple question but didn't find a solution. How do I plot a custom function. I have defined this function func - function(x) { y - exp(-0.5*((x-63.9)/23.2)^2) if(x 63.9) return(2 - y) else { return(y) } } and want to plot it in a specified range like x = seq(-10,150,length=500) y - func(x) plot(x,y,type=l,lwd=2,col=red) But it doesn't work because it expects a vector but I need to compare the scalar x. How do I do it correctly? Thanks a lot Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] less than full rank contrast methods
'On Tue, Dec 7, 2010 at 5:19 AM, mxkuhn mxk...@gmail.com wrote: Greg and Frank, Thanks for the replies. I didn't express myself very well; I'm not interest in the model fitting aspect. I'd just like to get the full set of dummy variables (optimally from model.matrix) Try this: levels(when$time) - c(morning, afternoon, night) levels(when$day) - c(Mon, Tue, Wed, Thu, Fri, Sat, Sun) contr.dummy - function(n, ...) diag(n) mm - suppressWarnings(model.matrix(~ day + time, when)) mm[is.na(mm)] - 1 mm You might also want to set the levels of your factors first so that it includes levels that are not in the data and so that the levels are sorted in an order other than alphabetical: etc. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting own function
You need to use 'ifelse' in this case since it will handle a vector and 'if' is only for single values: func - function(x) { y - exp(-0.5*((x-63.9)/23.2)^2) ifelse(x 63.9, 2 - y, y) } x = seq(-10,150,length=500) y - func(x) plot(x,y,type=l,lwd=2,col=red) On Tue, Dec 7, 2010 at 6:57 AM, Tobias Schultze webmas...@tubo-world.de wrote: Hello, I have a simple question but didn't find a solution. How do I plot a custom function. I have defined this function func - function(x) { y - exp(-0.5*((x-63.9)/23.2)^2) if(x 63.9) return(2 - y) else { return(y) } } and want to plot it in a specified range like x = seq(-10,150,length=500) y - func(x) plot(x,y,type=l,lwd=2,col=red) But it doesn't work because it expects a vector but I need to compare the scalar x. How do I do it correctly? Thanks a lot Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] increase or decrease variable by 1
many languages have shorthands for that operation like: variable += 1 or ++variable is there something like that in R ? -- View this message in context: http://r.789695.n4.nabble.com/increase-or-decrease-variable-by-1-tp3076390p3076390.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] latex() hangs R console
[Env: R 2.11.1, Win Xp, Miktex 2.7] I've just started using Hmisc::latex and friends, and find that running latex() produces the .tex and .dvi files, but hangs, presumably trying to run yap. An example is below. What could be wrong? My PATH seems OK: strsplit(Sys.getenv(path),';') $path [1] c:\\program files\\imagemagick-6.4.4-q16 c:\\Rtools\\bin [3] c:\\Rtools\\perl\\bin c:\\Rtools\\MinGW\\bin [5] C:\\Program Files\\MiKTeX 2.7\\miktex\\bin C:\\WINDOWS\\system32 [7] C:\\WINDOWS C:\\WINDOWS\\System32\\Wbem [9] C:\\Program Files\\Intel\\DMIX C:\\Program Files\\ATI Technologies\\ATI.ACE\\ [11] C:\\Program Files\\Common Files\\Roxio Shared\\DLLShared\\ C:\\WINDOWS\\system32\\nls [13] C:\\WINDOWS\\system32\\nls\\ENGLISH C:\\Program Files\\SecureCRT\\ [15] C:\\Program Files\\IDM Computer Solutions\\UltraEdit-32 C:\\Program Files\\SAS\\Shared Files\\Formats [17] C:\\Program Files\\Graphviz2.20\\Bin C:\\Program Files\\MATLAB\\R2008a\\bin [19] C:\\Program Files\\MATLAB\\R2008a\\bin\\win32 C:\\Program Files\\TortoiseSVN\\bin [21] C:\\Program Files\\HTML Help Workshop C:\\Program Files\\QuickTime\\QTSystem\\ Example: x - matrix(1:6, nrow=2, dimnames=list(c('a','b'),c('c','d','this that'))) latex(x, file=) % latex.default(x, file = ) % \begin{table}[!tbp] \begin{center} \begin{tabular}{lrrr}\hline\hline \multicolumn{1}{l}{x}\multicolumn{1}{c}{c}\multicolumn{1}{c}{d}\multicolumn{1}{c}{this that}\tabularnewline \hline a$1$$3$$5$\tabularnewline b$2$$4$$6$\tabularnewline \hline \end{tabular} \end{center} \end{table} cd(c:/r/test) latex(x) This is pdfTeX, Version 3.1415926-1.40.9 (MiKTeX 2.7) entering extended mode (C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.tex LaTeX2e 2005/12/01 Babel v3.8l and hyphenation patterns for english, dumylang, nohyphenation, ge rman, ngerman, french, loaded. (C:\Program Files\MiKTeX 2.7\tex\latex\base\report.cls Document Class: report 2005/09/16 v1.4f Standard LaTeX document class (C:\Program Files\MiKTeX 2.7\tex\latex\base\size10.clo)) (C:\Program Files\MiKTeX 2.7\tex\latex\geometry\geometry.sty (C:\Program Files\MiKTeX 2.7\tex\latex\graphics\keyval.sty) (C:\Program Files\MiKTeX 2.7\tex\latex\geometry\geometry.cfg)) No file file311f289a.aux. [1] (file311f289a.aux) ) Output written on file311f289a.dvi (1 page, 372 bytes). Transcript written on file311f289a.log. At this point, I have to press ESC after a few minutes to regain the console, and no .dvi (yap) window appears. If I go to the temp directory, C:/WINDOWS/TEMP/Rtmpz0QkT8/, the .dvi file is there and double-click launches yap. optionsCmds(xdvi) [1] yap Reading the code of print.latex - show.latex - show.dvi, I tried executing system() directly, in the forms system(paste(yap, C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.dvi), intern=TRUE) system(paste(yap, C:/WINDOWS/TEMP/Rtmpz0QkT8/file311f289a.dvi)) However, both of these result in the same behavior -- R console hangs until I press ESC. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Package install error: undefined symbol: _intel_fast_memcpy
Hi, I am trying to install the ncdf package on my Ubuntu 8.04 (Karmic) box in the basement. I have installed the most recent distribution of R, 2.12.0 without too many problems. However, when it comes to install the ncdf netcdf package, I unfortunately get the following error: Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/home/mpa/R/i486-pc-linux-gnu-library/2.12/ncdf/libs/ncdf.so': /home/mpa/R/i486-pc-linux-gnu-library/2.12/ncdf/libs/ncdf.so: undefined symbol: _intel_fast_memcpy I also get a similar error when trying to install the ncdf4 package. I have tried to find the meaning of the error, but I can't find anything - I'm assuming that its a dependency problem. Can anyone help me out here please? Best wishes, Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find out if a data frame has automatic row names?
That does it. Thanks! Check ?.row_names_info Peter Ehlers Andreas -- Andreas Borg Medizinische Informatik UNIVERSITÄTSMEDIZIN der Johannes Gutenberg-Universität Institut für Medizinische Biometrie, Epidemiologie und Informatik Obere Zahlbacher Straße 69, 55131 Mainz www.imbei.uni-mainz.de Telefon +49 (0) 6131 175062 E-Mail: b...@imbei.uni-mainz.de Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail und der darin enthaltenen Informationen ist nicht gestattet. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sparse matrix performance question
On Mon, Dec 6, 2010 at 1:11 PM, scott white distributedin...@gmail.com wrote: Btw, forgot to mention I am using the standard Matrix package and I am running version 2.10.1 of R. On Mon, Dec 6, 2010 at 11:04 AM, scott white distributedin...@gmail.comwrote: I have a very sparse square matrix which is 20K rows columns and I am trying to row standardize the matrix for the rows that have non-missing value as follows: row_sums - rowSums(M,na.rm=TRUE) nonzero_idxs - which(row_sums0) nonzero_M - M[nonzero_idxs,]/row_sums[nonzero_idxs] M[nonzero_idxs,] - nonzero_M Assignment of submatrices in a sparse matrix can be slow because there is so much checking that needs to be done. It is probably easier to do the calculation directly on the data component of the matrix and generate a new one. The tricky bit to remember is that the indices in the sparse matrix representation are 0-based so you need to add 1 when using them in R. I enclose a transcript. Each line completes well under a second except the last line which takes well over 10 seconds which is simply assigning the sub-matrix of rows that have non-missing values to the complete matrix. I am curious to know why it is so slow and how to speed it up. Should I be doing this differently or try a different sparse matrix library? Any feedback is appreciated. thanks, Scott [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. library(Matrix) Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from 'package:base': det set.seed(1234) M - sparseMatrix(i=sample(5000, 1000, replace=TRUE), + j=sample(5000, 1000, replace=TRUE), + x=rnorm(1000), dims=c(5000, 5000)) str(M) Formal class 'dgCMatrix' [package Matrix] with 6 slots ..@ i : int [1:1000] 2014 549 1098 3137 130 1523 2198 3921 4323 931 ... ..@ p : int [1:5001] 0 0 0 0 0 0 0 0 0 0 ... ..@ Dim : int [1:2] 5000 5000 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL ..@ x : num [1:1000] -0.4236 -0.5322 0.0675 -0.4105 -2.3708 ... ..@ factors : list() range(m...@i) [1]1 4996 str(rs - rowSums(M, na.rm=TRUE)) num [1:5000] 0 0.501 0 0.598 -0.957 ... res - sparseMatrix(i...@i, p...@p, dim...@dim, + x...@x/r...@i + 1L], index1=FALSE) str(res) Formal class 'dgCMatrix' [package Matrix] with 6 slots ..@ i : int [1:1000] 2014 549 1098 3137 130 1523 2198 3921 4323 931 ... ..@ p : int [1:5001] 0 0 0 0 0 0 0 0 0 0 ... ..@ Dim : int [1:2] 5000 5000 ..@ Dimnames:List of 2 .. ..$ : NULL .. ..$ : NULL ..@ x : num [1:1000] 1 1 1 -0.655 1 ... ..@ factors : list() table(rowSums(res)) 01 4082 918 proc.time() user system elapsed 3.010 0.120 3.612 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] less than full rank contrast methods
On Tue, Dec 7, 2010 at 7:54 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: 'On Tue, Dec 7, 2010 at 5:19 AM, mxkuhn mxk...@gmail.com wrote: Greg and Frank, Thanks for the replies. I didn't express myself very well; I'm not interest in the model fitting aspect. I'd just like to get the full set of dummy variables (optimally from model.matrix) Try this: levels(when$time) - c(morning, afternoon, night) levels(when$day) - c(Mon, Tue, Wed, Thu, Fri, Sat, Sun) contr.dummy - function(n, ...) diag(n) mm - suppressWarnings(model.matrix(~ day + time, when)) mm[is.na(mm)] - 1 mm You might also want to set the levels of your factors first so that it includes levels that are not in the data and so that the levels are sorted in an order other than alphabetical: The levels(when$day) lines should be: levels(when$day) - c(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] fast subsetting of lists in lists
Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
On Tue, Dec 7, 2010 at 9:47 AM, Alexander Senger sen...@physik.hu-berlin.de wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] This does not involve apply. You could time it to see if its any faster: test.un - unlist(test) unname(test.un[names(test.un) == a]) [1] 1 4 7 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
Hello, Alexander, does utest - unlist(test) utest[ names( utest) == a] come close to what you need? Hth, Gerrit On Tue, 7 Dec 2010, Alexander Senger wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] string
Hi, I'm running R 2.11 Does anyone know if it possible to transform one character vector to one character string ? Many thanks Benoit -- Benoit Wastine Laboratoire des Sciences du Climat et de l’Environnement (LSCE/IPSL) CEA-CNRS-UVSQ CE Saclay Orme des merisiers Bât 703 - Pte 13A 91191 Gif sur Yvette Cedex France Tel : 33 (0)1 69 08 21 97 Fax : 33 (0)1 69 08 77 16 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Package install error: _intel_fast_memcpy
Hi, I am trying to install the ncdf package on my Ubuntu 8.04 (Karmic) box in the basement. I have installed the most recent distribution of R, 2.12.0 without too many problems. However, when it comes to install the ncdf netcdf package, I unfortunately get the following error: Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/home/mpa/R/i486-pc-linux-gnu-library/2.12/ncdf/libs/ncdf.so': /home/mpa/R/i486-pc-linux-gnu-library/2.12/ncdf/libs/ncdf.so: undefined symbol: _intel_fast_memcpy I also get a similar error when trying to install the ncdf4 package. I have tried to find the meaning of the error, but I can't find anything - I'm assuming that its a dependency problem. Can anyone help me out here please? Best wishes, Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] string
?paste collapse = T may be necessary. -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 12/07/2010 10:11:41 AM: [image removed] [R] string Benoit Wastine to: r-help 12/07/2010 10:14 AM Sent by: r-help-boun...@r-project.org Hi, I'm running R 2.11 Does anyone know if it possible to transform one character vector to one character string ? Many thanks Benoit -- Benoit Wastine Laboratoire des Sciences du Climat et de l’Environnement (LSCE/IPSL) CEA-CNRS-UVSQ CE Saclay Orme des merisiers Bât 703 - Pte 13A 91191 Gif sur Yvette Cedex France Tel : 33 (0)1 69 08 21 97 Fax : 33 (0)1 69 08 77 16 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] string
Hi, If I understand what you mean (no example...), see ?paste and the collpase argument Ivan Le 12/7/2010 16:11, Benoit Wastine a écrit : Hi, I'm running R 2.11 Does anyone know if it possible to transform one character vector to one character string ? Many thanks Benoit -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] string
On Dec 7, 2010, at 10:11 AM, Benoit Wastine wrote: Hi, I'm running R 2.11 Does anyone know if it possible to transform one character vector to one character string ? ?gsub Also look at the even more powerful gsubfn package. There is also the stringr package. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] string
Ivan's advice is good, but understanding clearly what character string to separate the results might mean is a bit tricky! Example: cvec - c(J,e, ,m,',a,p,p,e,l,l,e, ,B,e,n,o,i,t) cstring - paste(cvec,collapse=) cstring # [1] Je m'appelle Benoit Now try it without the 'collapse='. Hoping this helps, Ted. On 07-Dec-10 15:19:39, Ivan Calandra wrote: Hi, If I understand what you mean (no example...), see ?paste and the collpase argument Ivan Le 12/7/2010 16:11, Benoit Wastine a écrit : Hi, I'm running R 2.11 Does anyone know if it possible to transform one character vector to one character string ? Many thanks Benoit -- Ivan CALANDRA E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 07-Dec-10 Time: 15:38:44 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
On 07.12.2010 14:43, madr wrote: many languages have shorthands for that operation like: variable += 1 or ++variable is there something like that in R ? No. Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] string
It took me quite some time to understand the difference between sep and collapse. The examples in Phil Spector's book (2008) helped me to get it: paste(c('X','Y'), 1:5, sep='_') X_1 Y_2 X_3 Y_4 X_5 paste(c('X','Y'), 1:5, collapse='|') ## sep= by default [1] X 1|Y 2|X 3|Y 4|X 5 paste(c('X','Y'), 1:5, sep='_', collapse='|') [1] X_1|Y_2|X_3|Y_4|X_5 Ivan Le 12/7/2010 16:38, (Ted Harding) a écrit : Ivan's advice is good, but understanding clearly what character string to separate the results might mean is a bit tricky! Example: cvec- c(J,e, ,m,',a,p,p,e,l,l,e, ,B,e,n,o,i,t) cstring- paste(cvec,collapse=) cstring # [1] Je m'appelle Benoit Now try it without the 'collapse='. Hoping this helps, Ted. On 07-Dec-10 15:19:39, Ivan Calandra wrote: Hi, If I understand what you mean (no example...), see ?paste and the collpase argument Ivan Le 12/7/2010 16:11, Benoit Wastine a écrit : Hi, I'm running R 2.11 Does anyone know if it possible to transform one character vector to one character string ? Many thanks Benoit -- Ivan CALANDRA E-Mail: (Ted Harding)ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 07-Dec-10 Time: 15:38:44 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] tableGrob and properties of a cell
Hello there, could you please help to modify gpar() properties of a cell inside tableGrob() output. In the following example I want to have different color for one out of 4 cells require(gridExtra) z-matrix(1:4,2,2) grid.draw(tableGrob(z)) The only way I found for now how to do it is to do something like this downViewport(current.vpTree()$children[[1]]$children[[6]]$name) grid.text('2',gp=gpar(col='red',fontface='bold')) But for some reasons when I try to print the table into jpeg the last grid.text() prints desired label text somewhere but not in the place I want it to be. Is there another more smart way to do it? Thanks in advance! Kind regards, Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
On Tue, Dec 7, 2010 at 8:43 AM, madr madra...@interia.pl wrote: many languages have shorthands for that operation like: variable += 1 or ++variable is there something like that in R ? You can do this: x - 3 `+`(x) - 1 x [1] 4 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to switch label font from Chinese to English
Hi I tried to plot something simple x=c('2010-08-20', '2010-08-30') y = c(1,2) t = strptime(x, %Y-%m-%d) plot(t,y) At the xlab, the fonts are Chinese. How can I switch it to English? I am working under Windows 7 64 bits Home Edition and R is Win32 version 2.11.1 Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating binary variable depending on strings of two dataframes
On Dec 7, 2010, at 11:30 AM, Pete Pete wrote: Hi, consider the following two dataframes: x1=c(232,3454,3455,342,13) x2=c(1,1,1,0,0) data1=data.frame(x1,x2) y1=c(232,232,3454,3454,3455,342,13,13,13,13) y2=c(E1,F3,F5,E1,E2,H4,F8,G3,E1,H2) data2=data.frame(y1,y2) I need a new column in dataframe data1 (x3), which is either 0 or 1 depending if the value E1 in y2 of data2 is true while x1=y1. The result of data1 should look like this: x1 x2 x3 1 232 1 1 2 3454 1 1 3 3455 1 0 4 342 0 0 5 13 0 1 I think a SQL command could help me but I am too inexperienced with it to get there. dat3 - merge(data1, data2[data2$y2==E1, ], by.x=x1, by.y=y1, all.x=TRUE) dat3$y2 - 0 + (dat3$y2 %in% E1) dat3 x1 x2 y2 1 13 0 1 2 232 1 1 3 342 0 0 4 3454 1 1 5 3455 1 0 (Admittedly not in the original order, but in my hands the R merge operation doesn't lend itself well to maintaining the original order. I see that Grothendieck's solution is better in this respect, a typical occurrence in comparison of our respective efforts with R.) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] please show me simple example how to plot
Well, maybe I didn't write it clear. I know how to create scatterplot, and how to import data from csv file. But I do not know how to add this fitting that mentioned in sumbject to a plot. I do not know for what function name to look for in R. I played some time with ls, and it didn't create a line. I know the name for the fitting I ned from Statistica, and this is from help from this program: A curve is fitted to the XY coordinate data according to the distance-weighted least squares smoothing procedure (the influence of individual points decreases with the horizontal distance from the respective points on the curve). For more information, see Distance-Weighted Least Squares. Now I need to recreate it in R. Sorry again for not being clear. -- View this message in context: http://r.789695.n4.nabble.com/please-show-me-simple-example-how-to-plot-Distance-Weighted-Least-Squares-fitting-tp3076824p3076863.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter gunter.ber...@gene.com wrote: Ted: Inline below... On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding ted.hard...@wlandres.net wrote: Indeed! x - x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)-1 (being mean with them) uses 9. The mean version of the first uses only 6: x-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)-1 gets worked out! AFAICS it doesn't. `+`(x)-1 Error in +x - 1 : could not find function +- Sorry, my code was missing the first line: `+-` - `+` x - 3 `+`(x) - 1 x [1] 4 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] please show me simple example how to plot Distance-Weighted Least Squares fitting
I got simple x,y pairs of data and simple scatterplot and just cannot figure how to do it , there are many examples but always there is error popping out please show me an example stripped with additional data just core of what I need to do to get this damn line -- View this message in context: http://r.789695.n4.nabble.com/please-show-me-simple-example-how-to-plot-Distance-Weighted-Least-Squares-fitting-tp3076824p3076824.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
I tried to hide the gory details as the structure of my datasets is rather complicated. Basically its a long list of lists which in turn contain character vectors, dates, numerics and dataframes, all named. While the hierarchy is fixed neither the number of elements nor their ordering is. But if I try to access a certain element, then I know it is there and contains sensible data. For a typical day of measurements the whole package weights around 1 GiB. How often and what I need to extract varies as the analyses is rather dynamic. As far as I can see a thorough refactoring of the datasets so that everything is contained in one large dataframe might be a solution. But I wouldn't be too unhappy if I could avoid this rather tedious work. Alex Am 07.12. 18:26, schrieb William Dunlap: To find the fastest method you need to tell more about the constraints on your problem. Do you always have a list of lists of scalars or are the lists buried at various depths or do the numeric vectors at the leaves have various lengths? If you always have a list of lists of scalars, do the names always come in the same order? (It may be faster to select by numeric position than by name). Do all the lists of numeric vectors contain an element by the given name? What is a typical size for the problem? How many times do you typically need to repeat the solution? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alexander Senger Sent: Tuesday, December 07, 2010 9:12 AM To: r-help@r-project.org Subject: Re: [R] fast subsetting of lists in lists Hello Gerrit, Gabor, thank you for your suggestion. Unfortunately unlist seems to be rather expensive. A short test with one of my datasets gives 0.01s for an extraction based on my approach and 5.6s for unlist alone. The reason seems to be that unlist relies on lapply internally and does so recursively? Maybe there is still another way to go? Alex Am 07.12.2010 15:59, schrieb Gerrit Eichner: Hello, Alexander, does utest - unlist(test) utest[ names( utest) == a] come close to what you need? Hth, Gerrit On Tue, 7 Dec 2010, Alexander Senger wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coxph failure
Larry, You found a data set that kills coxph. I'll have to think about what to do since on the one hand it's your own fault for trying to fit a very bad model, and on the other I'd like the routine to give a nice error message before it dies. In the data set you sent me the predictor variable is very skewed: quantile(anomaly1$CREAT, c(0, .5, .9, .999, 1)) 0%50%90% 99.9% 100% 0.5000 1.4000 2.2000 4.6027 7.3000 There are 1000 observations, the largest is 7.3 and the second largest is 4.6. The subject with a 7.3 was a failure. When you fit a 4 degree of freedom polynomial to this there is enough space between the two largest obvservations for the fit to turn nearly straight up and give a probability of failure of approx 1.0 to this point. This is the actual, true maximum likelihood solution, so the routine is doing the right thing to try and attain it. At iteration 1 the linear predictor from the Cox model has the following distribution. quantile(lp, c(0, .5, .9, .999, 1)) 0% 50% 90%99.9% 100% -1.65321482 -1.19164206 -0.08964025 31.05389866 900.67627778 Unfortunately exp(900) = Inf, and that pretty much does in my C routine right there; within another iteration there are NA values littered about and the return value for the coefficients is all NA. If instead you fit a smoothing spline to the data coxph(Surv(TTFAIL, FFAIL) ~ pspline(CREAT6MO, df=4), data=anomaly1) the fitted response is essentially linear from 0 to 5 before turning upward, but it never gets outrageous due to the shrinkage towards linearity. Catching this type of issue with an extremely skewed variable (creatinine^4) would be very hard to do reliably. The primary message is that polynomials and biology are a bad mix. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] latex() hangs R console
Michael, The easiest workaround is to assign the result of the latex() command. myfilename - latex(x) print.default(myfilename) It looks to me like the insides of the dvi.latex function aren't quite right for Windows. Rich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Creating binary variable depending on strings of two dataframes
Hi, consider the following two dataframes: x1=c(232,3454,3455,342,13) x2=c(1,1,1,0,0) data1=data.frame(x1,x2) y1=c(232,232,3454,3454,3455,342,13,13,13,13) y2=c(E1,F3,F5,E1,E2,H4,F8,G3,E1,H2) data2=data.frame(y1,y2) I need a new column in dataframe data1 (x3), which is either 0 or 1 depending if the value E1 in y2 of data2 is true while x1=y1. The result of data1 should look like this: x1 x2 x3 1 232 1 1 2 3454 1 1 3 3455 1 0 4 342 0 0 5 13 0 1 I think a SQL command could help me but I am too inexperienced with it to get there. Thanks for your help! -- View this message in context: http://r.789695.n4.nabble.com/Creating-binary-variable-depending-on-strings-of-two-dataframes-tp3076724p3076724.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
On Tue, Dec 7, 2010 at 12:12 PM, Alexander Senger sen...@physik.hu-berlin.de wrote: Hello Gerrit, Gabor, thank you for your suggestion. Unfortunately unlist seems to be rather expensive. A short test with one of my datasets gives 0.01s for an extraction based on my approach and 5.6s for unlist alone. The reason seems to be that unlist relies on lapply internally and does so recursively? Maybe there is still another way to go? Too bad it wasn't faster but note that unlist does not rely on lapply. Here is the complete source of unlist and from it we see the key portion is done internally, i.e. in C: unlist function (x, recursive = TRUE, use.names = TRUE) { if (.Internal(islistfactor(x, recursive))) { lv - unique(.Internal(unlist(lapply(x, levels), recursive, FALSE))) nm - if (use.names) names(.Internal(unlist(x, recursive, use.names))) res - .Internal(unlist(lapply(x, as.character), recursive, FALSE)) res - match(res, lv) structure(res, levels = lv, names = nm, class = factor) } else .Internal(unlist(x, recursive, use.names)) } environment: namespace:base -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] please show me simple example how to plot
On 2010-12-07 09:37, madr wrote: Well, maybe I didn't write it clear. I know how to create scatterplot, and how to import data from csv file. But I do not know how to add this fitting that mentioned in sumbject to a plot. I do not know for what function name to look for in R. I played some time with ls, and it didn't create a line. I know the name for the fitting I ned from Statistica, and this is from help from this program: A curve is fitted to the XY coordinate data according to the distance-weighted least squares smoothing procedure (the influence of individual points decreases with the horizontal distance from the respective points on the curve). For more information, see Distance-Weighted Least Squares. Sounds like loess() to me. Peter Ehlers Now I need to recreate it in R. Sorry again for not being clear. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to formulate constraint like abs(x) = y in constrOptim (or other)
Thanks a lot for your responses. Alabama and Rsolnp packages look promising. My first tests worked well. For others searching for alike problems I now use something like: #equality constraint function eqFkt-function(x){ #for sum(x)=sum_x sm-sum(x)-sum_x return(c(sm)) } ineqFkt-function(x){ #for -max_x x max_x ubound- -x+max_x lbound- x+max_x #for sum of all negative value to be min_x_neg negbound - sum(x[x0])-min_x_neg return(c(ubound, lbound, negbound)) } #define start start_weights-seq(0, 0, length.out=len_data) #where mini_func is the minimizing function res -auglag(start_weights, mini_func, heq=eqFkt, hin=ineqFkt) Benjamin -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Ravi Varadhan Gesendet: Montag, 6. Dezember 2010 23:53 An: 'Hans W Borchers'; r-h...@stat.math.ethz.ch Betreff: Re: [R] How to formulate constraint like abs(x) = y in constrOptim (or other) Hi Benjamin, If you just had abs(x_i) c_i, it will reduce to linear inequalities, but your constraint cannot be reduced to that. You might try alabama or Rsolnp packages. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Hans W Borchers Sent: Monday, December 06, 2010 1:08 PM To: r-h...@stat.math.ethz.ch Subject: Re: [R] How to formulate constraint like abs(x) = y in constrOptim (or other) Benjamin B. benj.bad.ac at googlemail.com writes: Hello list reader, I am trying to form some constraints for an optimization I am working on. I think I have understand the use of the constraints in matrix form. I use them like: [...] Now I would like to formulate a constraint like Sum(Abs(x_i))=limit But I have no idea how I could get such a condition by using the matrix constraint formulation. I have already searched the help, web and all searchable R resources I could find, but got no helping result. Is constrOptim the right function to use? Maybe you can give me a hint or can point me to a good description of constraint handling. Greetings and thanks in advance, Benjamin Benjamin B. Hamburg, Germany With 'constrOptim' you can formulate linear constraints only, and in most cases abs() is not linear. You might try one of the nonlinear optimization packages. Another possibility is to reformulate the absolute value with two binary values, if your optimization function itself is linear; you didn't tell us the whole story. Hans Werner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
On Dec 7, 2010, at 12:42 PM, Gabor Grothendieck wrote: On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter gunter.ber...@gene.com wrote: Ted: Inline below... On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding ted.hard...@wlandres.net wrote: Indeed! x - x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)-1 (being mean with them) uses 9. The mean version of the first uses only 6: x-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)-1 gets worked out! AFAICS it doesn't. `+`(x)-1 Error in +x - 1 : could not find function +- Sorry, my code was missing the first line: `+-` - `+` x - 3 `+`(x) - 1 x [1] 4 One can also attempt further creative violence to the language that shows that is possible to construct unary operators like the C prefix-+ that do not require shift-9 operand shift-0. `+` function (e1, e2) .Primitive(+) `+` - `-`# in a different universe perhaps 4 + 2 [1] 2 `+` - function (e1, e2) .Primitive(+) # attempt to restore 4 + 2# test function (e1, e2) .Primitive(+) ## oops `+` - .Primitive(+) 4 + 2 [1] 6 # works `!` - function(x) x + 1 # hijacking a logical NOT definition !3 [1] 4 # so this is a redefinition of one of the two unary operators # ( of which I am aware, I'm not an R-guru.) `!` - .Primitive(!) ## hoping to restore expected behavior !3 [1] FALSE # whew. That seemed dangerous but I appear to have survived. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] randomForest: How to append ID column along with predictions
Hi all, When running a prediction using RF on another data, I get two columns returned: row number(?) and predicted class. Is there a way of appending the unique row value from an ID column in the dataframe to the predictions instead of the row number? I'm assuming that the returned results follow the data frame in that the first result returned equals the first entry in the dataframe. i.e., instead of a prediction output like this: 1, ants 2, ants 3, bees 4, ants I'd like the first column to pull IDs from the dataframe associated with each row (row number in parenthesis for illustration): (1) 1130, ants (2) 1130, ants (3) 2139, bees (4) 1130, ants This is likely a simple procedure, but I haven't been able to get anything to work. Any help would be appreciated! Cheers, Dennis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
First, subset 'test' once, e.g. testT - test[1:3]; and then use sapply() on that, e.g. val - sapply(testT, FUN=function (x) { x$a }) Then you can avoid one level of function calls, by val - sapply(testT, FUN=[[, a) Second, there is some overhead in [[, $ etc. You can use .subset2() to avoid this, e.g. val - sapply(testT, FUN=.subset2, a) Third, it may be that using sapply() to structure you results is a bit overkill. If you know that the 'a' element is always of the same dimension, you can do it yourself, e.g. val - lapply(testT, FUN=.subset2, a) val - unlist(val, use.names=FALSE) # use.names=FALSE is much faster than TRUE See what that does /Henrik On Tue, Dec 7, 2010 at 6:47 AM, Alexander Senger sen...@physik.hu-berlin.de wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
Hello Alex, Assuming it was just an inadequate example (since a data.frame would suffice in that case), did you know that a data.frames' columns do not have to be vectors but can be lists? I don't know if that helps. DF = data.frame(a=1:3) DF$b = list(pi, 2:3, letters[1:5]) DF a b 1 1 3.141593 2 2 2, 3 3 3 a, b, c, d, e DF$b [[1]] [1] 3.141593 [[2]] [1] 2 3 [[3]] [1] a b c d e sapply(DF,class) a b integerlist That is still regular though in the sense that each row has a value for all the columns, even if that value is NA, or NULL in lists. If your data is not regular then one option is to flatten it into (row,column,value) tuple similar to how sparse matrices are stored. Your value column may be list rather than vector. Then (and yes you guessed this was coming) ... you can use data.table to query the flat structure quickly by setting a key on the first two columns, or maybe just the 2nd column when you need to pick out the values for one 'column' quickly for all 'rows'. There was a thread about using list() columns in data.table here : http://r.789695.n4.nabble.com/Suggest-a-cool-feature-Use-data-table-like-a-sorted-indexed-data-list-tp2544213p2544213.html Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] So in data.table if you wanted all the 'b' values, you might do something like this : setkey(DT,column) DT[J(b), value] which should return the list() quickly from the irregular data. Matthew Alexander Senger sen...@physik.hu-berlin.de wrote in message news:4cfe6aee.6030...@physik.hu-berlin.de... Hello Gerrit, Gabor, thank you for your suggestion. Unfortunately unlist seems to be rather expensive. A short test with one of my datasets gives 0.01s for an extraction based on my approach and 5.6s for unlist alone. The reason seems to be that unlist relies on lapply internally and does so recursively? Maybe there is still another way to go? Alex Am 07.12.2010 15:59, schrieb Gerrit Eichner: Hello, Alexander, does utest - unlist(test) utest[ names( utest) == a] come close to what you need? Hth, Gerrit On Tue, 7 Dec 2010, Alexander Senger wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
On Tue, Dec 7, 2010 at 1:12 PM, David Winsemius dwinsem...@comcast.net wrote: On Dec 7, 2010, at 12:42 PM, Gabor Grothendieck wrote: On Tue, Dec 7, 2010 at 12:25 PM, Bert Gunter gunter.ber...@gene.com wrote: Ted: Inline below... On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding ted.hard...@wlandres.net wrote: Indeed! x - x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)-1 (being mean with them) uses 9. The mean version of the first uses only 6: x-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)-1 gets worked out! AFAICS it doesn't. `+`(x)-1 Error in +x - 1 : could not find function +- Sorry, my code was missing the first line: `+-` - `+` x - 3 `+`(x) - 1 x [1] 4 One can also attempt further creative violence to the language that shows that is possible to construct unary operators like the C prefix-+ that do not require shift-9 operand shift-0. `+` function (e1, e2) .Primitive(+) `+` - `-` # in a different universe perhaps 4 + 2 [1] 2 `+` - function (e1, e2) .Primitive(+) # attempt to restore 4 + 2 # test function (e1, e2) .Primitive(+) ## oops `+` - .Primitive(+) 4 + 2 [1] 6 # works `!` - function(x) x + 1 # hijacking a logical NOT definition !3 [1] 4 # so this is a redefinition of one of the two unary operators # ( of which I am aware, I'm not an R-guru.) `!` - .Primitive(!) ## hoping to restore expected behavior !3 [1] FALSE # whew. That seemed dangerous but I appear to have survived. Unlike the above, +- is not predefined so its definition does not overwrite existing definitions. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
Indeed! x - x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)-1 (being mean with them) uses 9. The mean version of the first uses only 6: x-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)-1 gets worked out! Ted. On 07-Dec-10 16:23:17, Ivan Calandra wrote: x+1 is not that complicated... Am I missing something here? Le 12/7/2010 16:55, Gabor Grothendieck a écrit : On Tue, Dec 7, 2010 at 8:43 AM, madrmadra...@interia.pl wrote: many languages have shorthands for that operation like: variable += 1 or ++variable is there something like that in R ? You can do this: x- 3 `+`(x)- 1 x [1] 4 -- Ivan CALANDRA E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 07-Dec-10 Time: 16:42:44 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to get vector of data from line ?
I have created a density line d- density(X) now I need to read values from that line for example what is the value of this line at x = 1, 2, 3 etc... -- View this message in context: http://r.789695.n4.nabble.com/how-to-get-vector-of-data-from-line-tp3076943p3076943.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tableGrob and properties of a cell
Hi, Embarrassingly enough, it was quite straight-forward in the first versions of grid.table(). You might want to try with version r11 for example, source(http://gridextra.googlecode.com/svn-history/r11/trunk/R/tableGrob.r;) library(grid) tc = textConnection( carat VeryLongWordIndeed color clarity depth 14513 1.35 Ideal J VS2 61.4 28685 0.30 Good GVVS1 64.0 50368 0.75 Ideal F SI2 59.2) d = read.table(tc,head=T) close(tc) grid.newpage() g = grid.table(d) grid.ls(g) grid.edit(top-head-fill-5, gp=gpar(fill=red)) grid.edit(cells-label-33, label=expression(alpha),gp=gpar(col=orange)) As I recall, the reason why this is more difficult now (if at all possible, I have no idea), is that I placed the actual drawing code in a drawDetails method, so that it gets updated on-the-fly, etc. I hope this simpler version will suit you, I might re-include it in the package as an alternative. HTH, baptiste On 7 December 2010 16:53, Alex Bird sund...@gmail.com wrote: Hello there, could you please help to modify gpar() properties of a cell inside tableGrob() output. In the following example I want to have different color for one out of 4 cells require(gridExtra) z-matrix(1:4,2,2) grid.draw(tableGrob(z)) The only way I found for now how to do it is to do something like this downViewport(current.vpTree()$children[[1]]$children[[6]]$name) grid.text('2',gp=gpar(col='red',fontface='bold')) But for some reasons when I try to print the table into jpeg the last grid.text() prints desired label text somewhere but not in the place I want it to be. Is there another more smart way to do it? Thanks in advance! Kind regards, Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr. Baptiste Auguié Departamento de Química Física, Universidade de Vigo, Campus Universitario, 36310, Vigo, Spain tel: +34 9868 18617 http://webs.uvigo.es/coloides __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Efficient way to use data frame of indices to initialize matrix
I have a data frame with three columns, x, y, and a. I want to create a matrix from these values such that for matrix m: m[x,y] == a Obviously, I can go row by row through the data frame and insert the value a at the correct x,y location in the matrix. I can make that slightly more efficient (perhaps), by doing something like this: for (each.x in unique(df$x)) m[each.x, df$y[df$x == each.x]] - df$a[df$x == each.x] But I feel that there must be a more efficient, or at least more elegant way to do this. -- Gene __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] please show me simple example how to plot
Like Peter says, this sounds like loess, there are examples on the help page for scatter.smooth, you could also do this with lattice graphics using type=c('p','smooth'), or ggplot2 graphics (probably something like geom_smooth or geom_loess, I don't know ggplot2 that well yet). If you want to learn more about how loess works then use loess.demo in the TeachingDemos package. There are also other smoothers available, but we would need more information before knowing where to point you. For adding a general curve or line to a scatterplot also look at functions like lines, abline, and curve, as well as the entire ggplot2 package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of madr Sent: Tuesday, December 07, 2010 10:37 AM To: r-help@r-project.org Subject: Re: [R] please show me simple example how to plot Well, maybe I didn't write it clear. I know how to create scatterplot, and how to import data from csv file. But I do not know how to add this fitting that mentioned in sumbject to a plot. I do not know for what function name to look for in R. I played some time with ls, and it didn't create a line. I know the name for the fitting I ned from Statistica, and this is from help from this program: A curve is fitted to the XY coordinate data according to the distance-weighted least squares smoothing procedure (the influence of individual points decreases with the horizontal distance from the respective points on the curve). For more information, see Distance-Weighted Least Squares. Now I need to recreate it in R. Sorry again for not being clear. -- View this message in context: http://r.789695.n4.nabble.com/please- show-me-simple-example-how-to-plot-Distance-Weighted-Least-Squares- fitting-tp3076824p3076863.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] tweedie in gam
Hello, I have count data with a large number of zeros. To model this data using gams I want to try the Tweedie distribution instead. (The zero-inflated poisson willbe my next step) How do i decide on the value of the power 'p' parameter in the formula: family=Tweedie(p, link) ? For a glm, this can be found using the tweedie.profile function. But it doesnot work with the gam model formula where explantory variables are specified as s(x1) instead of x1. Will using a tweedie on discrete data affect my results? If my question has already been addressed before, a reference to the relevant information will be very much appreciated. Thanks, payal. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to switch label font from Chinese to English
On Tue, 7 Dec 2010, Jianhong Wang wrote: Hi I tried to plot something simple x=c('2010-08-20', '2010-08-30') y = c(1,2) t = strptime(x, %Y-%m-%d) plot(t,y) At the xlab, the fonts are Chinese. How can I switch it to English? I am working under Windows 7 64 bits Home Edition and R is Win32 version 2.11.1 Is this covered by the Windows FAQ at http://cran.r-project.org/bin/windows/base/rw-FAQ.html especially Qs 3.2 and 3.3? (We don't know what you see in Chinese.) I suspect the issue is the locale category LC_TIME which is used to 'print' date-times (and in my UK locale I get an x axis annotated ny 'Aug'). If I do Sys.setlocale('LC_TIME', 'zh_CN.utf8') [1] zh_CN.utf8 plot(t,y) I get Chinese labels If so, you can also use a different format for the annotations: see ?axis.POSIXct, e.g. plot(t, y, format='%m/%d') Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Efficient way to use data frame of indices to initialize matrix
index m as a vector and do the assignment in one step i - df$row + (df$col-1)*nrow(m) m[i] - df$a or something along those lines. -Whit On Tue, Dec 7, 2010 at 1:31 PM, Cutler, Gene gcut...@amgen.com wrote: I have a data frame with three columns, x, y, and a. I want to create a matrix from these values such that for matrix m: m[x,y] == a Obviously, I can go row by row through the data frame and insert the value a at the correct x,y location in the matrix. I can make that slightly more efficient (perhaps), by doing something like this: for (each.x in unique(df$x)) m[each.x, df$y[df$x == each.x]] - df$a[df$x == each.x] But I feel that there must be a more efficient, or at least more elegant way to do this. -- Gene __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to switch label font from Chinese to English
Thanks! Brian, As you said, if locale changes, it is fine now. What I add is Sys.setlocale(LC_TIME, American) On Tue, Dec 7, 2010 at 12:14 PM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: On Tue, 7 Dec 2010, Jianhong Wang wrote: Hi I tried to plot something simple x=c('2010-08-20', '2010-08-30') y = c(1,2) t = strptime(x, %Y-%m-%d) plot(t,y) At the xlab, the fonts are Chinese. How can I switch it to English? I am working under Windows 7 64 bits Home Edition and R is Win32 version 2.11.1 Is this covered by the Windows FAQ at http://cran.r-project.org/bin/windows/base/rw-FAQ.html especially Qs 3.2 and 3.3? (We don't know what you see in Chinese.) I suspect the issue is the locale category LC_TIME which is used to 'print' date-times (and in my UK locale I get an x axis annotated ny 'Aug'). If I do Sys.setlocale('LC_TIME', 'zh_CN.utf8') [1] zh_CN.utf8 plot(t,y) I get Chinese labels If so, you can also use a different format for the annotations: see ?axis.POSIXct, e.g. plot(t, y, format='%m/%d') Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/http://www.stats.ox.ac.uk/%7Eripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to get vector of data from line ?
There are a few different options depending on what you are trying to do. If you just need some data pairs (for plotting for example), then the return from density has a vector of x's and a vector of y's, just use those. If you have specific x values that you need the height at and they follow a regular pattern, then you can modify the from, to, and n parameters to generate your x values, then they are in the return value. You can approximate the values by passing the x and y from the return of density to the functions approx or approxfun. You can estimate the density in a different way using the logspline package, it provides functions to give you the height of the curve at specified values. You can just add the kernels together at your specified x values instead of using density (search the archives, I think Prof. Ripley recently posted a function to do this or similar). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of madr Sent: Tuesday, December 07, 2010 11:28 AM To: r-help@r-project.org Subject: [R] how to get vector of data from line ? I have created a density line d- density(X) now I need to read values from that line for example what is the value of this line at x = 1, 2, 3 etc... -- View this message in context: http://r.789695.n4.nabble.com/how-to-get- vector-of-data-from-line-tp3076943p3076943.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Efficient way to use data frame of indices to initialize matrix
tmpdf - data.frame( x = c(1,2,3), y=c(2,3,1), a=c(10,20,30) ) mymat - matrix(0, ncol=3, nrow=3) mymat[ as.matrix(tmpdf[,c('x','y')]) ] - tmpdf$a -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Cutler, Gene Sent: Tuesday, December 07, 2010 11:31 AM To: r-help@r-project.org Subject: [R] Efficient way to use data frame of indices to initialize matrix I have a data frame with three columns, x, y, and a. I want to create a matrix from these values such that for matrix m: m[x,y] == a Obviously, I can go row by row through the data frame and insert the value a at the correct x,y location in the matrix. I can make that slightly more efficient (perhaps), by doing something like this: for (each.x in unique(df$x)) m[each.x, df$y[df$x == each.x]] - df$a[df$x == each.x] But I feel that there must be a more efficient, or at least more elegant way to do this. -- Gene __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] randomForest: How to append ID column along with predictions
Hi all, When running a prediction using RF on another data, I get two columns returned: row number(?) and predicted class. Is there a way of appending the unique row value from an ID column in the dataframe to the predictions instead of the row number? I'm assuming that the returned results follow the data frame in that the first result returned equals the first entry in the dataframe. i.e., instead of a prediction output like this: 1, ants 2, ants 3, bees 4, ants I'd like the first column to pull IDs from the dataframe associated with each row (row number in parenthesis for illustration): (1) 1130, ants (2) 1130, ants (3) 2139, bees (4) 1130, ants This is likely a simple procedure, but I haven't been able to get anything to work. Any help would be appreciated! Cheers, Dennis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to get vector of data from line ?
On Dec 7, 2010, at 1:27 PM, madr wrote: I have created a density line d- density(X) now I need to read values from that line for example what is the value of this line at x = 1, 2, 3 etc... Learn to search: http://finzi.psych.upenn.edu/Rhelp10/2010-September/253910.html -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Statistical Analysis with R Beginner's Guide Book
Hi Everyone, I'm writing to announce my new R beginner's guide book and answer questions related to it. The primary focus of Statistical Analysis with R is helping new users become accustomed to R and empowering them to apply R to suit their own needs. It is a beginner's guide written for a broad audience and should be well received by businesspeople, IT professionals, researchers, and students alike. Statistical Analysis with R takes readers on a journey from their first installation and launch of R, to analyzing and assessing data, to communicating and visualizing results. You can http://rtutorialseries.blogspot.com/2010/11/r-beginners-guide-book-update.html learn more about the book on my R Tutorial Series blog. The book itself can be found on the http://link.packtpub.com/or7f1u Packt Publishing website . If you have questions about the book, such as its content coverage, approach, audience, etc., please respond and I will do my best to clarify. Sincerely, John M. Quick - John M. Quick * http://rTutorialSeries.blogspot.com R Tutorial Series Blog * http://link.packtpub.com/or7f1u R Beginner's Guide * http://www.johnmquick.com www.johnmquick.com -- View this message in context: http://r.789695.n4.nabble.com/Statistical-Analysis-with-R-Beginner-s-Guide-Book-tp3076991p3076991.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tableGrob and properties of a cell
Hi Baptiste! Grand-grand merci!!! It works! Thanks! Alex 2010/12/7 baptiste auguie baptiste.aug...@googlemail.com: baptiste __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
Hello, Matthew's hint is interesting: Am 07.12.2010 19:16, schrieb Matthew Dowle: Hello Alex, Assuming it was just an inadequate example (since a data.frame would suffice in that case), did you know that a data.frames' columns do not have to be vectors but can be lists? I don't know if that helps. DF = data.frame(a=1:3) DF$b = list(pi, 2:3, letters[1:5]) DF a b 1 1 3.141593 2 2 2, 3 3 3 a, b, c, d, e DF$b [[1]] [1] 3.141593 [[2]] [1] 2 3 [[3]] [1] a b c d e sapply(DF,class) a b integerlist That is still regular though in the sense that each row has a value for all the columns, even if that value is NA, or NULL in lists. My data is mostly regular, that is every sublist contains a data.frame which is the major contribution to overall size. The reason I use lists is mainly that I need also some bits of information about the environment. I thought about putting these into additional columns of the data.frame (and add redundancy and maybe 30% of overhead this way), one column per variable. But as memory usage is already close to the limit of my machine this might break things (the situation is a bit tricky, isn't it?). I didn't know that a column of a data.frame can be a list. So if I need only let's say 10 entries in that list, but my data.frame has several hundred rows, would the empty parts of the column-list be filled with cycled values or would they be really empty and thus not use additional memory? Secondly as I mentioned in another email to this topic: a whole day of data contains about 100 chunks of data that is 100 of the sublists described above. I could put them all into one large data.frame, but then I would have to extract the environmental data from the long list, now containing repeated occurrences of variables with the same name. I guess subsetting could become tricky here (dependend on name and position, I assume), but I'm eager to learn an easy way of doing so. Sorry for not submitting an illustrative example, but I'm afraid that would be quite lengthy and not so illustrative any more. The data.table mentioned below seems to be an interesting alternative; I'll definitely look into this. But it would also mean quite a bit of homework, as far as I can see... Thanks Alex If your data is not regular then one option is to flatten it into (row,column,value) tuple similar to how sparse matrices are stored. Your value column may be list rather than vector. Then (and yes you guessed this was coming) ... you can use data.table to query the flat structure quickly by setting a key on the first two columns, or maybe just the 2nd column when you need to pick out the values for one 'column' quickly for all 'rows'. There was a thread about using list() columns in data.table here : http://r.789695.n4.nabble.com/Suggest-a-cool-feature-Use-data-table-like-a-sorted-indexed-data-list-tp2544213p2544213.html Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] So in data.table if you wanted all the 'b' values, you might do something like this : setkey(DT,column) DT[J(b), value] which should return the list() quickly from the irregular data. Matthew Alexander Senger sen...@physik.hu-berlin.de wrote in message news:4cfe6aee.6030...@physik.hu-berlin.de... Hello Gerrit, Gabor, thank you for your suggestion. Unfortunately unlist seems to be rather expensive. A short test with one of my datasets gives 0.01s for an extraction based on my approach and 5.6s for unlist alone. The reason seems to be that unlist relies on lapply internally and does so recursively? Maybe there is still another way to go? Alex Am 07.12.2010 15:59, schrieb Gerrit Eichner: Hello, Alexander, does utest - unlist(test) utest[ names( utest) == a] come close to what you need? Hth, Gerrit On Tue, 7 Dec 2010, Alexander Senger wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] fast subsetting of lists in lists
Hello Gerrit, Gabor, thank you for your suggestion. Unfortunately unlist seems to be rather expensive. A short test with one of my datasets gives 0.01s for an extraction based on my approach and 5.6s for unlist alone. The reason seems to be that unlist relies on lapply internally and does so recursively? Maybe there is still another way to go? Alex Am 07.12.2010 15:59, schrieb Gerrit Eichner: Hello, Alexander, does utest - unlist(test) utest[ names( utest) == a] come close to what you need? Hth, Gerrit On Tue, 7 Dec 2010, Alexander Senger wrote: Hello, my data is contained in nested lists (which seems not necessarily to be the best approach). What I need is a fast way to get subsets from the data. An example: test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6), list(a = 7, b = 8, c = 9)) Now I would like to have all values in the named variables a, that is the vector c(1, 4, 7). The best I could come up with is: val - sapply(1:3, function (i) {test[[i]]$a}) which is unfortunately not very fast. According to R-inferno this is due to the fact that apply and its derivates do looping in R rather than rely on C-subroutines as the common [-operator. Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] Thank you for your advice Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Efficient way to use data frame of indices to initialize matrix
On Dec 7, 2010, at 1:49 PM, Greg Snow wrote: tmpdf - data.frame( x = c(1,2,3), y=c(2,3,1), a=c(10,20,30) ) mymat - matrix(0, ncol=3, nrow=3) mymat[ as.matrix(tmpdf[,c('x','y')]) ] - tmpdf$a cbind is also useful for assembly of arguments to the matrix-`[-` function: tmpdf - data.frame( x = c(1,2,3), y=c(2,3,1), a=c(10,20,30) ) mymat - matrix(NA, ncol=max(tmpdf$y), nrow=max(tmpdf$x)) mymat[ cbind(tmpdf$x,tmpdf$y) ] - tmpdf$a mymat [,1] [,2] [,3] [1,] NA 10 NA [2,] NA NA 20 [3,] 30 NA NA -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Cutler, Gene Sent: Tuesday, December 07, 2010 11:31 AM To: r-help@r-project.org Subject: [R] Efficient way to use data frame of indices to initialize matrix I have a data frame with three columns, x, y, and a. I want to create a matrix from these values such that for matrix m: m[x,y] == a Obviously, I can go row by row through the data frame and insert the value a at the correct x,y location in the matrix. I can make that slightly more efficient (perhaps), by doing something like this: for (each.x in unique(df$x)) m[each.x, df$y[df$x == each.x]] - df$a[df$x == each.x] But I feel that there must be a more efficient, or at least more elegant way to do this. -- Gene __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] please show me simple example how to plot Distance-Weighted Least Squares fitting
It's impossible to give you really good advice without an example of your data, the R code you used and the error message. But here's a simple scatterplot example: fakedata - data.frame(x=runif(15), y=runif(15)) plot(fakedata$x, fakedata$y) or since you mentioned a line: fakedata - fakedata[order(fakedata$x),] plot(fakedata$x, fakedata$y, type=l) For anything more, we would need the information requested in the R-help posting guide linked at the bottom of each and every R-help message. Sarah On Tue, Dec 7, 2010 at 12:17 PM, madr madra...@interia.pl wrote: I got simple x,y pairs of data and simple scatterplot and just cannot figure how to do it , there are many examples but always there is error popping out please show me an example stripped with additional data just core of what I need to do to get this damn line __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R problem
I'm using R version 2.12.0 I'm trying to open a stata file (.dta); but I keep getting the message: Error in read.dta(c:/p4subset_biology.dta) : Calloc could not allocate (-603966867 of 4) memory What does this mean? The file should contain lots of physiological data. Thank you for your help. -Bruce __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating binary variable depending on strings of two dataframes
On Tue, Dec 7, 2010 at 11:30 AM, Pete Pete noxyp...@gmail.com wrote: Hi, consider the following two dataframes: x1=c(232,3454,3455,342,13) x2=c(1,1,1,0,0) data1=data.frame(x1,x2) y1=c(232,232,3454,3454,3455,342,13,13,13,13) y2=c(E1,F3,F5,E1,E2,H4,F8,G3,E1,H2) data2=data.frame(y1,y2) I need a new column in dataframe data1 (x3), which is either 0 or 1 depending if the value E1 in y2 of data2 is true while x1=y1. The result of data1 should look like this: x1 x2 x3 1 232 1 1 2 3454 1 1 3 3455 1 0 4 342 0 0 5 13 0 1 I think a SQL command could help me but I am too inexperienced with it to get there. Try this: library(sqldf) sqldf(select x1, x2, max(y2 = 'E1') x3 from data1 d1 left join data2 d2 on (x1 = y1) group by x1, x2 order by d1.rowid) x1 x2 x3 1 232 1 1 2 3454 1 1 3 3455 1 0 4 342 0 0 5 13 0 1 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help on timeseries
i have time series of momentum signal. I want to get the date of each of the -1 signal period. for example , the first period of -1 signal begins on 2005-9-21 and ends on 2005-9-28. 2nd period of -1 signal begins on 2005-09-30 and ends on 2005-10-28. Thx Cameron datePx 200MA Signals 2005-09-15 26.27 25.838651 2005-09-16 26.07 25.832751 2005-09-19 26.00 25.827301 2005-09-20 25.84 25.820351 2005-09-21 25.49 25.81115 -1 2005-09-22 25.34 25.80250 -1 2005-09-23 25.27 25.79205 -1 2005-09-26 25.27 25.78225 -1 2005-09-27 25.34 25.77355 -1 2005-09-28 25.67 25.76565 -1 2005-09-29 25.94 25.759201 2005-09-30 25.73 25.75230 -1 2005-10-03 25.50 25.74400 -1 2005-10-04 24.98 25.73410 -1 2005-10-05 24.67 25.72270 -1 2005-10-06 24.73 25.71100 -1 2005-10-07 24.59 25.69910 -1 2005-10-10 24.46 25.68635 -1 2005-10-11 24.41 25.67415 -1 2005-10-12 24.30 25.66090 -1 2005-10-13 24.59 25.64935 -1 2005-10-14 24.67 25.63890 -1 2005-10-17 24.53 25.62795 -1 2005-10-18 24.57 25.61710 -1 2005-10-19 25.09 25.60835 -1 2005-10-20 24.79 25.59840 -1 2005-10-21 24.78 25.58855 -1 2005-10-24 25.10 25.58070 -1 2005-10-25 25.03 25.57185 -1 2005-10-26 25.11 25.56375 -1 2005-10-27 24.85 25.55410 -1 2005-10-28 25.53 25.55040 -1 2005-10-31 25.70 25.548301 2005-11-01 25.96 25.546501 2005-11-02 26.46 25.548901 2005-11-03 26.44 25.551801 2005-11-04 26.66 25.556851 -code library(tseries) library(timeSeries) msft - as.timeSeries(get.hist.quote(instrument=MSFT, start=1986-03-31, end=2008-09-10, quote=c(C), provider=yahoo, retclass=zoo)) msft - cbind(msft,as.timeSeries(rollapply(as.zoo(msft ),width=200,mean,align=right))) msft - cbind(msft,NA) msft[,3] - (ifelse(msft[,1]msft[,2],1,-1)) print(msft) -- View this message in context: http://r.789695.n4.nabble.com/help-on-timeseries-tp3076866p3076866.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Changing names of a string variable
Hello, Here is the data set I am working with: dat=read.csv('http://dl.dropbox.com/u/1852742/relexpressions.csv') names(dat) #Under the 'target' column, I want to change all of the values into all capital letters (e.g. fgf2 becomes FGF2). I have taken a loop approach but I think my Python background is confusing me. Here is what I attempted: for(line in dat[,1]){if(line=='fgf2'){line-'FGF2'}} #I made sure that it was looping through each line by entering: for(line in dat[,1]){if(line=='fgf2'){print(line)}} #Which did exactly what I thought it would. #This doesn't change anything, though. Also, after reading the documentation I am still confused how to add multiple if statements. I would need that because I need to change the names of fgf2, fgf7, and fgf10. #I am sure there is a built-in function to do what I need, but I haven't found it yet so I tried this loop method. Any help is greatly appreciated! Jahan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataframe from list of similar lists: not _a_ way, but _the best_ way
On 12/7/2010 1:03 AM, Nick Sabbe wrote: Hi All. I often find myself in this situation: . Based on some vector (or list) of values, I need to calculate a few new values for each of them, where some of the new values are numbers, but some are more of descriptive nature (so: character strings) . So I use e.g. sapply, passing a custom function that returns a list with all the calculated values . The result of this is: a list (=the return value of sapply) of lists, that all have the same kind of named values A silly example: list.of.lists-sapply(1:10, function(nr){list(org=nr, chr=as.character(nr))}) Actually, this is not a list of lists, but rather a list of vectors with dimensions. I didn't know such a thing existed, but obviously it does. It seems rather obvious that the result would be better structured as a dataframe. Now I know a few ways to do this (using do.call), but I fear most of these are rather bad in performance: I suspect all the data is being repetitively copied which may be slow. So, my question to the specialists: . Is the above way of working reasonable for this kind of problem? Or would you suggest otherwise? . What would be the best (as in: quickest) way of transforming this list of lists to a dataframe? The answer to this is probably based upon knowledge of the inner workings of R? Or is there any way in which this depends on the specifics of my function (for nontrivial functions and list sizes)? I don't know that this is best (in terms of fastest and/or least memory usage), but to me the following is best in that it hands off the problem to a package that is designed to handle such problems, so presumably does a better job than any one-off approach. library(plyr) DF - ldply(1:10, function(nr){data.frame(org=nr, chr=as.character(nr))}) Note that the internal function returns a data.frame rather than a list, and the *dply functions automatically stitch the individual data.frames together. Check out the documentation to the plyr package. Thanks! Nick Sabbe -- ping: nick.sa...@ugent.be link:http://biomath.ugent.be/ http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -- Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health Science University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to get vector of data from line ?
well, I found id the simplest answer is: d- approx(density(x),xout=...) where xout is a vector of the points where the data should be sampled -- View this message in context: http://r.789695.n4.nabble.com/how-to-get-vector-of-data-from-line-tp3076943p3077058.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing names of a string variable
Hello, To do what you want, see ?toupper : levels(dat$target) - toupper(levels(dat$target)) However, for clarity, dat$target is not a string variable, it is a factor, which you can verify with str(dat) Factors are enumerated types, and have a discrete set of 'levels' associated with them, which can be queried with the ?levels function. 'Behind the scenes', R is storing this variable as numeric codes, not the character string associated with each numeric code. This contrasts with character vectors. --Erik Jahan wrote: Hello, Here is the data set I am working with: dat=read.csv('http://dl.dropbox.com/u/1852742/relexpressions.csv') names(dat) #Under the 'target' column, I want to change all of the values into all capital letters (e.g. fgf2 becomes FGF2). I have taken a loop approach but I think my Python background is confusing me. Here is what I attempted: for(line in dat[,1]){if(line=='fgf2'){line-'FGF2'}} #I made sure that it was looping through each line by entering: for(line in dat[,1]){if(line=='fgf2'){print(line)}} #Which did exactly what I thought it would. #This doesn't change anything, though. Also, after reading the documentation I am still confused how to add multiple if statements. I would need that because I need to change the names of fgf2, fgf7, and fgf10. #I am sure there is a built-in function to do what I need, but I haven't found it yet so I tried this loop method. Any help is greatly appreciated! Jahan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing names of a string variable
Jahan - Try dat$target = toupper(dat$target) I would not recommend a loop for something like this. (You might also want to brush up on your python, because what you're trying doesn't work in python either.) - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 7 Dec 2010, Jahan wrote: Hello, Here is the data set I am working with: dat=read.csv('http://dl.dropbox.com/u/1852742/relexpressions.csv') names(dat) #Under the 'target' column, I want to change all of the values into all capital letters (e.g. fgf2 becomes FGF2). I have taken a loop approach but I think my Python background is confusing me. Here is what I attempted: for(line in dat[,1]){if(line=='fgf2'){line-'FGF2'}} #I made sure that it was looping through each line by entering: for(line in dat[,1]){if(line=='fgf2'){print(line)}} #Which did exactly what I thought it would. #This doesn't change anything, though. Also, after reading the documentation I am still confused how to add multiple if statements. I would need that because I need to change the names of fgf2, fgf7, and fgf10. #I am sure there is a built-in function to do what I need, but I haven't found it yet so I tried this loop method. Any help is greatly appreciated! Jahan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] increase or decrease variable by 1
Ted: Inline below... On Tue, Dec 7, 2010 at 8:42 AM, Ted Harding ted.hard...@wlandres.net wrote: Indeed! x - x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)-1 (being mean with them) uses 9. The mean version of the first uses only 6: x-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)-1 gets worked out! AFAICS it doesn't. `+`(x)-1 Error in +x - 1 : could not find function +- `+`(x,1) does: `+`(x,1) [1] 4 -- Bert Ted. On 07-Dec-10 16:23:17, Ivan Calandra wrote: x+1 is not that complicated... Am I missing something here? Le 12/7/2010 16:55, Gabor Grothendieck a écrit : On Tue, Dec 7, 2010 at 8:43 AM, madrmadra...@interia.pl wrote: many languages have shorthands for that operation like: variable += 1 or ++variable is there something like that in R ? You can do this: x- 3 `+`(x)- 1 x [1] 4 -- Ivan CALANDRA E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 07-Dec-10 Time: 16:42:44 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing names of a string variable
Phil Spector wrote: Jahan - Try dat$target = toupper(dat$target) Note that in this case, the above *will* coerce dat$target to a character vector, which may or may not be what is intended. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing names of a string variable
On Dec 7, 2010, at 2:31 PM, Erik Iverson wrote: Hello, To do what you want, see ?toupper : levels(dat$target) - toupper(levels(dat$target)) However, for clarity, dat$target is not a string variable, it is a factor, which you can verify with str(dat) And to further clarify, it is a factor because of the default behavior of read.table and data.frame in creating factors when offered streams of character data. The stringsAsFactors=FALSE argument can be used within these functions or can be set globally with options(). -- David. Factors are enumerated types, and have a discrete set of 'levels' associated with them, which can be queried with the ?levels function. 'Behind the scenes', R is storing this variable as numeric codes, not the character string associated with each numeric code. This contrasts with character vectors. --Erik Jahan wrote: Hello, Here is the data set I am working with: dat=read.csv('http://dl.dropbox.com/u/1852742/relexpressions.csv') names(dat) #Under the 'target' column, I want to change all of the values into all capital letters (e.g. fgf2 becomes FGF2). I have taken a loop approach but I think my Python background is confusing me. Here is what I attempted: for(line in dat[,1]){if(line=='fgf2'){line-'FGF2'}} #I made sure that it was looping through each line by entering: for(line in dat[,1]){if(line=='fgf2'){print(line)}} #Which did exactly what I thought it would. #This doesn't change anything, though. Also, after reading the documentation I am still confused how to add multiple if statements. I would need that because I need to change the names of fgf2, fgf7, and fgf10. #I am sure there is a built-in function to do what I need, but I haven't found it yet so I tried this loop method. Any help is greatly appreciated! Jahan David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] More elegant magnitude method
I have a need to find the order of number to get a scaling parameter as a power of 10. I have a function that works *so far*, but it is ugly and probably buggy. In the interest of avoiding code-based outliers in my data, I thought I would ask if anyone here has a better way. scl - function(x){ + length(charToRaw(format(trunc(x), scientific = F)))-1} a - 123456789 b - 1E15 c - 12.345 scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 Thanks -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fast subsetting of lists in lists
Alexander: I'm not sure exactly what you want, so the following may be irrelevant... BUT, noting that data frames ARE lists and IF what you have can then be abstracted as lists of lists of lists of ... to various depths AND IF what you want is just to pick out and combined all named vectors (which could be columns of data frames) with a given name at whatever depth they they appear in the lists THEN it is natural to do this recursively as follows: vaccuum - function(x,nm) ## x is a named list (of lists of ...) ## nm in the name searched for { y - NULL for(nmx in names(x)) y - c(y, { z - x[[nmx]] if(nmx==nm)z else if(is.list(z))Recall(z,nm) }) y } ##Example test - list(a=1:3, be = list(a=4:6,c=data.frame(a=10:15,b=I(letters[1:6] vaccuum(test,b) [1] a b c d e f vaccuum(test,a) [1] 1 2 3 4 5 6 10 11 12 13 14 15 caveat: If perchance this is (at least close to) what you want, it is likely to be rather inefficient. It also needs some robustifying. Cheers, Bert On Tue, Dec 7, 2010 at 10:54 AM, Alexander Senger sen...@physik.hu-berlin.de wrote: Hello, Matthew's hint is interesting: Am 07.12.2010 19:16, schrieb Matthew Dowle: Hello Alex, Assuming it was just an inadequate example (since a data.frame would suffice in that case), did you know that a data.frames' columns do not have to be vectors but can be lists? I don't know if that helps. DF = data.frame(a=1:3) DF$b = list(pi, 2:3, letters[1:5]) DF a b 1 1 3.141593 2 2 2, 3 3 3 a, b, c, d, e DF$b [[1]] [1] 3.141593 [[2]] [1] 2 3 [[3]] [1] a b c d e sapply(DF,class) a b integer list That is still regular though in the sense that each row has a value for all the columns, even if that value is NA, or NULL in lists. My data is mostly regular, that is every sublist contains a data.frame which is the major contribution to overall size. The reason I use lists is mainly that I need also some bits of information about the environment. I thought about putting these into additional columns of the data.frame (and add redundancy and maybe 30% of overhead this way), one column per variable. But as memory usage is already close to the limit of my machine this might break things (the situation is a bit tricky, isn't it?). I didn't know that a column of a data.frame can be a list. So if I need only let's say 10 entries in that list, but my data.frame has several hundred rows, would the empty parts of the column-list be filled with cycled values or would they be really empty and thus not use additional memory? Secondly as I mentioned in another email to this topic: a whole day of data contains about 100 chunks of data that is 100 of the sublists described above. I could put them all into one large data.frame, but then I would have to extract the environmental data from the long list, now containing repeated occurrences of variables with the same name. I guess subsetting could become tricky here (dependend on name and position, I assume), but I'm eager to learn an easy way of doing so. Sorry for not submitting an illustrative example, but I'm afraid that would be quite lengthy and not so illustrative any more. The data.table mentioned below seems to be an interesting alternative; I'll definitely look into this. But it would also mean quite a bit of homework, as far as I can see... Thanks Alex If your data is not regular then one option is to flatten it into (row,column,value) tuple similar to how sparse matrices are stored. Your value column may be list rather than vector. Then (and yes you guessed this was coming) ... you can use data.table to query the flat structure quickly by setting a key on the first two columns, or maybe just the 2nd column when you need to pick out the values for one 'column' quickly for all 'rows'. There was a thread about using list() columns in data.table here : http://r.789695.n4.nabble.com/Suggest-a-cool-feature-Use-data-table-like-a-sorted-indexed-data-list-tp2544213p2544213.html Does someone now a trick to do the same as above with the faster built-in subsetting? Something like: test[somesubsettingmagic] So in data.table if you wanted all the 'b' values, you might do something like this : setkey(DT,column) DT[J(b), value] which should return the list() quickly from the irregular data. Matthew Alexander Senger sen...@physik.hu-berlin.de wrote in message news:4cfe6aee.6030...@physik.hu-berlin.de... Hello Gerrit, Gabor, thank you for your suggestion. Unfortunately unlist seems to be rather expensive. A short test with one of my datasets gives 0.01s for an extraction based on my approach and 5.6s for unlist alone. The reason seems to be that unlist relies on lapply internally and does so recursively? Maybe there is still another way to go? Alex Am 07.12.2010 15:59, schrieb Gerrit Eichner: Hello, Alexander, does utest -
Re: [R] increase or decrease variable by 1
On 07/12/2010 12:42 PM, Gabor Grothendieck wrote: On Tue, Dec 7, 2010 at 12:25 PM, Bert Guntergunter.ber...@gene.com wrote: Ted: Inline below... On Tue, Dec 7, 2010 at 8:42 AM, Ted Hardingted.hard...@wlandres.net wrote: Indeed! x- x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)-1 (being mean with them) uses 9. The mean version of the first uses only 6: x-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)-1 gets worked out! AFAICS it doesn't. `+`(x)-1 Error in +x- 1 : could not find function +- Sorry, my code was missing the first line: `+-`- `+` x- 3 `+`(x)- 1 x [1] 4 Note that there are at least two subtle differences between your code and x += 1 or ++x: First, the value of `+`(x)- 1 is 1, i.e. print(`+`(x)- 1) will give 1 regardless of x, unlike ++x. Another difference is that `+`(x)- 1 is equivalent to x - x + 1, and in R, that doesn't necessarily increment x: the x on the right hand side might be a global variable, and the result of x + 1 will be assigned to a new local variable. For example, the sequence x - 3 f - function() `+`(x)- 1 f() x leaves x set to 3. (But it temporarily created a new variable called x in the evaluation frame of f().) I don't think the first difference is documented; I haven't checked the source to know if it's intentional. (It generally makes sense that foo - bar has value bar; the problem is that your assignment doesn't follow the rule that it assigns bar to foo.) The second one is a basic fact of life in R, and the source of a few bugs: the only way around it that I can see would be to allow users to declare things about variables (e.g. x is a global variable, don't create a local when I assign to it!). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] More elegant magnitude method
On Dec 7, 2010, at 2:43 PM, Jonathan P Daily wrote: I have a need to find the order of number to get a scaling parameter as a power of 10. I have a function that works *so far*, but it is ugly and probably buggy. In the interest of avoiding code-based outliers in my data, I thought I would ask if anyone here has a better way. scl - function(x){ + length(charToRaw(format(trunc(x), scientific = F)))-1} a - 123456789 b - 1E15 c - 12.345 scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 scl- function(x) trunc(log(x,10)) scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 Seems mathematically clearer. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] More elegant magnitude method
Jonathan, I'd just return the integer part of the common log: floor(log10(x)) Dave From: Jonathan P Daily jda...@usgs.gov To: r-help@r-project.org Date: 12/07/2010 01:44 PM Subject: [R] More elegant magnitude method Sent by: r-help-boun...@r-project.org I have a need to find the order of number to get a scaling parameter as a power of 10. I have a function that works *so far*, but it is ugly and probably buggy. In the interest of avoiding code-based outliers in my data, I thought I would ask if anyone here has a better way. scl - function(x){ + length(charToRaw(format(trunc(x), scientific = F)))-1} a - 123456789 b - 1E15 c - 12.345 scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 Thanks -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] More elegant magnitude method
What a brain fart... Thanks! -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly David Winsemius dwinsem...@comcast.net wrote on 12/07/2010 02:50:34 PM: [image removed] Re: [R] More elegant magnitude method David Winsemius to: Jonathan P Daily 12/07/2010 02:50 PM Cc: r-help On Dec 7, 2010, at 2:43 PM, Jonathan P Daily wrote: I have a need to find the order of number to get a scaling parameter as a power of 10. I have a function that works *so far*, but it is ugly and probably buggy. In the interest of avoiding code-based outliers in my data, I thought I would ask if anyone here has a better way. scl - function(x){ + length(charToRaw(format(trunc(x), scientific = F)))-1} a - 123456789 b - 1E15 c - 12.345 scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 scl- function(x) trunc(log(x,10)) scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 Seems mathematically clearer. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] More elegant magnitude method
I would prefer: round(log10(x)) Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David L Lorenz Sent: Tuesday, December 07, 2010 2:53 PM To: Jonathan P Daily Cc: r-help@r-project.org; r-help-boun...@r-project.org Subject: Re: [R] More elegant magnitude method Jonathan, I'd just return the integer part of the common log: floor(log10(x)) Dave From: Jonathan P Daily jda...@usgs.gov To: r-help@r-project.org Date: 12/07/2010 01:44 PM Subject: [R] More elegant magnitude method Sent by: r-help-boun...@r-project.org I have a need to find the order of number to get a scaling parameter as a power of 10. I have a function that works *so far*, but it is ugly and probably buggy. In the interest of avoiding code-based outliers in my data, I thought I would ask if anyone here has a better way. scl - function(x){ + length(charToRaw(format(trunc(x), scientific = F)))-1} a - 123456789 b - 1E15 c - 12.345 scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 Thanks -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.