I was reading the book 'Data Mining with R' and came across this code:
library(DMwR)
clean.algae <- knnImputation(algae, k = 10)
x <- sapply(names(clean.algae)[12:18],
function(x,names.attrs) {
f <- as.formula(paste(x,"~ ."))
dataset(f,clean.algae[,c(names.attrs,x)],x)
},
names(clean.algae)[1:11])
I thought x
could be rewritten as:
y <- sapply(names(clean.algae)[12:18],
function(x) {
f <- as.formula(paste(x,"~ ."))
dataset(f,clean.algae[,c(names(clean.algae)[1:11],x)],x)
}
)
However, identical(x,y)
returns FALSE
.
I decided to investigate why by restricting my attention to just the first element these lists.
I found that:
identical(attributes(x[[1]])$data,
attributes(y[[1]])$data)
[1] FALSE
However:
which(!(attributes(x[[1]])$data == attributes(y[[1]])$data))
integer(0)
Which to me means all elements in the data frame are equal, hence the two data frames must be identical. Why is this not the case?
I also have similar question for the object's formula attribute:
> identical(attributes(x[[1]])$formula,
+ attributes(y[[1]])$formula)
[1] FALSE
>
> attributes(x[[1]])$formula == attributes(y[[1]])$formula
[1] TRUE