when I use Apply () comes up the following warning ? Anyone knows, please help

I conduct data cleaning and met a problem.

When I use apply(notypos[ , -c(1,3)], 2 mean,na.rm=T), it presented a warning ( In mean.default(newX[, i], ...) :
argument is not numeric or logical: returning NA)

When I use apply (notypos[ , -c(1,3)], 2, sd, na.rm=T), it presented a a warning but simuanteouly presented Std (In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion.

Hi, it is probably something to do with the error above. It would be best to provide a reproducible example of the notypos dataset though:

I use a 6-Likert scale, I want to calculate the mean of items excluding categorical variables

head(notypos[ , 6:56])

A tibble: 6 x 51

 F1    F2    F3    F4    F5    F6    F7    F8    F9   F10   F11   F12   F13   F14


1 4 4 5 5 5 5 5 4 4 4 4 4 4 4
2 5 5 5 4 4 5 5 6 6 6 6 6 5 4
3 2 3 5 2 2 4 2 2 2 4 3 4 3 3
4 4 3 4 4 3 3 4 4 4 3 4 4 3 2
5 2 2 5 4 2 5 5 4 2 4 4 4 4 5
6 5 5 5 5 5 5 4 4 4 4 5 4 4 4

Please give a fully reproducible code that can run standalone. Then only we can help you.
You can see this excellent documenation and read/see at liesure - it will be useful in future too.

1 Like
str(data_1)
#> Error in str(data_1): object 'data_1' not found

summary(data_1)
#> Error in summary(data_1): object 'data_1' not found


notypos <- data_1 
#> Error in eval(expr, envir, enclos): object 'data_1' not found

apply(notypos[, c("gender","grade","major")], 2,table)
#> Error in apply(notypos[, c("gender", "grade", "major")], 2, table): object 'notypos' not found


apply(notypos[,c("gender","grade")],2,table) 
#> Error in apply(notypos[, c("gender", "grade")], 2, table): object 'notypos' not found
 

summary(notypos)
#> Error in summary(notypos): object 'notypos' not found

summary(notypos$GPA)
#> Error in summary(notypos$GPA): object 'notypos' not found

notypos$GPA[notypos$GPA>4] <-NA
#> Error in notypos$GPA[notypos$GPA > 4] <- NA: object 'notypos' not found

summary(notypos$GPA)
#> Error in summary(notypos$GPA): object 'notypos' not found


names(notypos)
#> Error in eval(expr, envir, enclos): object 'notypos' not found

head(notypos[ , 6:56])
#> Error in head(notypos[, 6:56]): object 'notypos' not found

notypos[ , 6:56] [ notypos[ , 6:56] > 6] <- NA
#> Error in notypos[, 6:56][notypos[, 6:56] > 6] <- NA: object 'notypos' not found

summary(notypos)
#> Error in summary(notypos): object 'notypos' not found


names(notypos)
#> Error in eval(expr, envir, enclos): object 'notypos' not found

Created on 2022-04-17 by the reprex package (v2.0.1)

Here is my script

Just post the output of dput(notypos) or something like datapasta::dpasta(notypos).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.