i have a very stupid problem that made me loose a few hours, hence I though about posting it here.
my data looks something like this
df<- data.frame("Reporter" = c("USA", "USA", "USA", "USA",
"Africa","Africa", "Africa","Africa"),
"Partner" = c("Africa", "Africa", "EU", "EU",
"USA", "USA", "EU", "EU"),
"Year" = c(1970, 1980, 1970, 1980, 1970, 1980,
1970, 1980),
"Flow" = c("001", "00", "1", "112", "0", "2", "23", "TOT"),
"Val" = runif(8, min=0, max=100), stringsAsFactors
= FALSE)
Flow is a character variable that include character and numbers. These are identifiers for the variable "Val"
class(df$Flow)
I would like to remove the rows that have letters in "Flow" while keeping the rest.
df <- df %>% filter(Flow != "TOT")
this approach works as I expect. The problem appears later once I remove the letters from flow, and save my data csv.
write.csv(df, "df.csv")
Once I re-upload my data, this has been radically transformed. All the 0s in front of number have been lost as the data has been stored as numeric
df2<- import("df.csv")
I have also tried write.csv2(df, "df.csv")
but the result does not change.
If I save in dta instead, the data work once re-uploaded, but I would like to save in csv
Does anyone know what I am doing wrong?