Hola,
La diferencia la tienes en que en la columna "gear" del data.frame grande
(DBx$gear) hay muchos "NAs" que no aparecen en los otros data.frames que
generas luego: DBharbour, DBsteaming, DBfishing, DBnight.
Una forma de verlo programáticamente es esta:
> DB.new <- rbind.data.frame(DBharbour, DBsteaming, DBfishing, DBnight)> DBnew
> <- DB.new[,1:26]> > dim(DBx)[1] 586561 26> dim(DBnew)[1] 509370 26> >
> a1 <- as.data.frame(summary(DBx$gear))> a2 <-
> as.data.frame(summary(DBnew$gear))> a1
> summary(DBx$gear)
BLL 62346
BLL / HL 0
BLL / PLL 26789
NotLic 27215
OUT 25270
PLL 163204
PLL / PoleLine 0
PoleLine 204546
PoleLine / PLL / BLL / Traps 0
Troll 0
NA's 77191> a2
summary(DBnew$gear)
BLL 62346
BLL / HL 0
BLL / PLL 26789
NotLic 27215
OUT 25270
PLL 163204
PLL / PoleLine 0
PoleLine 204546
PoleLine / PLL / BLL / Traps 0
Troll 0> > > > #
http://stackoverflow.com/questions/3171426/compare-two-data-frames-to-find-the-rows-in-data-frame-1-that-are-not-present-in>
library(sqldf)> DBx.Noen.DBnew <- sqldf("select * from a1 EXCEPT
select * from a2")> DBx.Noen.DBnew summary_DBx_gear_
1 77191
Saludos,
Carlos Ortega
www.qualityexcellence.es
El 9 de julio de 2014, 14:55, Carlos Ortega <[email protected]>
escribió:
> Hola,
>
> No, no te dan más datos de los que partes...
>
> > z1[1] 586561> z2+z4+z5+z6[1] 509370> z1 > (z2+z4+z5+z6)[1] TRUE
>
>
>
> Pero tampoco son iguales como esperabas.
>
>
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
>
>
>
> 2014-07-09 13:56 GMT+02:00 Marta valdes lopez <[email protected]>:
>
>> Hola a todos,
>>
>> Me gustaria pedir vuestra ayuda a encontrar el error que no consigo
>> encontrar en este archivo. He revisado todo mil veces y probado y no doy
>> con ello.Adjunto el archivo con Google drive porque es muy grande.
>>
>> â
>> monicap_50.csv
>> <https://docs.google.com/file/d/0B8o2KrPEgG7ATlBMc19lTVk1d3M/edit?usp=drive_web>
>> â
>> Este es el script, y lo que no entiendo que pasa es que tengo 592044
>> datos despues de limpiar los NA quedan 586561 datos , y cuando utilizo el
>> script la suma de z2+z4+z5+z6 , que son los estados deberia de darme lo
>> mismo que Z1 que es el valor total de datos pero no se que error existe que
>> me dan mas datos que los que hay.He comparado con el archivo en excel y los
>> datos de na estan correctos.
>>
>> library(chron)
>> library(xlsx)
>> filename<-"monicap_50.csv"
>> DBxy<-read.csv(filename, sep=";",header=TRUE,dec=",")
>> DBx<-na.omit(DBxy)
>> names(DBx)<-c("Boat","DateTime","TimeDiff", "Latitude", "Longitude",
>> "Course", "Speed", "distNm", "calcSpeed", "calcCourse", "distHb",
>> "Harbour", "idTrip","vmsAngle", "calcAngle", "vmsLeg", "calcLeg",
>> "Trip_vmsLeg", "Trip_calcLeg", "lengthTrip", "lengthTrip_vmsLeg",
>> "lengthTrip_calcLeg","Time", "Date")
>> #Formatting date and time variables
>> DBx$Date<-strptime(DBx$Date, "%d-%m-%Y")
>> DBx$Year<-as.POSIXlt(DBx$Date)$year+1900
>> if(filename!="monicap_50.csv") {DBx$Time<-paste(DBx$Time, ":00",
>> sep="")} #NOT necessary for Monicap and Univerest_50
>> DBx$Time<-times(DBx$Time) #Works for Monicap AND UNIVEREST_50
>> ONLY
>> DBx$Boat<-gsub("^\\s+|\\s+$", "", DBx$Boat)
>> #Read file with boat codes and gears
>> codeBoats<- read.csv("CODES_2002-2010New.csv",
>> sep=",",header=TRUE) #Laptop
>> codeBoats$CODIGO<-gsub("^\\s+|\\s+$", "", codeBoats$CODIGO)
>> #Assigning a Fishing license based on Boat and Year
>> DBx$gear<-codeBoats$Lic[match(paste(DBx$Boat,DBx$Year),
>> paste(codeBoats$CODIGO,codeBoats$Year))]
>> z0<-length(DBx$gear)
>> z1<-length(DBx$gear)
>> z1
>> #defining speed and distance limits
>> speedFishing<-2.0
>> speedHarb<-1.0
>> distHbRule<-3.0
>> speedSteam<-2.0
>> minTime<-times(c("05:59:59")) #usual beginning of fishing
>> operations
>> maxTime<- times(c("20:59:59")) #usual finishing of fishing
>> operations
>> #Selecting Harbour
>> DBharbour<- na.omit(DBx[DBx$distHb<=distHbRule &
>> DBx$calcSpeed<=speedHarb,])
>> DBharbour$State<-"Harbour" #MONICAP= 10618; UNIVER1= ; UNIVER2=
>> ; UNIVEREST= 1028
>> z2<-length(DBharbour$State)
>> #Selecting Steaming
>> DBsteaming<- na.omit(DBx[(DBx$calcSpeed>speedFishing) |
>> (DBx$distHb<=distHbRule & DBx$calcSpeed>speedHarb),])
>> DBsteaming$State<- "Steaming" #MONICAP= 88398; UNIVER1= ;
>> UNIVER2= ; UNIVEREST= 53748
>> DBsteaming$Harbour<-""
>> z4<-length(DBsteaming$State)
>> #Selecting Fishing
>> DBfishing<- na.omit(DBx[(DBx$calcSpeed<=speedFishing &
>> DBx$distHb>distHbRule & DBx$Time>minTime & DBx$Time<=maxTime),])
>> DBfishing$State<-"Fishing"
>> DBfishing$Harbour<-""
>> z5<-length(DBfishing$State)
>> #Selecting nigth
>> DBnight<- na.omit(DBx[(DBx$calcSpeed<=speedFishing &
>> DBx$distHb>distHbRule &(DBx$Time<=minTime | DBx$Time>maxTime)),])
>> DBnight$State<-"Night" #MONICAP=10434; UNIVER1= 16677; UNIVER2=
>> 25789
>> DBnight$Harbour<-""
>> z6<-length(DBnight$State)
>>
>> Si alguien ve el error y puede echarme una mano agradeceria, si no pues
>> seguire peleandome con el archivo!
>>
>> Muchas gracias, un saludo
>>
>>
>> _______________________________________________
>> R-help-es mailing list
>> [email protected]
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
--
Saludos,
Carlos Ortega
www.qualityexcellence.es
[[alternative HTML version deleted]]
_______________________________________________
R-help-es mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-help-es