I am not trying to "get you"; but you need to do your homework before
posting. Factor implementation is fully explained in Section 2.3.1 of
the "R Language Definition." You can also search on "enumerated
types"(mentioned in the Help page), a long established C construct,
for a fuller explanation.
Bert, you got me. Factors seem to be implemented as a sort of one-way street.
Mea maxima culpa!
I did some experiments and clearly I misunderstood the way factors in R are set
up. I made a series of factors of various kinds such as integer and logical and
character and they all are simply a cla
You do not understand factors. There is no "base type" that can be recovered.
> f <- factor(c(5.1, 6.2), labels = c("whoa","baby"))
> f
[1] whoa baby
Levels: whoa baby
> unclass(f)
[1] 1 2
attr(,"levels")
[1] "whoa" "baby"
> typeof(f)
[1] "integer"
Bert Gunter
"The trouble with having an open
This question is not clear. What do you mean by solution file? You can find
documentation for individual datasets by typing a question mark (?) followed by
the the name of the dataset.
Sample datasets are included in packages. There are several packages included
with R that have some datasets.
Glad we have solutions BUT I note that the more abstract question is how to
convert any columns that are factors to their base type and that may well NOT
be character. They can be integers or doubles or complex or Boolean and maybe
even raw.
So undoing factorization may require using something
Hello,
datasets is a base R package of built-in data sets (sorry), not a list
of problems.
There is no solution file.
If you have course problems that use base R datasets package, please
note that according to the posting guide R-Help doesn't do homework. You
should ask your instructor/teach
Awesome, thanks!
On Sun, Sep 19, 2021 at 4:22 PM Rui Barradas wrote:
>
> Hello,
>
> Using Jim's lapply(., is.factor) but simplified, you could do
>
>
> df1 <- df
> i <- sapply(df1, is.factor)
> df1[i] <- lapply(df1[i], as.character)
>
>
> a one-liner modifying df, not df1 is
>
>
> df[sapply(df, i
Hello,please guide me where I can find the solution file of the R built-in
datasets.regards
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PL
[Damn: now I'm forgetting that r-help has reply-to the individual respondent,
sorry for duplicate Email Charles but I'm sure this should be in the archives.]
Excellent: I'm sure that's it. I hadn't noticed that I'd loaded libraries in a
cached code block. I thought I'd learned not to do that: c
You should Google "r cache" yourself, but I have used memoise, R.cache, drake,
and targets, and I rate targets as #1 and R.cache as #2.
If you try to retrieve old cache objects (more than a few weeks, say) you are
likely to run into package/class changes that could cause the kind of issues
you
Can you point me to an example of this? I definitely need cacheing for this
work but I don't know
about data cacheing packages. Might be one of those things where my learning
time might outweigh
time saved but I lost a fair bit of time by being stupid with this so perhaps
not.
- Original
I avoid knitr (Rmarkdown uses knitr) caching like the plague. If I want
caching, I do it myself (with or without the aid of one of a data caching
package).
On September 19, 2021 10:28:49 AM PDT, "Berry, Charles"
wrote:
>Chris,
>
>
>> On Sep 18, 2021, at 12:26 PM, Chris Evans wrote:
>>
>> Thi
Chris,
> On Sep 18, 2021, at 12:26 PM, Chris Evans wrote:
>
> This question may belong somewhere else, if so, please signpost me and accept
> apologies.
>
> What is happening is that I have a large (for me, > 3k lines) Rmarkdown file
> with many R code blocks (no other code or
> engine is u
Dear R users,
I have started to work on an improved version of the format.ftable
function. The code and ideas should be reused to improve other R
functions (enabling more advanced format of the character output).
However, there are a number of open questions. These are focused on
standardiz
Hello,
Using Jim's lapply(., is.factor) but simplified, you could do
df1 <- df
i <- sapply(df1, is.factor)
df1[i] <- lapply(df1[i], as.character)
a one-liner modifying df, not df1 is
df[sapply(df, is.factor)] <- lapply(df[sapply(df, is.factor)], as.character)
Hope this helps,
Rui Barrada
Hi Luigi,
try this
library(taRifx)
df_noFact <- remove.factors(df)
str(df_noFact)
'data.frame': 5 obs. of 3 variables:
$ region : chr "A" "B" "C" "D" ...
$ sales : num 13 16 22 27 34
$ country: chr "a" "b" "c" "d" ...
I hope this helps
Fabio
Il giorno dom 19 set 2021 alle ore 12:04 Luigi M
thank you, they both work!
On Sun, Sep 19, 2021 at 1:12 PM Jim Lemon wrote:
>
> Hi Luigi,
> Okay, so you mean:
> I want to change all factors in a dataframe to character class, _not_
> remove them.
>
> factor2character<-function(x) if(is.factor(x)) return(as.character(x))
> else return(x)
> df1<-
Hi Luigi,
Okay, so you mean:
I want to change all factors in a dataframe to character class, _not_
remove them.
factor2character<-function(x) if(is.factor(x)) return(as.character(x))
else return(x)
df1<-lapply(df,factor2character)
Jim
On Sun, Sep 19, 2021 at 8:03 PM Luigi Marongiu wrote:
>
> Th
Thank you Jim, but I obtain:
```
> str(df)
'data.frame': 5 obs. of 3 variables:
$ region : Factor w/ 5 levels "A","B","C","D",..: 1 2 3 4 5
$ sales : num 13 16 22 27 34
$ country: Factor w/ 5 levels "a","b","c","d",..: 1 2 3 4 5
> df1<-df[,!unlist(lapply(df,is.factor))]
> str(df1)
num [1:5]
Hi Luigi,
It's easy:
df1<-df[,!unlist(lapply(df,is.factor))]
_except_ when there is only one column left, as in your example. In
that case, you will have to coerce the resulting vector back into a
one column data frame.
Jim
On Sun, Sep 19, 2021 at 6:18 PM Luigi Marongiu wrote:
>
> Hello,
> I w
On Sun, 19 Sep 2021 10:17:51 +0200
Luigi Marongiu wrote:
> Hello,
> I woul dlike to remove factors from all the columns of a dataframe.
What on earth do you mean by that? After struggling with your
(inadequate) example for a while, I conjecture that what you want to do
is to drop unused levels
Hello,
I woul dlike to remove factors from all the columns of a dataframe.
I can do it n a column at the time with
```
df <- data.frame(region=factor(c('A', 'B', 'C', 'D', 'E')),
sales = c(13, 16, 22, 27, 34), country=factor(c('a',
'b', 'c', 'd', 'e')))
new_df$region <- droplevel
Ah, I completely agree, I should have said! Definitely interested to hear from
others here though.
I cannot say how much I have learned here over a now rather frightening length
of time: hm, at least 16
years to judge from the oldest Email I've kept! Ouch, getting old.
I've put a plea about p
23 matches
Mail list logo