[R] Adding Column to a Data Frame

Lauren O'Connell locon833 at gmail.com
Wed Mar 11 17:01:59 CET 2015


I am trying to add a column with data to a data frame that already has
information but am getting this error:

> rich.stats4 = merge(rich.stats,Location,Month,by="X.SampleID")
Error in fix.by(by.x, x) :
  'by' must specify one or more columns as numbers, names or logical


I have two separate data frames that contain my sample names with location
and with month:

#Create data frame of all sample names and month sample was taken

Month =
data.frame(X.SampleID=sample_data(Lauren5000)$X.SampleID,MonthSampleTaken=sample_data(Lauren5000)$MonthSampleTaken)

head(Month)



#Create data frame of all samples names and location of sample

Location =
data.frame(X.SampleID=sample_data(Lauren5000)$X.SampleID,Location=sample_data(Lauren5000)$Location)

head(Location)

I was able to add my "MonthSampleTaken" variable by using this command:

>rich.stats2 = merge(rich.stats, Month,by="X.SampleID")

> head(rich.stats2)

  X.SampleID    mean       sd MonthSampleTaken

1      PE101 1421.34 19.44961         February

2      PE102 1336.24 25.43882         February

3      PE104 1418.75 21.92889            March

4      PE105 1331.03 20.55712            March

5      PE107 1320.21 20.91942            March

6      PE108 1328.41 20.49247            March


I now want to add my sample site location, but can't figure out how to do
this. Any help would be greatly appreciated.


Cheers,

Lauren

	[[alternative HTML version deleted]]



More information about the R-help mailing list