Extract data of special character

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Extract data of special character

roslinazairimah zakaria
Hi r-users,

I have these data and I would like to count (frequency) how many of
ATTRIBUTE related to TRAITS.

> dput(dd)
structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("AA11063",
"AA11127", "AA15194", "CB13086", "EA15058"), class = "factor"),
    NAME = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L,
    4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("FIONA ANAK
GASING",
    "JAMES WONG NGUONG DEK", "KOH BEE FONG", "NUR EZREEN BINTI JASNI",
    "SIOW SIN YANG"), class = "factor"), FACULTY = structure(c(1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L,
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L), .Label = c("FKASA", "FKEE", "FSKKP"), class =
"factor"),
    ATTRIBUTE = structure(c(7L, 9L, 1L, 5L, 6L, 4L, 3L, 2L, 8L,
    10L, 7L, 9L, 1L, 5L, 6L, 4L, 3L, 2L, 8L, 10L, 7L, 9L, 1L,
    5L, 6L, 4L, 3L, 2L, 8L, 10L, 7L, 9L, 1L, 5L, 6L, 4L, 3L,
    2L, 8L, 10L, 7L, 9L, 1L, 5L, 6L, 4L, 3L, 2L, 8L, 10L), .Label =
c("COMMUNICATION",
    "CREATIVITY", "ENTREPRENEURIAL SKILLS", "INFORMATION MANAGEMENT AND
LIFELONG LEARNING",
    "LEADERSHIP AND TEAMWORK SKILLS", "PROBLEM SOLVING", "SOCIAL SKILLS",
    "UNITY AND PATRIOTISM", "VALUES, ATTITUDES AND PROFESSIONALISM",
    "VOLUNTEERISM"), class = "factor"), POINT = structure(c(3L,
    20L, 21L, 3L, 12L, 25L, 19L, 12L, 11L, 21L, 11L, 11L, 26L,
    7L, 5L, 16L, 12L, 4L, 16L, 27L, 4L, 16L, 12L, 8L, 4L, 4L,
    19L, 19L, 25L, 15L, 6L, 1L, 14L, 9L, 14L, 4L, 15L, 22L, 23L,
    19L, 4L, 2L, 17L, 10L, 18L, 16L, 12L, 24L, 13L, 4L), .Label =
c("1,030",
    "1,160", "10", "120", "140", "2,100", "2,140", "2,380", "2,390",
    "2,440", "20", "240", "320", "340", "360", "40", "400", "440",
    "480", "520", "60", "600", "700", "720", "80", "810", "840"
    ), class = "factor"), SCORE = c(2L, 35L, 6L, 1L, 48L, 16L,
    96L, 24L, 2L, 6L, 4L, 1L, 81L, 100L, 28L, 8L, 48L, 12L, 4L,
    84L, 24L, 3L, 24L, 100L, 24L, 24L, 96L, 48L, 8L, 36L, 100L,
    69L, 34L, 100L, 68L, 24L, 72L, 60L, 70L, 48L, 24L, 77L, 40L,
    100L, 88L, 8L, 48L, 72L, 32L, 12L), TRAIT = structure(c(5L,
    5L, 5L, 3L, 4L, 5L, 2L, 5L, 5L, 5L, 5L, 5L, 2L, 2L, 5L, 5L,
    4L, 5L, 5L, 2L, 5L, 5L, 5L, 2L, 5L, 5L, 2L, 4L, 5L, 5L, 2L,
    6L, 5L, 2L, 6L, 5L, 1L, 6L, 1L, 4L, 5L, 1L, 4L, 2L, 2L, 5L,
    4L, 1L, 5L, 5L), .Label = c("ACHIEVER", "CONQUEROR", "INTROVERT",
    "NOVICE", "SEEKER", "SURVIVOR"), class = "factor")), class =
"data.frame", row.names = c(NA,-50L))

Thank you so much for any help given.
--
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: [hidden email] <[hidden email]>;
[hidden email] <[hidden email]>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

        [[alternative HTML version deleted]]

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

Re: Extract data of special character

Ivan Krylov
On Fri, 15 Mar 2019 03:06:28 +0800
roslinazairimah zakaria <[hidden email]> wrote:

> how many of ATTRIBUTE related to TRAITS.

The table() function can be used to count occurrences of each
combination of factor levels. Does extracting the two columns by
dd[,c('ATTRIBUTE','TRAIT')] and passing the result to table() help?

--
Best regards,
Ivan

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

Re: Extract data of special character

Rui Barradas
Hello,

Or more simple,

xtabs( ~ ATTRIBUTE + TRAIT, dd)


Hope this helps,

Rui Barradas

Às 19:27 de 14/03/2019, Ivan Krylov escreveu:
> On Fri, 15 Mar 2019 03:06:28 +0800
> roslinazairimah zakaria <[hidden email]> wrote:
>
>> how many of ATTRIBUTE related to TRAITS.
>
> The table() function can be used to count occurrences of each
> combination of factor levels. Does extracting the two columns by
> dd[,c('ATTRIBUTE','TRAIT')] and passing the result to table() help?
>

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

Re: Extract data of special character

roslinazairimah zakaria
Yes, it does.

table(dd$ATTRIBUTE, dd$TRAIT) #or
xtabs( ~ ATTRIBUTE + TRAIT, dd)

Thank you so much Rui and Ivan.

On Fri, Mar 15, 2019 at 5:51 AM Rui Barradas <[hidden email]> wrote:

> Hello,
>
> Or more simple,
>
> xtabs( ~ ATTRIBUTE + TRAIT, dd)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 19:27 de 14/03/2019, Ivan Krylov escreveu:
> > On Fri, 15 Mar 2019 03:06:28 +0800
> > roslinazairimah zakaria <[hidden email]> wrote:
> >
> >> how many of ATTRIBUTE related to TRAITS.
> >
> > The table() function can be used to count occurrences of each
> > combination of factor levels. Does extracting the two columns by
> > dd[,c('ATTRIBUTE','TRAIT')] and passing the result to table() help?
> >
>


--
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: [hidden email] <[hidden email]>;
[hidden email] <[hidden email]>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

        [[alternative HTML version deleted]]

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

Re: Extract data of special character

roslinazairimah zakaria
In reply to this post by Rui Barradas
Hi Rui and Ivan,
Yes both works well.

table(dd$ATTRIBUTE, dd$TRAIT) #or
xtabs( ~ ATTRIBUTE + TRAIT, dd)

I have another question,I also want to extract all the PCT_SCORE to draw
box plot. I have tried to draw box of PCT_SCORE for all attribute scores.

boxplot(dd$PCT_SCORE, ylim=c(0,100),
        main="Cohort 2015:Distribution of Score % of all attributes",
        xlab="Score(%) of all attribute",horizontal=TRUE,
cex.axis=0.8,cex.main=0.8, cex.lab=0.8, col="lightblue" )

However, I want to draw boxplot for each individual score of the
attributes. That is to extract data of the sub-attribute eg. COMMUNICATION,
CREATIVITY, ENTREPRENEURIAL SKILLS and etc.

Thank you.



On Fri, Mar 15, 2019 at 5:51 AM Rui Barradas <[hidden email]> wrote:

> Hello,
>
> Or more simple,
>
> xtabs( ~ ATTRIBUTE + TRAIT, dd)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 19:27 de 14/03/2019, Ivan Krylov escreveu:
> > On Fri, 15 Mar 2019 03:06:28 +0800
> > roslinazairimah zakaria <[hidden email]> wrote:
> >
> >> how many of ATTRIBUTE related to TRAITS.
> >
> > The table() function can be used to count occurrences of each
> > combination of factor levels. Does extracting the two columns by
> > dd[,c('ATTRIBUTE','TRAIT')] and passing the result to table() help?
> >
>


--
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: [hidden email] <[hidden email]>;
[hidden email] <[hidden email]>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

        [[alternative HTML version deleted]]

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

Re: Extract data of special character

Ivan Krylov
В Fri, 15 Mar 2019 08:06:52 +0800
roslinazairimah zakaria <[hidden email]> пишет:

> I want to draw boxplot for each individual score of the
> attributes.

You mean, a box per every possible ATTRIBUTE value? This is easily
doable with the bwplot() function from library(lattice).

--
Best regards,
Ivan

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

Re: Extract data of special character

Rui Barradas
In reply to this post by roslinazairimah zakaria
Hello,

Something like this?


old_par <- par(mar = par("mar") + c(5, 0, -2, 0))
boxplot(SCORE ~ ATTRIBUTE, dd, cex.axis = 0.6, las = 2)
par(old_par)


Hope this helps,

Rui Barradas

Às 00:06 de 15/03/2019, roslinazairimah zakaria escreveu:

> Hi Rui and Ivan,
> Yes both works well.
>
> table(dd$ATTRIBUTE, dd$TRAIT) #or
> xtabs( ~ ATTRIBUTE + TRAIT, dd)
>
> I have another question,I also want to extract all the PCT_SCORE to draw
> box plot. I have tried to draw box of PCT_SCORE for all attribute scores.
>
> boxplot(dd$PCT_SCORE, ylim=c(0,100),
>          main="Cohort 2015:Distribution of Score % of all attributes",
>          xlab="Score(%) of all attribute",horizontal=TRUE,
> cex.axis=0.8,cex.main=0.8, cex.lab=0.8, col="lightblue" )
>
> However, I want to draw boxplot for each individual score of the
> attributes. That is to extract data of the sub-attribute eg.
> COMMUNICATION, CREATIVITY, ENTREPRENEURIAL SKILLS and etc.
>
> Thank you.
>
>
>
> On Fri, Mar 15, 2019 at 5:51 AM Rui Barradas <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hello,
>
>     Or more simple,
>
>     xtabs( ~ ATTRIBUTE + TRAIT, dd)
>
>
>     Hope this helps,
>
>     Rui Barradas
>
>     Às 19:27 de 14/03/2019, Ivan Krylov escreveu:
>      > On Fri, 15 Mar 2019 03:06:28 +0800
>      > roslinazairimah zakaria <[hidden email]
>     <mailto:[hidden email]>> wrote:
>      >
>      >> how many of ATTRIBUTE related to TRAITS.
>      >
>      > The table() function can be used to count occurrences of each
>      > combination of factor levels. Does extracting the two columns by
>      > dd[,c('ATTRIBUTE','TRAIT')] and passing the result to table() help?
>      >
>
>
>
> --
> *Roslinazairimah Zakaria*
> *Tel: +609-5492370; Fax. No.+609-5492766*
> *Email: [hidden email] <mailto:[hidden email]>;
> [hidden email] <mailto:[hidden email]>
> *
> Faculty of Industrial Sciences & Technology
> University Malaysia Pahang
> Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

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