Re: [R] split a factor into single elements

2024-04-02 Thread Bert Gunter
> > correct example is > > > > > > mydf <- data.frame(id_station = 1234, string_data = as.factor(2024, 12, > > 1, 0, 0), rainfall_value= 55) > > > > > > In this case mydf$string_data is a factor, but of length 1 (and not 5 > > like in the initial ex

Re: [R] split a factor into single elements

2024-04-02 Thread Ebert,Timothy Aaron
-help@r-project.org Subject: Re: [R] split a factor into single elements [External Email] Hi, why would this simple procedure not work? --- snip --- mydf <- data.frame(id_station = 1234, string_data = c(2024, 12, 1, 0, 0), rainfall_value= 55) mydf$string_data <- as.factor(mydf$strin

Re: [R] split a factor into single elements

2024-04-02 Thread Kimmo Elo
s.numeric(mydf[[new_var_name]]) >  } > # remove trash > mydf <- mydf[,-4] > # Provide more useful names > colnames(mydf) <- c("id_station", "string_data", "rainfall_mm", "Year", > "Month", "Day", "hour", "mi

Re: [R] split a factor into single elements

2024-03-28 Thread Ebert,Timothy Aaron
Provide more useful names colnames(mydf) <- c("id_station", "string_data", "rainfall_mm", "Year", "Month", "Day", "hour", "minute") Regards, Tim -Original Message- From: R-help On Behalf Of Stefano Sofia

Re: [R] split a factor into single elements

2024-03-28 Thread Duncan Murdoch
On 28/03/2024 7:48 a.m., Stefano Sofia wrote: as.factor(2024, 12, 1, 0, 0) That doesn't work. You need to put the numbers in a single vector as Fabio did, or you'll see this: Error in as.factor(2024, 12, 1, 0, 0) : unused arguments (12, 1, 0, 0) Duncan Murdoch

Re: [R] split a factor into single elements

2024-03-28 Thread Stefano Sofia
r-help@R-project.org Oggetto: Re: [R] split a factor into single elements Non si ricevono spesso messaggi di posta elettronica da dagostinof...@gmail.com. Informazioni sul perch� � importante<https://aka.ms/LearnAboutSenderIdentification> Hi Stefano, maybe something like this can help you? myfacto

Re: [R] split a factor into single elements

2024-03-28 Thread Stefano Sofia
-mail: stefano.so...@regione.marche.it ---Oo-oO Da: Fabio D'Agostino Inviato: gioved� 28 marzo 2024 12:20 A: Stefano Sofia; r-help@R-project.org Oggetto: Re: [R] split a factor into single elements Non si ric

Re: [R] split a factor into single elements

2024-03-28 Thread Fabio D'Agostino
Hi Stefano, maybe something like this can help you? myfactor <- as.factor(c(2024, 2, 1, 0, 0)) # Convert factor values to integers first_element <- as.integer(as.character(myfactor)[1]) second_element <- as.integer(as.character(myfactor)[2]) third_element <- as.integer(as.character(myfactor)[3])

[R] split a factor into single elements

2024-03-28 Thread Stefano Sofia
Dear R-list users, forgive me for this silly question, I did my best to find a solution with no success. Suppose I have a factor type like myfactor <- as.factor(2024, 2, 1, 0, 0) There are no characters (and therefore strsplit for eample does not work). I need to store separately the 1st, 2