similar to: A more idiomatic way to write this

Displaying 20 results from an estimated 10000 matches similar to: "A more idiomatic way to write this"

2001 Feb 01
1
constructing a vector from a dataframe and another vector
Hi All, I have a dataframe, divs, that looks like this: > divs date ticker dividend 263 20010322 ADBE 0.025 264 20010628 ADBE 0.025 265 20010927 ADBE 0.025 4308 20010212 ED 0.550 4309 20010514 ED 0.410 5416 20010330 GE 0.137 5417 20010629 GE 0.137 5418 20010928
2008 Feb 11
2
Questions about histograms
Hello I'm doing some experiments with the various histogram functions and I have a two questions about the "prob" option and binning. First, here's a simple plot of my data using the default hist() function: > hist(data[,1], prob = TRUE, xlim = c(0, 35)) http://go.sneakymustard.com/tmp/hist.jpg My first question is regarding the resulting plot from hist.scott() and
2013 May 24
10
[PATCH 0/4] ARM/early-printk: Improve reusability and add Calxeda support
The current early-printk support for ARM is rather hard-coded, making it hard to add machines or tweak settings. This series slightly moves some code to gather UART settings in xen/arch/arm/Rules.mk instead of the actual .c files. Also it allows two different machines with different settings to share the same driver, which the last patch exploits to add support the Calxeda Midway hardware. This
2008 Jul 04
3
problem with NA and if
Hi I would like to sum a number of time series, some of them having NA's Standard action is here that if I sum a value with a NA, then the result is NA. I would like it to just keep the value. I then try to: a = NA; if (a == NA) { a = 0} just to try it out, but it says Error in if (a == NA) { : missing value where TRUE/FALSE needed What is wrong, and can I do it smarter? I looked at
2007 Nov 06
1
A suggestion for an amendment to tapply
Dear R-developers, when tapply() is invoked on factors that have empty levels, it returns NA. This behaviour is in accord with the tapply documentation, and is reasonable in many cases. However, when FUN is sum, it would also seem reasonable to return 0 instead of NA, because "the sum of an empty set is zero, by definition." I'd like to raise a discussion of the possibility of an
2008 Feb 13
2
apply on large arrays
I have a big contingency table, approximately of size 60*2*500*500, and I need to count the number of cells containing a count of 1 for each of the factors values defining the first dimension. Here is my attempt: tab1<-with(pisa1,table(CNT,GENDER,ISCOF,ISCOM)) tab2<-apply(tab1,1:4,function(x)ifelse(sum(x)==1,1,0)) tab3<-apply(tab2,1,sum) Computing tab2 is very slow. Is there a faster
2005 Dec 21
3
NextMethod causes R 2.2.0 to crash (PR#8416)
I found writing the following default method the for the generic function "julian" causes R to crash. julian.default <- function(x, ...) { x <- as.Date(x) NextMethod("julian", x, ...) } Here is a test example > m <- as.Date("1972-09-27") + 0:10 > m [1] "1972-09-27" "1972-09-28" "1972-09-29"
2007 Mar 25
2
resolving expand.grid & NA errors
I am hoping for some advice regarding resolving error messages I have received when trying to use the expand.grid command. library(nnet) library(MASS) library(car) mod.multacute <-multinom(kc$group ~ kc$in.acute.danger * kc$violent.convictions, na.rm=T) summary(mod.multacute, cor=F, Wald=T) Anova (mod.multacute) confint (mod.multacute) > predictors <- expand.grid(group=1:3,
2008 Feb 01
6
Accessing the elements of a list
Hi R, I wanted to know how do we access the elements of a list. In particular, v=list(c(1,2,3,4,5),c(1,2,33,4,5),c(1,2,333,4,5),c(1,2,3333,4,5)) I want to access all the thirds items of the elements of the list. i.e., I want to access the elements, 3,33,333,3333. This can be done through sapply as: sapply(v,function(x) x[3]) But I need to access this without using
2007 Jul 03
1
termplot - changes in defaults
While termplot is under discussion, here's another proposal. I'd like to change the default for partial.resid to TRUE, and for smooth to panel.smooth. I'd be surprised if those changes were to break existing code. John Maindonald email: john.maindonald at anu.edu.au phone : +61 2 (6125)3473 fax : +61 2(6125)5549 Centre for Mathematics & Its Applications, Room
2006 Dec 22
5
substitute creates an object which prints incorrectly (PR#9427)
The function "substitute" seems to fail to make a genuine substitution, although the printed verision seems fine. Here is an example. > m <- substitute(Y <- function(x) FUN(x+1), + list(Y = as.name("y"), FUN = as.name("sin"))) > m y <- function(x) sin(x + 1) > eval(m) > y function(x) FUN(x+1) However the story doesn't end there. The
2008 Apr 13
4
R equivalent of erfcinv in matlab
I am converting some matlab code into R that use inverse of the complementary error function, erfcinv and did not find an equivalent in R, is there such a function in some contributed modules? Thanks.
2007 Nov 15
3
generate combination set
I have a set data={A,B,C,D,E,F,G} I want to choose 2 letter from 8 letters, i.e. generate the combination set for choose 2 letters from 8 letters. I want to get the liking: combination set={AB,AC,AD,....} Does anyone konw how to do in R. thanks, Aimin
2005 Apr 30
3
as.numeric method for objects of class "difftime"
I have just become painfully aware that objects of class "difftime", generated by the difference of two POSIXct objects, carry a "units" attribute, which flashes by when the object is printed, for example. The pain was occasioned when I tried to turn these objects into numberic objects for use elsewhere as a covariate. as.numeric(difftime object) simply turns off the units
2008 Mar 04
6
vector manipulations
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080304/9de37092/attachment.pl
2006 Feb 10
14
[PATCH] TC: bug fixes to the "sample" clause
PATCH 1 ======= On my machine tc does not parse filter "sample" for the u32 filter. Eg: tc filter add dev eth2 parent 1:0 protocol ip prio 1 u32 ht 801: \ classid 1:3 \ sample ip protocol 1 0xff match ip protocol 1 0xff Illegal "sample" The reason is a missing memset. This patch fixes it. diff -Nur iproute-20051007.keep/tc/f_u32.c iproute-20051007/tc/f_u32.c
2006 Jan 14
2
initialize expression in 'quasi' (PR#8486)
This is not so much a bug as an infelicity in the code that can easily be fixed. The initialize expression in the quasi family function is, (uniformly for all links and all variance functions): initialize <- expression({ n <- rep.int(1, nobs) mustart <- y + 0.1 * (y == 0) }) This is inappropriate (and often fails) for variance function "mu(1-mu)".
2007 Jul 02
2
termplot with uniform y-limits
Does anyone have, or has anyone ever considered making, a version of 'termplot' that allows the user to specify that all plots should have the same y-limits? This seems a natural thing to ask for, as the plots share a y-scale. If you don't have the same y-axes you can easily misread the comparative contributions of the different components. Notes: the current version of termplot
2007 Jul 02
2
termplot with uniform y-limits
Does anyone have, or has anyone ever considered making, a version of 'termplot' that allows the user to specify that all plots should have the same y-limits? This seems a natural thing to ask for, as the plots share a y-scale. If you don't have the same y-axes you can easily misread the comparative contributions of the different components. Notes: the current version of termplot
2010 May 04
3
Idiomatic looping over list name, value pairs in R
Considering the python code: for k, v in d.items(): do_something(k); do_something_else(v) I have the following for R: for (i in c(1:length(d))) { do_something(names(d[i])); do_something_else(d[[i]]) } This does not seem seems idiomatic. What is the best way of doing the same with R? Thanks. Luis