Group Abstract Group Abstract

Message Boards Message Boards

0
|
348 Views
|
8 Replies
|
4 Total Likes
View groups...
Share
Share this post:
GROUPS:

Unable to use TransformMissing to fill missing data with data from another column

Posted 19 days ago

Suppose I have the following table:

tab1 = Tabular[ 
  {    {"001", , 2, 3}, {"002", 4, 5, 6}, {"003", , 6, 7}, {"004", 8, 
    9, 10}, {"005", 8, 9, 11}, {"006", 8, 6, 10} },
   {"ID", "num1", "num2", "num3"}  ]

I simply want to complete the missing numbers in column "num1" with the values in column "num2" I did something like this:

TransformMissing[  tab1, "num1" -> {#num2}  ]

But didn't work.
I also tried:

TransformColumns[  tab1, 
 "num4" -> Function[  If[  MissingQ[#"num1"], "a", #"num1"   ]  ]
 ]

It didn't work either.
Any suggestions?

8 Replies

I am attaching some rows of the data

Posted 19 days ago

Great! And you do have Missing elements. Now, what's the rule you want to use to transform the missing items?

POSTED BY: Eric Rimbey

I want to replace missing Lat and Long with coordenadasy and coordenadasx

Posted 19 days ago

This works for me (assign your tabular data to the symbol example):

TransformColumns[
  example, 
  {"Lat" -> (If[MissingQ[#Lat], #"coordenadas_y", #Lat] &), 
   "Long" -> (If[MissingQ[#Long], #"coordenadas_x", #Long] &)}]

Your data had actual Missing items in it, so I'm using MissingQ instead of comparing to Null.

POSTED BY: Eric Rimbey

Yes!!! It works. Thank you very much Eric. I was doing something similar, but somehow I didn't manage to make it work.

Posted 19 days ago

In Mathematica, "missing" usually refers to an expression with head Missing. In an expression like {"001", , 2, 3}, no elements match Missing (which you can check with MissingQ /@ {"001", , 2, 3}. The second element of {"001", , 2, 3} is actually Null. You could transform each Null to Misssing[], but I actually don't think that will help you here. I don't use Tabular much, so I could be wrong, but the documentation for TransformMissing looks like it can only reference other items in the same column, not the same row.

But you can use TransformColumns like this:

TransformColumns[tab1, "num1" -> (If[Null === #num1, #num2, #num1] &)]
POSTED BY: Eric Rimbey

Thank you Eric. My actual table is very large and has a lot of missing values. I tried TransformColumns the way you put it, but didn't work :(

Posted 19 days ago

Show me one row from your data.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard