Dear sir/madam, I tried to recode some complex multiple variables and run into a problem that r can change only some column that I want to change. I can reproduce the problem with this idfortest <- c(6,23,46,63,200,238,297,321,336,364,386,392,414,434,441) id <- seq(1:500) id[id==idfortest] the result showed Warning in id == idfortest : longer object length is not a multiple of shorter object length [1] 200 386 434 can you enlighten me for this, thank you in advance. Regards, Wisarut [[alternative HTML version deleted]]
you probably want to use %in%:> idfortest <- c(6,23,46,63,200,238,297,321,336,364,386,392,414,434,441) > id <- seq(1:500) > id[id %in% idfortest][1] 6 23 46 63 200 238 297 321 336 364 386 392 414 434 441 take a look at what 'id == idfortest' gives; study up on the recycling of arguments. On Thu, Aug 18, 2011 at 5:52 AM, Rut S <wissri at hotmail.com> wrote:> > Dear sir/madam, > > I tried to recode some complex multiple variables and run into a problem that > r can change only some column that I want to change. > > I can reproduce the problem with this > > idfortest <- c(6,23,46,63,200,238,297,321,336,364,386,392,414,434,441) > id <- seq(1:500) > id[id==idfortest] > > the result showed > Warning in id == idfortest : > ?longer object length is not a multiple of shorter object length > [1] 200 386 434 > > can you enlighten me for this, thank you in advance. > > Regards, > Wisarut > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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?
On Aug 18, 2011, at 5:52 AM, Rut S wrote:> > Dear sir/madam, > > I tried to recode some complex multiple variables and run into a > problem that > r can change only some column that I want to change. > > I can reproduce the problem with this > > idfortest <- c(6,23,46,63,200,238,297,321,336,364,386,392,414,434,441) > id <- seq(1:500) > id[id==idfortest] > > the result showed > Warning in id == idfortest : > longer object length is not a multiple of shorter object length > [1] 200 386 434 > > can you enlighten me for this, thank you in advance.What is the puzzle? Seems that the warning is fairly clear. "id" is nto the same length as "idfortest". Is your confusion about how "==" works or about how argument recycling operates in the situation where arguemtns have unequal lengths? -- David Winsemius, MD West Hartford, CT
On Thu, Aug 18, 2011 at 04:52:58PM +0700, Rut S wrote:> I tried to recode some complex multiple variables and run into a problem that > r can change only some column that I want to change. > > I can reproduce the problem with this > > idfortest <- c(6,23,46,63,200,238,297,321,336,364,386,392,414,434,441) > id <- seq(1:500) > id[id==idfortest] > > the result showed > Warning in id == idfortest : > longer object length is not a multiple of shorter object length > [1] 200 386 434 > > can you enlighten me for this, thank you in advance.Others have already pointed out what the problem is. I'd like to add that you are probablyu looking for the %in% operator. cu Philipp