반응형 ifelse()2 (R)Make a new variable/ mutate() mutate() : make a new variable 'msleep' is a data set in ggplot2 which consists of 'name', 'genus' , 'vore',...'bodywt'. I will make a new data set named 'new_msleep' which contains a new variable 'ratio_ram' which does not exist in 'msleep' data set. >library(ggplot2) -----------for dataset 'msleep' in ggplot2>library(dplyr) ------------for mutate(), filter() > str(msleep)tibble [61 x 12] (S3: .. 2020. 7. 27. (R) ifelse() ifelse() Using ifelse(), you can make a new variable based on the test you made. >library(ggplot2)> summary(diamonds$carat) -------------carat: size of carat in each diamond Min. 1st Qu. Median Mean 3rd Qu. Max. 0.2000 0.4000 0.7000 0.7979 1.0400 5.0100 To make a new variable 'carattt' which consists of small and big, I will use a test in ifelse() 1st test:diamonds$carat diamonds$carattt carattt.. 2020. 7. 23. 이전 1 다음 반응형