How to delete columns if there is'nt enough data?

조회 수: 6 (최근 30일)
Gerrit Liedtke
Gerrit Liedtke 2018년 5월 7일
편집: Ameer Hamza 2018년 5월 7일
Hi,
I want to delete some columns of my data if there are less than 13 observations in it. If I would use rmmissing and 'MinNumMissing' then the column would be deleted if there are 13 values missing.
Thanks for help.
  댓글 수: 3
Gerrit Liedtke
Gerrit Liedtke 2018년 5월 7일
I have NaN when a observation is missing
Bob Thompson
Bob Thompson 2018년 5월 7일
편집: Bob Thompson 2018년 5월 7일
I would suggest using a for loop with an if statement that looks for nan values.
for k = 1:size(data,2);
if sum(~isnan(data(:,k)))<13;
data = [data(:,1:k-1),data(:,k+1:end)];
end
end
You would need to have some check for first and last rows, but that should get you started on what I was thinking about.

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

답변 (2개)

David Fletcher
David Fletcher 2018년 5월 7일
prunedData = rmmissing(dataMatrix,2,'MinNumMissing',13)

Ameer Hamza
Ameer Hamza 2018년 5월 7일
편집: Ameer Hamza 2018년 5월 7일
Do it as follow
data = data(:, sum(~isnan(data))>=13)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by