Re: [R] why there is no quarters?

2013-12-16 Thread Pancho Mulongeni
Hi,
I also would like to use quarters. I think a work around would be to just label 
each record in the dataframe by its quarter.
i.e. you add a factor called 'Quarter' with four levels (Q1 to Q4) for each row 
and you assign the level based on the month of the date.
You can easily do this with as.Date and as.character.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


[R] R reference group in Cape Town South Africa

2013-10-16 Thread Pancho Mulongeni
Hi R users in Cape Town,
I will be starting the Epidemiology/Clinical Research program at the University 
of Cape Town in the Summer of Jan 2014 and so I am looking to meet any useRs. I 
assume there is a refeRence group in Cape Town?
Please do email me as I would love to corRespond with you,
Best

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] converting a summary table to survey database form

2013-08-23 Thread Pancho Mulongeni
Thank you!

-Original Message-
From: arun [mailto:smartpink...@yahoo.com] 
Sent: 22 August 2013 17:17
To: Pancho Mulongeni
Cc: R help
Subject: Re: [R] converting a summary table to survey database form

Hi,

May be this helps:

dat1- structure(...
 dat1$ID- row.names(dat1)
library(reshape2)
dat2-melt(dat1,id.vars=ID)
dat2New-dat2[order(as.numeric(dat2$ID)),]
 head(dat2New)
#   ID variable value
#1   1   Ramses 4
#11  1   Sheiks 5
#21  1  Trojans 7
#31  1  Unnamed 2
#2   2   Ramses 4
#12  2   Sheiks 5


A.K.



- Original Message -
From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Thursday, August 22, 2013 12:08 PM
Subject: [R] converting a summary table to survey database form

Hi!
I am looking to choose a condom based on its pleasure score.
I received some summarised data from 10 individuals:
structure(list(Ramses = c(4, 4, 5, 5, 6, 3, 4, 4, 3, 4), Sheiks = c(5, 5, 6, 4, 
7, 6, 4, 5, 6, 3), Trojans = c(7, 8, 7, 9, 6, 3, 2, 2, 2, 3), Unnamed = c(2, 1, 
1, 3, 3, 4, 5, 4, 4, 3)), .Names = c(Ramses, Sheiks, Trojans, Unnamed), 
row.names = c(NA, 10L), class = data.frame)

However to do an annova to see if the mean score is not the same for all 
brands, I understand I need to have the data in survey database form i.e.
1 Ramses 4
1 Sheiks 4
1 Trojans 7
1 Unamed 2
2 Ramses 4
...
10 Unamed 3

I would have a dataframe with two factor 'brand' and 'score'. I would then do 
an aov(score~brand,data=condom.dataframe) for instance.

However to get my original condomData which has the tabulated scores per brand 
into the summarised form is a pain. 
I tried to just get a vector that essentially has all the rows of condomData 
put into one long vector from i.e. c( 
a1_1,a1_2...a1_5,a2_1,2_..a2_5...a10_5)
I would then bind this together with a names vector of 
rep(c('Ramses','Sheiks','Trojans','Unamed),10) and I would have my desired 
datafram for anova.
But alas my attempt below does not work:
r-dim(condomData)[1]
scoreS-c()
for (i in 1:r) {
score-as.numeric(condomData[r,])
scoreS-c(scoreS,s)
}
It just gives me the last row of condomData copied 10 times.
Any help? 
Thank you, I really want to know if all condoms are equal.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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. 

__
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.


[R] converting a summary table to survey database form

2013-08-22 Thread Pancho Mulongeni
Hi!
I am looking to choose a condom based on its pleasure score.
I received some summarised data from 10 individuals:
structure(list(Ramses = c(4, 4, 5, 5, 6, 3, 4, 4, 3, 4), Sheiks = c(5, 
5, 6, 4, 7, 6, 4, 5, 6, 3), Trojans = c(7, 8, 7, 9, 6, 3, 2, 
2, 2, 3), Unnamed = c(2, 1, 1, 3, 3, 4, 5, 4, 4, 3)), .Names = c(Ramses, 
Sheiks, Trojans, Unnamed), row.names = c(NA, 10L), class = data.frame)

However to do an annova to see if the mean score is not the same for all 
brands, I understand I need to have the data in survey database form i.e.
1 Ramses 4
1 Sheiks 4
1 Trojans 7
1 Unamed 2
2 Ramses 4
...
10 Unamed 3

I would have a dataframe with two factor 'brand' and 'score'. I would then do 
an aov(score~brand,data=condom.dataframe) for instance.

However to get my original condomData which has the tabulated scores per brand 
into the summarised form is a pain. 
I tried to just get a vector that essentially has all the rows of condomData 
put into one long vector from i.e. c( 
a1_1,a1_2...a1_5,a2_1,2_..a2_5...a10_5)
I would then bind this together with a names vector of 
rep(c('Ramses','Sheiks','Trojans','Unamed),10) and I would have my desired 
datafram for anova.
But alas my attempt below does not work:
r-dim(condomData)[1]
scoreS-c()
for (i in 1:r) {
score-as.numeric(condomData[r,])
scoreS-c(scoreS,s)
}
 It just gives me the last row of condomData copied 10 times.
 Any help? 
Thank you, I really want to know if all condoms are equal.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] Hungarian R User's Group (Gergely Dar?czi)

2013-08-13 Thread Pancho Mulongeni
Hi Gergely!
This sounds so exciting - so R is turning 20 years old? How did you set up your 
R users' group? What are the best practices in going about to set one up?
I would be keen on establishing one here in Windhoek, Namibia.


Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


[R] Upgrading to R and keeping packages

2013-08-08 Thread Pancho Mulongeni
Hi! I just installed the latest R 3.01.
I then wanted to update my packages.
I believe the advice given is to take the library folder from the old R version 
and copy it on top of (overwrite) the library folder of the new R version, in 
my case the library of R 2.15.2 to library of R 3.01.

When I did this, the next time I started R 3.01, I had an error message
Error in .Call(R_isMethodsDispatchOn, onOff, PACKAGE = base) :
  R_isMethodsDispatchOn not available for .Call() for package base

also the update.packages() function was 'not available'.
Where did I go wrong?
I think I will just update the packages I want rather than the whole folder and 
see if this works,

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


[R] Splitting coordinates into two

2013-07-08 Thread Pancho Mulongeni
Hi users,
I have a simple vector of five coordinates in form of ('lat1, 
long1','lat2,long2',...,'latn,longn')
And I would like to create two vectors, one just with the first coordinate
G1-c('lat1,'lat2',..,'latn')
G2-c('long1,'long2',...,'longn')

I am trying to apply strsplit(x=g,split=',') on my object g, but it is not 
working, any help?
I struggle to understand how to use the regular expressions.
structure(c(32L, 38L, 40L, 34L, 27L), .Label = c(-17.394217,15.886574, 
-17.406994,14.393463, -17.491495,14.992905, -17.5005,24.274635, 
-17.776151,15.765724, -17.779911,15.699806, -17.905569,15.977211, 
-17.921576,19.758911, -18.607204,17.166481, -18.804918,17.046661, 
-18.805731,16.940403, -19.030476,16.467304, -19.12441,13.616567, 
-19.163006,15.916443, -19.243736,17.710304, -19.562702,18.11697, 
-19.6303,17.342606, -19.939787,13.013306, -20.107201,16.154966, 
-20.363618,14.965954, -20.460469,16.652012, -20.484914,17.233429, 
-21.256102,17.869263, -21.418555,15.949402, -21.491128,17.853234, 
-21.943046,17.363892, -21.980459,16.91328, -22.000992,15.582733, 
-22.084367,16.750031, -22.182318,17.072754, -22.447841,18.962746, 
-22.576608,17.07859, -22.649502,14.532166, -22.832516,17.183304, 
-22.934365,14.521008, -22.947328,14.508991, -24.45,15.801086, 
-24.621739,17.959728, -25.460983,19.438198, -26.567955,18.134651, 
-26.645292,15.153944, -27.915553,17.490921, -28.017742,18.745594
), class = factor)

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] Splitting coordinates into two

2013-07-08 Thread Pancho Mulongeni
Thank you,
So my mistake was my data was a factor and not character,for strsplit
Thanks so much 

-Original Message-
From: Rui Barradas [mailto:ruipbarra...@sapo.pt] 
Sent: 08 July 2013 15:55
To: Pancho Mulongeni
Cc: r-help@r-project.org
Subject: Re: [R] Splitting coordinates into two

Hello,

Try the following

x - structure(...)


sp - strsplit(as.character(x), ,)
G1 - sapply(sp, `[`, 1)
G2 - sapply(sp, `[`, 2)


Hope this helps,

Rui Barradas

Em 08-07-2013 14:49, Pancho Mulongeni escreveu:
 Hi users,
 I have a simple vector of five coordinates in form of ('lat1, 
 long1','lat2,long2',...,'latn,longn')
 And I would like to create two vectors, one just with the first 
 coordinate
 G1-c('lat1,'lat2',..,'latn')
 G2-c('long1,'long2',...,'longn')

 I am trying to apply strsplit(x=g,split=',') on my object g, but it is not 
 working, any help?
 I struggle to understand how to use the regular expressions.
 structure(c(32L, 38L, 40L, 34L, 27L), .Label = 
 c(-17.394217,15.886574, -17.406994,14.393463, 
 -17.491495,14.992905, -17.5005,24.274635, -17.776151,15.765724, 
 -17.779911,15.699806, -17.905569,15.977211, 
 -17.921576,19.758911, -18.607204,17.166481, 
 -18.804918,17.046661, -18.805731,16.940403, 
 -19.030476,16.467304, -19.12441,13.616567, -19.163006,15.916443, 
 -19.243736,17.710304, -19.562702,18.11697, -19.6303,17.342606, 
 -19.939787,13.013306, -20.107201,16.154966, 
 -20.363618,14.965954, -20.460469,16.652012, 
 -20.484914,17.233429, -21.256102,17.869263, 
 -21.418555,15.949402, -21.491128,17.853234, 
 -21.943046,17.363892, -21.980459,16.91328, -22.000992,15.582733, 
 -22.084367,16.750031, -22.182318,17.072754, 
 -22.447841,18.962746, -22.576608,17.07859, -22.649502,14.532166, 
 -22.832516,17.183304, -22.934365,14.521008, -22.947328,14.508991, 
 -24.45,15.801086, -24.621739,17.959728, -25.460983,19.438198, 
 -26.567955,18.134651, -26.645292,15.153944, -27.915553,17.490921, 
 -28.017742,18.745594
 ), class = factor)

 Pancho Mulongeni
 Research Assistant
 PharmAccess Foundation
 1 Fouché Street
 Windhoek West
 Windhoek
 Namibia

 Tel:   +264 61 419 000
 Fax:  +264 61 419 001/2
 Mob: +264 81 4456 286

 __
 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.


__
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.


[R] Unique in discerning missing values NA

2013-07-05 Thread Pancho Mulongeni
Hi,
I am trying to remove duplicate Patient numbers in a clinical record, I used 
unique
menPatients[1:40,1]
 [1] abr1160(C)/001 ABR1363(A)/001 ABR1363(A)/001 ABR1363(A)/001 abr1772(B)/001
 [6] AFR0003/001AFR0003/001afr0290(C)/001 afr1861(B)/001 Aga0007/001   
[11] AGA1548(A)/001 AGA1548(A)/001 AGA1548(A)/001 AGU1680(A)/001 AGU1680(A)/001
[16] AIS0492/001AIS0492/001AKO4268(C)/001 AKO4268(C)/001 AKT0042(B)/001
[21] AKT0042(B)/001 AKT0042(B)/001 AKT0042(B)/001 AKT0042(B)/001 AKT0042(B)/001
[26] AKT0042(B)/001 alb4423(C)/001 ALF1651(A)/001 alf1722(B)/001 ALF1735(A)/001
[31] ALF1735(A)/001 ALP4321(C)/001 NA   NA   ALU4262(B)/001
[36] ALV4286(C)/001 ALW2579(C)/001 NA   ALW4330(B)/001 AMA0011/001   
3886 Levels: 0750/002 0751/001 0984/002 ABE2560(C)/001 ... zul1737(B)/001

testData-menPatients[1:40,1]

I then used unique, please note the NA at position 32 in testData
testUnique-unique(testData)
testUnique
 [1] abr1160(C)/001 ABR1363(A)/001 abr1772(B)/001 AFR0003/001afr0290(C)/001
 [6] afr1861(B)/001 Aga0007/001AGA1548(A)/001 AGU1680(A)/001 AIS0492/001   
[11] AKO4268(C)/001 AKT0042(B)/001 alb4423(C)/001 ALF1651(A)/001 alf1722(B)/001
[16] ALF1735(A)/001 ALP4321(C)/001 NA   ALU4262(B)/001 ALV4286(C)/001
[21] ALW2579(C)/001 ALW4330(B)/001 AMA0011/001   

The missing value NA originally at position 32 in testdata is still there, it 
is in position 18. Why is this? How can I prevent this?
I tried using incomprables=c(NA), but this did not work.

Thanks


Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] Unique in discerning missing values NA

2013-07-05 Thread Pancho Mulongeni
Yes thanks, this is what I ended up doing, but I though there would be a 
'internal' way to disregard NAs in unique.
Thanks for the tip on dput

-Original Message-
From: Rui Barradas [mailto:ruipbarra...@sapo.pt] 
Sent: 05 July 2013 11:39
To: Pancho Mulongeni
Cc: r-help@r-project.org
Subject: Re: [R] Unique in discerning missing values NA

Hello,

Your data example is difficult to read into an R session. Next time, post the 
output of ?dput. Like this:

dput(menPatients[1:40, 1])  # post the output of this


The help page for unique says that Missing values are regarded as equal  so 
you should expect one NA to still be present in the final result.
If you want to remove NAs, use ?is.na. With fake data,

x1 - c(1:3, NA, 4, NA, 2:9)
x2 - unique(x1)
x3 - x2[!is.na(x2)]
x3


Hope this helps,

Rui Barradas


Em 05-07-2013 10:28, Pancho Mulongeni escreveu:
 Hi,
 I am trying to remove duplicate Patient numbers in a clinical record, 
 I used unique menPatients[1:40,1]
   [1] abr1160(C)/001 ABR1363(A)/001 ABR1363(A)/001 ABR1363(A)/001 
 abr1772(B)/001
   [6] AFR0003/001AFR0003/001afr0290(C)/001 afr1861(B)/001 Aga0007/001
 [11] AGA1548(A)/001 AGA1548(A)/001 AGA1548(A)/001 AGU1680(A)/001 
 AGU1680(A)/001
 [16] AIS0492/001AIS0492/001AKO4268(C)/001 AKO4268(C)/001 
 AKT0042(B)/001
 [21] AKT0042(B)/001 AKT0042(B)/001 AKT0042(B)/001 AKT0042(B)/001 
 AKT0042(B)/001 [26] AKT0042(B)/001 alb4423(C)/001 ALF1651(A)/001 
 alf1722(B)/001 ALF1735(A)/001
 [31] ALF1735(A)/001 ALP4321(C)/001 NA   NA   
 ALU4262(B)/001
 [36] ALV4286(C)/001 ALW2579(C)/001 NA   ALW4330(B)/001 AMA0011/001
 3886 Levels: 0750/002 0751/001 0984/002 ABE2560(C)/001 ... 
 zul1737(B)/001

 testData-menPatients[1:40,1]

 I then used unique, please note the NA at position 32 in testData
 testUnique-unique(testData)
 testUnique
   [1] abr1160(C)/001 ABR1363(A)/001 abr1772(B)/001 AFR0003/001
 afr0290(C)/001
   [6] afr1861(B)/001 Aga0007/001AGA1548(A)/001 AGU1680(A)/001 AIS0492/001
 [11] AKO4268(C)/001 AKT0042(B)/001 alb4423(C)/001 ALF1651(A)/001 
 alf1722(B)/001
 [16] ALF1735(A)/001 ALP4321(C)/001 NA   ALU4262(B)/001 
 ALV4286(C)/001
 [21] ALW2579(C)/001 ALW4330(B)/001 AMA0011/001

 The missing value NA originally at position 32 in testdata is still there, it 
 is in position 18. Why is this? How can I prevent this?
 I tried using incomprables=c(NA), but this did not work.

 Thanks


 Pancho Mulongeni
 Research Assistant
 PharmAccess Foundation
 1 Fouché Street
 Windhoek West
 Windhoek
 Namibia

 Tel:   +264 61 419 000
 Fax:  +264 61 419 001/2
 Mob: +264 81 4456 286

 __
 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.


__
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.


[R] Problem with DateVisit-gives wrong year?

2013-04-17 Thread Pancho Mulongeni
Hi I have the following factor of dates that I want to converted to Date class 
so I can extract the month
 test.date
 [1] 14/05/2012 14/05/2012 14/05/2012 14/05/2012 14/05/2012 14/05/2012
 [7] 14/05/2012 14/05/2012 14/05/2012 14/05/2012
201 Levels: 01/10/2012 01/11/2012 01/12/2012 02/07/2012 ... 28/09/2012
I use code below
ntest.date-as.Date(test.date,'%d/%m/%y')

but the output has the wrong year, and the reverse order
ntest.date
 [1] 2020-05-14 2020-05-14 2020-05-14 2020-05-14 2020-05-14
 [6] 2020-05-14 2020-05-14 2020-05-14 2020-05-14 2020-05-14

What am I doing wrong?
I dare not say the word 'bug'
Thanks
Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] Problem with DateVisit-gives wrong year?

2013-04-17 Thread Pancho Mulongeni
Thank you,
I see this was due to me using %y instead of %Y,
See ?strptime

-Original Message-
From: arun [mailto:smartpink...@yahoo.com] 
Sent: 17 April 2013 12:31
To: Pancho Mulongeni
Cc: R help
Subject: Re: [R] Problem with DateVisit-gives wrong year?

HI,
test.date- rep(c(14/05/2012,01/10/2012,28/09/2012),each=6)
 as.Date(test.date,%d/%m/%Y)
# [1] 2012-05-14 2012-05-14 2012-05-14 2012-05-14 2012-05-14
 #[6] 2012-05-14 2012-10-01 2012-10-01 2012-10-01 2012-10-01
#[11] 2012-10-01 2012-10-01 2012-09-28 2012-09-28 2012-09-28
#[16] 2012-09-28 2012-09-28 2012-09-28
 test.date1- factor(test.date)
 as.Date(test.date1,%d/%m/%Y)
# [1] 2012-05-14 2012-05-14 2012-05-14 2012-05-14 2012-05-14
 #[6] 2012-05-14 2012-10-01 2012-10-01 2012-10-01 2012-10-01
#[11] 2012-10-01 2012-10-01 2012-09-28 2012-09-28 2012-09-28
#[16] 2012-09-28 2012-09-28 2012-09-28
A.K.




- Original Message -
From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Wednesday, April 17, 2013 7:18 AM
Subject: [R] Problem with DateVisit-gives wrong year?

Hi I have the following factor of dates that I want to converted to Date class 
so I can extract the month
 test.date
[1] 14/05/2012 14/05/2012 14/05/2012 14/05/2012 14/05/2012 14/05/2012 [7] 
14/05/2012 14/05/2012 14/05/2012 14/05/2012
201 Levels: 01/10/2012 01/11/2012 01/12/2012 02/07/2012 ... 28/09/2012 I use 
code below
ntest.date-as.Date(test.date,'%d/%m/%y')

but the output has the wrong year, and the reverse order ntest.date [1] 
2020-05-14 2020-05-14 2020-05-14 2020-05-14 2020-05-14
[6] 2020-05-14 2020-05-14 2020-05-14 2020-05-14 2020-05-14

What am I doing wrong?
I dare not say the word 'bug'
Thanks
Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.

__
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.


[R] question about attaching data

2013-03-28 Thread Pancho Mulongeni
Hi I just would like to know,
When I have a dataframe, like this one called 'dummy'
And I attach it.
Then I run my code. 
I then update the dataframe by making changes and I still call it 'dummy'.
I run my code again.
Now dummy is at position 1 and position 2 of the search path and if I run the 
code again, with another version of 'dummy' it updates and eventually my search 
path looks like this
[1] .GlobalEnvdummy dummy
 [4] dummy package:stats package:graphics 
 [7] package:grDevices package:datasets  package:rcom 
[10] package:rscproxy  package:utils package:methods  
[13] RExcelEnv Autoloads package:base

I get the correct data, as the previous versions of dummy are 'masked from the 
search path'. What stops me from continuing this process ad infinitum?
What's the use of detaching dummy using detach()?
Thanks


Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


[R] Commercial or not?

2013-02-21 Thread Pancho Mulongeni
Hi All,
Let's say someone uses an R package (prefer to not disclose which) that comes 
with two different distributions,the commercial and non-commercial license. Now 
the non commercial license has conditions,bit it never runs out. So if this 
person knows they should be using the commercial license, because they are not 
a student and are paid for their work , (ie they are outside the non-commercial 
license) how can one convince management at the institution/company/not for 
profit to buy the commercial one? Is it even necessary? Thanks.
__
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.


[R] RESOLVED: Using table to get frequencies of several factors at once

2013-01-16 Thread Pancho Mulongeni
Thanks, 
I hereby declare this thread as resolved.

-Original Message-
From: S Ellison [mailto:s.elli...@lgcgroup.com] 
Sent: Wednesday, January 16, 2013 4:27 PM
To: Pancho Mulongeni; R help
Subject: RE: Using table to get frequencies of several factors at once

You could use a variant of apply(), probably sapply

For example
d - as.data.frame( matrix(sample(0:1, 200, replace=TRUE), ncol=5))

head(d)

sapply(d, table)

S Ellison
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of Pancho Mulongeni
 Sent: 11 January 2013 11:18
 To: R help
 Subject: [R] Using table to get frequencies of several factors at once
 
 Hi, I have a dataframe with n columns, but I am only looking at five 
 of them. And lots of rows, over 700.
 So I would like to find frequencies for each of the numeric columns 
 (variables) using the table function. However, is there a fast way to 
 produce a frequency table where the 5 rows represent the 5 numeric 
 variables and the columns refer to the values (levels) of the 
 respective numeric variables, which in this case are 0 and 1.
 The only way I have figured it out is via a for loop:
 m-seq(218,222,1) #these are columns of the variables in the larger 
 dataframe tm-m[1:5] #I need this for the for loop
 l.tm-length(tm)
 B-matrix(nrow=l.tm,ncol=2)  #the matrix to hold the freqs for (p in 
 1:l.tm) { var.num-m[p]
 B[p,]-table(DATA[,var.num])
 }
 
  B
  [,1] [,2]
 [1,]  6979
 [2,]  512  194
 [3,]  604  102
 [4,]  7006
 [5,]  706  706
 So the rows represent my five variables (columns) that occupy 
 columns 218 through 222 in the DATA dataframe.
 So the second column represents my frequencies of the value 
 1, which is what I am interested in. The last row has a 
 double entry, because there was only one value, 0, with a 
 freq of 706 and so R duplicated in the two columns, but 
 that's ok, I can just ignore it. 
 
 So is there are better way to do this? Is there a way to use 
 the so called tapply function? I struggle to understand the 
 help doc for this.function.
 
 
 Pancho Mulongeni
 Research Assistant
 PharmAccess Foundation
 1 Fouché Street
 Windhoek West
 Windhoek
 Namibia
  
 Tel:   +264 61 419 000
 Fax:  +264 61 419 001/2
 Mob: +264 81 4456 286
 
 __
 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.
 

***
This email and any attachments are confidential. Any use...{{dropped:9}}

__
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.


[R] Removing an attached object

2013-01-15 Thread Pancho Mulongeni
Dear All,
I am a bit confused, I attached my data frame using 'attach(DATA)'
Then I removed it using 'rm(DATA)'
But for some reason it is still at position 2 at the search path
search()
 [1] .GlobalEnvDATA  package:foreign  
 [4] package:stats package:graphics  package:grDevices
 [7] package:datasets  package:rcom  package:rscproxy 
[10] package:utils package:methods   RExcelEnv
[13] Autoloads package:base 

Also when I enter the names of factors in this dataframe, such as 'AGE', I get 
a list of data values.
This is weird, why does it not disappear from the search path?
Thanks

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] Removing an attached object

2013-01-15 Thread Pancho Mulongeni
Thanks, that makes it clear

-Original Message-
From: Pascal Oettli [mailto:kri...@ymail.com] 
Sent: Tuesday, January 15, 2013 1:07 PM
To: Pancho Mulongeni
Cc: R help
Subject: Re: [R] Removing an attached object

Hi,

Please read the following:

http://stackoverflow.com/questions/3536036/rmlist-ls-doesnt-completely-clear-the-workspace

HTH,
Pascal


Le 15/01/2013 19:55, Pancho Mulongeni a écrit :
 Dear All,
 I am a bit confused, I attached my data frame using 'attach(DATA)'
 Then I removed it using 'rm(DATA)'
 But for some reason it is still at position 2 at the search path
 search()
   [1] .GlobalEnvDATA  package:foreign
   [4] package:stats package:graphics  package:grDevices
   [7] package:datasets  package:rcom  package:rscproxy
 [10] package:utils package:methods   RExcelEnv
 [13] Autoloads package:base

 Also when I enter the names of factors in this dataframe, such as 'AGE', I 
 get a list of data values.
 This is weird, why does it not disappear from the search path?
 Thanks

 Pancho Mulongeni
 Research Assistant
 PharmAccess Foundation
 1 Fouché Street
 Windhoek West
 Windhoek
 Namibia

 Tel:   +264 61 419 000
 Fax:  +264 61 419 001/2
 Mob: +264 81 4456 286

 __
 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.


__
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.


Re: [R] Using table to get frequencies of several factors at once

2013-01-14 Thread Pancho Mulongeni
Yes thank you, that worked.

-Original Message-
From: John Kane [mailto:jrkrid...@inbox.com] 
Sent: Friday, January 11, 2013 4:23 PM
To: Pancho Mulongeni; R help
Subject: RE: [R] Using table to get frequencies of several factors at once

Does something like this do what you want?  It returns a list of tables

md  -  data.frame((matrix(sample(1:5, 100, replace = TRUE),nrow= 10)))
  str(md)
  apply(md, 2, table)

John Kane
Kingston ON Canada


 -Original Message-
 From: p.mulong...@namibia.pharmaccess.org
 Sent: Fri, 11 Jan 2013 11:17:42 +
 To: r-help@r-project.org
 Subject: [R] Using table to get frequencies of several factors at once
 
 Hi, I have a dataframe with n columns, but I am only looking at five 
 of them. And lots of rows, over 700.
 So I would like to find frequencies for each of the numeric columns
 (variables) using the table function. However, is there a fast way to 
 produce a frequency table where the 5 rows represent the 5 numeric 
 variables and the columns refer to the values (levels) of the 
 respective numeric variables, which in this case are 0 and 1.
 The only way I have figured it out is via a for loop:
 m-seq(218,222,1) #these are columns of the variables in the larger 
 dataframe tm-m[1:5] #I need this for the for loop
 l.tm-length(tm)
 B-matrix(nrow=l.tm,ncol=2)  #the matrix to hold the freqs for (p in 
 1:l.tm) { var.num-m[p]
 B[p,]-table(DATA[,var.num])
 }
 
 B
  [,1] [,2]
 [1,]  6979
 [2,]  512  194
 [3,]  604  102
 [4,]  7006
 [5,]  706  706
 So the rows represent my five variables (columns) that occupy columns 
 218 through 222 in the DATA dataframe.
 So the second column represents my frequencies of the value 1, which 
 is what I am interested in. The last row has a double entry, because 
 there was only one value, 0, with a freq of 706 and so R duplicated in 
 the two columns, but that's ok, I can just ignore it.
 
 So is there are better way to do this? Is there a way to use the so 
 called tapply function? I struggle to understand the help doc for 
 this.function.
 
 
 Pancho Mulongeni
 Research Assistant
 PharmAccess Foundation
 1 Fouché Street
 Windhoek West
 Windhoek
 Namibia
 
 Tel:   +264 61 419 000
 Fax:  +264 61 419 001/2
 Mob: +264 81 4456 286
 
 __
 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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks  orcas on your 
desktop!
Check it out at http://www.inbox.com/marineaquarium



__
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.


[R] Using table to get frequencies of several factors at once

2013-01-11 Thread Pancho Mulongeni
Hi, I have a dataframe with n columns, but I am only looking at five of them. 
And lots of rows, over 700. 
So I would like to find frequencies for each of the numeric columns (variables) 
using the table function. However, is there a fast way to produce a frequency 
table where the 5 rows represent the 5 numeric variables and the columns refer 
to the values (levels) of the respective numeric variables, which in this case 
are 0 and 1.  
The only way I have figured it out is via a for loop:
m-seq(218,222,1) #these are columns of the variables in the larger dataframe
tm-m[1:5] #I need this for the for loop
l.tm-length(tm)
B-matrix(nrow=l.tm,ncol=2)  #the matrix to hold the freqs
for (p in 1:l.tm) {
var.num-m[p]
B[p,]-table(DATA[,var.num])
}

 B
 [,1] [,2]
[1,]  6979
[2,]  512  194
[3,]  604  102
[4,]  7006
[5,]  706  706
So the rows represent my five variables (columns) that occupy columns 218 
through 222 in the DATA dataframe.
So the second column represents my frequencies of the value 1, which is what I 
am interested in. The last row has a double entry, because there was only one 
value, 0, with a freq of 706 and so R duplicated in the two columns, but that's 
ok, I can just ignore it. 

So is there are better way to do this? Is there a way to use the so called 
tapply function? I struggle to understand the help doc for this.function.


Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


[R] Recode function car package erases previous values

2012-10-24 Thread Pancho Mulongeni
Hi all,
I am attempting to create a new variable based on values of other variables. 
The variable is called pharm. It basically takes the numeric code of 1 as yes 
and 0 to be No from the variable B20_C1 (a question on a survey). However, I 
would also like to have a level for non-respondents and these are captured in 
the variable nr.B20C, which is a 1 when there is a non-response on the whole 
group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will 
have three levels, 
Yes No and no resp.
See below what happens

 pharm-as.factor(recode(B20_C1,1='Yes';0='No'))
 table(pharm)
pharm
 No Yes 
716   7 
 levels(pharm)-c('No','Yes','no resp')
 table(pharm)
pharm
 No Yes no resp 
716   7   0 
 pharm-as.factor(recode(nr.B20C,1='no resp'))
 table(pharm)
pharm
  0 no resp 
723   6 

The recode variable just cannot seem to 'remember' I had just recoded 7 values 
to 'Yes' and 716 to be 'No'  and instead it assigns the level '0' which comes 
from nr.B20C (it has values 0 or 1). 
This inconvenient as I would like to have ultimately the following table 
pharm
 No Yes no resp 
716   7   6 (FROM nr.B20C where row has value 1).

Background. The variable pharm assess where you used the pharmacy to get your 
contraception.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.


Re: [R] Recode function car package erases previous values

2012-10-24 Thread Pancho Mulongeni


-Original Message-
From: arun [mailto:smartpink...@yahoo.com] 
Sent: Wednesday, October 24, 2012 3:31 PM
To: Pancho Mulongeni
Cc: R help
Subject: Re: [R] Recode function car package erases previous values

Hi,
May be this helps:
set.seed(1)
dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA))
dat1
#  B20_C1 B20_C2 nrB20C
#1 NA NA  1
#2  0  0 NA
#3  0  1 NA
#4  0  0 NA
#5  1  1 NA
#6 NA  1 NA
 dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no 
response,ifelse(dat1[,1]==1,Yes,No))
dat2-within(dat1,{pharm-factor(pharm)})
 levels(dat2$pharm)
#[1] No  no response Yes
 dat2
#  B20_C1 B20_C2 nrB20C   pharm
#1 NA NA  1 no response
#2  0  0 NA  No
#3  0  1 NA  No
#4  0  0 NA  No
#5  1  1 NA Yes
#6 NA  1 NA    NA

table(dat2$pharm)

# No no response Yes
 # 3   1   1 

A.K.

Thank you, once I understand what you did I will use it, for now, I use a 
workaround
1. First I use the recode function
pharm-as.factor(recode(B20_C1,1='Yes';0='No'))
2. Now I just subset
pharm[nr.B20C==1]-'no resp'
and this gives me the desired output
 No Yes no resp
716   7   6 


- Original Message -
From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Wednesday, October 24, 2012 5:17 AM
Subject: [R] Recode function car package erases previous values

Hi all,
I am attempting to create a new variable based on values of other variables. 
The variable is called pharm. It basically takes the numeric code of 1 as yes 
and 0 to be No from the variable B20_C1 (a question on a survey). However, I 
would also like to have a level for non-respondents and these are captured in 
the variable nr.B20C, which is a 1 when there is a non-response on the whole 
group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will 
have three levels, Yes No and no resp.
See below what happens

 pharm-as.factor(recode(B20_C1,1='Yes';0='No'))
 table(pharm)
pharm
No Yes
716   7 
 levels(pharm)-c('No','Yes','no resp')
 table(pharm)
pharm
     No     Yes no resp
    716       7       0 
 pharm-as.factor(recode(nr.B20C,1='no resp'))
 table(pharm)
pharm
      0 no resp
    723       6 

The recode variable just cannot seem to 'remember' I had just recoded 7 values 
to 'Yes' and 716 to be 'No'  and instead it assigns the level '0' which comes 
from nr.B20C (it has values 0 or 1). 
This inconvenient as I would like to have ultimately the following table pharm
     No     Yes no resp
    716       7       6 (FROM nr.B20C where row has value 1).

Background. The variable pharm assess where you used the pharmacy to get your 
contraception.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.

__
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.


Re: [R] Recode function car package erases previous values

2012-10-24 Thread Pancho Mulongeni
Hi Arun,
I also used to get that error, but what class is your nr.B20C, mine is not a 
factor, it is numeric and perhaps that's why it works


-Original Message-
From: arun [mailto:smartpink...@yahoo.com] 
Sent: Wednesday, October 24, 2012 4:35 PM
To: Pancho Mulongeni
Cc: R help
Subject: Re: [R] Recode function car package erases previous values

Hi Pancho,

I tried ur method:
pharm-as.factor(recode(dat1$B20_C1,1='Yes';0='No'))
 pharm
#[1] NA No   No   Yes  Yes  NA
#Levels: No Yes


pharm[dat1$nrB20C==1]-'no resp'
#Warning message:
#In `[-.factor`(`*tmp*`, dat1$nr.B20C == 1, value = no resp) :
 # invalid factor level, NAs generated
 pharm
#[1] NA No   No   Yes  Yes  NA
#Levels: No Yes


Not sure how you got the result.
A.K.

 



- Original Message -
From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org
To: arun smartpink...@yahoo.com
Cc: R help r-help@r-project.org
Sent: Wednesday, October 24, 2012 9:51 AM
Subject: RE: [R] Recode function car package erases previous values



-Original Message-
From: arun [mailto:smartpink...@yahoo.com]
Sent: Wednesday, October 24, 2012 3:31 PM
To: Pancho Mulongeni
Cc: R help
Subject: Re: [R] Recode function car package erases previous values

Hi,
May be this helps:
set.seed(1)
dat1-data.frame(B20_C1=c(NA,sample(0:1,4,replace=TRUE),NA),B20_C2=c(NA,sample(0:1,3,replace=TRUE),sample(0:1,2,replace=TRUE)),nrB20C=c(1,NA,NA,NA,NA,NA))
dat1
#  B20_C1 B20_C2 nrB20C
#1 NA NA  1
#2  0  0 NA
#3  0  1 NA
#4  0  0 NA
#5  1  1 NA
#6 NA  1 NA
 dat1$pharm-ifelse(apply(dat1,1,function(x) all(is.na(x[1:2]))),no 
response,ifelse(dat1[,1]==1,Yes,No))
dat2-within(dat1,{pharm-factor(pharm)})
 levels(dat2$pharm)
#[1] No  no response Yes
 dat2
#  B20_C1 B20_C2 nrB20C   pharm
#1 NA NA  1 no response
#2  0  0 NA  No
#3  0  1 NA  No
#4  0  0 NA  No
#5  1  1 NA Yes
#6 NA  1 NA    NA

table(dat2$pharm)

# No no response Yes
 # 3   1   1 

A.K.

Thank you, once I understand what you did I will use it, for now, I use a 
workaround 1. First I use the recode function
pharm-as.factor(recode(B20_C1,1='Yes';0='No'))
2. Now I just subset
pharm[nr.B20C==1]-'no resp'
and this gives me the desired output
     No     Yes no resp
    716       7       6 


- Original Message -
From: Pancho Mulongeni p.mulong...@namibia.pharmaccess.org
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Wednesday, October 24, 2012 5:17 AM
Subject: [R] Recode function car package erases previous values

Hi all,
I am attempting to create a new variable based on values of other variables. 
The variable is called pharm. It basically takes the numeric code of 1 as yes 
and 0 to be No from the variable B20_C1 (a question on a survey). However, I 
would also like to have a level for non-respondents and these are captured in 
the variable nr.B20C, which is a 1 when there is a non-response on the whole 
group of variable B20_C1 to B20_C5. So ultimately the variable pharmacy will 
have three levels, Yes No and no resp.
See below what happens

 pharm-as.factor(recode(B20_C1,1='Yes';0='No'))
 table(pharm)
pharm
No Yes
716   7 
 levels(pharm)-c('No','Yes','no resp')
 table(pharm)
pharm
     No     Yes no resp
    716       7       0 
 pharm-as.factor(recode(nr.B20C,1='no resp'))
 table(pharm)
pharm
      0 no resp
    723       6 

The recode variable just cannot seem to 'remember' I had just recoded 7 values 
to 'Yes' and 716 to be 'No'  and instead it assigns the level '0' which comes 
from nr.B20C (it has values 0 or 1). 
This inconvenient as I would like to have ultimately the following table pharm
     No     Yes no resp
    716       7       6 (FROM nr.B20C where row has value 1).

Background. The variable pharm assess where you used the pharmacy to get your 
contraception.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
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.

__
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.


Re: [R] Setting all rows of a certain level to NA in a factor

2012-10-22 Thread Pancho Mulongeni
Perfect, thanks 

-Original Message-
From: Rui Barradas [mailto:ruipbarra...@sapo.pt] 
Sent: Wednesday, October 17, 2012 9:49 PM
To: Pancho Mulongeni
Cc: r-help@r-project.org
Subject: Re: [R] Setting all rows of a certain level to NA in a factor

Hello,

Try the following.


b - factor(ifelse(!B20_A %in% c(No , Yes), NA, B20_A), labels = c(No , 
Yes))
str(b)


Hope this helps,

Rui Barradas
Em 17-10-2012 15:51, Pancho Mulongeni escreveu:
 Hello everyone.
 My task is set certain levels (that is all rows of that level) as missing 
 values in factor B20_A.
 Excuse the notation, it happens to be a question number in a survey.
 So I thought it would work easily by defining the levels
 and their labels using the 'factor' function.

 levels(B20_A)
 [1] 5.6 No  Yes
 #as you can see 'No' is a level.
 #I below define the levels, I expect 5.6 and blank to be set as NA
 B20_A-factor(B20_A,levels=c('No','Yes'),labels=c('No','Yes'))
 summary(B20_A)

No  Yes NA's
 0  149  580
 to my surprise, 'No' is also set as NA, why is this happening?

 I am a frequent SPSS user and I am surprised that this operation does not 
 seem to be so straight forward in R.
 Thanks
 my object is defined below.
 structure(c(4L, 1L, 4L, 4L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 1L,
 3L, 3L, 1L, 1L, 4L, 1L, 4L, 4L, 3L, 1L, 3L, 4L, 3L, 4L, 3L, 3L,
 1L, 1L, 3L, 1L, 3L, 4L, 4L, 3L, 1L, 1L, 4L, 4L, 3L, 3L, 3L, 1L,
 3L, 3L, 3L, 1L, 4L, 1L, 4L, 1L, 1L, 1L, 3L, 3L, 1L, 4L, 4L, 3L,
 1L, 1L, 4L, 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L, 1L, 3L, 3L, 1L,
 1L, 3L, 3L, 1L, 3L, 1L, 3L, 4L, 1L, 1L, 3L, 1L, 1L, 3L, 3L, 1L,
 3L, 4L, 1L, 3L, 3L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 4L, 1L, 3L,
 1L, 4L, 4L, 3L, 4L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 1L, 1L,
 1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 3L, 3L, 1L,
 1L, 3L, 3L, 1L, 4L, 1L, 4L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 3L, 4L,
 3L, 3L, 3L, 4L, 4L, 3L, 4L, 1L, 3L, 1L, 1L, 1L, 1L, 4L, 1L, 4L,
 4L, 1L, 3L, 4L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 3L, 1L, 1L,
 1L, 1L, 3L, 4L, 1L, 1L, 3L, 3L, 4L, 4L, 1L, 3L, 1L, 4L, 1L, 3L,
 1L, 1L, 1L, 1L, 3L, 3L, 1L, 3L, 4L, 1L, 1L, 4L, 3L, 1L, 3L, 1L,
 1L, 3L, 1L, 1L, 4L, 1L, 1L, 1L, 4L, 3L, 1L, 3L), .Label = c(   ,
 5.6, No , Yes), class = factor)

 Pancho Mulongeni
 Research Assistant
 PharmAccess Foundation
 1 Fouchè Street
 Windhoek West
 Windhoek
 Namibia
   
 Tel:   +264 61 419 000
 Fax:  +264 61 419 001/2
 Mob: +264 81 276 6075

 __
 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.

__
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.


[R] Setting all rows of a certain level to NA in a factor

2012-10-17 Thread Pancho Mulongeni
Hello everyone.
My task is set certain levels (that is all rows of that level) as missing 
values in factor B20_A.
Excuse the notation, it happens to be a question number in a survey.
So I thought it would work easily by defining the levels
and their labels using the 'factor' function.

 levels(B20_A)
[1] 5.6 No  Yes
#as you can see 'No' is a level.
#I below define the levels, I expect 5.6 and blank to be set as NA
B20_A-factor(B20_A,levels=c('No','Yes'),labels=c('No','Yes'))
summary(B20_A)

  No  Yes NA's 
   0  149  580 
to my surprise, 'No' is also set as NA, why is this happening?

I am a frequent SPSS user and I am surprised that this operation does not seem 
to be so straight forward in R.
Thanks
my object is defined below.
structure(c(4L, 1L, 4L, 4L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 
3L, 3L, 1L, 1L, 4L, 1L, 4L, 4L, 3L, 1L, 3L, 4L, 3L, 4L, 3L, 3L, 
1L, 1L, 3L, 1L, 3L, 4L, 4L, 3L, 1L, 1L, 4L, 4L, 3L, 3L, 3L, 1L, 
3L, 3L, 3L, 1L, 4L, 1L, 4L, 1L, 1L, 1L, 3L, 3L, 1L, 4L, 4L, 3L, 
1L, 1L, 4L, 4L, 3L, 1L, 1L, 3L, 1L, 4L, 3L, 3L, 3L, 1L, 4L, 3L, 
3L, 4L, 4L, 4L, 4L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 1L, 3L, 1L, 
1L, 1L, 3L, 1L, 1L, 4L, 3L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 
3L, 1L, 3L, 3L, 4L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 
4L, 1L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 
4L, 4L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 3L, 3L, 4L, 4L, 1L, 
1L, 3L, 3L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 1L, 4L, 
3L, 3L, 1L, 3L, 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L, 3L, 1L, 1L, 
1L, 1L, 3L, 4L, 1L, 1L, 3L, 3L, 4L, 4L, 1L, 3L, 1L, 4L, 1L, 3L, 
1L, 1L, 1L, 1L, 3L, 3L, 1L, 3L, 4L, 1L, 1L, 4L, 3L, 1L, 3L, 1L, 
1L, 3L, 1L, 1L, 4L, 1L, 1L, 1L, 4L, 3L, 1L, 3L), .Label = c(   , 
5.6, No , Yes), class = factor)

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouchè Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 276 6075

__
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.