Hi
now you omitted data, but never mind :-)
▾ Quoted text (23 lines)
My loop is the following
counter = 0
for (i in 1:nrow(y))
{
for (j in 1:ncol(y))
{
if (y[i,j]=="Func_0005634") {
counter = counter + 1 }
if(y[i,j]=="Func_0005737"){
counter = counter + 1 }
if(y[i,j]=="Func_0005515"){
counter = counter + 1 }
}
if(counter == 3 ){
cat(y[i,1], file = "foo.csv", "\n")
}
counter = 0
}
If I remember correctly you want to inspect each row if it contains any of
"Func" values and how many of them.
structure(list(prot = c(1, 2, 3, 4), X1 = structure(c(1L, 1L,
1L, 2L), .Label = c("a", " "), class = "factor"), X2 = structure(c(3L,
2L, 3L, 3L), .Label = c("a", "b", " "), class = "factor"), X3 =
structure(c(3L,
3L, 3L, 2L), .Label = c("b", "c", " "), class = "factor"), X4 =
structure(c(1L,
1L, 1L, 3L), .Label = c("c", "d", " "), class = "factor"), X5 =
structure(c(2L,
1L, 1L, 1L), .Label = c("d", " "), class = "factor")), .Names = c("prot",
"X1", "X2", "X3", "X4", "X5"), row.names = c(NA, 4L), class =
"data.frame")
So
▾ Quoted text (1 line)
rowSums((y=="a") | (y=="b") | (y=="d"))
1 2 3 4
1 3 2 1
gives you number of values (a,b,d) in each row.
Your construction comes from some differnt programming world.
Regards
Petr
▾ Quoted text (14 lines)
and after read.table("foo.csv")
I get
V1
1 45
which is the last result
why does it overwrite? how can I have all the results?
Eager to a reply from you!
--
View this message in context:
http://r.789695.n4.nabble.com/Writing-to-a-
▾ Quoted text (3 lines)
file-tp3070617p4364149.html
Sent from the R help mailing list archive at Nabble.com.
▾ Mailing list footer
______________________________________________
R-help at 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
▾ Mailing list footer
and provide commented, minimal, self-contained, reproducible code.
Message-ID:
<OFB077042F.0DF13C34-ONC125799E.00264FB4-C125799E.002820DC@precheza.cz>
In-Reply-To:
<1328606295498-4364149.post@n4.nabble.com>