r - Assign value to a column from another column based on condition -


Say I have a list like this:

  & gt; Desired & lt; - c ("10001", "10004")   

and such a sample data frame:

  & gt; , 10020), CBSA = c (Representative ("New York", 20): -; desired_sample_df & lt data.frame (ground = representative ("other", 30), zip = c (delegate (10001: 10010, 2) , 10011 Representative ("CA", 10))) & gt; desired_sample_df Geo zip CBSA 1 other 10001 New York 2 Other 10002 New York 3 Other 10003 New York 4 Other 10004 New York 5 Other 10005 New York 6 Other 10006 New York 7 Other 10007 New York 8 Other 10008 New York 9 Other 10009 New York 10 Other 10010 New York 11 Other 10001 New York 12 Other 10002 New York 13 Other 10003 New York A 14 Other 10004 New York 15 Other 10005 New York 16 Other 10006 New York 17 Other 10007 New York 18 Other 10008 New York 19 Other 10009 New York 20 Other 10010 New York 21 Other 10011 CA 22 Other 10012 CA 23 Other 10013 CA 24 Other 10014 CA 25 Other 10015 CA 26 Other 10016 CA 27 Other 10017 CA 28 Other 10018 CA 29 Other 10019 CA 30 Other 10020 CA  GO  want to overwrite the column I with zip if a value of zip only  desired < / Code> starts in the list Land.  

Here's what I've tried:

  & gt; Desired_sample_df $ Geo [desired_sample_df% $ zip% desired] & lt; --wanted_sample_df $ zip warning message [which is% desired (desired_sample_df $ zip%)]: `[& lt; $ Factor = (`* tmp *`, desired_sample_df.% In% zip, value = c (NA ,: invalid factor level, NA generate & gt; wanted_sample_df $ geo & lt [% wanted desired_sample_df $ zip%] ; - desired_sample_df $ zip warning messages: 1: `in [[LT; -factor` (` * * TMP * ', desired_common_df $ zip %% desired, value = C (NA,: invalid factor level, NA generated 2: ` [& Lt; - Factor * (`* tmp * ', desired in the desired_common_df $ zip%, value = c (na,: the length of the replacement is not a tribute    < P> 

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -