Error : the argument is neither numerical nor logical: return of NA
1
0
Entering edit mode
2.5 years ago
Bioinfo ▴ 20

I have a data in CSV format that contains 45 columns ( variables ) and 320 lines

The first column is the samples names and second column is group where sample belong

i imported the data in R using the followning command : data <- read.csv("C:/Users/ut/Desktop/Doctorat_Perpignan/R/MYDATA.csv", row.names = 1, sep=";")

when i wanted to calculate the mean using the following command : mean(data)

i obtained this error : Warning message: In mean.default(data_1) : the argument is neither numerical nor logical: return of NA

how can i solve this error please ?

also i wanted to calculate the the mean of all columns except the first and second columns using the following command : colMeans(data_1[ , 2:45]) , but i obtained the mean of each column and not the mean of all columns

Can you help me please to czlculate the mean of this data, Thank you

R Statistics Mean • 1.2k views
ADD COMMENT
0
Entering edit mode
2.5 years ago
ATpoint 81k

The base function mean expects a vector, not a data.frame. You will need to use apply to go over rows or columns, e.g. rowwise mean would be:

apply(your_df, 1, mean)

For the mean of all values in the object you could do something like:

mean(unlist(c(your_object)))
ADD COMMENT
0
Entering edit mode

Thank you for your answers, but i still get same error msg ! (the argument is neither numerical nor logical: return of NA)

maybe there's something wrong with recognizing the data ?!

ADD REPLY
0
Entering edit mode

The function expects that all cells are populated either by numbers or true/false values (numerical or logical). There is something in your data frame that is neither numerical nor logical, which is why you get the error. It is not a big dataset, you should be able to catch it by visually inspecting the file.

ADD REPLY
0
Entering edit mode

Yes i have two columns which are , name of variables and second one is the group of variable , that's why i wanted to calculate mean of columns from 2 to 45

ADD REPLY
0
Entering edit mode

Add some data please, input and expected output. Right now this is not reproducible.

ADD REPLY

Login before adding your answer.

Traffic: 2524 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6