[R] Aggregation across two variables in data.table

2017-12-13 Thread Michael Haenlein
Dear all, I have a data.frame that includes a series of demographic variables for a set of respondents plus a dependent variable (Theta). For example: AgeEducation Marital Familysize IncomeHousingTheta 1: 50 Ass

[R] change in behavior of c.trellis

2017-12-13 Thread Richard M. Heiberger
> library(latticeExtra) Loading required package: lattice Loading required package: RColorBrewer > t11 <- xyplot(1 ~ 1) > t11 > c(t11, t11) Warning message: In formals(fun) : argument is not a function > version _ platform x86_64-w64-mingw32 arch x86_64 os

Re: [R] match and new columns

2017-12-13 Thread William Dunlap via R-help
Try the following (which won't work with factors): > i <- match(tdat$B, tdat$A) > newColumns <- tdat[i, c("B", "C")] > newColumns[is.na(newColumns)] <- "0" > transform(tdat, D=newColumns[["B"]], E=newColumns[["C"]]) A B CY D E 1 A12 B03 C04 0.70 0 0 2 A23 B05 C06 0.05 0 0 3

Re: [R] match and new columns

2017-12-13 Thread Val
Hi Bill, I put stringsAsFactors = FALSE still did not work. tdat <- read.table(textConnection("A B C Y A12 B03 C04 0.70 A23 B05 C06 0.05 A14 B06 C07 1.20 A25 A23 A12 3.51 A16 A25 A14 2,16"),header = TRUE ,stringsAsFactors = FALSE) tdat$D <- 0 tdat$E <- 0 tdat$D <- (ifelse(tdat$B %in% tdat$A, td

Re: [R] match and new columns

2017-12-13 Thread William Dunlap via R-help
Use the stringsAsFactors=FALSE argument to read.table when making your data.frame - factors are getting in your way here. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Dec 13, 2017 at 3:02 PM, Val wrote: > Thank you Rui, > I did not get the desired result. Here is the output from your sc

Re: [R] match and new columns

2017-12-13 Thread Val
Thank you Rui, I did not get the desired result. Here is the output from your script A B CY D E 1 A12 B03 C04 0.70 0 0 2 A23 B05 C06 0.05 0 0 3 A14 B06 C07 1.20 0 0 4 A25 A23 A12 3.51 1 1 5 A16 A25 A14 2,16 4 4 On Wed, Dec 13, 2017 at 4:36 PM, Rui Barradas wrote: > Hello, > > Here i

Re: [R] match and new columns

2017-12-13 Thread Rui Barradas
Hello, Here is one way. tdat$D <- ifelse(tdat$B %in% tdat$A, tdat$A[tdat$B], 0) tdat$E <- ifelse(tdat$B %in% tdat$A, tdat$A[tdat$C], 0) Hope this helps, Rui Barradas On 12/13/2017 9:36 PM, Val wrote: Hi all, I have a data frame tdat <- read.table(textConnection("A B C Y A12 B03 C04 0.70 A2

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread MacQueen, Don
Because ifelse is not intended to be an alternative to if ... else. They exist for different purposes. (besides the other replies, a careful reading of their help pages, and trying the examples, should explain the different purposes). -- Don MacQueen Lawrence Livermore National Laboratory 7000

[R] match and new columns

2017-12-13 Thread Val
Hi all, I have a data frame tdat <- read.table(textConnection("A B C Y A12 B03 C04 0.70 A23 B05 C06 0.05 A14 B06 C07 1.20 A25 A23 A12 3.51 A16 A25 A14 2,16"),header = TRUE) I want match tdat$B with tdat$A and populate the column values of tdat$A ( col A and Col B) in the newly created columns

[R] running Cox regression model for 1000 markers

2017-12-13 Thread Ding, Yuan Chun
HI All, Sorry to bother you. I have a data matrix with 1000 genes in rows and 100 samples in columns; I need to run Cox regression model for each of the 1000 markers. I know how to run Cox regression model for individual marker. Does anyone know a R package or method to run Cox model for tho

Re: [R] Best R GUIs

2017-12-13 Thread Wensui Liu
how could you miss emacs + ess? On Wed, Dec 13, 2017 at 5:04 AM, Juan Telleria wrote: > Dear R Community Members, > > I would like to add to one article I have written the best Graphical User > Interfaces the R programming language has. > > For the moment I know: > A) Rstudio. > B) R Tools for V

Re: [R] Add vectors of unequal length without recycling?

2017-12-13 Thread William Michels via R-help
Maingo, See previous discussion below on rbind.na() and cbind.na() scripts: https://stat.ethz.ch/pipermail/r-help/2016-December/443790.html You might consider binding first then adding orthogonally. So rbind.na() then colSums(), OR cbind.na() then rowSums(). Best of luck, W Michels, Ph.D. O

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread Duncan Murdoch
On 13/12/2017 10:31 AM, Jinsong Zhao wrote: Hi there, I don't know why the following codes are return different results. > ifelse(3 > 2, 1:3, length(1:3)) [1] 1 > if (3 > 2) 1:3 else length(1:3) [1] 1 2 3 Any hints? The documentation in the help page ?ifelse and ?"if" explains it pretty

Re: [R] Add vectors of unequal length without recycling?

2017-12-13 Thread William Dunlap via R-help
Without recycling you would get: u <- c(10, 20, 30) u + 1 #[1] 11 20 30 which would be pretty inconvenient. (Note that the recycling rule has to make a special case for when one argument has length zero - the output then has length zero as well.) Bill Dunlap TIBCO Software wdunlap ti

Re: [R] [ESS] M-x R gives no choice of starting dir

2017-12-13 Thread Paul Johnson
If Emacs is not asking for starting directory, it is very likely your init file has this somewhere: (setq ess-ask-for-ess-directory nil) On Mon, Sep 11, 2017 at 3:23 PM, Enrico Schumann wrote: > On Mon, 11 Sep 2017, Christian writes: > >> Hi, >> >> I experienced a sudden change in the behavior

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread Eric Berger
ifelse returns the "shape" of the first argument In your ifelse the shape of "3 > 2" is a vector of length one, so it will return a vector length one. Avoid "ifelse" until you are very comfortable with it. It can often burn you. On Wed, Dec 13, 2017 at 5:33 PM, jeremiah rounds wrote: > ifel

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread jeremiah rounds
ifelse is vectorized. On Wed, Dec 13, 2017 at 7:31 AM, Jinsong Zhao wrote: > Hi there, > > I don't know why the following codes are return different results. > > > ifelse(3 > 2, 1:3, length(1:3)) > [1] 1 > > if (3 > 2) 1:3 else length(1:3) > [1] 1 2 3 > > Any hints? > > Best, > Jinsong > > _

[R] difference between ifelse and if...else?

2017-12-13 Thread Jinsong Zhao
Hi there, I don't know why the following codes are return different results. > ifelse(3 > 2, 1:3, length(1:3)) [1] 1 > if (3 > 2) 1:3 else length(1:3) [1] 1 2 3 Any hints? Best, Jinsong __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more

Re: [R] Best R GUIs

2017-12-13 Thread Juan Telleria
Thank you all, some of the best free IDEs are specified in the following article: http://www.linuxlinks.com/article/20110306113701179/GUIsforR.html Plus pluggable IDEs: A) ESS for Emacs B) IRkernel for Jupyter notebooks C) StatET for Eclipse D) Vim-R for vim Kind regards, Juan [[altern

Re: [R] Best R GUIs

2017-12-13 Thread Mehta, Gaurang
Hi Zahn, I thought Shiny package in R was the GUI equivalent for R applications. Tools such as Rstudio is an IDE (integrated development environment) to me. Regards, Gaurang Mehta -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ista Zahn Sent: 13 December

[R] overlay two histograms ggplot

2017-12-13 Thread Elahe chalabi via R-help
Hi all, How can I overlay these two histograms? ggplot(gg, aes(gg$Alz, fill = gg$veg)) + geom_histogram(alpha = 0.2) ggplot(tt, aes(tt$Cont, fill = tt$veg)) + geom_histogram(alpha = 0.2) thanks for any help! Elahe __ R-help@r-project.org mailing list

Re: [R] Best R GUIs

2017-12-13 Thread Ista Zahn
On Dec 13, 2017 6:05 AM, "Juan Telleria" wrote: Dear R Community Members, I would like to add to one article I have written the best Graphical User Interfaces the R programming language has. For the moment I know: A) Rstudio. B) R Tools for Visual Studio. C) Open Analytics Architect. Many edi

[R] Best R GUIs

2017-12-13 Thread Juan Telleria
Dear R Community Members, I would like to add to one article I have written the best Graphical User Interfaces the R programming language has. For the moment I know: A) Rstudio. B) R Tools for Visual Studio. C) Open Analytics Architect. Are there others worth to mention? Thank you. Kind regard