Using R Nested IfElse statements to compare two variable strings -


sample input data (stored in csv in working directory):

emplid,from_deptcode,fromdept,to_deptcode,to_dept,transactiontypecode,transactiontype,effectivedate,changetype 0239583290,21,sales,43,customerservice,10,promotion,12/12/2012 1230495829,21,sales,21,sales,10,promotion,9/1/2013 4059503918,93,operations,93,operations,13,demotion,11/18/2014 3040593021,19,headquarters,23,international,11,reorg,12/13/2011 7029406920,15,marketing,84,development,19,reassignment,1/5/2010 2039052819,19,headquarters,19,headquarters,10,promotion,4/15/2015 

code:

transfers <- read.csv(file="transfers.csv", head=true, sep=",",colclasses=c(na,na,na,na,na,na,na,"date",na))  transfers$changetype <- ifelse(transfers$from_deptcode == transfers$to_deptcode, "no change", ifelse(transfers$transactiontype == "reorg", "reorg", "transfer"))   transfers2 <- subset(transfers, changetype != "no change")  print(transfers2) 

expected output:

emplid,from_deptcode,fromdept,to_deptcode,to_dept,transactiontypecode,transactiontype,effectivedate,changetype 0239583290,21,sales,43,customerservice,10,promotion,12/12/2012,transfer 3040593021,19,headquarters,23,international,11,reorg,12/13/2011,reorg 7029406920,15,marketing,84,development,19,reassignment,1/5/2010,transfer 

actual:

> print(transfers2) error in print(transfers2) : object 'transfers2' not found 

at loss why occurring.

so found issue..

in order code work, had place cursor @ end of line of each block of code , run them individually in order.

i skipping bottom of script , putting cursor below last line of code , running , getting error.

why necessary me run each block of code 1 @ time cursor in block itself?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -