df = data.frame(num=1,chr='a') df ## num chr ## 1 1 a str(df) ## 'data.frame': 1 obs. of 2 variables: ## $ num: num 1 ## $ chr: Factor w/ 1 level "a": 1 df_I = data.frame(num=1,chr=I('a')) str(df_I) ## 'data.frame': 1 obs. of 2 variables: ## $ num: num 1 ## $ chr: 'AsIs' chr "a" 那么為什么要改變?問題在哪里?我們使用unlist()函數(shù)來演示問題。 unlist(list(df)) ## num chr ## 1 1 unlist(list(df_I)) ## num chr ## "1" "a" 你可以在這里下載R4.0體驗(yàn)版windows系統(tǒng):https://cran./bin/windows/base/rdevel.html version ## _ ## platform x86_64-w64-mingw32 ## arch x86_64 ## os mingw32 ## system x86_64, mingw32 ## status ## major 4 ## minor 0.0 ## year 2020 ## month 02 ## day 21 ## svn rev 77847 ## language R ## version.string R Under development(unstable) ## nickname Unsuffered Consequences df_4=data.frame(num=1,chr='a') str(df_4) ## 'data.frame': 1 obs. of 2 variables: ## $ num: num 1 ## $ chr: Factor w/ 1 level "a": 1 是否將string轉(zhuǎn)換為factor,一定要自己小心。
|
|