I have a dataframe(df)
that looks like below:
Date Group Value
01-04-2029 Saffron 62.78
01-04-2029 Green 75.65
01-05-2019 Saffron 67.89
01-06-2019 Saffron 54.56
01-06-2019 Green 77.00
01-07-2019 Green 71.22
Objective: I want to create two seperate dataframes based on Group
. Essentially I am looking for the followings
df_saffron:
Date Group Value
01-04-2029 Saffron 62.78
01-05-2019 Saffron 67.89
01-06-2019 Saffron 54.56
df_green:
Date Group Value
01-04-2029 Green 75.65
01-06-2019 Green 77.00
01-07-2019 Green 71.22
Specifically, if I use the following code snippet (this thread)
for(i in unique(as.character(df$Group))) {
nam <- paste("df", i, sep = ".")
assign(nam, df[df$Group==i,])
}
I am not getting any dataframe like df.Green
or df.Saffron
. I mean I am getting
<0 rows> (or 0 -length row.names)
I have also taken a look at this SO thread, but I am getting errors.
Error in assign(as.character(v, data %>% filter(data$Group == v), envir = .GlobalEnv)) :
argument "value" is missing, with no default
In addition: Warning message:
In data.matrix(data) : NAs introduced by coercion
I am novice to R and thus asking for any clue on where I am missing out?