[R] What am I doing wrong with sapply ?

eric ericstrom at aol.com
Thu May 26 06:49:04 CEST 2011


Statement 9 using sapply does not seem to give the correct answer (or at
least to me). Yet I do what I think is the same thing with statement 11 and
I get the answer I'm looking for. 

9 : s <-sapply(unlist(v[c(1:length(v))]), max)
11: for(i in 1 :length(v)) v1[i] <- max(unlist(v[i]))

Shouldn't I get the same answer ? 


library(XML)
rm(list=ls())
url <-
"http://webapp.montcopa.org/sherreal/salelist.asp?saledate=05/25/2011"
tbl <-data.frame(readHTMLTable(url))[2:404, c(3,5,6,8,9)]
names(tbl) <- c("Address", "Township", "Parcel", "SaleDate", "Costs");
rownames(tbl) <- c(1:length(tbl[,1]))
x <-tbl
v <- gregexpr("( aka )|( AKA )",x$Address)
s <-sapply(unlist(v[c(1:length(v))]), max)
v1 <-numeric(length(v))
for(i in 1 :length(v)) v1[i] <- max(unlist(v[i]))

--
View this message in context: http://r.789695.n4.nabble.com/What-am-I-doing-wrong-with-sapply-tp3551598p3551598.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list