Creating a species Accumulation Curve with different format - r

I am currently working on a dataframe which looks like this:
data.frame(Plot_ID=c(1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4),
Species=c("a","a","a","b","b","c","c","b","b","b","b","d","d","d","e","e","e","e","a","a","a")
DBH=c(12,32,44,11,14,66,43,22,88,22,23,45,354,6,7,45,12,11,5,6,8))
DBH is just the diameter of the species. What I want to create is a species accumulation curve, however the packet specaccum only allows for a different format which is like this:
data.frame (Spec1=c(1,0,2,3),Spec2=c(0,0,0,4),Spec3=c(1,1,2,3))
My data has over 3000 rows, with more that a hundred species which makes it very difficult to reformat the data accordingly. Is there a way to easily reformat the data, or to use the data like it is with a different package?

Ok after a while I remembered the pivot-table of LibreOffice, where you can exactly format the data to have the species in columns, each plot in a row and the sum in between.
For that, create a 3rd column which includes only the number 1, your data should look like this:
d1<-data.frame(Plot_ID=c(1,1,2,2,3,3),
Species=c("a","b","a","c","d","c"),
Count=c(1,1,1,1,1,1))
Export the data frame as .csv file using
write.table(d1, "~/path/of/desire/d1.csv")
Import the csv. table in Libreoffice by using space as separator. Delete the first column as it is the internal R-ID and shifts the headings.
Mark your data and go to Data->Pivot-table, select marked data and click OK.
You will see something like this
Loai.cay is the Species here. Drag the Species to the column-cields, the Plot_ID to the row-fields and the Count to the data-fields, as it is the case in the picture. Press OK and copy the result in a extra table. Press CTRL+SHIFT+S and select save as .csv file. Import the csv-file in R and use the specaccum function as described in the description of the function.
Hope this helps someone else than me.

Related

Paste name of column to other columns in R?

I have recently received an output from the online survey (ESRI Survey123), storing the each recored attribte as a new column of teh table. The survey reports characteristics of single trees located on study site: e.g. beech1, beech2, etc. For each beech, several attributes are recorded such as height, shape, etc.
This is how the output table looks like in Excel. ID simply represent the site number:
Now I wonder, how can I read those data into R to make sure that columns 1:3 belong to beech1, columns 4:6 represent beech2, etc.? I am looking for something that would paste the beech1 into names of the following columns: beech1.height, beech1.shape. But I am not sure how to do it?

Is there any method to extract pdf table tidy with R?

I need an automatic code to extract pdf table in R.
So I searched website, find tabulizer package.
and I use
extract_tables(f2,pages = 25,guess=TRUE,encoding = 'UTF-8',method="stream")#f2 is pdf file name
I tried every method type, but the outcome is not tidy.
Some columns are mixed and there is a lot of blank as you can see image file.
I think I would do modify the data directly. But the purpose is automizing it. So general method is needed. And every pdf file is not organized. Some table is very tidy with every related line matched perfectly but others are not..
As you can see in my outcome image, in column 4, the number is mixed in same column. Other columns, the number is matched one by one what I mean is I want to make column tidy like table in pdf automatically.
Is there any package or some method to make extracted table tidy?
my Code result
table in PDF

How to convert categorical string variables in Excel to numeric variables?

I am trying to analyze road collision data. I need to convert the categorical data into numeric data in Excel before I import it to RStudio, but I am not able to do it.
Excel file containing the sample data to be used:
Have a look at this, as I don't know which value you want to search with and which you want as the result, I have shown it taking the weather and returning the leftmost column.
You can change that as you need as I have used Index() with match().
So, based on the comment, all you need is left() to get the number, I have used find() to get the space just in case you have 2 or 3 digit numbers...
=LEFT(C3,FIND(" ",C3,1)-1)
C3 is the target cell, drag down as far as...

R rows unanalysed

So I'm trying to format my xls data in a way that the first row will be seen in R, but it won't be analysed as in this example: http://bowtie-bio.sourceforge.net/recount/ExpressionSets/bodymap_eset.RData
When you open the exprs(bm) expression data in this the first row gives you the gene names, but these aren't e.g. being log transformed.
I formatted my own data into a similar table, but cannot figure out how to omit the first table from showing up in R and more importantly being used in calculations, which of course results in error codes all the way.
Hope that makes sense?
Cheers

View( ) function in R: How to view part of huge data frame as spreadsheet in R

I have a huge data frame df in R. Now,if I invoke View(df) then Rstudio does not respond since it's too big. So, I am wondering, if there is any way to view, say first 500 lines, of a data frame as spreadsheet.
(I know it's possible to view using head but I want to see it as spreadsheet since it has too many columns and using head to see too many columns is not really user friendly)
If you want to see first 100 lines of the data frame df as spreadsheet, use
View(head(df,100))
You can look at the dataframe as a matrix such as df[rowfrom:rowto, columnfrom:columnto], for example in your case:
df[1:500,]

Resources