[R] Replace / swap values of subset of a data.frame
Dear R users, I have 1 data.frame of 1500x80 - data1. I found out that there are a few cells of data that I have misplace, and I need to fix the ordering of them. In an attempt trying to swap column 22 23 of the Subject with misplaced data, I did the following: data2 - data1 subset(data1,(Subject==25 Session==1))[,22] - subset(data2,(Subject==25 Session==1))[,23] (error messages... Could not find function subset-) subset(data1,(Subject==25 Session==1))[,23] - subset(data2,(Subject==25 Session==1))[,22] (error messages... Could not find function subset-) Please, please point me to some ways to achieve the swapping. Thanks a lot! Cheers, John __ R-help@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.
Re: [R] Replace / swap values of subset of a data.frame
Exactly what are you trying to do? Are you trying to just change a subset of the values? 'subset' does not have an 'assignment' operator. Maybe you want something like this (but it is not clear from your description. Also it is not clear if you have exactly the same set of matching values in the two data frames for the subset conditions. If you do, then this might work: data1[(data1$Subject==25) (data1$Session==1), 22] - data2[(data2$Subject==25)(data2$Session==1), 23] On Tue, May 19, 2009 at 3:50 PM, tsunhin wong thjw...@gmail.com wrote: Dear R users, I have 1 data.frame of 1500x80 - data1. I found out that there are a few cells of data that I have misplace, and I need to fix the ordering of them. In an attempt trying to swap column 22 23 of the Subject with misplaced data, I did the following: data2 - data1 subset(data1,(Subject==25 Session==1))[,22] - subset(data2,(Subject==25 Session==1))[,23] (error messages... Could not find function subset-) subset(data1,(Subject==25 Session==1))[,23] - subset(data2,(Subject==25 Session==1))[,22] (error messages... Could not find function subset-) Please, please point me to some ways to achieve the swapping. Thanks a lot! Cheers, John __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Replace / swap values of subset of a data.frame
If DF is your data frame: DF2 - edit(DF) and then make the changes manually in the spreadsheet that pops up. On Tue, May 19, 2009 at 3:50 PM, tsunhin wong thjw...@gmail.com wrote: Dear R users, I have 1 data.frame of 1500x80 - data1. I found out that there are a few cells of data that I have misplace, and I need to fix the ordering of them. In an attempt trying to swap column 22 23 of the Subject with misplaced data, I did the following: data2 - data1 subset(data1,(Subject==25 Session==1))[,22] - subset(data2,(Subject==25 Session==1))[,23] (error messages... Could not find function subset-) subset(data1,(Subject==25 Session==1))[,23] - subset(data2,(Subject==25 Session==1))[,22] (error messages... Could not find function subset-) Please, please point me to some ways to achieve the swapping. Thanks a lot! Cheers, John __ R-help@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. __ R-help@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.