lundi 16 avril 2018

Running a ifelse() in lists

I have this list here:

structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6), Sepal.Width = c(3.5, 
3, 3.2, 3.1), Petal.Length = c(1.4, 1.4, 1.3, 1.5), Petal.Width = c(0.2, 
0.2, 0.2, 0.2), Species = structure(c(1L, 1L, 1L, 1L), .Label = c("setosa", 
"versicolor", "virginica"), class = "factor")), .Names = c("Sepal.Length", 
"Sepal.Width", "Petal.Length", "Petal.Width", "Species"), row.names = c(NA, 
4L), class = "data.frame")

I would like to change the symbols (* and .) to numbers (* to a 0 and . to a 1) inside each list.

Incidentally, if any thing else than a symbol comes up (like a letter), than I would like the list to print NA.

I've tried this, which doesn't change anything...

ifelse(board_split_vec == "*", 0, 
      ifelse(board_split_vec == ".", 1, board_split_vec))

Ideally, I have to find a way to do this using Base R functions..no packages please!

Aucun commentaire:

Enregistrer un commentaire