Reputation: 23
I'm very new to r. How should I make r read dash(-) or skip it and calculate average of No. of plant(last column).
Genotype Rep No. of plant
184 1 8
7 1 7
98 1 -
101 2 7
X 2 8
62 2 -
24 3 3
30 3 4
78 3 8
119 3 8
Upvotes: 1
Views: 4772
Reputation: 893
There are several options.
gsub
to convert it to an NA
. For example gsub('-', NA, dat$'No. of plant', fixed=TRUE)
. (Use backticks instead of quotes). Then convert the data to numeric using as.numeric()
Below is an example:
dat=data.frame(Genotype=c(184, 7, 98, 101, 'X'),
Rep=c(1,1,1,2,2),
No=c(8,7,'-',7,8))
dat$No <- gsub('-',NA,dat$No,fixed=TRUE)
dat$No <- as.numeric(dat$No)
Upvotes: 1