Data frame challenge [🇷 for BE/BA]
Hi Mittyri,
❝ !grepl("[-]?[0-9]+[.]?[0-9]*|[-]?[0-9]+[L]?|[-]?[0-9]+[.]?[0-9]*[eE][0-9]+",x), 0))})
❝ isnotnumeric <- !grepl("[-]?[0-9]+[.]?[0-9]*|[-]?[0-9]+[L]?|[-]?[0-9]+[.]?[0-9]*[eE][0-9]+",x)
❝ # we need to replace them with 0
❝ replaced0 <- replace(x, isnotnumeric, 0)
❝ # and to convert it all to numeric
❝ return(as.numeric(replaced0))
My eyes! My eyes! It hurts.

❝ A=read.table("SomeFile.csv", header=T, stringsAsFactors = F, sep=",")
❝ apply(A, 2, function(x){
❝ !grepl("[-]?[0-9]+[.]?[0-9]*|[-]?[0-9]+[L]?|[-]?[0-9]+[.]?[0-9]*[eE][0-9]+",x), 0))})
❝
❝ But more readable would be
❝ A=read.table("SomeFile.csv", header=T, stringsAsFactors = F, sep=",")
❝ checkandreplace <- function(x){
❝ isnotnumeric <- !grepl("[-]?[0-9]+[.]?[0-9]*|[-]?[0-9]+[L]?|[-]?[0-9]+[.]?[0-9]*[eE][0-9]+",x)
❝ # we need to replace them with 0
❝ replaced0 <- replace(x, isnotnumeric, 0)
❝ # and to convert it all to numeric
❝ return(as.numeric(replaced0))
❝ }
❝ apply(A, 2, checkandreplace)
My eyes! My eyes! It hurts.


—
Pass or fail!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- Data frame challenge ElMaestro 2016-12-17 19:40
- Data frame challenge mittyri 2016-12-18 01:41
- Data frame challengeElMaestro 2016-12-18 11:47
- Data frame challenge wligtenberg 2016-12-19 14:29
- Data frame challenge zizou 2016-12-19 18:41
- Data frame challenge ElMaestro 2016-12-19 21:06
- Data frame challenge mittyri 2016-12-18 01:41