You are on page 1of 1

> # Tạo khung dữ liệu dframe

> dframe <- data.frame(


+ ten = c("Binh", "Hoa", "Hậu", "Thọ", "Trường", "Cửu"),
+ gioi_tinh = c("M", "F", "M", "M", "F", "M"),
+ muc_do_hai_long = c("Cao", "Trung bình", "Thập", "Cao", "Trung bình", "Cao"),
+ tuoi = c(41, NA, 41, NA, 21, 60)
+ )
>
> # Thay thế giá trị thiếu trong cột tuổi
> dframe$tuoi[is.na(dframe$tuoi)] <- c(15, 106)
>
> # Tạo khung dữ liệu mydata từ các cột ten, tuoi, gioi_tinh, muc_do_hai_long của
dframe
> mydata <- dframe[, c("ten", "tuoi", "gioi_tinh", "muc_do_hai_long")]
>
> # Tạo khung dữ liệu mydatal
> mydatal <- data.frame(
+ ten = c("Lan", "Mai", "Cúc", "Trúc"),
+ tuoi = c(NA, 30, NA, 56),
+ gioi_tinh = c("F", "M", "F", "M"),
+ muc_do_hai_long = c("Coo", "Trung bình", "Thập", "Coo"),
+ noi_sinh = c("Đà Nẵng", "Quảng Bình", "Phú Yên", "Cà Mau")
+ )
>
> # Gộp hai khung dữ liệu mydata và mydatal
> mydataframe <- rbind(mydata, mydatal)
Error in rbind(deparse.level, ...) :
numbers of columns of arguments do not match
>
> # Lọc các đối tượng là nữ
> mydataframe_filtered <- mydataframe[mydataframe$gioi_tinh == "F", ]
Error: object 'mydataframe' not found
>
> # Lọc các đối tượng có mức độ hài lòng Trung bình hoặc Cao
> mydataframe_filtered <- mydataframe_filtered[mydataframe_filtered$muc_do_hai_long
%in% c("Trung bình", "Cao"), ]
Error: object 'mydataframe_filtered' not found
>
> # Lấy dữ liệu về Tên và Tuổi
> mydataframe_filtered <- mydataframe_filtered[, c("ten", "tuoi")]
Error: object 'mydataframe_filtered' not found
>
> # Hiển thị kết quả
> mydataframe_filtered
Error: object 'mydataframe_filtered' not found
>

You might also like