I am a novice R user & have reviewed related questions on the site. Although the title of my question has been asked before I am experiencing some additional issues that I am unable to solve.
I was able to successfully use R console to make a boxplot with data I imported via .csv that includes some NA values (using boxplot(Test)
), where Test is the name of my data and includes 3 columns of data with labels with 20 data points each.
But when I tried to calculate mean (by using: mean(Test)
or try to add it to the successfully made boxplot (by using: abline(v=mean(Test)
) it gave me the following warning message:
Warning message:
In mean.default(Test) : argument is not numeric or logical: returning NA
Now when I tried: sapply(Test, mean, na.rm = TRUE)
, I did get the correct results but they were followed by the warning message:
Warning message:
In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
All the right calculations comes out when using: Summary (Test)
without any warning messages. I am confused as to what the issue is? Any advice would really help please! thank you
UPDATE2: Thank you for the answer below, worked well.
UPDATE1:
Thank you to those who helped below - using colMeans(Test, na.rm=TRUE)
returns the means for all my columns. However, is it possible to add the mean as a point for each individual column of data into a boxplot of all the data (i.e. all three columns)? Using abline(v=colMeans(Test))
only adds a single line into the whole plot.
Additional Info:
When I use: class(Test)
it returns:
[1] "data.frame"
Also I checked the type of my data (apologies if I am using any incorrect words) using sapply(Test, mode)
and it returns "numeric" for all 3 columns of my data.
Partial Dataset only
a b c
0.68 0.68 0.68
0.28 0.28 0.28
0.62 0.62 0.62
0.73 0.73 0.73