简体   繁体   中英

argument is not numeric or logical: returning NA`

I have a Column of a Excelfile

> str(Hausarbeit_f)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   42 obs. of  15 variables:
 $ ...1 : num  125 122 140 146 129 137 150 142 156 144 ...
 $ ...2 : num  83 77 88 81 82 80 94 91 93 81 ...
 $ ...3 : num  68 73 63 61 65 63 62 71 64 68 ...
 $ ...4 : num  146 142 132 136 144 126 130 125 135 142 ...
 $ ...5 : num  88 84 89 82 88 80 84 80 82 91 ...
 $ ...6 : num  71 74 65 73 75 86 86 72 81 84 ...
 $ ...7 : num  146 132 134 132 147 134 154 125 121 139 ...
 $ ...8 : num  83 86 80 80 80 88 90 74 79 82 ...
 $ ...9 : num  70 72 76 77 68 80 78 100 84 91 ...
 $ ...10: num  131 133 125 127 118 135 140 136 118 140 ...
 $ ...11: num  81 85 73 76 77 78 90 82 82 76 ...
 $ ...12: num  72 63 64 73 74 86 79 81 77 87 ...
 $ ...13: num  86.8 86.4 86.1 87 86.2 85.8 86.9 85.8 85.4 86 ...
 $ ...14: num  0 0 0 0 0 0 0 0 0 0 ...
 $ ...15: chr  "Montag" "Dienstag" "Mittwoch" "Donnerstag" ...

and want to calculate the mean of it. "b" is the column number 5

 > str(b)
    List of 1
     $ Dia...5: num [1:42] 88 84 89 82 88 80 84 80 82 91 ...
    > mean(b)
    [1] NA
    Warning:
    In mean.default(b) : 
    argument is not numeric or logical: returning NA`
    

I tried to transform the column to, either a vector or dataframe, but it didnt work

If Hausarbeit_f is your dataframe and b is the column of your interest then try:

mean(Hausarbeit_f$b)

or

mean(as.numeric(Hausarbeit_f$b))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM