I have an csv file and i want to get a specialized output with just typing in the ID (PIPAPNr) for a letter for example input = PIPAP1147
output Roger Nadal 11.07.1993
Pipapnr="PIPAP1147"
for (i in 1:nrow(Patienten)){
if (Patienten$PIPAP.Nr.==Pipapnr)
DOB<- (Patienten$Geburtsdatum[i])
Name<- (Patienten$Name[i])}
The error is
In if (Patienten$PIPAP.Nr. == Pipapnr) DOB <- (Patienten$Geburtsdatum[i]) :
the condition has length > 1 and only the first element will be used
CodePudding user response:
In if (Patienten$PIPAP.Nr. == Pipapnr) DOB <- (Patienten$Geburtsdatum[i]) : the condition has length > 1 and only the first element will be used
In this code Pipapnr
contains just one value, however Patienten$PIPAP.Nr.
probably contains lots of values so there are many comparisons and only the first is used.
That is the explanation of the error message. Probably you wanted the if
clause to read as if (Patienten$PIPAP.Nr.[i]==Pipapnr) ...
Still, John Garland is right in his comment, that these things can be handled more elegantly in R. Maybe something like which(Patienten$PIPAP.Nr.==Pipapnr
?
As your Code reads German, maybe you are interested in the German R forum at http://forum.r-statistik.de ?