Skip to content

Invalid Type of Char Argument When Sum() is Used

2 messages · Gundala Viswanath, jim holtman

#
Hi all,

I have the following data

AAA  1e+06 1222.312
AAC  100.2  0.33

However the following command

dat <- read.table("mydat.txt");

print(dat)

n1 <- sum(as.matrix(dat$V1));

gives:
Error in sum(as.matrix(dat$V1)) : invalid 'type' (character) of argument


What's wrong with the data type so that it gives such error?


- Gundala Viswanath
Jakarta - Indonesia
#
Do an 'str(dat)' and see what the structure is.  When I read in your data I get:
V1        V2       V3
1 AAA 1000000.0 1222.312
2 AAC     100.2    0.330
'data.frame':   2 obs. of  3 variables:
 $ V1: Factor w/ 2 levels "AAA","AAC": 1 2
 $ V2: num  1000000 100
 $ V3: num  1222.31 0.33
Error in Summary.factor(1:2, na.rm = FALSE) :
  sum not meaningful for factors
[1] 1000100

So you 'V1" might be characters which is exactly what your error
message is telling you.
On Fri, Mar 13, 2009 at 4:37 AM, Gundala Viswanath <gundalav at gmail.com> wrote: