Hello,
I wrote a small function to change row values over some columns.
I mea, I just copy some column values from rows x to rows y. And I declared "v" as a condition in order to change a value to 1.
But when I tried to applied, in some rows, I just simply didn't preserve the change I declared.
I don't know if tha't because I am mixing a data frame nd a tibble object or anything related.
Here I am listing the rows 1589 and 1590. They should appear with the values from 125, but It doesn't.
edic_c(125,1589,0)
daaz>%filter(orden %in% c(125,1589,1590))
flip src num1 num2 lastN
<chr> <chr> <dbl> <chr>
1 NA 14 - … 1.30e7 9 ALE
2 NA 17 - … NA NA ALE
3 NA 17 - … NA NA ALE
I tried using dplyr and maggrite the same goal. I can see the changes when I run a line directly. but the function doesn't store the changes. I have no idea. I used %<>% on magritte. I even declared using dplyr dataz=dataz%>%... but the output is always the same...
Having a quick read I think this is what is currently wrong from the code you have. Your function call (edic_c ) should have its output assigned to an object:
#Example
df_output <- edic_c(125,1589,0)
Secondly, change your function edic_c to have a fourth argument which is the dataframe as it looks like you have both daaz and dataz as dataframes that contain information. If you do these two changes it should get you there.
This is due to namespaces.
When you are in a function and assigning values, you do so in that functions namespace, rather than in the global environment.
To illustrate:
I think you were right, nirgrahamuk.
Using <<- declaring the function seems that was the issue.
I was using = or <-, so the function worked using directly the console, but not as a function.