On Mon, Jun 8, 2009 at 8:56 PM, Mao Jianfeng wrote:
> Dear Ruser's
>
> I ask for helps on how to substitute missing values (NAs) by mean of the
> group it is belonging to.
>
> my dummy dataframe is:
>
>> df
> group traits
> 1 BSPy01-10 NA
> 2 BSPy01-10 7.3
> 3 BSPy01-10 7.3
> 4
Dear Mao,
Here is another way:
yourdata$traits2 <- with(yourdata, do.call(c, tapply(traits, group,
function(y){
ym <-
mean(y,na.rm=TRUE)
y[is.na(y)]<- ym
On Jun 8, 2009, at 9:56 PM, Mao Jianfeng wrote:
Dear Ruser's
I ask for helps on how to substitute missing values (NAs) by mean of
the
group it is belonging to.
my dummy dataframe is:
df
group traits
1 BSPy01-10 NA
2 BSPy01-107.3
3 BSPy01-107.3
4 BSPy01-115.3
5
Try this:
d$traits[is.na(d$traits)] <- ave(d$traits,
d$group,
FUN=function(x)mean(x,
na.rm = T))[is.na(d$traits)]
On 6/8/09, Mao Jianfeng wrote:
> Dear Ruser's
>
> I ask for helps on how to substitute missing
Dear Ruser's
I ask for helps on how to substitute missing values (NAs) by mean of the
group it is belonging to.
my dummy dataframe is:
> df
group traits
1 BSPy01-10 NA
2 BSPy01-107.3
3 BSPy01-107.3
4 BSPy01-115.3
5 BSPy01-115.4
6 BSPy01-115.6
7 BSPy01-11
5 matches
Mail list logo