ple[i, 5] == "B") {
samplemod[i,j] <- switch(sample[i,j], AA = 0,
AB = 1, BA = 1, BB = 2)
}
}
}
}
}
--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4
g of all the values in the row. You seem to be coding as if i was
> a
> single integer (as in a for loop).
>
> --
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 778
Hello,
Your data.frame is composed exclusively of factors, but try this
(I've changed the name to 'sampl', because 'sample' is an R function.)
# logical index vectors
iA <- sampl$AorB == "A"
iB <- sampl$AorB == "B"
new.sampl <- data.frame(
apply(sampl, 2, function(x){
i
May 16, 2012 3:08 AM
> To: r-help@r-project.org
> Subject: [R] Help needed for efficient way to loop through rows and
> columns
>
> Dear R-helpers:
>
> I am trying to write a script that iterates through a dataframe that
> looks
> like this:
>
>
> Example datas
Dear R-helpers:
I am trying to write a script that iterates through a dataframe that looks
like this:
Example dataset called "sample":
names <- c("S1", "S2", "S3", "S4")
X <- c("BB", "AB", "AB", "AA")
Y <- c("BB", "BB", "AB", "AA")
Z <- c("BB", "BB", "AB", NA)
AorB <- c("A", "A", "A", "B")
sam
5 matches
Mail list logo