EnginO
EnginO

Reputation: 341

Using Mean Function for a specified part of column of a matrix in R

I am very new to R Programming,

I am triyng to calculate the mean of z[1] and keeping 70=<z[2]<=72 by the way

z[1] includes NA s.

I try this

 mean([z[1]!is.na(z[1])]& 70 =<z[2]<= 72)

but does not work.

If you help me , I would really appreciate.

Thanks

Upvotes: 0

Views: 43

Answers (1)

akrun
akrun

Reputation: 887183

I guess you need

mean(z[,1][70 <= z[,2] & z[,2] <= 72], na.rm=TRUE)

data

set.seed(45)
z <- matrix(sample(c(NA,70:80), 5*10, replace=TRUE), ncol=5, nrow=10)

Upvotes: 2

Related Questions