[R] Select certain elements from dataframe
Petr PIKAL
petr.pikal at precheza.cz
Tue May 20 10:58:40 CEST 2008
Hi
r-help-bounces at r-project.org napsal dne 20.05.2008 10:25:00:
>
> First of all thank you very much, that helped a lot!
>
> Now I have another related problem, again I want to limit a dataframe on
> certain elements, the dataframe looks like this:
> > colnames(sd_all)
> [1] "X" "mydata.a"
> [3] "mydata.x" "mydata.sd.a"
> .
> .
> .
> [13] "mydata.mad.x" "snr"
>
> X denotes the identifier and I want to select all rows which identifiers
are
> in a cluster.
> >clusterX
> [1] 101KF4319097339 102KF4319101170 103KF4319047549 104KF4319046389
> [5] 125KF4319063638 126KF4319102180 127KF4319107122 128KF4319019607
> .
> .
> .
> [125] 795KS4242028634 797KS4242032582 798KS4242035374
> 127 Levels: 101KF4319097339 102KF4319101170 103KF4319047549 ...
> 798KS4242035374
>
> I tried :
> >sd_all_clusterX<-sd_all[as.character(clusterX),]
Maybe you want %in% function
sd_all_clusterX<-sd_all[clusterX%in%sd_all$X),] # not tested
Regards
Petr
>
> but that results in all colums being NA. for example:
> >sd_all_clusterX[8]
> NA NA
> NA.1 NA
> NA.2 NA
> NA.3 NA
> .
> .
> NA.126 NA
>
> Again help would be very much appreciated,
>
> Sebastian
>
>
>
>
>
>
> jholtman wrote:
> >
> > 'xx1' is a 'factor' and you have to convert to a character before
> > selecting:
> >
> > data.xx1<-data[ ,as.character(xx1)]
> >
> > On Mon, May 19, 2008 at 5:20 AM, SebastianEck <sebastianeck at web.de>
wrote:
> >
> >>
> >> Hello,
> >>
> >> I have a specific problem, I have a large dataframe, and after
clustering
> >> I
> >> want to select certain colums, the elements of a subcluster.
> >>
> >> My dataframe looks like this :
> >>
> >> > colnames(data)
> >> [1] "101KF4319097339" "102KF4319101170" "103KF4319047549"
> >> "104KF4319046389"
> >> [5] "105KF4319013260" "106KF4319025582" "107KF4319108763"
> >> "108KF4319047040"
> >> [9] "109KF4319060241" "110KF4319056658" "111KF4319036131"
> >> "112KF4319097194"
> >> .
> >> .
> >> .
> >> [701] "821KS4242126913" "822KS4242026026" "823KS4242003122"
"824IHT06020"
> >> [705] "825IHT06020" "826IHT06005" "827IHT06005"
> >>
> >> My subcluster looks like this
> >>
> >> > xx1
> >> xx1
> >> [1] 101KF4319097339 102KF4319101170 103KF4319047549 104KF4319046389
> >> [5] 125KF4319063638 126KF4319102180 127KF4319107122 128KF4319019607
> >> [9] 135KF4319037854 138KF4319050003 140KF4319069150 152KF4319109279
> >> .
> >> .
> >> .
> >> [125] 795KS4242028634 797KS4242032582 798KS4242035374
> >> 127 Levels: 101KF4319097339 102KF4319101170 103KF4319047549 ...
> >> 798KS4242035374
> >>
> >> Now I want to select all elements from data that are in xx1, I tried
> >>
> >> >data.xx1<-data[ ,xx1]
> >>
> >> but that selects the just the first 127 (127 is the number of
elements /
> >> length from xx1) elements from data.
> >>
> >> Any help would be very appreciated :)
> >>
> >> Sebastian
> >> --
> >> View this message in context:
> >>
http://www.nabble.com/Select-certain-elements-from-dataframe-tp17314209p17314209.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> ______________________________________________
> >> 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<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 you are trying to solve?
> >
> > [[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.
> >
> >
>
> --
> View this message in context:
http://www.nabble.com/Select-certain-elements-
> from-dataframe-tp17314209p17335609.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list