Hi all, I'm working to apply a function that will generate a matrix of results only when a specific criteria is met.
I want my final results to be a matrix with both the values that meet the criteria (the results of the function), and those that to do in the same positions in the matrix (the original numbers). Here's a sample of what I would like to do: t.mean.1.c <- c(-15, -20, -30, -20, -25, -35, -40, -8, 9, 10) cdem <- c(300, 400, 700, 900, 1000, 250, 200, 300, 500, 650, 650, 1200, 1400, 3200, 2000) cdem.mat <- matrix(NA, 10, 15) cdem.mat <- cdem.mat(sapply(cdem[which(cdem >= 900)], function(x) get("t.mean.1.c") - (x * -0.0065))) I want cdem.mat to be the same size as the the first call of it, with NA values where the cdem is < 899. I thought this would fill it in but it seems to just over write it and I only end up with the rows where cdem is greater than 900. Thank you, Katrina -- Katrina E. Bennett PhD Student University of Alaska Fairbanks International Arctic Research Center 930 Koyukuk Drive, PO Box 757340 Fairbanks, Alaska 99775-7340 907-474-1939 office 907-385-7657 cell kebenn...@alaska.edu Personal Address: UAF, PO Box 752525 Fairbanks, Alaska 99775-2525 bennett.katr...@gmail.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.