levels

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

levels

andy elprama
Dear R-users,

Something strange happened within the command "levels"

R version 3.6.1
name <- c("a","b","c")
values <- c(1,2,3)
data <- data.frame(name,values)
levels(data$name)
[1] "a" "b" "c"

R version 4.0
name <- c("a","b","c")
values <- c(1,2,3)
data <- data.frame(name,values)
levels(data$name)
[1] NULL

What is happening here?

        [[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: levels

Jeff Newmiller
Read the NEWS about R4.0.0 [1] (search for stringsAsFactors), or read any of the many announcements in blogs and forums around the Internet.

[1] https://cran.r-project.org/doc/manuals/r-release/NEWS.html

On July 15, 2020 1:31:06 AM PDT, andy elprama <[hidden email]> wrote:

>Dear R-users,
>
>Something strange happened within the command "levels"
>
>R version 3.6.1
>name <- c("a","b","c")
>values <- c(1,2,3)
>data <- data.frame(name,values)
>levels(data$name)
>[1] "a" "b" "c"
>
>R version 4.0
>name <- c("a","b","c")
>values <- c(1,2,3)
>data <- data.frame(name,values)
>levels(data$name)
>[1] NULL
>
>What is happening here?
>
> [[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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[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: levels

Eric Berger
In reply to this post by andy elprama
Hi Andy,
I believe this is because R 4.0 has changed the default behavior of
data.frame().
Prior to 4.0, the default was stringsAsFactors=TRUE.
In 4.0, the default is stringsAsFactors=FALSE.

If you run your code in R 3.6.1 and change the command to

data <- data.frame(name,values,stringsAsFactors=FALSE)

you will get the same behavior as in R 4.0.

HTH,
Eric


On Wed, Jul 15, 2020 at 6:45 PM andy elprama <[hidden email]> wrote:

> Dear R-users,
>
> Something strange happened within the command "levels"
>
> R version 3.6.1
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] "a" "b" "c"
>
> R version 4.0
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] NULL
>
> What is happening here?
>
>         [[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.
>

        [[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: levels

R help mailing list-2
In reply to this post by andy elprama

> On Jul 15, 2020, at 4:31 AM, andy elprama <[hidden email]> wrote:
>
> Dear R-users,
>
> Something strange happened within the command "levels"
>
> R version 3.6.1
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] "a" "b" "c"
>
> R version 4.0
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] NULL
>
> What is happening here?


Hi,

The default value for 'stringsAsFactors' for data.frame() and read.table() changed from TRUE to FALSE in version 4.0.0, per the news() file:

"R now uses a stringsAsFactors = FALSE default, and hence by default no longer converts strings to factors in calls to data.frame() and read.table()."


Using 4.0.2:

data <- data.frame(name, values, stringsAsFactors = TRUE)

> levels(data$name)
[1] "a" "b" "c"


If you see behavioral changes from one version of R to another, especially major version increments, check the news() file.

Regards,

Marc Schwartz

 
______________________________________________
[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: levels

Erin Hodgess-2
In reply to this post by andy elprama
Hi Andy:

I just checked in "options", and the following appears:


$stringsAsFactors

[1] FALSE


I think this might be it.


You may want to look at options() in R-3.6.1.


Thanks,

Erin


Erin Hodgess, PhD
mailto: [hidden email]


On Wed, Jul 15, 2020 at 9:45 AM andy elprama <[hidden email]> wrote:

> Dear R-users,
>
> Something strange happened within the command "levels"
>
> R version 3.6.1
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] "a" "b" "c"
>
> R version 4.0
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] NULL
>
> What is happening here?
>
>         [[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.
>

        [[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: levels

Chris Gordon-Smith
In reply to this post by R help mailing list-2
There is an interesting item on stringsAsFactors in this useR! 2020 session:

https://www.youtube.com/watch?v=X_eDHNVceCU&feature=youtu.be

It's about 27 minutes in.

Chris Gordon-Smith

On 15/07/2020 17:16, Marc Schwartz via R-help wrote:

>> On Jul 15, 2020, at 4:31 AM, andy elprama <[hidden email]> wrote:
>>
>> Dear R-users,
>>
>> Something strange happened within the command "levels"
>>
>> R version 3.6.1
>> name <- c("a","b","c")
>> values <- c(1,2,3)
>> data <- data.frame(name,values)
>> levels(data$name)
>> [1] "a" "b" "c"
>>
>> R version 4.0
>> name <- c("a","b","c")
>> values <- c(1,2,3)
>> data <- data.frame(name,values)
>> levels(data$name)
>> [1] NULL
>>
>> What is happening here?
>
> Hi,
>
> The default value for 'stringsAsFactors' for data.frame() and read.table() changed from TRUE to FALSE in version 4.0.0, per the news() file:
>
> "R now uses a stringsAsFactors = FALSE default, and hence by default no longer converts strings to factors in calls to data.frame() and read.table()."
>
>
> Using 4.0.2:
>
> data <- data.frame(name, values, stringsAsFactors = TRUE)
>
>> levels(data$name)
> [1] "a" "b" "c"
>
>
> If you see behavioral changes from one version of R to another, especially major version increments, check the news() file.
>
> Regards,
>
> Marc Schwartz
>
>  
> ______________________________________________
> [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.

        [[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: levels

andy elprama
Thanks, I will check it out.

Op za 18 jul. 2020 om 00:47 schreef Chris Gordon-Smith <
[hidden email]>:

> There is an interesting item on stringsAsFactors in this useR! 2020
> session:
>
> https://www.youtube.com/watch?v=X_eDHNVceCU&feature=youtu.be
>
> It's about 27 minutes in.
>
> Chris Gordon-Smith
> On 15/07/2020 17:16, Marc Schwartz via R-help wrote:
>
> On Jul 15, 2020, at 4:31 AM, andy elprama <[hidden email]> <[hidden email]> wrote:
>
> Dear R-users,
>
> Something strange happened within the command "levels"
>
> R version 3.6.1
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] "a" "b" "c"
>
> R version 4.0
> name <- c("a","b","c")
> values <- c(1,2,3)
> data <- data.frame(name,values)
> levels(data$name)
> [1] NULL
>
> What is happening here?
>
> Hi,
>
> The default value for 'stringsAsFactors' for data.frame() and read.table() changed from TRUE to FALSE in version 4.0.0, per the news() file:
>
> "R now uses a stringsAsFactors = FALSE default, and hence by default no longer converts strings to factors in calls to data.frame() and read.table()."
>
>
> Using 4.0.2:
>
> data <- data.frame(name, values, stringsAsFactors = TRUE)
>
>
> levels(data$name)
>
> [1] "a" "b" "c"
>
>
> If you see behavioral changes from one version of R to another, especially major version increments, check the news() file.
>
> Regards,
>
> Marc Schwartz
>
>
> [hidden email] mailing list -- To UNSUBSCRIBE and more, seehttps://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]]

______________________________________________
[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.