Dear ALL:
I have two quick questions about how to perform some steps in R. Could you
please see the attached MS file if the data not clean enough in this email.
Thank you so much for all your helps.
Abou
Here it is:
========================
Consider the following matrix:
data<-matrix(c(2,2,12,2,1,10,10,4,10,1,1,2,2,1,2,10,3,1,1,1,3,5,17,23,9,9,3,3,15,5,
4,5,5,5,4,8,1,15,3,3,1,6,3,6,3,4,5,14,4,
0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0),49,2)
[,1] [,2]
[1,] 2 0
[2,] 2 0
[3,] 12 0
[4,] 2 0
[5,] 1 0
[6,] 10 1
[7,] 10 1
[8,] 4 0
[9,] 10 1
[10,] 1 1
[11,] 1 0
[12,] 2 1
[13,] 2 1
[14,] 1 0
[15,] 2 0
[16,] 10 1
[17,] 3 0
[18,] 1 1
[19,] 1 0
[20,] 1 0
[21,] 3 0
[22,] 5 1
[23,] 17 0
[24,] 23 0
[25,] 9 0
[26,] 9 0
[27,] 3 0
[28,] 3 0
[29,] 15 1
[30,] 5 1
[31,] 4 0
[32,] 5 1
[33,] 5 1
[34,] 5 1
[35,] 4 0
[36,] 8 0
[37,] 1 0
[38,] 15 0
[39,] 3 0
[40,] 3 0
[41,] 1 0
[42,] 6 0
[43,] 3 0
[44,] 6 0
[45,] 3 0
[46,] 4 0
[47,] 5 0
[48,] 14 0
[49,] 4 0
Q1. Column one is the data set, and column two is an indicator of 1 and 0. Some
values
in column one corresponding to indicator 1 in column two are different,
and some
are the same. There are 5 different groups of values in column one with
indicator 1
in column two.
(a) How I can choose only one value (only one observation) from each of these
groups to
develop a vector of length 5 as: (1 2 5 10 15).
(b) How I can find number of observations in each of these groups as a vector
as:
(2 2 5 4 1).
These are the values with indicator 1.
[,1] [,2]
[1,] 1 1
[2,] 1 1
[3,] 2 1
[4,] 2 1
[5,] 5 1
[6,] 5 1
[7,] 5 1
[8,] 5 1
[9,] 5 1
[10,] 10 1
[11,] 10 1
[12,] 10 1
[13,] 10 1
[14,] 15 1
====================
=========================AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
Tel: (207) 228-8389
Fax: (207) 780-5607
Email: aaboueissa at usm.maine.edu
aboueiss at yahoo.com
Office: 301C Payson Smith
At 23:07 01.03.2008, AbouEl-Makarim Aboueissa wrote:>Dear ALL: > >I have two quick questions about how to perform some steps in R. >Could you please see the attached MS file if the data not clean >enough in this email. > >Thank you so much for all your helps. > > >Abou > > > >Here it is: >========================> >Consider the following matrix: > >data<-matrix(c(2,2,12,2,1,10,10,4,10,1,1,2,2,1,2,10,3,1,1,1,3,5,17,23,9,9,3,3,15,5, > 4,5,5,5,4,8,1,15,3,3,1,6,3,6,3,4,5,14,4, > >0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0, > 0,0,0,0,0,0,0,0,0,0,0,0,0,0),49,2) > > > [,1] [,2] > [1,] 2 0 > [2,] 2 0 > [3,] 12 0 > [4,] 2 0 > [5,] 1 0 > [6,] 10 1 > [7,] 10 1 > [8,] 4 0 > [9,] 10 1 >[10,] 1 1 >[11,] 1 0 >[12,] 2 1 >[13,] 2 1 >[14,] 1 0 >[15,] 2 0 >[16,] 10 1 >[17,] 3 0 >[18,] 1 1 >[19,] 1 0 >[20,] 1 0 >[21,] 3 0 >[22,] 5 1 >[23,] 17 0 >[24,] 23 0 >[25,] 9 0 >[26,] 9 0 >[27,] 3 0 >[28,] 3 0 >[29,] 15 1 >[30,] 5 1 >[31,] 4 0 >[32,] 5 1 >[33,] 5 1 >[34,] 5 1 >[35,] 4 0 >[36,] 8 0 >[37,] 1 0 >[38,] 15 0 >[39,] 3 0 >[40,] 3 0 >[41,] 1 0 >[42,] 6 0 >[43,] 3 0 >[44,] 6 0 >[45,] 3 0 >[46,] 4 0 >[47,] 5 0 >[48,] 14 0 >[49,] 4 0 > > > > > >Q1. Column one is the data set, and column two is an indicator of 1 >and 0. Some values > in column one corresponding to indicator 1 in column two > are different, and some > are the same. There are 5 different groups of values in > column one with indicator 1 > in column two. > >(a) How I can choose only one value (only one observation) from each >of these groups to > develop a vector of length 5 as: (1 2 5 10 15). >table1 <- table(data[data[, 2]==1, 1]) as.numeric(dimnames(table1)[[1]]) [1] 1 2 5 10 15>(b) How I can find number of observations in each of these groups as >a vector as: > (2 2 5 4 1). >as.vector(table1) [1] 2 2 5 4 1 greetings Heinz>These are the values with indicator 1. > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > [3,] 2 1 > [4,] 2 1 > [5,] 5 1 > [6,] 5 1 > [7,] 5 1 > [8,] 5 1 > [9,] 5 1 >[10,] 10 1 >[11,] 10 1 >[12,] 10 1 >[13,] 10 1 >[14,] 15 1 > >====================> > > > > >=========================>AbouEl-Makarim Aboueissa, Ph.D. >Assistant Professor of Statistics >Department of Mathematics & Statistics >University of Southern Maine >96 Falmouth Street >P.O. Box 9300 >Portland, ME 04104-9300 > >Tel: (207) 228-8389 >Fax: (207) 780-5607 >Email: aaboueissa at usm.maine.edu > aboueiss at yahoo.com >Office: 301C Payson Smith > > > >______________________________________________ >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.
Try this:
data <- as.data.frame(data)
names(data) <- c('Data', 'Indicator')
a)
sort(unique(subset(data, Indicator == 1))[,1])
b) with(subset(data, Indicator == 1),
tapply(Indicator, Data, sum))
On 01/03/2008, AbouEl-Makarim Aboueissa <aaboueissa at usm.maine.edu>
wrote:> Dear ALL:
>
> I have two quick questions about how to perform some steps in R. Could you
> please see the attached MS file if the data not clean enough in this email.
>
> Thank you so much for all your helps.
>
>
> Abou
>
>
>
> Here it is:
> ========================>
> Consider the following matrix:
>
>
data<-matrix(c(2,2,12,2,1,10,10,4,10,1,1,2,2,1,2,10,3,1,1,1,3,5,17,23,9,9,3,3,15,5,
> 4,5,5,5,4,8,1,15,3,3,1,6,3,6,3,4,5,14,4,
> 0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0),49,2)
>
>
> [,1] [,2]
> [1,] 2 0
> [2,] 2 0
> [3,] 12 0
> [4,] 2 0
> [5,] 1 0
> [6,] 10 1
> [7,] 10 1
> [8,] 4 0
> [9,] 10 1
> [10,] 1 1
> [11,] 1 0
> [12,] 2 1
> [13,] 2 1
> [14,] 1 0
> [15,] 2 0
> [16,] 10 1
> [17,] 3 0
> [18,] 1 1
> [19,] 1 0
> [20,] 1 0
> [21,] 3 0
> [22,] 5 1
> [23,] 17 0
> [24,] 23 0
> [25,] 9 0
> [26,] 9 0
> [27,] 3 0
> [28,] 3 0
> [29,] 15 1
> [30,] 5 1
> [31,] 4 0
> [32,] 5 1
> [33,] 5 1
> [34,] 5 1
> [35,] 4 0
> [36,] 8 0
> [37,] 1 0
> [38,] 15 0
> [39,] 3 0
> [40,] 3 0
> [41,] 1 0
> [42,] 6 0
> [43,] 3 0
> [44,] 6 0
> [45,] 3 0
> [46,] 4 0
> [47,] 5 0
> [48,] 14 0
> [49,] 4 0
>
>
>
>
>
> Q1. Column one is the data set, and column two is an indicator of 1 and 0.
> Some values
> in column one corresponding to indicator 1 in column two are
> different, and some
> are the same. There are 5 different groups of values in column one
> with indicator 1
> in column two.
>
> (a) How I can choose only one value (only one observation) from each of
> these groups to
> develop a vector of length 5 as: (1 2 5 10 15).
>
>
>
>
> (b) How I can find number of observations in each of these groups as a
> vector as:
> (2 2 5 4 1).
>
>
>
>
>
>
>
>
>
>
>
> These are the values with indicator 1.
>
> [,1] [,2]
> [1,] 1 1
> [2,] 1 1
> [3,] 2 1
> [4,] 2 1
> [5,] 5 1
> [6,] 5 1
> [7,] 5 1
> [8,] 5 1
> [9,] 5 1
> [10,] 10 1
> [11,] 10 1
> [12,] 10 1
> [13,] 10 1
> [14,] 15 1
>
> ====================>
>
>
>
>
> =========================> AbouEl-Makarim Aboueissa, Ph.D.
> Assistant Professor of Statistics
> Department of Mathematics & Statistics
> University of Southern Maine
> 96 Falmouth Street
> P.O. Box 9300
> Portland, ME 04104-9300
>
> Tel: (207) 228-8389
> Fax: (207) 780-5607
> Email: aaboueissa at usm.maine.edu
> aboueiss at yahoo.com
> Office: 301C Payson Smith
>
>
>
--
Henrique Dallazuanna
Curitiba-Paran?-Brasil
25? 25' 40" S 49? 16' 22" O
Dear ALL:
How I can find the number of observations less than each value in column one
with indicator 1 in column two. Please see the data below.
For example: number of observations less than 1 with indicator 1 (including
those 1 with indicator 1) =2
number of observations less than 2 with indicator 1
(including those 2 with indicator 1) =11
number of observations less than 5 with indicator 1
(including those 5 with indicator 1) =33
number of observations less than 10 with indicator 1
(including those 10 with indicator 1) =43
number of observations less than 15 with indicator 1
(including those 15 with indicator 1) =46
(1, 2,5,10,15) are the values in column one with indicator 1 in column two.
which means I need to create a vector(2,11,33,43,46) for the data in column one.
With many thanks.
Abou
Here is the data:
==========
Consider the following matrix:
data<-matrix(c(2,2,12,2,1,10,10,4,10,1,1,2,2,1,2,10,3,1,1,1,3,5,17,23,9,9,3,3,15,5,
4,5,5,5,4,8,1,15,3,3,1,6,3,6,3,4,5,14,4,
0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0),49,2)
[,1] [,2]
[1,] 2 0
[2,] 2 0
[3,] 12 0
[4,] 2 0
[5,] 1 0
[6,] 10 1
[7,] 10 1
[8,] 4 0
[9,] 10 1
[10,] 1 1
[11,] 1 0
[12,] 2 1
[13,] 2 1
[14,] 1 0
[15,] 2 0
[16,] 10 1
[17,] 3 0
[18,] 1 1
[19,] 1 0
[20,] 1 0
[21,] 3 0
[22,] 5 1
[23,] 17 0
[24,] 23 0
[25,] 9 0
[26,] 9 0
[27,] 3 0
[28,] 3 0
[29,] 15 1
[30,] 5 1
[31,] 4 0
[32,] 5 1
[33,] 5 1
[34,] 5 1
[35,] 4 0
[36,] 8 0
[37,] 1 0
[38,] 15 0
[39,] 3 0
[40,] 3 0
[41,] 1 0
[42,] 6 0
[43,] 3 0
[44,] 6 0
[45,] 3 0
[46,] 4 0
[47,] 5 0
[48,] 14 0
[49,] 4 0
=========================AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
Tel: (207) 228-8389
Fax: (207) 780-5607
Email: aaboueissa at usm.maine.edu
aboueiss at yahoo.com
Office: 301C Payson Smith
Dear Ellison:
it did not do it.
I edited my previous email to make my question more clear.
The out put should be: (2,11,33,43,46)
For example:
number of all observations less than 1 with indicator 1 (including those 1 with
indicator 1 but not 1 with indicator 0) =2
number of all observations less than 2 with indicator 1 (including those 2 with
indicator 1 but not 2 with indicator 0) =11
number of all observations less than 5 with indicator 1 (including those 5 with
indicator 1 but not 5 with indicator 0) =33
number of all observations less than 10 with indicator 1 (including those 10
with indicator 1 but not 10 with indicator 0) =43
number of all observations less than 15 with indicator 1 (including those 15
with indicator 1 but not 15 with indicator 0) =46
(1, 2,5,10,15) are the values in column one with indicator 1 in column two.
which means I need to create a vector(2,11,33,43,46) for the data in column one.
=========================AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
Tel: (207) 228-8389
Fax: (207) 780-5607
Email: aaboueissa at usm.maine.edu
aboueiss at yahoo.com
Office: 301C Payson Smith
>>> "S Ellison" <S.Ellison at lgc.co.uk> 3/3/2008 10:36
AM >>>
table(data[data[,2]==1,1])
>>> "AbouEl-Makarim Aboueissa" <aaboueissa at
usm.maine.edu> 03/03/2008
15:20:21 >>>
Dear ALL:
How I can find the number of observations less than each value in
column one with indicator 1 in column two. Please see the data below.
For example: number of observations less than 1 with indicator 1
(including those 1 with indicator 1) =2
number of observations less than 2 with indicator 1
(including those 2 with indicator 1) =11
number of observations less than 5 with indicator 1
(including those 5 with indicator 1) =33
number of observations less than 10 with indicator
1 (including those 10 with indicator 1) =43
number of observations less than 15 with indicator
1 (including those 15 with indicator 1) =46
(1, 2,5,10,15) are the values in column one with indicator 1 in column
two.
which means I need to create a vector(2,11,33,43,46) for the data in
column one.
With many thanks.
Abou
Here is the data:
==========
Consider the following matrix:
data<-matrix(c(2,2,12,2,1,10,10,4,10,1,1,2,2,1,2,10,3,1,1,1,3,5,17,23,9,9,3,3,15,5,
4,5,5,5,4,8,1,15,3,3,1,6,3,6,3,4,5,14,4,
0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0),49,2)
[,1] [,2]
[1,] 2 0
[2,] 2 0
[3,] 12 0
[4,] 2 0
[5,] 1 0
[6,] 10 1
[7,] 10 1
[8,] 4 0
[9,] 10 1
[10,] 1 1
[11,] 1 0
[12,] 2 1
[13,] 2 1
[14,] 1 0
[15,] 2 0
[16,] 10 1
[17,] 3 0
[18,] 1 1
[19,] 1 0
[20,] 1 0
[21,] 3 0
[22,] 5 1
[23,] 17 0
[24,] 23 0
[25,] 9 0
[26,] 9 0
[27,] 3 0
[28,] 3 0
[29,] 15 1
[30,] 5 1
[31,] 4 0
[32,] 5 1
[33,] 5 1
[34,] 5 1
[35,] 4 0
[36,] 8 0
[37,] 1 0
[38,] 15 0
[39,] 3 0
[40,] 3 0
[41,] 1 0
[42,] 6 0
[43,] 3 0
[44,] 6 0
[45,] 3 0
[46,] 4 0
[47,] 5 0
[48,] 14 0
[49,] 4 0
=========================AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
Tel: (207) 228-8389
Fax: (207) 780-5607
Email: aaboueissa at usm.maine.edu
aboueiss at yahoo.com
Office: 301C Payson Smith
______________________________________________
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.
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}