Re: [R] NA Replacement by lowest value?
Joel Fürstenberg-Hägg wrote: Hi all, I need to replace missing values in a matrix by 10 % of the lowest available value in the matrix. I've got a function I've used earlier to replace negative values by the lowest value, in a data frame, but I'm not sure how to modify it... nonNeg = as.data.frame(apply(orig.df, 2, function(col) # Change negative values to a small value, close to zero { min.val = min(col[col 0]) col[col 0] = (min.val / 10) col # Column index })) I think this is how to start, but the NA replacement part doesn't work... newMatrix = as.matrix(apply(oldMatrix, 2, function(col) { min.val = min(mData, na.rm = T) # Find the smallest value in the dataset col[col == NA] = (min.val / 10) # Doesn't work... use is.na(col) t find the NA's. cheers, Paul col # Column index } Does any of you have any suggestions? Best regards, Joel _ Hitta kärleken i vinter! http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NA Replacement by lowest value?
Thanks a lot Paul!! Best, Joel Date: Thu, 28 Jan 2010 10:48:37 +0100 From: p.hiems...@geo.uu.nl To: joel_furstenberg_h...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] NA Replacement by lowest value? Joel Fürstenberg-Hägg wrote: Hi all, I need to replace missing values in a matrix by 10 % of the lowest available value in the matrix. I've got a function I've used earlier to replace negative values by the lowest value, in a data frame, but I'm not sure how to modify it... nonNeg = as.data.frame(apply(orig.df, 2, function(col) # Change negative values to a small value, close to zero { min.val = min(col[col 0]) col[col 0] = (min.val / 10) col # Column index })) I think this is how to start, but the NA replacement part doesn't work... newMatrix = as.matrix(apply(oldMatrix, 2, function(col) { min.val = min(mData, na.rm = T) # Find the smallest value in the dataset col[col == NA] = (min.val / 10) # Doesn't work... use is.na(col) t find the NA's. cheers, Paul col # Column index } Does any of you have any suggestions? Best regards, Joel _ Hitta kärleken i vinter! http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul _ Hitta hetaste singlarna på MSN Dejting! http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NA Replacement by lowest value?
On 01/28/2010 08:35 PM, Joel Fürstenberg-Hägg wrote: Hi all, I need to replace missing values in a matrix by 10 % of the lowest available value in the matrix. I've got a function I've used earlier to replace negative values by the lowest value, in a data frame, but I'm not sure how to modify it... nonNeg = as.data.frame(apply(orig.df, 2, function(col) # Change negative values to a small value, close to zero { min.val = min(col[col 0]) col[col 0] = (min.val / 10) col # Column index })) I think this is how to start, but the NA replacement part doesn't work... newMatrix = as.matrix(apply(oldMatrix, 2, function(col) { min.val = min(mData, na.rm = T) # Find the smallest value in the dataset col[col == NA] = (min.val / 10) # Doesn't work... col # Column index } Does any of you have any suggestions? Hi Joel, You probably want to use: col[is.na(col)]-min.val/10 Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NA Replacement by lowest value?
Hi Jim, That's what Pauls suggested too, works great! Best, Joel Date: Thu, 28 Jan 2010 20:57:57 +1100 From: j...@bitwrit.com.au To: joel_furstenberg_h...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] NA Replacement by lowest value? On 01/28/2010 08:35 PM, Joel Fürstenberg-Hägg wrote: Hi all, I need to replace missing values in a matrix by 10 % of the lowest available value in the matrix. I've got a function I've used earlier to replace negative values by the lowest value, in a data frame, but I'm not sure how to modify it... nonNeg = as.data.frame(apply(orig.df, 2, function(col) # Change negative values to a small value, close to zero { min.val = min(col[col 0]) col[col 0] = (min.val / 10) col # Column index })) I think this is how to start, but the NA replacement part doesn't work... newMatrix = as.matrix(apply(oldMatrix, 2, function(col) { min.val = min(mData, na.rm = T) # Find the smallest value in the dataset col[col == NA] = (min.val / 10) # Doesn't work... col # Column index } Does any of you have any suggestions? Hi Joel, You probably want to use: col[is.na(col)]-min.val/10 Jim _ Hitta kärleken i vinter! http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.