Dr.R

Laden...

Quicknavigation

Reading Tables

Reason:

R cannot find the file in the working directory or the given directory, respectively. This can be due to a differently spelled filename or the file is not located in the given directory.

Solution:

Check the path of your working directory:

getwd()

To change the working directory, give the respective path, e.g. on Windows:

setwd("C:/Users/Daniel/R-Course/")

You can also copy the path from the path line in your Windows Explorer. Notice the necessity to swap the slashes: from \ to /. The path needs to be in quotes!

If the path is correct, check if the file really is located in the given directory and that there are no typos (this also includes the file extension (e.g. " .txt" oder " .csv" etc.) !!)

 

More questions? Dr R can help!

War das hilfreich?

Reason:

The number of columns does not match the number column names. This can have different reasons, e.g. the numbers really do no match due to missing values either in the table or in the colomn names.  

In case of a tabstopp-separated text file ( .txt), blank spaces and empty cells can result in incorrect separation of columns. Also the double use of commas as decimal point as well as for separation leads to this error.

Solution:

Check the number of columns and the respective column names. Ideally, these are contiguous strings (blank spaces can be replaced e.g. by underscores _) and do not include special characters.

If the column names are correct, check in tabstopp-separated text files the content of your table for blank spaces and replace them e.g. by underscores. Empty cells can be replaced by NA.

In case a comma is used as decimal point, be aware not to use a comma as separator as well (e.g. in csv-files), but a semicolon or a tabstopp and set the respective arguments in your reading function, e.g.

 dec=",", sep=";"

 

More questions? Dr R can help!

War das hilfreich?

NAs

Reason:

The vector includes at least one NA.

Solution:

Either remove all NAs from the vector, e.g. by

x <- x[!is.na(x)]

(whereas x represents the vector object named x) or use the na.rm argument:

mean(x, na.rm=TRUE)

 

More questions? Dr R can help!

War das hilfreich?

Indexing

Reason:

A data.frame is a two-dimensional object (with rows and columns). This needs to be taken into account.

Solution:

To consider the second dimension, a comma must be given either before or after the condition, depending on if the condition is to be applied on rows or columns. Here we want to apply the condition on rows, hence the comma needs to come after the condition:

X[!is.na(X$Y),]

 

More questions? Dr R can help!

War das hilfreich?