Re: [R] [FORGED] Re: Value Labels: SPSS Dataset to R

2020-02-07 Thread Rolf Turner



Dear Yawo,

I would suggest that you learn to use R, rather than thrashing around 
blindly and expecting or hoping to get others to do your work for you.


To get you started, the characteristics that you call "labels" are 
stored as *attributes* of the columns of your tibble/data frame.  E.g.

X$Animal prints as


 [1] 0 0 0 0 0 0 0 0 0 0
attr(,"label")
[1] "Animal"
attr(,"labels")
Cat Dog 
  0   1 
attr(,"class")

[1] "haven_labelled"


(where "X" is the head of CatsDogs that you dput()-ed and sent to the list.)

I would start by doing something like

CatsDogs$Animal <- factor(CatsDogs$Animal,levels=c(0,1),
  labels=c("Cat","Dog"))
and similarly for the other columns.  When you have learnt a bit about 
R, doing your frequency tabulations and barplots will then be easy.


cheers,

Rolf Turner

On 8/02/20 7:03 pm, Yawo Kokuvi wrote:

Thanks for all. Here is output from dput.  I used a different dataset
containing categorical variables since the previous one is on a different
computer.

In the following dataset, my interest is in getting frequencies and
barplots for the two variables: Training and Dance, with value labels
displayed.

thanks again - cY


=
dput(head(CatsDogs, n = 10))
structure(
   list(
 Animal = structure(
   c(0, 0, 0, 0, 0, 0, 0, 0, 0,
 0),
   label = "Animal",
   labels = c(Cat = 0, Dog = 1),
   class = "haven_labelled"
 ),
 Training = structure(
   c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
   label = "Type of Training",
   labels = c(`Food as Reward` = 0,
  `Affection as Reward` = 1),
   class = "haven_labelled"
 ),
 Dance = structure(
   c(1,
 1, 1, 1, 1, 1, 1, 1, 1, 1),
   label = "Did they dance?",
   labels = c(No = 0,
  Yes = 1),
   class = "haven_labelled"
 )
   ),
   row.names = c(NA,-10L),
   class = c("tbl_df", "tbl", "data.frame")
)




__
R-help@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.


Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Yawo Kokuvi
Thanks for all. Here is output from dput.  I used a different dataset
containing categorical variables since the previous one is on a different
computer.

In the following dataset, my interest is in getting frequencies and
barplots for the two variables: Training and Dance, with value labels
displayed.

thanks again - cY


=
dput(head(CatsDogs, n = 10))
structure(
  list(
Animal = structure(
  c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0),
  label = "Animal",
  labels = c(Cat = 0, Dog = 1),
  class = "haven_labelled"
),
Training = structure(
  c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
  label = "Type of Training",
  labels = c(`Food as Reward` = 0,
 `Affection as Reward` = 1),
  class = "haven_labelled"
),
Dance = structure(
  c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1),
  label = "Did they dance?",
  labels = c(No = 0,
 Yes = 1),
  class = "haven_labelled"
)
  ),
  row.names = c(NA,-10L),
  class = c("tbl_df", "tbl", "data.frame")
)


On Fri, Feb 7, 2020 at 10:14 PM Bert Gunter  wrote:

> Yes. Most attachments are stripped by the server.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Fri, Feb 7, 2020 at 5:34 PM John Kane  wrote:
>
>> Hi,
>> Could you upload some sample data in dput form?  Something like
>> dput(head(Scratch, n=13)) will give us some real data to examine. Just
>> copy
>> and paste the output of dput(head(Scratch, n=13))into the email. This is
>> the best way to ensure that R-help denizens are getting the data in the
>> exact format that you have.
>>
>> On Fri, 7 Feb 2020 at 15:32, Yawo Kokuvi  wrote:
>>
>> > Thanks for all your assistance
>> >
>> > Attached please is the Rdata scratch I have been using
>> >
>> > -
>> >
>> > > head(Scratch, n=13)
>> > # A tibble: 13 x 6
>> >   ID   maritalsex  racepaeducspeduc
>> >  
>> >  1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
>> >  2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
>> >  3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
>> >  4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
>> >  5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
>> >  6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
>> >  7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
>> >  8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
>> >  9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
>> > 1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
>> > 1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
>> > 1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
>> > 1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA
>> >
>> > -
>> >
>> > and below is my script/command file.
>> >
>> > *#1: Load library and import SPSS dataset*
>> > library(haven)
>> > Scratch <- read_sav("~/Desktop/Scratch.sav")
>> >
>> > *#2: save the dataset with a name*
>> > save(ScratchImport, file="Scratch.Rdata")
>> >
>> > *#3: install & load necessary packages for descriptive statistics*
>> > install.packages ("freqdist")
>> > library (freqdist)
>> >
>> > install.packages ("sjlabelled")
>> > library (sjlabelled)
>> >
>> > install.packages ("labelled")
>> > library (labelled)
>> >
>> > install.packages ("surveytoolbox")
>> > library (surveytoolbox)
>> >
>> > *#4: Check the value labels of gender and marital status*
>> > Scratch$sex %>% attr('labels')
>> > Scratch$marital %>% attr('labels')
>> >
>> > *#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
>> > Variables such as Gender - SEX*
>> > freqdist(Scratch$sex)
>> > barplot(table(Scratch$marital))
>> >
>> > -
>> >
>> > As you can see from above, I use the  package to import the data
>> > from SPSS.  Apparently, the haven function keeps the value labels, as
>> the
>> > attribute options in section #4 of my script shows.
>> > The problem is that when I run frequency distribution for any of the
>> > categorical variables like sex or marital status, only the numbers (1,
>> 2,)
>> > are displayed in the output.  The labels (male, female) for example are
>> > not.
>> >
>> > Is there any way to force these to be shown in the output?  Is there a
>> > global property that I have to set so that these value labels are
>> reliably
>> > displayed with every output?  I read I can declare them as factors using
>> > the , but once I do so, how do I invoke them in my
>> commands so
>> > that the value labels show...
>> >
>> > Sorry about all the noobs questions, but Ihopefully, I am able 

Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Bert Gunter
Yes. Most attachments are stripped by the server.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Feb 7, 2020 at 5:34 PM John Kane  wrote:

> Hi,
> Could you upload some sample data in dput form?  Something like
> dput(head(Scratch, n=13)) will give us some real data to examine. Just copy
> and paste the output of dput(head(Scratch, n=13))into the email. This is
> the best way to ensure that R-help denizens are getting the data in the
> exact format that you have.
>
> On Fri, 7 Feb 2020 at 15:32, Yawo Kokuvi  wrote:
>
> > Thanks for all your assistance
> >
> > Attached please is the Rdata scratch I have been using
> >
> > -
> >
> > > head(Scratch, n=13)
> > # A tibble: 13 x 6
> >   ID   maritalsex  racepaeducspeduc
> >  
> >  1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
> >  2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
> >  3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
> >  4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
> >  5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
> >  6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
> >  7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
> >  8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
> >  9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
> > 1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
> > 1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
> > 1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
> > 1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA
> >
> > -
> >
> > and below is my script/command file.
> >
> > *#1: Load library and import SPSS dataset*
> > library(haven)
> > Scratch <- read_sav("~/Desktop/Scratch.sav")
> >
> > *#2: save the dataset with a name*
> > save(ScratchImport, file="Scratch.Rdata")
> >
> > *#3: install & load necessary packages for descriptive statistics*
> > install.packages ("freqdist")
> > library (freqdist)
> >
> > install.packages ("sjlabelled")
> > library (sjlabelled)
> >
> > install.packages ("labelled")
> > library (labelled)
> >
> > install.packages ("surveytoolbox")
> > library (surveytoolbox)
> >
> > *#4: Check the value labels of gender and marital status*
> > Scratch$sex %>% attr('labels')
> > Scratch$marital %>% attr('labels')
> >
> > *#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
> > Variables such as Gender - SEX*
> > freqdist(Scratch$sex)
> > barplot(table(Scratch$marital))
> >
> > -
> >
> > As you can see from above, I use the  package to import the data
> > from SPSS.  Apparently, the haven function keeps the value labels, as the
> > attribute options in section #4 of my script shows.
> > The problem is that when I run frequency distribution for any of the
> > categorical variables like sex or marital status, only the numbers (1,
> 2,)
> > are displayed in the output.  The labels (male, female) for example are
> > not.
> >
> > Is there any way to force these to be shown in the output?  Is there a
> > global property that I have to set so that these value labels are
> reliably
> > displayed with every output?  I read I can declare them as factors using
> > the , but once I do so, how do I invoke them in my commands
> so
> > that the value labels show...
> >
> > Sorry about all the noobs questions, but Ihopefully, I am able to get
> this
> > working.
> >
> > Thanks in advance.
> >
> >
> > Thanks - cY
> >
> >
> > On Fri, Feb 7, 2020 at 1:14 PM  wrote:
> >
> > > I've never used it, but there is a labels function in haven...
> > >
> > > On 7 Feb 2020 17:05, Bert Gunter  wrote:
> > >
> > > What does your data look like after importing? -- see ?head and ?str to
> > > tell us. Show us the code that failed to provide "labels." See the
> > posting
> > > guide below for how to post questions that are likely to elicit helpful
> > > responses.
> > >
> > > I know nothing about the haven package, but see ?factor or go through
> an
> > R
> > > tutorial or two to learn about factors, which may be part of the issue
> > > here. R *generally* obtains whatever "label" info it needs from the
> > object
> > > being tabled -- see ?tabulate, ?table etc. -- if that's what you're
> > doing.
> > >
> > > Bert Gunter
> > >
> > > "The trouble with having an open mind is that people keep coming along
> > and
> > > sticking things into it."
> > > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> > >
> > >
> > > On Fri, Feb 7, 2020 at 8:28 AM Yawo Kokuvi  wrote:
> > >
> > > > Hello,
> > > >
> > > > I am just 

Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread John Kane
Hi,
Could you upload some sample data in dput form?  Something like
dput(head(Scratch, n=13)) will give us some real data to examine. Just copy
and paste the output of dput(head(Scratch, n=13))into the email. This is
the best way to ensure that R-help denizens are getting the data in the
exact format that you have.

On Fri, 7 Feb 2020 at 15:32, Yawo Kokuvi  wrote:

> Thanks for all your assistance
>
> Attached please is the Rdata scratch I have been using
>
> -
>
> > head(Scratch, n=13)
> # A tibble: 13 x 6
>   ID   maritalsex  racepaeducspeduc
>  
>  1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
>  2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
>  3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
>  4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
>  5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
>  6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
>  7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
>  8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
>  9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
> 1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
> 1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
> 1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
> 1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA
>
> -
>
> and below is my script/command file.
>
> *#1: Load library and import SPSS dataset*
> library(haven)
> Scratch <- read_sav("~/Desktop/Scratch.sav")
>
> *#2: save the dataset with a name*
> save(ScratchImport, file="Scratch.Rdata")
>
> *#3: install & load necessary packages for descriptive statistics*
> install.packages ("freqdist")
> library (freqdist)
>
> install.packages ("sjlabelled")
> library (sjlabelled)
>
> install.packages ("labelled")
> library (labelled)
>
> install.packages ("surveytoolbox")
> library (surveytoolbox)
>
> *#4: Check the value labels of gender and marital status*
> Scratch$sex %>% attr('labels')
> Scratch$marital %>% attr('labels')
>
> *#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
> Variables such as Gender - SEX*
> freqdist(Scratch$sex)
> barplot(table(Scratch$marital))
>
> -
>
> As you can see from above, I use the  package to import the data
> from SPSS.  Apparently, the haven function keeps the value labels, as the
> attribute options in section #4 of my script shows.
> The problem is that when I run frequency distribution for any of the
> categorical variables like sex or marital status, only the numbers (1, 2,)
> are displayed in the output.  The labels (male, female) for example are
> not.
>
> Is there any way to force these to be shown in the output?  Is there a
> global property that I have to set so that these value labels are reliably
> displayed with every output?  I read I can declare them as factors using
> the , but once I do so, how do I invoke them in my commands so
> that the value labels show...
>
> Sorry about all the noobs questions, but Ihopefully, I am able to get this
> working.
>
> Thanks in advance.
>
>
> Thanks - cY
>
>
> On Fri, Feb 7, 2020 at 1:14 PM  wrote:
>
> > I've never used it, but there is a labels function in haven...
> >
> > On 7 Feb 2020 17:05, Bert Gunter  wrote:
> >
> > What does your data look like after importing? -- see ?head and ?str to
> > tell us. Show us the code that failed to provide "labels." See the
> posting
> > guide below for how to post questions that are likely to elicit helpful
> > responses.
> >
> > I know nothing about the haven package, but see ?factor or go through an
> R
> > tutorial or two to learn about factors, which may be part of the issue
> > here. R *generally* obtains whatever "label" info it needs from the
> object
> > being tabled -- see ?tabulate, ?table etc. -- if that's what you're
> doing.
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along
> and
> > sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Fri, Feb 7, 2020 at 8:28 AM Yawo Kokuvi  wrote:
> >
> > > Hello,
> > >
> > > I am just transitioning from SPSS to R.
> > >
> > > I used the haven library to import some of my spss data files to R.
> > >
> > > However, when I run procedures such as frequencies or crosstabs, value
> > > labels for categorical variables such as gender (1=male, 2=female) are
> > not
> > > shown. The same applies to many other output.
> > >
> > > I am confused.
> > >
> > > 1. Is there a global setting that I can use to force all categorical
> > > variables to display labels?
> > >
> > > 2. Or, are these labels to be set for each function or package?
> 

Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Heinz Tuechler

Maybe it helps searching at https://rseek.org/ for "SPSS to R transition
value labels".
In particular
https://cran.r-project.org/web/packages/expss/vignettes/labels-support.html
seems useful, as well as
https://www.r-bloggers.com/migrating-from-spss-to-r-rstats/

best regards,
Heinz

Jim Lemon wrote on 07.02.2020 22:58:

Hi Yawo,

From your recent post, you say you have coerced the variables to

factors. If so, perhaps:

as.character(x) is what you want.

If not, creating a new variable like this:

Scratch$new_race<-factor(as.character(Scratch$race),levels=c("WHITE","BLACK"))

may do it. Note the "levels" argument to get the numeric values in the
same order as the original.

Jim

On Sat, Feb 8, 2020 at 7:32 AM Yawo Kokuvi  wrote:


Thanks for all your assistance

Attached please is the Rdata scratch I have been using

-


head(Scratch, n=13)

# A tibble: 13 x 6
  ID   maritalsex  racepaeducspeduc
 
 1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
 2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
 3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
 4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
 5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
 6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
 7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
 8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
 9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA

-

and below is my script/command file.

*#1: Load library and import SPSS dataset*
library(haven)
Scratch <- read_sav("~/Desktop/Scratch.sav")

*#2: save the dataset with a name*
save(ScratchImport, file="Scratch.Rdata")

*#3: install & load necessary packages for descriptive statistics*
install.packages ("freqdist")
library (freqdist)

install.packages ("sjlabelled")
library (sjlabelled)

install.packages ("labelled")
library (labelled)

install.packages ("surveytoolbox")
library (surveytoolbox)

*#4: Check the value labels of gender and marital status*
Scratch$sex %>% attr('labels')
Scratch$marital %>% attr('labels')

*#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
Variables such as Gender - SEX*
freqdist(Scratch$sex)
barplot(table(Scratch$marital))

-

As you can see from above, I use the  package to import the data
from SPSS.  Apparently, the haven function keeps the value labels, as the
attribute options in section #4 of my script shows.
The problem is that when I run frequency distribution for any of the
categorical variables like sex or marital status, only the numbers (1, 2,)
are displayed in the output.  The labels (male, female) for example are not.

Is there any way to force these to be shown in the output?  Is there a
global property that I have to set so that these value labels are reliably
displayed with every output?  I read I can declare them as factors using
the , but once I do so, how do I invoke them in my commands so
that the value labels show...

Sorry about all the noobs questions, but Ihopefully, I am able to get this
working.

Thanks in advance.


Thanks - cY


On Fri, Feb 7, 2020 at 1:14 PM  wrote:


I've never used it, but there is a labels function in haven...

On 7 Feb 2020 17:05, Bert Gunter  wrote:

What does your data look like after importing? -- see ?head and ?str to
tell us. Show us the code that failed to provide "labels." See the posting
guide below for how to post questions that are likely to elicit helpful
responses.

I know nothing about the haven package, but see ?factor or go through an R
tutorial or two to learn about factors, which may be part of the issue
here. R *generally* obtains whatever "label" info it needs from the object
being tabled -- see ?tabulate, ?table etc. -- if that's what you're doing.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Feb 7, 2020 at 8:28 AM Yawo Kokuvi  wrote:


Hello,

I am just transitioning from SPSS to R.

I used the haven library to import some of my spss data files to R.

However, when I run procedures such as frequencies or crosstabs, value
labels for categorical variables such as gender (1=male, 2=female) are

not

shown. The same applies to many other output.

I am confused.

1. Is there a global setting that I can use to force all categorical
variables to display labels?

2. Or, are these 

Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Yawo Kokuvi
Thanks Jim:

So one option is to go through the data, select all the categorical
variables I want and re-define them as factor variables ?  As in the
following example for gender?

mydata$sex<- factor(mydata$sex, levels = c(1,2), labels = c("male",
"female"))

thanks - cY

On Fri, Feb 7, 2020 at 4:58 PM Jim Lemon  wrote:

> Hi Yawo,
> From your recent post, you say you have coerced the variables to
> factors. If so, perhaps:
>
> as.character(x) is what you want.
>
> If not, creating a new variable like this:
>
>
> Scratch$new_race<-factor(as.character(Scratch$race),levels=c("WHITE","BLACK"))
>
> may do it. Note the "levels" argument to get the numeric values in the
> same order as the original.
>
> Jim
>
> On Sat, Feb 8, 2020 at 7:32 AM Yawo Kokuvi  wrote:
> >
> > Thanks for all your assistance
> >
> > Attached please is the Rdata scratch I have been using
> >
> > -
> >
> > > head(Scratch, n=13)
> > # A tibble: 13 x 6
> >   ID   maritalsex  racepaeducspeduc
> >  
> >  1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
> >  2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
> >  3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
> >  4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
> >  5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
> >  6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
> >  7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
> >  8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
> >  9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
> > 1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
> > 1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
> > 1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
> > 1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA
> >
> > -
> >
> > and below is my script/command file.
> >
> > *#1: Load library and import SPSS dataset*
> > library(haven)
> > Scratch <- read_sav("~/Desktop/Scratch.sav")
> >
> > *#2: save the dataset with a name*
> > save(ScratchImport, file="Scratch.Rdata")
> >
> > *#3: install & load necessary packages for descriptive statistics*
> > install.packages ("freqdist")
> > library (freqdist)
> >
> > install.packages ("sjlabelled")
> > library (sjlabelled)
> >
> > install.packages ("labelled")
> > library (labelled)
> >
> > install.packages ("surveytoolbox")
> > library (surveytoolbox)
> >
> > *#4: Check the value labels of gender and marital status*
> > Scratch$sex %>% attr('labels')
> > Scratch$marital %>% attr('labels')
> >
> > *#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
> > Variables such as Gender - SEX*
> > freqdist(Scratch$sex)
> > barplot(table(Scratch$marital))
> >
> > -
> >
> > As you can see from above, I use the  package to import the data
> > from SPSS.  Apparently, the haven function keeps the value labels, as the
> > attribute options in section #4 of my script shows.
> > The problem is that when I run frequency distribution for any of the
> > categorical variables like sex or marital status, only the numbers (1,
> 2,)
> > are displayed in the output.  The labels (male, female) for example are
> not.
> >
> > Is there any way to force these to be shown in the output?  Is there a
> > global property that I have to set so that these value labels are
> reliably
> > displayed with every output?  I read I can declare them as factors using
> > the , but once I do so, how do I invoke them in my commands
> so
> > that the value labels show...
> >
> > Sorry about all the noobs questions, but Ihopefully, I am able to get
> this
> > working.
> >
> > Thanks in advance.
> >
> >
> > Thanks - cY
> >
> >
> > On Fri, Feb 7, 2020 at 1:14 PM  wrote:
> >
> > > I've never used it, but there is a labels function in haven...
> > >
> > > On 7 Feb 2020 17:05, Bert Gunter  wrote:
> > >
> > > What does your data look like after importing? -- see ?head and ?str to
> > > tell us. Show us the code that failed to provide "labels." See the
> posting
> > > guide below for how to post questions that are likely to elicit helpful
> > > responses.
> > >
> > > I know nothing about the haven package, but see ?factor or go through
> an R
> > > tutorial or two to learn about factors, which may be part of the issue
> > > here. R *generally* obtains whatever "label" info it needs from the
> object
> > > being tabled -- see ?tabulate, ?table etc. -- if that's what you're
> doing.
> > >
> > > Bert Gunter
> > >
> > > "The trouble with having an open mind is that people keep coming along
> and
> > > sticking things into it."
> > > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> > >
> > >
> > > On Fri, Feb 7, 2020 

Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Jim Lemon
Hi Yawo,
>From your recent post, you say you have coerced the variables to
factors. If so, perhaps:

as.character(x) is what you want.

If not, creating a new variable like this:

Scratch$new_race<-factor(as.character(Scratch$race),levels=c("WHITE","BLACK"))

may do it. Note the "levels" argument to get the numeric values in the
same order as the original.

Jim

On Sat, Feb 8, 2020 at 7:32 AM Yawo Kokuvi  wrote:
>
> Thanks for all your assistance
>
> Attached please is the Rdata scratch I have been using
>
> -
>
> > head(Scratch, n=13)
> # A tibble: 13 x 6
>   ID   maritalsex  racepaeducspeduc
>  
>  1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
>  2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
>  3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
>  4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
>  5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
>  6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
>  7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
>  8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
>  9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
> 1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
> 1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
> 1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
> 1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA
>
> -
>
> and below is my script/command file.
>
> *#1: Load library and import SPSS dataset*
> library(haven)
> Scratch <- read_sav("~/Desktop/Scratch.sav")
>
> *#2: save the dataset with a name*
> save(ScratchImport, file="Scratch.Rdata")
>
> *#3: install & load necessary packages for descriptive statistics*
> install.packages ("freqdist")
> library (freqdist)
>
> install.packages ("sjlabelled")
> library (sjlabelled)
>
> install.packages ("labelled")
> library (labelled)
>
> install.packages ("surveytoolbox")
> library (surveytoolbox)
>
> *#4: Check the value labels of gender and marital status*
> Scratch$sex %>% attr('labels')
> Scratch$marital %>% attr('labels')
>
> *#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
> Variables such as Gender - SEX*
> freqdist(Scratch$sex)
> barplot(table(Scratch$marital))
>
> -
>
> As you can see from above, I use the  package to import the data
> from SPSS.  Apparently, the haven function keeps the value labels, as the
> attribute options in section #4 of my script shows.
> The problem is that when I run frequency distribution for any of the
> categorical variables like sex or marital status, only the numbers (1, 2,)
> are displayed in the output.  The labels (male, female) for example are not.
>
> Is there any way to force these to be shown in the output?  Is there a
> global property that I have to set so that these value labels are reliably
> displayed with every output?  I read I can declare them as factors using
> the , but once I do so, how do I invoke them in my commands so
> that the value labels show...
>
> Sorry about all the noobs questions, but Ihopefully, I am able to get this
> working.
>
> Thanks in advance.
>
>
> Thanks - cY
>
>
> On Fri, Feb 7, 2020 at 1:14 PM  wrote:
>
> > I've never used it, but there is a labels function in haven...
> >
> > On 7 Feb 2020 17:05, Bert Gunter  wrote:
> >
> > What does your data look like after importing? -- see ?head and ?str to
> > tell us. Show us the code that failed to provide "labels." See the posting
> > guide below for how to post questions that are likely to elicit helpful
> > responses.
> >
> > I know nothing about the haven package, but see ?factor or go through an R
> > tutorial or two to learn about factors, which may be part of the issue
> > here. R *generally* obtains whatever "label" info it needs from the object
> > being tabled -- see ?tabulate, ?table etc. -- if that's what you're doing.
> >
> > Bert Gunter
> >
> > "The trouble with having an open mind is that people keep coming along and
> > sticking things into it."
> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> > On Fri, Feb 7, 2020 at 8:28 AM Yawo Kokuvi  wrote:
> >
> > > Hello,
> > >
> > > I am just transitioning from SPSS to R.
> > >
> > > I used the haven library to import some of my spss data files to R.
> > >
> > > However, when I run procedures such as frequencies or crosstabs, value
> > > labels for categorical variables such as gender (1=male, 2=female) are
> > not
> > > shown. The same applies to many other output.
> > >
> > > I am confused.
> > >
> > > 1. Is there a global setting that I can use to force all categorical
> > > variables to display labels?
> > >
> > > 2. Or, are these labels to 

Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Yawo Kokuvi
Thanks for all your assistance

Attached please is the Rdata scratch I have been using

-

> head(Scratch, n=13)
# A tibble: 13 x 6
  ID   maritalsex  racepaeducspeduc
 
 1 1 3 [DIVORCED]  1 [MALE]   1 [WHITE]NANA
 2 2 1 [MARRIED]   1 [MALE]   1 [WHITE]NANA
 3 3 3 [DIVORCED]  1 [MALE]   1 [WHITE] 4NA
 4 4 4 [SEPARATED] 1 [MALE]   1 [WHITE]16NA
 5 5 3 [DIVORCED]  1 [MALE]   1 [WHITE]18NA
 6 6 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1420
 7 7 1 [MARRIED]   2 [FEMALE] 2 [BLACK]NA12
 8 8 1 [MARRIED]   2 [FEMALE] 1 [WHITE]NA12
 9 9 3 [DIVORCED]  2 [FEMALE] 1 [WHITE]11NA
1010 1 [MARRIED]   2 [FEMALE] 1 [WHITE]1612
1111 5 [NEVER MARRIED] 2 [FEMALE] 2 [BLACK]NANA
1212 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]NANA
1313 3 [DIVORCED]  2 [FEMALE] 2 [BLACK]16NA

-

and below is my script/command file.

*#1: Load library and import SPSS dataset*
library(haven)
Scratch <- read_sav("~/Desktop/Scratch.sav")

*#2: save the dataset with a name*
save(ScratchImport, file="Scratch.Rdata")

*#3: install & load necessary packages for descriptive statistics*
install.packages ("freqdist")
library (freqdist)

install.packages ("sjlabelled")
library (sjlabelled)

install.packages ("labelled")
library (labelled)

install.packages ("surveytoolbox")
library (surveytoolbox)

*#4: Check the value labels of gender and marital status*
Scratch$sex %>% attr('labels')
Scratch$marital %>% attr('labels')

*#5:  Frequency Distribution and BarChart for Categorical/Ordinal Level
Variables such as Gender - SEX*
freqdist(Scratch$sex)
barplot(table(Scratch$marital))

-

As you can see from above, I use the  package to import the data
from SPSS.  Apparently, the haven function keeps the value labels, as the
attribute options in section #4 of my script shows.
The problem is that when I run frequency distribution for any of the
categorical variables like sex or marital status, only the numbers (1, 2,)
are displayed in the output.  The labels (male, female) for example are not.

Is there any way to force these to be shown in the output?  Is there a
global property that I have to set so that these value labels are reliably
displayed with every output?  I read I can declare them as factors using
the , but once I do so, how do I invoke them in my commands so
that the value labels show...

Sorry about all the noobs questions, but Ihopefully, I am able to get this
working.

Thanks in advance.


Thanks - cY


On Fri, Feb 7, 2020 at 1:14 PM  wrote:

> I've never used it, but there is a labels function in haven...
>
> On 7 Feb 2020 17:05, Bert Gunter  wrote:
>
> What does your data look like after importing? -- see ?head and ?str to
> tell us. Show us the code that failed to provide "labels." See the posting
> guide below for how to post questions that are likely to elicit helpful
> responses.
>
> I know nothing about the haven package, but see ?factor or go through an R
> tutorial or two to learn about factors, which may be part of the issue
> here. R *generally* obtains whatever "label" info it needs from the object
> being tabled -- see ?tabulate, ?table etc. -- if that's what you're doing.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Fri, Feb 7, 2020 at 8:28 AM Yawo Kokuvi  wrote:
>
> > Hello,
> >
> > I am just transitioning from SPSS to R.
> >
> > I used the haven library to import some of my spss data files to R.
> >
> > However, when I run procedures such as frequencies or crosstabs, value
> > labels for categorical variables such as gender (1=male, 2=female) are
> not
> > shown. The same applies to many other output.
> >
> > I am confused.
> >
> > 1. Is there a global setting that I can use to force all categorical
> > variables to display labels?
> >
> > 2. Or, are these labels to be set for each function or package?
> >
> > 3. How can I request the value labels for each function I run?
> >
> > Thanks in advance for your help..
> >
> > Best, Yawo
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@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]]
>
> 

Re: [R] Plotting DMRs (Differentially Methylated Regions) using Gviz package in R

2020-02-07 Thread pooja sinha
Thanks, I'll check it out.

On Fri, Feb 7, 2020 at 1:08 PM Martin Morgan 
wrote:

> Probably have more success asking on https://support.bioconductor.org.
>
> Martin Morgan
>
> On 2/7/20, 12:57 PM, "R-help on behalf of pooja sinha" <
> r-help-boun...@r-project.org on behalf of pjsinh...@gmail.com> wrote:
>
> Hi All,
>
> I have a file list consisting of Chromosome, Start , End & Methylation
> Difference in the following format in excel:
>
> Chrom Start  End  Meth. Diff
>
> chr1 38565900 38566000 -0.20276818
>
> chr1 38870400 38870500 -0.342342342
>
> chr1 39469400 39469500 -0.250260552
>
> chr1 52013600 52013700 -0.37797619
>
> chr1 52751700 52751800  0.257575758
>
> chr1 75505100 75505200 -0.262847308
>
> I need help in plotting the DMRs using Gviz package in R. I tried a
> code
> below but it doesn't turn out correct.
>
> library(GenomicRanges)
> library(grid)
> library(Gviz)
> library(rtracklayer)
> library(BSgenome)
> library(readxl)
> library(BSgenome.Rnorvegicus.UCSC.rn6)
> genome <- getBSgenome("BSgenome.Rnorvegicus.UCSC.rn6")
> genome
> data1 <- read_excel("DMRs_plots.xlsx")
> head(data1)
> data1$Chrom = Chrom$chr1
>
> track1 <- DataTrack(data = data1, from = "38565900" , to = "28225",
> chromosome = Chrom$chr1, name = "DMRs")
>
> itrack <- IdeogramTrack(genome = genome, chromosome = chr)
>
> plotTracks(track1, itrack)
>
>
> If anyone know how to plot and correct my code including how to add
> methylation difference values, then that will be of great help.
>
>
> Thanks,
>
> Puja
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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]]

__
R-help@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.


Re: [R] Plotting DMRs (Differentially Methylated Regions) using Gviz package in R

2020-02-07 Thread Martin Morgan
Probably have more success asking on https://support.bioconductor.org.

Martin Morgan

On 2/7/20, 12:57 PM, "R-help on behalf of pooja sinha" 
 wrote:

Hi All,

I have a file list consisting of Chromosome, Start , End & Methylation
Difference in the following format in excel:

Chrom Start  End  Meth. Diff

chr1 38565900 38566000 -0.20276818

chr1 38870400 38870500 -0.342342342

chr1 39469400 39469500 -0.250260552

chr1 52013600 52013700 -0.37797619

chr1 52751700 52751800  0.257575758

chr1 75505100 75505200 -0.262847308

I need help in plotting the DMRs using Gviz package in R. I tried a code
below but it doesn't turn out correct.

library(GenomicRanges)
library(grid)
library(Gviz)
library(rtracklayer)
library(BSgenome)
library(readxl)
library(BSgenome.Rnorvegicus.UCSC.rn6)
genome <- getBSgenome("BSgenome.Rnorvegicus.UCSC.rn6")
genome
data1 <- read_excel("DMRs_plots.xlsx")
head(data1)
data1$Chrom = Chrom$chr1

track1 <- DataTrack(data = data1, from = "38565900" , to = "28225",
chromosome = Chrom$chr1, name = "DMRs")

itrack <- IdeogramTrack(genome = genome, chromosome = chr)

plotTracks(track1, itrack)


If anyone know how to plot and correct my code including how to add
methylation difference values, then that will be of great help.


Thanks,

Puja

[[alternative HTML version deleted]]

__
R-help@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.

__
R-help@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.


[R] Plotting DMRs (Differentially Methylated Regions) using Gviz package in R

2020-02-07 Thread pooja sinha
Hi All,

I have a file list consisting of Chromosome, Start , End & Methylation
Difference in the following format in excel:

Chrom Start  End  Meth. Diff

chr1 38565900 38566000 -0.20276818

chr1 38870400 38870500 -0.342342342

chr1 39469400 39469500 -0.250260552

chr1 52013600 52013700 -0.37797619

chr1 52751700 52751800  0.257575758

chr1 75505100 75505200 -0.262847308

I need help in plotting the DMRs using Gviz package in R. I tried a code
below but it doesn't turn out correct.

library(GenomicRanges)
library(grid)
library(Gviz)
library(rtracklayer)
library(BSgenome)
library(readxl)
library(BSgenome.Rnorvegicus.UCSC.rn6)
genome <- getBSgenome("BSgenome.Rnorvegicus.UCSC.rn6")
genome
data1 <- read_excel("DMRs_plots.xlsx")
head(data1)
data1$Chrom = Chrom$chr1

track1 <- DataTrack(data = data1, from = "38565900" , to = "28225",
chromosome = Chrom$chr1, name = "DMRs")

itrack <- IdeogramTrack(genome = genome, chromosome = chr)

plotTracks(track1, itrack)


If anyone know how to plot and correct my code including how to add
methylation difference values, then that will be of great help.


Thanks,

Puja

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R-es] Cannot allocate a vector of size...

2020-02-07 Thread Xavier-Andoni Tibau Alberdi
Depende de la operació que quieras hacer con la matriz. Si quitas filas y
columnas en algun momento, quiza lo puedes hacer por bloques y luego la
juntas.  O quizá puedes cargarlo directamente como data.frame? Quanta RAM
tienes? Cuanto pésan los datos?





El vie., 7 feb. 2020 18:04,  escribió:

> Es la primera vez que trabajo con este tipo de datos...No se si se puede
> dividir esa matriz. ¿Cómo lo podría hacer?
>
> Muchas gracias!
> El Vie, 7 de Febrero de 2020, 17:55, Xavier-Andoni Tibau Alberdi escribió:
> > Significa que tus datos són muy grandes y no se pueden guardar en la RAM.
> > Tienes alternativas para dividir la matriz?
> >
> > El vie., 7 feb. 2020 17:26,  escribió:
> >
> >> Buenas tardes,
> >>
> >> Estoy haciendo un análisis de contenido con el paquete tm. A la hora de
> >> ejecutar este código:
> >>  tdm<-TermDocumentMatrix(corpus,control=list(weighting =weightTf))
> >>  tdm.reviews.m<-as.matrix(tdm)
> >>
> >> La primera línea sí me la ejecuta bien pero en la segunda tengo este
> >> error:
> >> Error: cannot allocate vector of size 14.0 Gb
> >>
> >> ¿Cómo puedo corregirlo? Estoy usando la versión de 64bits de R.
> >>
> >> Un saludo
> >>
> >> Miriam
> >>
> >> ___
> >> R-help-es mailing list
> >> R-help-es@r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-help-es
> >>
> >
>
>
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Bert Gunter
What does your data look like after importing? -- see ?head and ?str to
tell us. Show us the code that failed to provide "labels." See the posting
guide below for how to post questions that are likely to elicit helpful
responses.

I know nothing about the haven package, but see ?factor or go through an R
tutorial or two to learn about factors, which may be part of the issue
here. R *generally* obtains whatever "label" info it needs from the object
being tabled -- see ?tabulate, ?table etc. -- if that's what you're doing.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Feb 7, 2020 at 8:28 AM Yawo Kokuvi  wrote:

> Hello,
>
> I am just transitioning from SPSS to R.
>
> I used the haven library to import some of my spss data files to R.
>
> However, when I run procedures such as frequencies or crosstabs, value
> labels for categorical variables such as gender (1=male, 2=female) are not
> shown. The same applies to many other output.
>
> I am confused.
>
> 1. Is there a global setting that I can use to force all categorical
> variables to display labels?
>
> 2. Or, are these labels to be set for each function or package?
>
> 3. How can I request the value labels for each function I run?
>
> Thanks in advance for your help..
>
> Best, Yawo
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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]]

__
R-help@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.


Re: [R-es] Cannot allocate a vector of size...

2020-02-07 Thread Carlos J. Gil Bellosta
La primera matriz es sparse y la segunda no. Tal vez puedas continuar
dentro del universo de tm eliminando términos irrelevantes antes de
construir una matriz no completa. O tal vez puedas construir una matriz
sparse directamente.

El vie., 7 feb. 2020 17:26,  escribió:

> Buenas tardes,
>
> Estoy haciendo un análisis de contenido con el paquete tm. A la hora de
> ejecutar este código:
>  tdm<-TermDocumentMatrix(corpus,control=list(weighting =weightTf))
>  tdm.reviews.m<-as.matrix(tdm)
>
> La primera línea sí me la ejecuta bien pero en la segunda tengo este error:
> Error: cannot allocate vector of size 14.0 Gb
>
> ¿Cómo puedo corregirlo? Estoy usando la versión de 64bits de R.
>
> Un saludo
>
> Miriam
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Cannot allocate a vector of size...

2020-02-07 Thread miriam . alzate
Es la primera vez que trabajo con este tipo de datos...No se si se puede
dividir esa matriz. ¿Cómo lo podría hacer?

Muchas gracias!
El Vie, 7 de Febrero de 2020, 17:55, Xavier-Andoni Tibau Alberdi escribió:
> Significa que tus datos són muy grandes y no se pueden guardar en la RAM.
> Tienes alternativas para dividir la matriz?
>
> El vie., 7 feb. 2020 17:26,  escribió:
>
>> Buenas tardes,
>>
>> Estoy haciendo un análisis de contenido con el paquete tm. A la hora de
>> ejecutar este código:
>>  tdm<-TermDocumentMatrix(corpus,control=list(weighting =weightTf))
>>  tdm.reviews.m<-as.matrix(tdm)
>>
>> La primera línea sí me la ejecuta bien pero en la segunda tengo este
>> error:
>> Error: cannot allocate vector of size 14.0 Gb
>>
>> ¿Cómo puedo corregirlo? Estoy usando la versión de 64bits de R.
>>
>> Un saludo
>>
>> Miriam
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Cannot allocate a vector of size...

2020-02-07 Thread Xavier-Andoni Tibau Alberdi
Significa que tus datos són muy grandes y no se pueden guardar en la RAM.
Tienes alternativas para dividir la matriz?

El vie., 7 feb. 2020 17:26,  escribió:

> Buenas tardes,
>
> Estoy haciendo un análisis de contenido con el paquete tm. A la hora de
> ejecutar este código:
>  tdm<-TermDocumentMatrix(corpus,control=list(weighting =weightTf))
>  tdm.reviews.m<-as.matrix(tdm)
>
> La primera línea sí me la ejecuta bien pero en la segunda tengo este error:
> Error: cannot allocate vector of size 14.0 Gb
>
> ¿Cómo puedo corregirlo? Estoy usando la versión de 64bits de R.
>
> Un saludo
>
> Miriam
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


[R] Value Labels: SPSS Dataset to R

2020-02-07 Thread Yawo Kokuvi
Hello,

I am just transitioning from SPSS to R.

I used the haven library to import some of my spss data files to R.

However, when I run procedures such as frequencies or crosstabs, value
labels for categorical variables such as gender (1=male, 2=female) are not
shown. The same applies to many other output.

I am confused.

1. Is there a global setting that I can use to force all categorical
variables to display labels?

2. Or, are these labels to be set for each function or package?

3. How can I request the value labels for each function I run?

Thanks in advance for your help..

Best, Yawo

[[alternative HTML version deleted]]

__
R-help@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.


[R] k-nearest neighbours from distance matrix in spdep

2020-02-07 Thread Juan Antonio Rodriguez Perez
Dear all,


I am using the spdep package to compute Local Moran Index.

My problem is that I am using 3D coordinates (x,y,z), and I would like to 
compute the k-nearest neighbours (k=10) for each point in my 3D space. I have 
already done this in 2D, by doing the following:


>neighs_k <- knn2nb(knearneigh(as.matrix(full),
k = 10))
> neighs_mat_k <- nb2listw(neighs_k
 style = "W",
 zero.policy = TRUE)

And then I can easily proceed using the neighs_mat_k object.

However, when using x,y,z coordinates I can't run the knearneigh() function on 
it. I tried converting my data to a distance matrix and using mat2listw() 
function like this:

>D <- as.matrix(dist(full, diag=FALSE, upper=FALSE))
>test1 <- mat2listw(D)

...but now I don't know how to retrieve the k-nearest weights from my test1 
object (which would correspond to k-nearest neighbours) without changing the 
class of test1, which is:

> class(test1)
[1] "listw" "nb"
## and contains...:
> ls(test1)
[1] "neighbours" "style"  "weights"


How should I do this? Is this even the right way to proceed?

Thanks all in advance!!
Best wishes,

Juan

[[alternative HTML version deleted]]

__
R-help@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.


[R-es] Cannot allocate a vector of size...

2020-02-07 Thread miriam . alzate
Buenas tardes,

Estoy haciendo un análisis de contenido con el paquete tm. A la hora de
ejecutar este código:
 tdm<-TermDocumentMatrix(corpus,control=list(weighting =weightTf))
 tdm.reviews.m<-as.matrix(tdm)

La primera línea sí me la ejecuta bien pero en la segunda tengo este error:
Error: cannot allocate vector of size 14.0 Gb

¿Cómo puedo corregirlo? Estoy usando la versión de 64bits de R.

Un saludo

Miriam

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [ESS] Prevent new buffer for help from point

2020-02-07 Thread Dirk Eddelbuettel via ESS-help


On 7 February 2020 at 09:06, Alex Branham wrote:
| Can you reproduce this without your .emacs file?

But ESS would not be turned on without it.
 
| Does that buffer's name match any entry in display-buffer-alist or all the
| similar variables?

The buffer my focus is stolen from is any off buffer in R mode, call it R/foo.R

The buffer the focus is moved is called *ess-command-output*

Per C-h v, the value of display-buffer-alist is nil.

Dirk

| On Fri, Feb 7, 2020, 3:39 AM Dirk Eddelbuettel via ESS-help <
| ess-help@r-project.org> wrote:
| 
| >
| > On 6 February 2020 at 10:19, James W. MacDonald wrote:
| > | It's not clear from your question exactly what the behaviour is, but it
| > | sounds like auto complete?
| >
| > No, I like autocomplete.
| >
| > As I wrote in what is still below, I have irony-mode and other helpers.
| > But what is annoying as hell is that ESS decided to
| >   - move focus away from where I am (writing R code)
| >   - move to a completely new buffer (showing help I did not ask for)
| >   - require me to kill the new buffer to get back to where I was
| > which happens *each and every time* I type a token it knows and could
| > complete to a help page it then takes me to.
| >
| > Anyone have an idea what I need to turn on to suppress this?
| >
| > Dirk
| >
| > | On Thu, Feb 6, 2020 at 2:15 AM Dirk Eddelbuettel via ESS-help <
| > | ess-help@r-project.org> wrote:
| > |
| > | >
| > | > When I have e.g. a local variable arr (for array) and start typing
| > | >
| > | >   print(arr
| > | >
| > | > in an ESS buffer, I first (briefly) get a helpful and uninstrusive
| > dropdown
| > | > starting with arrows, array and more.
| > | >
| > | > But annoyingly, a split second later it flips to a new help buffer
| > | > (entitled
| > | > *ess-command-output*) which the help text for arrows. I absolutely do
| > not
| > | > want that.  I have been unable to turn it off though.
| > | >
| > | > I am running the last release, and I have a somewhat muddled .emacs
| > also
| > | > enabled irony and a few more modes helpful for programming in different
| > | > languages, but this behaviour seems to be ESS specific. How do I stop
| > it?
| > | >
| > | > Sorry to be asking such a noob question after what must now be a
| > quarter
| > | > century of Emacs, R and ESS...
| > | >
| > | > Dirk
| > | >
| > | > --
| > | > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
| > | >
| > | > __
| > | > ESS-help@r-project.org mailing list
| > | > https://stat.ethz.ch/mailman/listinfo/ess-help
| > | >
| > |
| > |
| > | --
| > | James W. MacDonald, M.S.
| > | Biostatistician
| > | University of Washington
| > | Environmental and Occupational Health Sciences
| > | 4225 Roosevelt Way NE, # 100
| > | Seattle WA 98105-6099
| >
| > --
| > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
| >
| > __
| > ESS-help@r-project.org mailing list
| > https://stat.ethz.ch/mailman/listinfo/ess-help
| >

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [ESS] Prevent new buffer for help from point

2020-02-07 Thread Alex Branham via ESS-help
Can you reproduce this without your .emacs file?

Does that buffer's name match any entry in display-buffer-alist or all the
similar variables?

On Fri, Feb 7, 2020, 3:39 AM Dirk Eddelbuettel via ESS-help <
ess-help@r-project.org> wrote:

>
> On 6 February 2020 at 10:19, James W. MacDonald wrote:
> | It's not clear from your question exactly what the behaviour is, but it
> | sounds like auto complete?
>
> No, I like autocomplete.
>
> As I wrote in what is still below, I have irony-mode and other helpers.
> But what is annoying as hell is that ESS decided to
>   - move focus away from where I am (writing R code)
>   - move to a completely new buffer (showing help I did not ask for)
>   - require me to kill the new buffer to get back to where I was
> which happens *each and every time* I type a token it knows and could
> complete to a help page it then takes me to.
>
> Anyone have an idea what I need to turn on to suppress this?
>
> Dirk
>
> | On Thu, Feb 6, 2020 at 2:15 AM Dirk Eddelbuettel via ESS-help <
> | ess-help@r-project.org> wrote:
> |
> | >
> | > When I have e.g. a local variable arr (for array) and start typing
> | >
> | >   print(arr
> | >
> | > in an ESS buffer, I first (briefly) get a helpful and uninstrusive
> dropdown
> | > starting with arrows, array and more.
> | >
> | > But annoyingly, a split second later it flips to a new help buffer
> | > (entitled
> | > *ess-command-output*) which the help text for arrows. I absolutely do
> not
> | > want that.  I have been unable to turn it off though.
> | >
> | > I am running the last release, and I have a somewhat muddled .emacs
> also
> | > enabled irony and a few more modes helpful for programming in different
> | > languages, but this behaviour seems to be ESS specific. How do I stop
> it?
> | >
> | > Sorry to be asking such a noob question after what must now be a
> quarter
> | > century of Emacs, R and ESS...
> | >
> | > Dirk
> | >
> | > --
> | > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
> | >
> | > __
> | > ESS-help@r-project.org mailing list
> | > https://stat.ethz.ch/mailman/listinfo/ess-help
> | >
> |
> |
> | --
> | James W. MacDonald, M.S.
> | Biostatistician
> | University of Washington
> | Environmental and Occupational Health Sciences
> | 4225 Roosevelt Way NE, # 100
> | Seattle WA 98105-6099
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
>
> __
> ESS-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>

[[alternative HTML version deleted]]

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R-es] TEST DE SEPARABILIDAD CON R

2020-02-07 Thread Xavier-Andoni Tibau Alberdi
Buenas,

He encontrado el artículo muy interesante, gracias.

Pues hasta donde yo sé, no hay ninguna implementación. En el articulo
original, los autores ofrecen el código en Fortran (aquí
).
Si lo conoces puedes usar-lo. Sino, tienes algún paquete que te permite
usar Fortran en R, pero igualmente necesitaras un poco de comprensión de
Fortran. Creo que lo mejor, si es muy importante es re-implementarlo en R
(Si lo haces, siempre puedes compartirlo con la comunidad :)).

Finalmente, si no tiene que ser exactamente el mismo algoritmo, creo que el
apartaro 3 del artículo da buenos consejos sobre como saber si hay sesgo en
la distribución observada de tus variables.

Espero que te sirva de algo. Un saludo!

Xavi

Missatge de Pedro José Martínez Córdoba  del dia
dv., 7 de febr. 2020 a les 9:54:

> Buenos días, Xavier-Andoni:
>
> Muchas gracias por su aportación, la tengo en cuenta. Respecto al test de
> separabilidad, me refiero al test desarrollado en el paper de Daraio et
> al., 2018, por si lo conocía y sabia como hecerlo en R.
>
> Gracias por todo.
>
> Un saludo.
>
> Daraio, C., Simar, L., & Wilson, P. W. (2018). Central limit theorems for
> conditional efficiency measures and tests of the ‘separability’condition in
> non‐parametric, two‐stage models of production. *The Econometrics Journal*
> , *21*(2), 170-191.
> El 6/2/20 a las 17:05, Xavier-Andoni Tibau Alberdi escribió:
>
> Buenas,
>
> No entiendo demasiado bien a que te refieres con un test de separabilidad.
> Entiendo mejor "confirmar que las variables ambientales no condicionan la
> producción de eficiencia". Si te refieres a estar seguros que la función
> de probabilidad de tus variables ambientales es independiente de la función
> de probabilidad de tus variables de producción de eficiencia [P(Producción
> eficiencia / ambientales) =P(Producción eficiencia)], entonces tenes que
> hacer tests de independencia/dependencia. Podrías usar un test normal de
> coeficiente de correlación de pearson, en caso de la relación sea lineal o
> información mutua de shannon si no.
>
> Esto en caso que quieras probar que las variables ambientales no tienen
> ningún efecto sobre la producción de eficiencia.
>
> Si existiera dicha relación, puedes condicionar tu regresión a la misma.
> buscando la condicionada P(Producción eficiencia / ambientales ) y usándola
> en la regresión.
>
> Espero haberte ayudado.
>
> Xavier-Andoni Tibau
>
> Missatge de Pedro José Martínez Córdoba  del
> dia dj., 6 de febr. 2020 a les 16:51:
>
>> Buenas tardes:
>>
>> Soy Pedro José Martínez, del Departamento de Economía Financiera y
>> Contabilidad de la Universidad de Murcia y tengo una duda sobre R.
>>
>> Mi investigación se basa en calcular la eficiencia de los servicios
>> municipales con DEA (packages deaR), y posteriormente identificar los
>> determinantes de dicho nivel con una regresión truncada (packages
>> truncreg). Para calcular la eficiencia utilizo inputs/outputs y en la
>> regresión variables ambientales relacionadas con las características de
>> las DMU. En esta segunda fase, es cuando surge el problema de
>> separabilidad entre las variables ambientales y los inputs/output
>> utilizados.
>>
>> Mi pregunta es, ¿conocéis algún test de separabilidad que sirva para
>> esto (confirmar que las variables ambientales no condicionan la
>> producción de eficiencia) y se pueda realizar con R?
>>
>> Muchas gracias.
>>
>> Un saludo.
>>
>> Pedro.
>>
>> --
>> Pedro José Martínez Córdoba
>> Departamento de Economía Financiera y Contabilidad
>> Campus de Espinardo, 30100-Murcia
>> Universidad de Murcia
>> Teléfono +34 86760
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
> --
> Pedro José Martínez Córdoba
> Departamento de Economía Financiera y Contabilidad
> Campus de Espinardo, 30100-Murcia
> Universidad de Murcia
> Teléfono +34 86760
>
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [ESS] Prevent new buffer for help from point

2020-02-07 Thread Dirk Eddelbuettel via ESS-help


On 6 February 2020 at 10:19, James W. MacDonald wrote:
| It's not clear from your question exactly what the behaviour is, but it
| sounds like auto complete?

No, I like autocomplete.

As I wrote in what is still below, I have irony-mode and other helpers.
But what is annoying as hell is that ESS decided to
  - move focus away from where I am (writing R code)
  - move to a completely new buffer (showing help I did not ask for)
  - require me to kill the new buffer to get back to where I was
which happens *each and every time* I type a token it knows and could
complete to a help page it then takes me to.

Anyone have an idea what I need to turn on to suppress this?

Dirk
 
| On Thu, Feb 6, 2020 at 2:15 AM Dirk Eddelbuettel via ESS-help <
| ess-help@r-project.org> wrote:
| 
| >
| > When I have e.g. a local variable arr (for array) and start typing
| >
| >   print(arr
| >
| > in an ESS buffer, I first (briefly) get a helpful and uninstrusive dropdown
| > starting with arrows, array and more.
| >
| > But annoyingly, a split second later it flips to a new help buffer
| > (entitled
| > *ess-command-output*) which the help text for arrows. I absolutely do not
| > want that.  I have been unable to turn it off though.
| >
| > I am running the last release, and I have a somewhat muddled .emacs also
| > enabled irony and a few more modes helpful for programming in different
| > languages, but this behaviour seems to be ESS specific. How do I stop it?
| >
| > Sorry to be asking such a noob question after what must now be a quarter
| > century of Emacs, R and ESS...
| >
| > Dirk
| >
| > --
| > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
| >
| > __
| > ESS-help@r-project.org mailing list
| > https://stat.ethz.ch/mailman/listinfo/ess-help
| >
| 
| 
| -- 
| James W. MacDonald, M.S.
| Biostatistician
| University of Washington
| Environmental and Occupational Health Sciences
| 4225 Roosevelt Way NE, # 100
| Seattle WA 98105-6099

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help