[R] Extract row form a dataframe by row names in another vector and factor . Need explanation

Mohammad Tanvir Ahamed mashranga at yahoo.com
Thu Mar 3 03:05:37 CET 2016


Hi,Here i have written an example to explain my problem
## Data Generationdat<-data.frame(matrix(1:50,ncol=5))
rownames(dat)<-letters[1:10]
colnames(dat)<- c("SA1","SA2","SA3","SA4","SA5")

dat1<-data.frame(matrix(letters[1:20],ncol=4))
colnames(dat1)<-c("AA","BB","CC","DD")

## Row names
v1<-dat1[,"BB"]                   # Factor
v2<-as.vector(dat1[,"BB"])  # Vector

is(v1) # Factor
is(v2) # Vector

# Result
res1<-dat[v1,]
res2<-dat[v2,]
##########################################################i assumed res1 and res2 are same . but it is not . Can any body please explain why ? 
 
 
Tanvir Ahamed 
Göteborg, Sweden  | mashranga at yahoo.com
	[[alternative HTML version deleted]]



More information about the R-help mailing list