0

I´m trying to do redundancy analysis (RDA) on my data in R. The data frame I´m using was uploaded as a Microsoft Excel csv file. The data frame looks something like this:

site biomass index

1     0.001 1.5

2    0.122  2.3

3    0.255  4.9

When trying to create a formula for the RDA, I constantly get the following message: "Error in formula.data.frame(object, env = baseenv()) : cannot create a formula from a zero-column data frame"

Does anyone know how I can change my data frame so that I no longer get this error message?

Thanks in advance!

SabDeM
  • 7,050
  • 2
  • 25
  • 38
  • 1
    can you share instead the `dput()` of your data? – erasmortg Aug 06 '15 at 16:26
  • Error in formula.data.frame(object, env = baseenv()) - Seems like it has nothing to do with RDA , the problem is with your data – RInatM Aug 06 '15 at 16:43
  • Hi erasmortg, thanks for your answer. This appeared when I did the dput() on my data: > dput(env) structure(list(), .Names = character(0), class = "data.frame", row.names = c("Tr.1-1m;0.300233333;0.5", "Tr.1-4m;0.107733333;0.5", "Tr.2-1m;0.0195;0.923", "Tr.2-10m;0.150866667;0.5", "Tr.3-1m;0.099733333;0.857", "Tr.3-9m;0.0576;0.5", "Tr.4-1m;0.057433333;0.125", "Tr.4-9m;0.064066667;0.375", "Tr.5-1m;0.130466667;0.2", "Tr.5-10m;0.2125;0.66" )) – Jóhann Garðar Þorbjörnsson Aug 06 '15 at 16:43
  • structure(list() - - data.frame is empty. Show how you download your data – RInatM Aug 06 '15 at 16:48
  • Hi Rina, I was using: <- read.csv("data.csv", row.names=1) to import my data into R. – Jóhann Garðar Þorbjörnsson Aug 06 '15 at 17:38
  • try <- read.csv("data.csv", row.names=FALSE, sep=';') – RInatM Aug 07 '15 at 07:48
  • I tried what you suggested and this error messaged showed up: <-read.csv("data.csv", row.names=FALSE, sep=';') Error in read.table(file = file, header = header, sep = sep, quote = quote, : invalid 'row.names' specification There has to be something wrong with the way I´m setting up my data prior to importing. – Jóhann Garðar Þorbjörnsson Aug 07 '15 at 13:33
  • Please paste the first few rows of the csv file into the question – Rich Scriven Aug 07 '15 at 16:49

2 Answers2

0

You load all your data to row.names instead of columns

  1. you used default separator ',' while your data is separated by ';'
  2. you specified row.names = 1 so that first column (and the only one as the separator is wrong) goes to row.names.

that's why your data.frame has no columns. To fix this, use

read.csv('data.csv', sep = ';', row.names=NULL)
RInatM
  • 1,208
  • 1
  • 17
  • 39
0

Problem solved :) Thanks for the your answers. I tried the suggestions but what ended up working was to import the data with the <- read.csv2("data.csv", row.names=1), so basically to use read.csv2 instead of read.csv, as it seems to be used in many European locales.

There is more info on the difference between csv and csv2 here: Difference between read.csv() and read.csv2() in R

Community
  • 1
  • 1