Quantcast

Count observation

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Count observation

Mestat
Hi listers,
I have the following code...

data<-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
n<-nrow(data)
m<-n-1
boot<-data[sample(m,replace=T),]

So, I need to count the number of times each observation was selected at the sample with replacement...
Suppose I sampled...
4 5 1 3 7 5 1 4 7

So, I would count...
x  count
1  2
2  0
3  1
4  2
5  2
6  0
7  2
8  0
9  0
10 0

Thanks in advance,
Marcio
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Count observation

milton ruser
Hi Marcio,

data.frame(table(boot))
?

milton
brazil=toronto
On Thu, Jun 11, 2009 at 3:13 PM, MarcioRibeiro <[hidden email]> wrote:

>
> Hi listers,
> I have the following code...
>
> data<-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
> n<-nrow(data)
> m<-n-1
> boot<-data[sample(m,replace=T),]
>
> So, I need to count the number of times each observation was selected at
> the
> sample with replacement...
> Suppose I sampled...
> 4 5 1 3 7 5 1 4 7
>
> So, I would count...
> x  count
> 1  2
> 2  0
> 3  1
> 4  2
> 5  2
> 6  0
> 7  2
> 8  0
> 9  0
> 10 0
>
> Thanks in advance,
> Marcio
> --
> View this message in context:
> http://www.nabble.com/Count-observation-tp23987251p23987251.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Count observation

Jorge I Velez
In reply to this post by Mestat
Dear Marcio,
Here is one way. Please notice that even thought I changed the name of your
data as well as its structure, you can easily modify it to your needs.

# Data
somedata <- 1:10
n<-length(somedata)
m<-n-1

# 1 sample
boot <- somedata[ sample(m,replace=T) ]
table(factor( boot, levels=1:10 ) )

# 100 samples
boots <- replicate(100, somedata[ sample(m,replace=T)] )

# The counts
apply(boots, 2, function(x) table(factor(x,levels=1:10)) )

see ?replicate, and ?apply for more information.

HTH,

Jorge



On Thu, Jun 11, 2009 at 3:13 PM, MarcioRibeiro <[hidden email]> wrote:

>
> Hi listers,
> I have the following code...
>
> data<-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
> n<-nrow(data)
> m<-n-1
> boot<-data[sample(m,replace=T),]
>
> So, I need to count the number of times each observation was selected at
> the
> sample with replacement...
> Suppose I sampled...
> 4 5 1 3 7 5 1 4 7
>
> So, I would count...
> x  count
> 1  2
> 2  0
> 3  1
> 4  2
> 5  2
> 6  0
> 7  2
> 8  0
> 9  0
> 10 0
>
> Thanks in advance,
> Marcio
> --
> View this message in context:
> http://www.nabble.com/Count-observation-tp23987251p23987251.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Count observation

Mestat
In reply to this post by milton ruser
Hey... Milton...
Is that a equation... Brazil=Toronto
If so, mine is... Brazil=Montreal
You got it...
I am not having a good time with R... There is no help for data manipulation at all...
Thanks for the help...
Marcio


milton ruser wrote
Hi Marcio,

data.frame(table(boot))
?

milton
brazil=toronto
On Thu, Jun 11, 2009 at 3:13 PM, MarcioRibeiro <mestat@pop.com.br> wrote:

>
> Hi listers,
> I have the following code...
>
> data<-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
> n<-nrow(data)
> m<-n-1
> boot<-data[sample(m,replace=T),]
>
> So, I need to count the number of times each observation was selected at
> the
> sample with replacement...
> Suppose I sampled...
> 4 5 1 3 7 5 1 4 7
>
> So, I would count...
> x  count
> 1  2
> 2  0
> 3  1
> 4  2
> 5  2
> 6  0
> 7  2
> 8  0
> 9  0
> 10 0
>
> Thanks in advance,
> Marcio
> --
> View this message in context:
> http://www.nabble.com/Count-observation-tp23987251p23987251.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Count observation

Henrique Dallazuanna
In reply to this post by Mestat
Try this also:

cbind(data, tabulate(boot, nbins=nrow(data)))

On Thu, Jun 11, 2009 at 4:13 PM, MarcioRibeiro <[hidden email]> wrote:

>
> Hi listers,
> I have the following code...
>
> data<-as.matrix(c(1,2,3,4,5,6,7,8,9,10),nrow=10,ncol=1,byrow=TRUE)
> n<-nrow(data)
> m<-n-1
> boot<-data[sample(m,replace=T),]
>
> So, I need to count the number of times each observation was selected at
> the
> sample with replacement...
> Suppose I sampled...
> 4 5 1 3 7 5 1 4 7
>
> So, I would count...
> x  count
> 1  2
> 2  0
> 3  1
> 4  2
> 5  2
> 6  0
> 7  2
> 8  0
> 9  0
> 10 0
>
> Thanks in advance,
> Marcio
> --
> View this message in context:
> http://www.nabble.com/Count-observation-tp23987251p23987251.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Loading...