Hello I have a dataset named "b2" with 1521 rows, in that dataset i have 64 rows containing specific information. the rownumbers with specific info are: + i [1] 22 53 104 127 151 196 235 238 249 250 263 335 344 353 362 370 389 422 458 459 473 492 502 530 561 624 647 651 666 671 [31] 715 784 791 807 813 823 830 841 862 865 1036 1051 1062 1068 1092 1109 1171 1187 1283 1293 1325 1335 1342 1360 1379 1414 1419 1425 1447 1452 [61] 1465 1489 1512 1518 So what i want is that everytime the rownumber equals a number in "i" (which obviously indicate a rownumber i b2), i want it indicated in a vector called b2$totalvac. Fx. in rownumber 22 in b2 the b2$totalvac vector should have the value 1. So thougth of b2$totalvac <- ifelse(,1,0), but i don't what to put as the "if"-sentence. Hope you can help me -- View this message in context: http://www.nabble.com/Use-of-ifelse-for-indicating-specific-rownumber-tp22098418p22098418.html Sent from the R help mailing list archive at Nabble.com.
I think you are looking for something like: ifelse(1:nrow(b2) %in% i, 1, 0) Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") joe1985 wrote:> Hello > > I have a dataset named "b2" with 1521 rows, in that dataset i have 64 rows > containing specific information. > > the rownumbers with specific info are: > > + i > [1] 22 53 104 127 151 196 235 238 249 250 263 335 344 353 > 362 370 389 422 458 459 473 492 502 530 561 624 647 651 666 > 671 > [31] 715 784 791 807 813 823 830 841 862 865 1036 1051 1062 1068 > 1092 1109 1171 1187 1283 1293 1325 1335 1342 1360 1379 1414 1419 1425 1447 > 1452 > [61] 1465 1489 1512 1518 > > So what i want is that everytime the rownumber equals a number in "i" (which > obviously indicate a rownumber i b2), i want it indicated in a vector called > b2$totalvac. Fx. in rownumber 22 in b2 the > b2$totalvac vector should have the value 1. > > So thougth of b2$totalvac <- ifelse(,1,0), but i don't what to put as the > "if"-sentence. > > Hope you can help me >
why use ifelse? Shouldn't b2$totalvac<-rep(0,1521) b2$totalvac[i]<-1 do the trick? joe1985 schrieb:> Hello > > I have a dataset named "b2" with 1521 rows, in that dataset i have 64 rows > containing specific information. > > the rownumbers with specific info are: > > + i > [1] 22 53 104 127 151 196 235 238 249 250 263 335 344 353 > 362 370 389 422 458 459 473 492 502 530 561 624 647 651 666 > 671 > [31] 715 784 791 807 813 823 830 841 862 865 1036 1051 1062 1068 > 1092 1109 1171 1187 1283 1293 1325 1335 1342 1360 1379 1414 1419 1425 1447 > 1452 > [61] 1465 1489 1512 1518 > > So what i want is that everytime the rownumber equals a number in "i" (which > obviously indicate a rownumber i b2), i want it indicated in a vector called > b2$totalvac. Fx. in rownumber 22 in b2 the > b2$totalvac vector should have the value 1. > > So thougth of b2$totalvac <- ifelse(,1,0), but i don't what to put as the > "if"-sentence. > > Hope you can help me >-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790