[R] how use the subset?
jim holtman
jholtman at gmail.com
Fri Jul 31 13:57:50 CEST 2009
'scan' creates a 'list'; subset is typically used on dataframes. I
can get a similar message below:
> x <- list(a=1:10, b=1:10)
> subset(x, a<5)
Error in subset.default(x, a < 5) : object 'a' not found
> # now convert the list to a dataframe
> x.df <- as.data.frame(x)
> subset(x.df, a < 5)
a b
1 1 1
2 2 2
3 3 3
4 4 4
>
On Fri, Jul 31, 2009 at 12:02 AM, Jie TANG<totangjie at gmail.com> wrote:
> hi ,everyone
>
> I want subtract some dataset by subset.
>
> >From the help running help(subset), ths information is "*subset(airquality,
> Day == 1, select = -Temp)* "
>
>
>
> while I running my script written as "*g1data<-subset(errdata, fac>12) *"
> ,it is wrong with the error information "*subset.default(newerrdata,
> fac>12),can not find fac*"
>
>
> and g1 in read from the file as shown below
> *errdata<-scan("err.dat",what = list(mon=0,day=0,err=0,fac=0))*
>
> While I changed to *g1data<-subset(errdata, errdata$fac>12)*, there is no
> error message any more but it seems that *g1data* dooes be selected.
>
> who can help me to subset the dataset?
>
> thank you .:)
>
> --
> TANG Jie
> Email: totangjie at gmail.com
> Tel: 0086-2154896104
> Shanghai Typhoon Institute,China
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list