Skip to content

replace some values of a column with diffrent values

2 messages · Pete Brecknock, PIKAL Petr

#
Hi Valerie

One way would be to use the match function.

# Your Data
u =data.frame(coe=c(0,0,0,0,0,0,0,0),
             
name=c("Time","Poten","AdvExp","Share","Change","Accounts","Work","Rating"))

v = data.frame(coeff=c(0.7272727,0.3211112,0.0500123),
               enter=c("Accounts","Time","Poten"))

# Match Function
updates = v[match(u$name,v$enter),"coeff"]
u$coe = ifelse(!is.na(updates), updates, u$coe)   

HTH

Pete


valerie wrote
--
View this message in context: http://r.789695.n4.nabble.com/replace-some-values-of-a-column-with-diffrent-values-tp4360035p4360249.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi

For such tasks I would use merge

 merge(u, v, by.x="name", by.y = "enter", all.x=TRUE)

If you do not want coe column anymore you can easily get rid of it.

Regards
Petr
name=c("Time","Poten","AdvExp","Share","Change","Accounts","Work","Rating"))
in v.
0.0000000
http://r.789695.n4.nabble.com/replace-some-
http://www.R-project.org/posting-guide.html