I have a question with using strsplit with laaply function. I'm using titanic dataset and wants to split name by ",","." and extract "Mr", "Mrs" and so on.
I tried this code and gives me error
lapply(data$Name, strsplit(data$Name, split = "[,.]")[[1]][2])
Error in get(as.character(FUN), mode = "function", envir = envir) : object ' Mr' of mode 'function' was not found
However, this code works
lapply(data$Name, function(x)strsplit(x, split = "[,.]")[[1]][2])
[[995]] [1] " Mr" ...
I don't know what's the difference between those two..