How to find NaN in a cell of type table then delete the entire row

조회 수: 18 (최근 30일)
Hi there,
If anyone can help me out please that would be greatly appreciated. I have this huge data that consist of 20k rows and 75 columns in excel (.csv). But I created a small working file which looks like this.
sampleFile2.PNG
As seen, there are NaN values in this data table. So what I want to do is:
  • go through the data and locate all the NaN values.
  • if a row contains at least 1 NaN in the cell, I want to store the whole row to another list.
  • once its gone through the list, I want to create a function that deletes the listed rows at the same time.
At the end, Im hoping to not see rows that contains any NaN values in any cell. is this possible? I have been trying to figure it out for the past couple weeks. tried bits and pieces from different solutions. nothing just seems to work. it would be greatly appreciated if anyone out there knows. PLEASE.
  댓글 수: 2
madhan ravi
madhan ravi 2019년 1월 7일
편집: madhan ravi 2019년 1월 7일
attach your data as .mat file or .xlsx file
Andrea Del Rosario
Andrea Del Rosario 2019년 1월 7일
my raw data comes out as (.csv) file so I have attached the excel file here.

댓글을 달려면 로그인하십시오.

채택된 답변

madhan ravi
madhan ravi 2019년 1월 7일
편집: madhan ravi 2019년 1월 7일
Try the below example:
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 NaN; 122 80];
T = table(Age,Smoker,Height,Weight,BloodPressure);
T=T{:,:}; % adapt this to your data
T(~any(isnan(T),2),:) % adapt this to your data
  댓글 수: 9
Luna
Luna 2019년 1월 7일
unique function may help you on this but how will you decide which duplicate you want to remove or keep?
Andrea Del Rosario
Andrea Del Rosario 2019년 1월 7일
I was thinking as you can see there is a 'TestTime' in my set of data. the last time stamp determines that it's the unique row I want to keep! Would you be able to guide me on this?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by