Displaying 3 results from an estimated 3 matches for "cars2".
Did you mean:
cars
2010 Dec 16
2
Compare two dataframes
...the two DFs
based on this unique ID.
Is there a better way?
Many thanks for your help,
Mark
#compare two dataframes and extract uncommon rows
#MAKE SOME DATA
cars$id<-paste(cars$speed,cars$dist,sep="") $create unique ID field by
pasting all columns together
cars1<-cars[1:35,]
cars2<-cars[16:50,]
#EXTRACT UNIQUE ROWS
cars1_unique<-cars1[cars1$id %in% setdiff(cars1$id,cars2$id),] #rows
unique to cars1 (i.e., not in cars2)
cars2_unique<-cars2[cars2$id %in% setdiff(cars2$id,cars1$id),] #rows
unique to cars2
2010 May 17
4
Adding a row at top of dataframe
I have a large data frame 48:2185 with different numbers.
I would like to add only one row at the very top of my data frame with
0's or NA's.
I don't know which approach to use. Should i create 2 different data
frames and merge them? Ive also tried the rbind command with no luck.
I would appreciate some help to achieve what I'm trying to create.
Thanks!
2010 May 04
1
Extract rows with non-zero elements
...rix.
The beginning of my code is:
Cars <- read.csv(filename, header=TRUE, row.names=NULL, sep=";")
attach(Cars)
n <- as.numeric(n)
s <- as.numeric(s)
# et cetera, the other variabeles are declared as numeric or as factors
# I've tried to extract the data the following way:
Cars2 <- Cars[Cars$s!=0]
#However, then I get the error message:
Error in `[.data.frame`(Cars, Cars$s != 0) : undefined columns selected
# If I try
s[s!=0]
# I do get the positive s-values, but how can I get all colums in a matrix?
Does anyone know how this can be done? Your help would be greatly...