我有一個名爲decision_tree
的數據框。我需要用條件從數據框中打印一行。例如:Student_id == 100.如何在R中打印無標題和NA值的行
selected_row <- filter(decision_tree, Student_id=100)
但是我收到了一些奇怪的錯誤。
Error: Each variable must be a 1d atomic vector or list.
Problem variables: 'Student_id'
decision_tree <- plyr::ldply(Recommendations, rbind)
decision_tree$Student_id <- select(r_df, Student_id)
colnames(decision_tree) <- c("Recommended Course 1","Recommended Course 2","Recommended Course 3","Recommended Course 4","Recommended Course 5","Student_id")
數據幀看起來像:
最後場是數字和其它字段是與7級或9的水平的因素。
即使我將colnames設置爲NULL。最後一列將有一個Student_id。前5列名稱將從1到5
結構(列表(Recommended Course 1
=結構(c(NA,NA,NA, 5L,NA,NA,NA,NA,8L,2L),。標籤= c(「p_F20BC」,「p_F20DL」, 「p_F20DP」,「p_F20DV」,「p_F20GP」,「p_F20MA」,「p_F20MC」,「p_F20RO」, 「p_F20RS」),class =「factor」),Recommended Course 2
=結構(c(NA, NA,9L,NA,NA,NA,2L,7L),標籤= c(「p_F20BC」,「p_F20DL」, 「p_F20DP」,「p_F20DV」,「p_F20GP 「,」p_F20MA「,」p_F20MC「,」p_F20RO「, 」p_F20RS「),class =」factor「),Recommended Course 3
= structure(c(NA, NA,NA,NA,NA,NA,NA,NA, 1L,3L),。標籤= c(「p_F20BC」,「p_F20DL」, 「p_F20DP 」, 「p_F20GP」, 「p_F20MC」, 「p_F20RO」),類= 「因子」), Recommended Course 4
=結構(C(NA_integer_,NA_integer_, NA_integer_,NA_integer_,NA_integer_,NA_integer_,NA_integer_, NA_integer_,NA_integer_,NA_integer_ ),標籤=「p_F20BC」,class =「factor」), Student_id = structure(list(Student_id = c(55L,68L,70L, 99L,100L,101L,103L,105L,106L,107L) .Names =「Student_id」,row.names = c(NA, 10L),class =「data.frame」)),.Names = c(「推薦課程1」, 「推薦課程2」,「 3「,」Recommended Course 4「, 」Student_id「),row.names = c(NA,10L),class =」data.frame「)
你能不能做到?:selected_row < - 構造判定[其中(判定樹[ 「student_id數據」] == 100)] –
@EvanFriedland沒錯,就是工作。但它也會打印帶有na值的標題和列。如何像列表一樣打印?只是單元格的價值。一個在另一個下方 –
你可以粘貼你想要的輸出嗎?我在這裏猜測。 –