Hi Cassie, I'm not sure exactly what you are trying to get: i assume that each station will have a different ppt value for each year-month combination, but it looks like you're trying to get one ppt value for each station.
Steve On Thu, Jul 28, 2011 at 1:30 AM, Wilson, Cassandra J <cwil...@ku.edu> wrote: > I am having a hard time putting the below into a loop, where it pulls out ppt > from all he stations I have versus having to go through and hard code the > data to the specific stations. I tried > stnID <- stnid[which(duplicated(stnid)==FALSE)] > for(i in 1:length(stnID)) > { > ppt[i] <- ppt[which(stnid==[i])] > } > > but it doesn't like to use the which function inside a for loop? Any idea's > here is a sample of my code... thanks-Cassie > > ### label data ### > stnid <- dat1[,1] #list of stations > lat <- dat1[,2] #latitude of station > lon <- dat1[,3] #longitude of station > year <- dat1[,4] # data year > month <- dat1[,5] #data month > ppt <- dat2 #precipiation data > > > #### station's missing zero years ### > ppt2 <- matrix(ppt[,which(stnid == '140365')],ncol=1) > year2 <- year[which(stnid == '140365')] > year2 <- year2[which(duplicated(year2) == FALSE)] > month2 <- month[which(stnid == '140365')] > > ppt3 <- matrix(ppt[,which(stnid == '140405')],ncol=1) > year3 <- year[which(stnid == '140405')] > year3 <- year3[which(duplicated(year3) == FALSE)] > month3 <- month[which(stnid == '140405')] > > ______________________________________________ > 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.