Re: [R] creating dummy variables based on conditions

2013-07-14 Thread Anup Nandialath
--- > From: Anup Nandialath > To: r-help@r-project.org > Cc: > Sent: Sunday, July 14, 2013 7:30 AM > Subject: [R] creating dummy variables based on conditions > > Hello everyone, > > I have a dataset which includes the first three variables from the demo > data below (yea

Re: [R] creating dummy variables based on conditions

2013-07-14 Thread arun
   0 A.K. - Original Message - From: Anup Nandialath To: r-help@r-project.org Cc: Sent: Sunday, July 14, 2013 7:30 AM Subject: [R] creating dummy variables based on conditions Hello everyone, I have a dataset which includes the first three variables from the demo data below (year, id and

Re: [R] creating dummy variables based on conditions

2013-07-14 Thread Rui Barradas
Hello, Your data seems to be of class 'matrix'. The following code needs it to be a data.frame. dat <- as.data.frame(your input matrix) res <- do.call(rbind, lapply(split(dat, list(dat$id, dat$year)), function(x){ x$ans <- if(any(x$var == 1)) 1 else 0 x})) rownames(res) <- N

[R] creating dummy variables based on conditions

2013-07-14 Thread Anup Nandialath
Hello everyone, I have a dataset which includes the first three variables from the demo data below (year, id and var). I need to create the new variable ans as follows If var=1, then for each year (where var=1), i need to create a new dummy ans which takes the value of 1 for all corresponding id'

Re: [R] creating dummy variables

2013-04-20 Thread Santosh
R is for dummies (like me, but I don't use dummy variables) or for the non-Dummies like all experts who help us all the time@@.. so dummy variables are not needed! :) QED... On Sat, Apr 20, 2013 at 6:16 PM, Rolf Turner wrote: > On 21/04/13 10:56, Eva Prieto Castro wrote: > >> Hi, >> >> Why do y

Re: [R] creating dummy variables

2013-04-20 Thread Rolf Turner
On 21/04/13 10:56, Eva Prieto Castro wrote: Hi, Why do you write that dummy variables are not needed in R?. I would like you explain it. As others have said --- do some self-study. But a brief answer is that in any "reasonable" modelling problem in which dummy variables might arise, R crea

Re: [R] creating dummy variables

2013-04-20 Thread Bert Gunter
iables are not needed in R?. I would like > you explain it. > > Thanks, > > Eva > > --- El *dom, 21/4/13, David Winsemius * escribió: > > > De: David Winsemius > Asunto: Re: [R] creating dummy variables > Para: "Bert Gunter" > CC: "r-help@R-p

Re: [R] creating dummy variables

2013-04-20 Thread David Winsemius
avid Winsemius escribió: > > De: David Winsemius > Asunto: Re: [R] creating dummy variables > Para: "Bert Gunter" > CC: "r-help@R-project.org" , "shyam basnet" > > Fecha: domingo, 21 de abril, 2013 00:38 > > > On Apr 20, 2

Re: [R] creating dummy variables

2013-04-20 Thread Eva Prieto Castro
Hi, Why do you write that dummy variables are not needed in R?. I would like you explain it. Thanks, Eva --- El dom, 21/4/13, David Winsemius escribió: De: David Winsemius Asunto: Re: [R] creating dummy variables Para: "Bert Gunter" CC: "r-help@R-project.org" , &q

Re: [R] creating dummy variables

2013-04-20 Thread David Winsemius
On Apr 20, 2013, at 2:03 PM, Bert Gunter wrote: > Dummy variables are not needed in R. > > Bert > Bert is correct on this point, but if you what to know how the regression functions in R do this "behind the scenes" then you could always look at: ?model.matrix # where _some_ of the the au

Re: [R] creating dummy variables

2013-04-20 Thread Patrick Coulombe
Hello Shyam, if your data is stored in variable "dataset", for example, the following code will create the desired dummy-coded variables and attach them to the dataset: ## #init vars SWHE=BARL <- vector(length=nrow(dataset)) SWHE[]=BARL[] <- 0 #initialize dummy-coded vars wi

Re: [R] creating dummy variables

2013-04-20 Thread Bert Gunter
Dummy variables are not needed in R. Bert Sent from my iPhone -- please excuse typos. On Apr 20, 2013, at 11:23 AM, shyam basnet wrote: > Hello R-users, > > The below is a snippet of my data: > > > fid crop year value > 5_1_1 SWHE 1995 171 > 5_1_1 SWHE 1997 696 > 5_1_1

[R] creating dummy variables

2013-04-20 Thread shyam basnet
Hello R-users,   The below is a snippet of my data:   fid crop year value 5_1_1 SWHE 1995 171 5_1_1 SWHE 1997 696 5_1_1 BARL 1996 114 5_1_1 BARL 1997 344 5_2_2 SWHE 1995 120 5_2_2 SWHE 1996 511 5_2_2 BARL 1996 239 5_2_2 BARL 1997 349   Here,

Re: [R] Creating dummy variables in r

2013-01-30 Thread peter dalgaard
On Jan 30, 2013, at 04:58 , Bert Gunter wrote: > You almost never need dummy variables in R. R creates them > automatically from factors given model and possibly contrasts > specification. > > ?contrasts ## for some technical details. > > If you have not read "An Introduction to R" do so now.

Re: [R] Creating dummy variables in r

2013-01-29 Thread Bert Gunter
You almost never need dummy variables in R. R creates them automatically from factors given model and possibly contrasts specification. ?contrasts ## for some technical details. If you have not read "An Introduction to R" do so now. Pay particular attention to the chapter on modeling and categor

[R] Creating dummy variables in r

2013-01-29 Thread Joseph Norman Thomson
Hello, Semi-new r user here and still learning the ropes. I am creating dummy variables for a dataset on stock prices in r. One dummy variable is called prev1 and is: prev1 <- ifelse(ret1 >= .5, 1, 0) where ret1 is the previous day's return. The variable "prev1" is created fine and works in my

Re: [R] Creating dummy variables

2010-06-03 Thread Bert Gunter
AM To: bt_jan...@yahoo.de; r-help@r-project.org Subject: Re: [R] Creating dummy variables hey thanks I did solve it already, it had more mistakes as you see :S bye Arantzazu Blanco Bernardeau Dpto de Qummica Agrmcola, Geologma y Edafologma Universidad de Murcia-Campus de Espinardo > D

Re: [R] Creating dummy variables

2010-06-03 Thread Arantzazu Blanco Bernardeau
i]>=3.3){datos$cambi[i]=1}else{0} > > } > > --- Arantzazu Blanco Bernardeau schrieb am Do, > 3.6.2010: > > > Von: Arantzazu Blanco Bernardeau > > Betreff: [R] Creating dummy variables > > An: r-help@r-project.org > > Datum: Donnerstag, 3. Juni, 2010 1

Re: [R] Creating dummy variables

2010-06-03 Thread Jannis
(i in > 1:length(datos$cambi)){if(datos$codsuelo[i]>=3.1 > && > datos$codsuelo[i]>=3.3){datos$cambi[i]=1}else{0} > } --- Arantzazu Blanco Bernardeau schrieb am Do, 3.6.2010: > Von: Arantzazu Blanco Bernardeau > Betreff: [R] Creating dummy variables > An: r-he

[R] Creating dummy variables

2010-06-03 Thread Arantzazu Blanco Bernardeau
Hello R project I am a R beginner trying to create a dummy variable to clasificate soil types. So, I have a column in my database called codtipo (typecode in english) where soil type is coded as 1.1 to 1.4 arenosol (I have 4 types) 2.1 to 2.3 calcisols 4.1 to 4.4 fluvisols and so on To make dum

Re: [R] Creating Dummy Variables in R

2009-12-16 Thread Tom Fletcher
om: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of whitaker m. (mw1006) Sent: Wednesday, December 16, 2009 8:59 AM To: r-help@r-project.org Subject: [R] Creating Dummy Variables in R Hi, I am trying to create a set of dummy variables to use within a multiple linear

Re: [R] Creating Dummy Variables in R

2009-12-16 Thread Achim Zeileis
On Wed, 16 Dec 2009, whitaker m. (mw1006) wrote: Hi, I am trying to create a set of dummy variables to use within a multiple linear regression and am unable to find the codes within the manuals. For example i have: Price Weight Clarity IF VVS1VVS2 5

Re: [R] Creating Dummy Variables in R

2009-12-16 Thread S Devriese
On 12/16/2009 03:58 PM, whitaker m. (mw1006) wrote: > Hi, > I am trying to create a set of dummy variables to use within a multiple > linear regression and am unable to find the codes within the manuals. > > For example i have: > Price Weight Clarity > IF

[R] Creating Dummy Variables in R

2009-12-16 Thread whitaker m. (mw1006)
Hi, I am trying to create a set of dummy variables to use within a multiple linear regression and am unable to find the codes within the manuals. For example i have: Price Weight Clarity IF VVS1VVS2 5008 1 0 0 1000