Thank you for your response
I have a vector of unknown values BZ which is defined already BZ=numeric(N)
and i want to transfer BZ to ordered categorical variable with 4
categories W but when i write this code
for(j in 1:1){
if(BZ[j] < 0.25){
W[j] = 1
}else if(BZ[j] >=0.25 & BZ[j] < 0.5){
W[j] = 2
}else if(BZ[j] >=0.5 & BZ[j] < 0.75){
W[j] = 3
}else{
W[j] = 4
}}
i found the values of W are only 0, but if i change for(j in 1:N) the
values of W will be only 1. how can i solve this problem?
Regards
On 4 November 2015 at 06:35, Boris Steipe <boris.steipe at utoronto.ca>
wrote:
> Why don't you just multiply by four, round, and add one?
>
>
>
> B.
> On Nov 3, 2015, at 10:02 PM, thanoon younis <thanoon.younis80 at
gmail.com>
> wrote:
>
> > Dear R-users
> >
> > I have a problem in the code below, the problem is because i want to
> change
> > the variable BZ which is a vector with 200x1 dimension to the var. W
> which
> > is categorical variable with same dimension of BZ but with categorical
> > values with 4 categories but i got on only zero values in w why? any
> help
> > would be appreciated.
> >
> > N<-200;P<-9 #Sample size
> > BZ=numeric(N)
> >
> > W<-numeric(N)
> >
> > for (t in 1:1) {
> > #Generate the data for the simulation study
> > for (i in 1:N) {
> >
> > #transform theta to ordered categorical variables
> >
> >
> > for(j in 1:1){
> > if(BZ[j] < 0.25){
> > W[j] = 1
> > }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> > W[j] = 2
> > }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> > W[j] = 3
> > }else{
> > W[j] = 4
> > }}
> >
> >
> > #Input data set
> > data<-list(N=200,P=9,Q=W)
> >
> > }} #end
> >
> > W
> >
> >
> >
> >
> > Regards
> >
> >
> > --
> > Thanoon Y. Thanoon
> > PhD Candidate
> > Department of Mathematical Sciences
> > Faculty of Science
> > University Technology Malaysia, UTM
> > E.Mail: Thanoon.younis80 at gmail.com
> > E.Mail: dawn_prayer80 at yahoo.com
> > Facebook:Thanoon Younis AL-Shakerchy
> > Twitter: Thanoon Alshakerchy
> > H.P:00601127550205
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
>
--
Thanoon Y. Thanoon
PhD Candidate
Department of Mathematical Sciences
Faculty of Science
University Technology Malaysia, UTM
E.Mail: Thanoon.younis80 at gmail.com
E.Mail: dawn_prayer80 at yahoo.com
Facebook:Thanoon Younis AL-Shakerchy
Twitter: Thanoon Alshakerchy
H.P:00601127550205
[[alternative HTML version deleted]]
Your approach does not make sense.
If you initialize a vector as say ...
BZ <- numeric(5)
... what do you _expect BZ contains?
Also: if you run a loop like you do
for (j in 1:1) {
print(j)
}
... what do you _expect_ will happen?
B.
On Nov 3, 2015, at 10:43 PM, thanoon younis <thanoon.younis80 at
gmail.com> wrote:
> Thank you for your response
>
> I have a vector of unknown values BZ which is defined already BZ=numeric(N)
and i want to transfer BZ to ordered categorical variable with 4 categories W
but when i write this code
>
> for(j in 1:1){
> if(BZ[j] < 0.25){
> W[j] = 1
> }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> W[j] = 2
> }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> W[j] = 3
> }else{
> W[j] = 4
> }}
>
> i found the values of W are only 0, but if i change for(j in 1:N) the
values of W will be only 1. how can i solve this problem?
> Regards
>
> On 4 November 2015 at 06:35, Boris Steipe <boris.steipe at
utoronto.ca> wrote:
> Why don't you just multiply by four, round, and add one?
>
>
>
> B.
> On Nov 3, 2015, at 10:02 PM, thanoon younis <thanoon.younis80 at
gmail.com> wrote:
>
> > Dear R-users
> >
> > I have a problem in the code below, the problem is because i want to
change
> > the variable BZ which is a vector with 200x1 dimension to the var. W
which
> > is categorical variable with same dimension of BZ but with categorical
> > values with 4 categories but i got on only zero values in w why? any
help
> > would be appreciated.
> >
> > N<-200;P<-9 #Sample size
> > BZ=numeric(N)
> >
> > W<-numeric(N)
> >
> > for (t in 1:1) {
> > #Generate the data for the simulation study
> > for (i in 1:N) {
> >
> > #transform theta to ordered categorical variables
> >
> >
> > for(j in 1:1){
> > if(BZ[j] < 0.25){
> > W[j] = 1
> > }else if(BZ[j] >=0.25 & BZ[j] < 0.5){
> > W[j] = 2
> > }else if(BZ[j] >=0.5 & BZ[j] < 0.75){
> > W[j] = 3
> > }else{
> > W[j] = 4
> > }}
> >
> >
> > #Input data set
> > data<-list(N=200,P=9,Q=W)
> >
> > }} #end
> >
> > W
> >
> >
> >
> >
> > Regards
> >
> >
> > --
> > Thanoon Y. Thanoon
> > PhD Candidate
> > Department of Mathematical Sciences
> > Faculty of Science
> > University Technology Malaysia, UTM
> > E.Mail: Thanoon.younis80 at gmail.com
> > E.Mail: dawn_prayer80 at yahoo.com
> > Facebook:Thanoon Younis AL-Shakerchy
> > Twitter: Thanoon Alshakerchy
> > H.P:00601127550205
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
>
>
>
> --
> Thanoon Y. Thanoon
> PhD Candidate
> Department of Mathematical Sciences
> Faculty of Science
> University Technology Malaysia, UTM
> E.Mail: Thanoon.younis80 at gmail.com
> E.Mail: dawn_prayer80 at yahoo.com
> Facebook:Thanoon Younis AL-Shakerchy
> Twitter: Thanoon Alshakerchy
> H.P:00601127550205
Are you telling me it contains only zeros? Or is it a vector of length zero? B. On Nov 3, 2015, at 11:07 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote:> BZ is hidden variable with zero values. > > On 4 November 2015 at 07:02, Boris Steipe <boris.steipe at utoronto.ca> wrote: > Your approach does not make sense. > > If you initialize a vector as say ... > > BZ <- numeric(5) > ... what do you _expect BZ contains? > > Also: if you run a loop like you do > for (j in 1:1) { > print(j) > } > ... what do you _expect_ will happen? > > > B. > > On Nov 3, 2015, at 10:43 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote: > > > Thank you for your response > > > > I have a vector of unknown values BZ which is defined already BZ=numeric(N) and i want to transfer BZ to ordered categorical variable with 4 categories W but when i write this code > > > > for(j in 1:1){ > > if(BZ[j] < 0.25){ > > W[j] = 1 > > }else if(BZ[j] >=0.25 & BZ[j] < 0.5){ > > W[j] = 2 > > }else if(BZ[j] >=0.5 & BZ[j] < 0.75){ > > W[j] = 3 > > }else{ > > W[j] = 4 > > }} > > > > i found the values of W are only 0, but if i change for(j in 1:N) the values of W will be only 1. how can i solve this problem? > > Regards > > > > On 4 November 2015 at 06:35, Boris Steipe <boris.steipe at utoronto.ca> wrote: > > Why don't you just multiply by four, round, and add one? > > > > > > > > B. > > On Nov 3, 2015, at 10:02 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote: > > > > > Dear R-users > > > > > > I have a problem in the code below, the problem is because i want to change > > > the variable BZ which is a vector with 200x1 dimension to the var. W which > > > is categorical variable with same dimension of BZ but with categorical > > > values with 4 categories but i got on only zero values in w why? any help > > > would be appreciated. > > > > > > N<-200;P<-9 #Sample size > > > BZ=numeric(N) > > > > > > W<-numeric(N) > > > > > > for (t in 1:1) { > > > #Generate the data for the simulation study > > > for (i in 1:N) { > > > > > > #transform theta to ordered categorical variables > > > > > > > > > for(j in 1:1){ > > > if(BZ[j] < 0.25){ > > > W[j] = 1 > > > }else if(BZ[j] >=0.25 & BZ[j] < 0.5){ > > > W[j] = 2 > > > }else if(BZ[j] >=0.5 & BZ[j] < 0.75){ > > > W[j] = 3 > > > }else{ > > > W[j] = 4 > > > }} > > > > > > > > > #Input data set > > > data<-list(N=200,P=9,Q=W) > > > > > > }} #end > > > > > > W > > > > > > > > > > > > > > > Regards > > > > > > > > > -- > > > Thanoon Y. Thanoon > > > PhD Candidate > > > Department of Mathematical Sciences > > > Faculty of Science > > > University Technology Malaysia, UTM > > > E.Mail: Thanoon.younis80 at gmail.com > > > E.Mail: dawn_prayer80 at yahoo.com > > > Facebook:Thanoon Younis AL-Shakerchy > > > Twitter: Thanoon Alshakerchy > > > H.P:00601127550205 > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > 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. > > > > > > > > > > -- > > Thanoon Y. Thanoon > > PhD Candidate > > Department of Mathematical Sciences > > Faculty of Science > > University Technology Malaysia, UTM > > E.Mail: Thanoon.younis80 at gmail.com > > E.Mail: dawn_prayer80 at yahoo.com > > Facebook:Thanoon Younis AL-Shakerchy > > Twitter: Thanoon Alshakerchy > > H.P:00601127550205 > > > > > -- > Thanoon Y. Thanoon > PhD Candidate > Department of Mathematical Sciences > Faculty of Science > University Technology Malaysia, UTM > E.Mail: Thanoon.younis80 at gmail.com > E.Mail: dawn_prayer80 at yahoo.com > Facebook:Thanoon Younis AL-Shakerchy > Twitter: Thanoon Alshakerchy > H.P:00601127550205
Whatever - just type: W <- floor(BZ * 4) + 1 B. On Nov 3, 2015, at 11:09 PM, Boris Steipe <boris.steipe at utoronto.ca> wrote:> Are you telling me it contains only zeros? Or is it a vector of length zero? > > B. > > > On Nov 3, 2015, at 11:07 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote: > >> BZ is hidden variable with zero values. >> >> On 4 November 2015 at 07:02, Boris Steipe <boris.steipe at utoronto.ca> wrote: >> Your approach does not make sense. >> >> If you initialize a vector as say ... >> >> BZ <- numeric(5) >> ... what do you _expect BZ contains? >> >> Also: if you run a loop like you do >> for (j in 1:1) { >> print(j) >> } >> ... what do you _expect_ will happen? >> >> >> B. >> >> On Nov 3, 2015, at 10:43 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote: >> >>> Thank you for your response >>> >>> I have a vector of unknown values BZ which is defined already BZ=numeric(N) and i want to transfer BZ to ordered categorical variable with 4 categories W but when i write this code >>> >>> for(j in 1:1){ >>> if(BZ[j] < 0.25){ >>> W[j] = 1 >>> }else if(BZ[j] >=0.25 & BZ[j] < 0.5){ >>> W[j] = 2 >>> }else if(BZ[j] >=0.5 & BZ[j] < 0.75){ >>> W[j] = 3 >>> }else{ >>> W[j] = 4 >>> }} >>> >>> i found the values of W are only 0, but if i change for(j in 1:N) the values of W will be only 1. how can i solve this problem? >>> Regards >>> >>> On 4 November 2015 at 06:35, Boris Steipe <boris.steipe at utoronto.ca> wrote: >>> Why don't you just multiply by four, round, and add one? >>> >>> >>> >>> B. >>> On Nov 3, 2015, at 10:02 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote: >>> >>>> Dear R-users >>>> >>>> I have a problem in the code below, the problem is because i want to change >>>> the variable BZ which is a vector with 200x1 dimension to the var. W which >>>> is categorical variable with same dimension of BZ but with categorical >>>> values with 4 categories but i got on only zero values in w why? any help >>>> would be appreciated. >>>> >>>> N<-200;P<-9 #Sample size >>>> BZ=numeric(N) >>>> >>>> W<-numeric(N) >>>> >>>> for (t in 1:1) { >>>> #Generate the data for the simulation study >>>> for (i in 1:N) { >>>> >>>> #transform theta to ordered categorical variables >>>> >>>> >>>> for(j in 1:1){ >>>> if(BZ[j] < 0.25){ >>>> W[j] = 1 >>>> }else if(BZ[j] >=0.25 & BZ[j] < 0.5){ >>>> W[j] = 2 >>>> }else if(BZ[j] >=0.5 & BZ[j] < 0.75){ >>>> W[j] = 3 >>>> }else{ >>>> W[j] = 4 >>>> }} >>>> >>>> >>>> #Input data set >>>> data<-list(N=200,P=9,Q=W) >>>> >>>> }} #end >>>> >>>> W >>>> >>>> >>>> >>>> >>>> Regards >>>> >>>> >>>> -- >>>> Thanoon Y. Thanoon >>>> PhD Candidate >>>> Department of Mathematical Sciences >>>> Faculty of Science >>>> University Technology Malaysia, UTM >>>> E.Mail: Thanoon.younis80 at gmail.com >>>> E.Mail: dawn_prayer80 at yahoo.com >>>> Facebook:Thanoon Younis AL-Shakerchy >>>> Twitter: Thanoon Alshakerchy >>>> H.P:00601127550205 >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> 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. >>> >>> >>> >>> >>> -- >>> Thanoon Y. Thanoon >>> PhD Candidate >>> Department of Mathematical Sciences >>> Faculty of Science >>> University Technology Malaysia, UTM >>> E.Mail: Thanoon.younis80 at gmail.com >>> E.Mail: dawn_prayer80 at yahoo.com >>> Facebook:Thanoon Younis AL-Shakerchy >>> Twitter: Thanoon Alshakerchy >>> H.P:00601127550205 >> >> >> >> >> -- >> Thanoon Y. Thanoon >> PhD Candidate >> Department of Mathematical Sciences >> Faculty of Science >> University Technology Malaysia, UTM >> E.Mail: Thanoon.younis80 at gmail.com >> E.Mail: dawn_prayer80 at yahoo.com >> Facebook:Thanoon Younis AL-Shakerchy >> Twitter: Thanoon Alshakerchy >> H.P:00601127550205 > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Hi thanoon, The problem may lie in your definition of BZ (which I see Boris has also noticed). Given your code, it will be a vector containing 200 zeros. Your code will generate 200 ones as zero is less than 0.25. Try defining BZ as follows: BZ<-runif(200) You should get something more interesting from your code or that suggested by Boris, or even this: W<-as.numeric(cut(BZ,breaks=c(0,0.25,0.5,0.75,1))) Jim On Wed, Nov 4, 2015 at 2:43 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote:> Thank you for your response > > I have a vector of unknown values BZ which is defined already BZ=numeric(N) > and i want to transfer BZ to ordered categorical variable with 4 > categories W but when i write this code > > for(j in 1:1){ > if(BZ[j] < 0.25){ > W[j] = 1 > }else if(BZ[j] >=0.25 & BZ[j] < 0.5){ > W[j] = 2 > }else if(BZ[j] >=0.5 & BZ[j] < 0.75){ > W[j] = 3 > }else{ > W[j] = 4 > }} > > i found the values of W are only 0, but if i change for(j in 1:N) the > values of W will be only 1. how can i solve this problem? > Regards > > On 4 November 2015 at 06:35, Boris Steipe <boris.steipe at utoronto.ca> > wrote: > > > Why don't you just multiply by four, round, and add one? > > > > > > > > B. > > On Nov 3, 2015, at 10:02 PM, thanoon younis <thanoon.younis80 at gmail.com> > > wrote: > > > > > Dear R-users > > > > > > I have a problem in the code below, the problem is because i want to > > change > > > the variable BZ which is a vector with 200x1 dimension to the var. W > > which > > > is categorical variable with same dimension of BZ but with categorical > > > values with 4 categories but i got on only zero values in w why? any > > help > > > would be appreciated. > > > > > > N<-200;P<-9 #Sample size > > > BZ=numeric(N) > > > > > > W<-numeric(N) > > > > > > for (t in 1:1) { > > > #Generate the data for the simulation study > > > for (i in 1:N) { > > > > > > #transform theta to ordered categorical variables > > > > > > > > > for(j in 1:1){ > > > if(BZ[j] < 0.25){ > > > W[j] = 1 > > > }else if(BZ[j] >=0.25 & BZ[j] < 0.5){ > > > W[j] = 2 > > > }else if(BZ[j] >=0.5 & BZ[j] < 0.75){ > > > W[j] = 3 > > > }else{ > > > W[j] = 4 > > > }} > > > > > > > > > #Input data set > > > data<-list(N=200,P=9,Q=W) > > > > > > }} #end > > > > > > W > > > > > > > > > > > > > > > Regards > > > > > > > > > -- > > > Thanoon Y. Thanoon > > > PhD Candidate > > > Department of Mathematical Sciences > > > Faculty of Science > > > University Technology Malaysia, UTM > > > E.Mail: Thanoon.younis80 at gmail.com > > > E.Mail: dawn_prayer80 at yahoo.com > > > Facebook:Thanoon Younis AL-Shakerchy > > > Twitter: Thanoon Alshakerchy > > > H.P:00601127550205 > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > 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. > > > > > > > -- > Thanoon Y. Thanoon > PhD Candidate > Department of Mathematical Sciences > Faculty of Science > University Technology Malaysia, UTM > E.Mail: Thanoon.younis80 at gmail.com > E.Mail: dawn_prayer80 at yahoo.com > Facebook:Thanoon Younis AL-Shakerchy > Twitter: Thanoon Alshakerchy > H.P:00601127550205 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Dear R-Users
After correct some errors in the code below i have only this error
"Error in if (BZ[i] < 0.25) { : missing value where TRUE/FALSE
needed"
how can i solve this problem please?
N<-200;P<-9 #Sample size
BZ=matrix(NA, nrow=N, ncol=1)
W=matrix(NA, nrow=N, ncol=1)
for (t in 1:100) {
#Generate the data for the simulation study
for (i in 1:N) {
#transform theta to ordered categorical variables
for(j in 1:1){
if(BZ[i] < 0.25){
W[i] = 1
}else if(BZ[i] >=0.25 & BZ[i] < 0.5){
W[i] = 2
}else if(BZ[i] >=0.5 & BZ[i] < 0.75){
W[i] = 3
}else{
W[i] = 4
}}}}
[[alternative HTML version deleted]]
Hi thanoon, Well, you have generated a one column matrix of missing values (NA) and then tried to use those values in a logical test... Jim On Wed, Nov 4, 2015 at 8:02 PM, thanoon younis <thanoon.younis80 at gmail.com> wrote:> Dear R-Users > > After correct some errors in the code below i have only this error > > "Error in if (BZ[i] < 0.25) { : missing value where TRUE/FALSE needed" > > how can i solve this problem please? > > > > N<-200;P<-9 #Sample size > BZ=matrix(NA, nrow=N, ncol=1) > > > W=matrix(NA, nrow=N, ncol=1) > > > for (t in 1:100) { > #Generate the data for the simulation study > for (i in 1:N) { > > #transform theta to ordered categorical variables > > > for(j in 1:1){ > if(BZ[i] < 0.25){ > W[i] = 1 > }else if(BZ[i] >=0.25 & BZ[i] < 0.5){ > W[i] = 2 > }else if(BZ[i] >=0.5 & BZ[i] < 0.75){ > W[i] = 3 > }else{ > W[i] = 4 > }}}} > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]