[R] Fwd: Questions about working with a dataframe
John Kane
jrkrideau at inbox.com
Tue Jun 25 17:57:11 CEST 2013
Hi, welcome to R
Try using the function str() on both files so str(WWA) and str(oWWA) and compare the structures that you get. Probably one of the varables you defined when creating the original WWA data set has changed from a character variable to a factor or vis versa.
It is a good idea to use dput to supply sample data here.
So dput(WWA) and paste the results into the email and repeat with the other data set. Then readers can paste the actual data sets into R and work on them directly.
If the str() approach does not give you enough information please paste in the dput results in your next email.
Good luck
John Kane
Kingston ON Canada
> -----Original Message-----
> From: jacqueline.oehri at gmx.ch
> Sent: Tue, 25 Jun 2013 16:25:59 +0200
> To: r-help at r-project.org
> Subject: [R] Fwd: Questions about working with a dataframe
>
>
>
>> 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
>> ). 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"(
>> ) 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
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails
More information about the R-help
mailing list