Re: [R] Help needed for efficient way to loop through rows and columns

2012-05-17 Thread David L Carlson
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

Re: [R] Help needed for efficient way to loop through rows and columns

2012-05-16 Thread Priya Bhatt
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

Re: [R] Help needed for efficient way to loop through rows and columns

2012-05-16 Thread Rui Barradas
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

Re: [R] Help needed for efficient way to loop through rows and columns

2012-05-16 Thread David L Carlson
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

[R] Help needed for efficient way to loop through rows and columns

2012-05-16 Thread Priya Bhatt
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