Home > other >  R language function problem, ask everybody to help, homework,
R language function problem, ask everybody to help, homework,

Time:10-08


SplitInfo<- the function (data, first, second) {

Result<- data. Frame # () results in the data frame

For (I in 1: length (data) [1]) {# each line of data for a cycle

If (data [I, first]==second) {# if the specified data

Result<- rbind (result, data [I, test-first])} # will be divided into the same other attribute classification together, such as the age of youth, the same classification of other attributes in a data frame

}

Return (result)

}

The data
X y z
[1], "1" "1" "1" "y"
[2] "2" "1" "1" "y"
[3], "3" "1" "0" "n"
[4], "4" "0" "1" "n"
[5], "5" "1" "1" "n"

Error: SplitInfo (data, 2, 1)
X. 1. X. 1.. 1 X.y.
1 1 1 y
2 & lt; NA> 1 y
3 & lt; NA>
4 & lt; NA> 1 & lt; NA>
Warning messages:
1: In ` [& lt; - factor ` (TMP ` * * `, ri, value="https://bbs.csdn.net/topics/2") :
Invalid factor level, NA generated
2: In ` [& lt; - factor ` (TMP ` * * `, ri, value="https://bbs.csdn.net/topics/3") :
Invalid factor level, NA generated
3: In ` [& lt; - factor ` (TMP ` * * `, ri, value="https://bbs.csdn.net/topics/0") :
Invalid factor level, NA generated
4: In ` [& lt; - factor ` (TMP ` * * `, ri, value="https://bbs.csdn.net/topics/n") :
Invalid factor level, NA generated
5: In ` [& lt; - factor ` (TMP ` * * `, ri, value="https://bbs.csdn.net/topics/5") :
Invalid factor level, NA generated
6: In ` [& lt; - factor ` (TMP ` * * `, ri, value="https://bbs.csdn.net/topics/n") :
Invalid factor level, NA generated

Where have problem, please help inform!

CodePudding user response:

Why will display into Na Na should be other data, why not show

CodePudding user response:

???????????????????

CodePudding user response:

You assign a value of the original attributes do not?