AK, I decided to convert your âwithâ statement back to index-by-number, and I did look up the ?with help info, but Iâm confused about my replacement code below. I got the wrong answer (R didnât apply the function to my column 1 variable âA_CaseIDâ). What am I doing wrong? Do I need to change my function code re: index â4â (otherwise known as âD_MW_EEsDueTotalâ --- my attempts at that have failed also)? thanks.
#this is your correct code > data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))])) # MW_EEsDue_ERRORS #1 1882 #2 1884 #3 1885 #these are my incorrect scripts > data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[4!=rowSums(cbind(2,3))])) # MW_EEsDue_ERRORS #1 1881 #2 1882 #3 1883 #4 1884 #5 1885 > data.frame(MW_EEsDue_ERRORS=with(dat3,dat3[[1]][4!=rowSums(cbind(2,3))])) # MW_EEsDue_ERRORS #1 1881 #2 1882 #3 1883 #4 1884 #5 1885 > data.frame(MW_EEsDue_ERRORS=with(dat3,1[4!=rowSums(cbind(2,3))])) # MW_EEsDue_ERRORS #1 1 Original database: dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885), B_MW_EEsDue1 = c(2, 2, 1, 4, 6), C_MW_EEsDue2 = c(5, 5, 4, 1, 6), D_MW_EEsDueTotal = c(7, 9, 5, 6, 112)) dat3 # A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal # 1 1881 2 5 7 # 2 1882 2 5 9 # 3 1883 1 4 5 # 4 1884 4 1 6 # 5 1885 6 6 112 From: arun kirshna [via R] [mailto:ml-node+s789695n4671365...@n4.nabble.com] Sent: Thursday, July 11, 2013 4:55 PM To: Crombie, Burnette N Subject: Re: create new matrix from user-defined function Hi BNC, No problem. You could also use ?with() data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))])) # MW_EEsDue_ERRORS #1 1882 #2 1884 #3 1885 A.K. -- View this message in context: http://r.789695.n4.nabble.com/create-new-matrix-from-user-defined-function-tp4671250p4671445.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.