[R] Fwd: Questions about working with a dataframe

Jacqueline Oehri jacqueline.oehri at gmx.ch
Tue Jun 25 16:25:59 CEST 2013



> Dear R-Users, 
> I hope this is the right e-mail adress to post questions about Programming in R, and I hope somebody of you can help me with the troubles I have :)
> 
> 
> 1) First Question:
> 
> I have a dataframe called "WWA" (its attached to this e-mail
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: WWA.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130625/f8a2e152/attachment-0001.txt>
-------------- next part --------------
> ). It looks a little bit like the following one:
> 
> 
> testcoordID testcommunity testaltitude     testSpeciesName
> 1      503146       Bournes        523.2     Bellis perennis
> 2      503146       Bournes        321.5 Cynosurus cristatus
> 3      557154       Bournes        654.1   Festuca pratensis
> 4      557154         Aigle        938.6     Bellis perennis
> 5      569226         Aigle        401.3     Bellis perennis
> 6      599246         Aigle        765.9   Prunella vulgaris
> 
> ((I programmed this little one like this: 
> testcoordID <-c(as.integer("503146"),as.integer("503146"),as.integer("557154"),as.integer("557154"),as.integer("569226"),as.integer("599246"))
> testcommunity <-factor(c("Bournes","Bournes","Bournes", "Aigle", "Aigle", "Aigle"))
> testaltitude <- c(523.2,321.5,654.1,938.6,401.3,765.9)
> testSpeciesName <-c( "Bellis perennis",
>                      "Cynosurus cristatus",
>                      "Festuca pratensis",
>                     "Bellis perennis",
>                     "Bellis perennis",
>                      "Prunella vulgaris")
> testframe <- data.frame(testcoordID,testcommunity,testaltitude, testSpeciesName))
> 
> 
> 
> I needed to manipulate WWA in Excel, therefore i wrote
> it as a text-file:
> 
>> write.table(WWA, "WWA.txt", col.names=T, row.names=F, sep= ";", quote =T)
> 
> Then I manipulated the WWA.txt in Excel and saved it as "noWWA.csv"(
-------------- next part --------------
> ) and re-importet it under the new name "oWWA" in R:
> 
>> oWWA <- read.csv("~/Desktop/NCCR master projekt/BDM Beschreibungen/BDM Daten/noWWA.csv", header=TRUE, sep=";")
> 
> What i need to do with this "WWA" or "oWWA"is finally to create a list (or a dataframe but this is not possible i think), that shows for each coordinateID ("testcoordID") the species Names occuring at this place:
> 
>> species_per_coordID1<- tapply((WWA$speciesName), WWA$coordID, list)
>> species_per_coordID2 <- split(WWA$speciesName, WWA$coordID)
> 
> ---> now my Question: This works very well with the WWA table, but not with the oWWA!! I think i changed something in the dataframe by converting it to a .txt file and than back to a .csv;
> But does anybody know why it works with WWA and not with oWWA? how can I treat the WWA dataframe in Excel without changing any format of it?
> 
> 
> Thaanks a lot for any help or suggestions!!!!!
> 
> Have a nice day, 
> 
> Kind regards Jacqueline
> 



More information about the R-help mailing list