Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c() malfunction?

Tags:

r

Not sure what I am doing wrong here, and would appreciate any assistance.

Trying to make a new variable named "control" and coding it 1 when the row variable is equal to these numbers, and 0 when it is not.

data$control= ifelse (data$row==c(146, 297, 313, 171, 262, 233, 292, 304, 264, 228, 279,      
281, 290, 277, 152, 161, 250, 263, 245,  83,  67, 101,  98, 251, 148, 155, 322, 265, 
159, 271, 278, 289, 274, 282, 158, 196, 154, 260, 163, 307, 272, 299, 300, 273, 167, 
286, 149, 316, 147, 162, 178), 1, 0)

It makes a new variable named "control" but only codes it as 1 for row=149 and row=264. I really cannot figure this out.

Thanks for the help, Chris

like image 959
Chris Grady Avatar asked Jan 23 '26 10:01

Chris Grady


1 Answers

You mean to use %in% rather than ==:

data$control= ifelse (data$row %in% c(146, 297, 313, 171, 262, 233, 292, 304, 264, 228, 279, 281, 290, 277, 152, 161, 250, 263, 245, 83, 67, 101, 98, 251, 148, 155, 322, 265, 159, 271, 278, 289, 274, 282, 158, 196, 154, 260, 163, 307, 272, 299, 300, 273, 167, 286, 149, 316, 147, 162, 178), 1, 0)
like image 112
David Robinson Avatar answered Jan 25 '26 17:01

David Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!