Hi,
One alternative would be to change colnames:

colnames(dat3)<-1:4

 data.frame(MW_EEsDue_ERRORS=with(dat3,`1`[`4`!=rowSums(cbind(`2`,`3`))]))
  #MW_EEsDue_ERRORS
#1             1882
#2             1884
#3             1885


Also, check these:
with(dat3,4)
#[1] 4
 with(dat3,`4`)
#[1]   7   9   5   6 112
with(dat3,7)
#[1] 7
 with(dat3,`7`)
#Error in eval(expr, envir, enclos) : object '7' not found


A.K.

----- Original Message -----
From: bcrombie <bcrom...@utk.edu>
To: r-help@r-project.org
Cc: 
Sent: Friday, July 12, 2013 4:45 PM
Subject: Re: [R] create new matrix from user-defined function

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.


______________________________________________
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.

Reply via email to