作为R的新手,正在学习R数据的导入。以前习惯用stata,所有数据都储存为stata格式。
stata的数据格式如下:
dh:int
gender:cha
age:int(出生年份)
希望统计出age的平均值
library(foreign)
rx<- read.dta("d:\stata\data1.dta")
str(rx)
> yr<-rx["age"]
> mean(yr)
[1] NA
Warning message:
In mean.default(yr) : argument is not numeric or logical: returning NA
> View(yr)
> str(yr)
'data.frame': 30140 obs. of 1 variable:
$ age: int 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 ...
> y1<-as.numeric(yr)
Error: (list) object cannot be coerced to type 'double'
求教各位大牛,改如何解决这个问题?谢谢!