User Tools

Site Tools


en:data_import_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:data_import_examples [2019/01/21 00:15]
David Zelený [Import directly from *.xls and *.xlsx file]
en:data_import_examples [2019/02/03 16:21] (current)
David Zelený [Import directly from Excel (*.xls or *.xlsx) file]
Line 99: Line 99:
 Note that in the function ''​download.file''​ it is important to specify the argument ''​mode = '​wb'''​ (on Windows, if the argument ''​mode''​ is not set up, the type of the file will be determined from the file extension; in case of *.xls and *.xlsx files R would attempt to download these files as plain text, but in fact these files need to be downloaded as binaries). Note that in the function ''​download.file''​ it is important to specify the argument ''​mode = '​wb'''​ (on Windows, if the argument ''​mode''​ is not set up, the type of the file will be determined from the file extension; in case of *.xls and *.xlsx files R would attempt to download these files as plain text, but in fact these files need to be downloaded as binaries).
  
-The library ''​readxl''​ is a part of the ''​tidyverse''​ packages, and as such it does not use standard ''​data.frame''​ format for data frames, but unique ''​tibble''​ (as discussed above). One feature of ''​tibble''​ is that **it does not have rownames, and rownames are therefore imported as the first column of the data frame**. This may or may not be handy for future ​analysis since most of the functions ​we will use for numerical analysis here use data in standard ''​data.frame''​ format with rownames indicating ​plot IDs. To convert ''​tibble''​ into standard ''​data.frame'',​ use the function ''​as.data.frame'',​ and move the first column into the rownames of the newly created data frame (see above). Alternatively,​ there are functions like ''​[[https://​www.rdocumentation.org/​packages/​tibble/​versions/​1.4.2/​topics/​rownames|column_to_rownames]]''​ in the package ''​tibble''​ which can help you with that.+The library ''​readxl''​ is a part of the ''​tidyverse''​ packages, and as such it does not use standard ''​data.frame''​ format for data frames, but unique ''​tibble''​ (as discussed above). One feature of ''​tibble''​ is that **it does not have rownames, and rownames are therefore imported as the first column of the data frame**. This is often not handy for analysis ​of community ecology data since most of the functions ​used for numerical analysis here use data in standard ''​data.frame''​ format with rownames indicating ​plots ID. To convert ''​tibble''​ into standard ''​data.frame'',​ use the function ''​as.data.frame'',​ and move the first column into the rownames of the newly created data frame (see above). Alternatively,​ there are functions like ''​[[https://​www.rdocumentation.org/​packages/​tibble/​versions/​1.4.2/​topics/​rownames|column_to_rownames]]''​ in the package ''​tibble''​ which can help you with that (it creates ''​tibble''​ with rownames, which can be used in (most) functions accepting data.frame).  
 + 
 +==== Import *.RData file ==== 
 +Binary data storing the R object can be loaded into R using function ''​load''​. Download data {{https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​vltava.RData|vltava.RData}} to your computer and use: 
 + 
 +<code rsplus>​ 
 +load ('​c:/​path/​to/​data/​folder/​vltava.RData'​) 
 +</​code>​ 
 + 
 +This should create the variable ''​vltava''​ in your Global environment (it will appear among variables), which is  alist of variables (see details [[en:​data:​vltava#​all_vltava_dataset_matrices_as_a_single_r_object_list_vltava|here]]). Do not assign the result to a new variable, it will not work (if you use ''​vltava.spe <- load ('​vltava.RData'​)'',​ the object ''​vltava.spe''​ will be assigned the character string ''​vltava'',​ not the data). 
 + 
 +Alternatively,​ ''​load''​ function can read directly data from website, if the URL link is wrapped by function ''​url'':​ 
 +<code rsplus>​ 
 +load (url ('​https://​raw.githubusercontent.com/​zdealveindy/​anadat-r/​master/​data/​vltava.RData'​)) 
 +</​code>​
  
 ===== Import from cc! (cep) format ===== ===== Import from cc! (cep) format =====
en/data_import_examples.1548000953.txt.gz · Last modified: 2019/01/21 00:15 by David Zelený