I am VERY confused with the following: Using data.table I am creating a dataframe as a copy of an existing one. Then I create a new column in the new dataframe ... and the original dataframe gets the new column also!
df1<- c("A", "B", "C", "D", "E")
df1<-data.table(df1)
> head(df1)
df1
1: A
2: B
3: C
4: D
5: E
df2 <- df1[]
df2 <- df2[,col2:=10,]
> head(df1)
df1 col2
1: A 10
2: B 10
3: C 10
4: D 10
5: E 10
Please notice that the second head() refers to the original dataframe, which I do not want any new column. I tried this using dataframes (NOT data.table) and worked fine.
df1<- c("A", "B", "C", "D", "E")
df1<-as.data.frame(df1)
df2<-df1[]
df2$col2<-10
> head(df1)
df1
1 A
2 B
3 C
4 D
5 E
Plaese advice. Any help wellcomed