[R] problem regarding the data
Jim Lemon
jim at bitwrit.com.au
Fri Sep 18 11:33:16 CEST 2009
On 09/18/2009 04:10 PM, meghana kulkarni wrote:
> Hi,
> This is Meghana Kulkarni.
> I have a problem regarding the data I am working with.
>
> I have a data frame as follows:
>
>> x
>>
> V1 V2 V3............V10
> 414 A
> 416 A
> 417 A
> 417 B
> 418 A
> 421 A
> 421 B
> 421 C
> 422 A
> I want to conver this data frame in the following format.
>
> > x
>
> V1 V2 V3............V10
> 414 A
>
> 416 A
>
> 417 A
> 417 B
>
> 418 A
>
> 421 A
> 421 B
> 421 C
>
> 422 A
>
> i.e. I want to insert a blank row after new entry in the 1st column. So that
> it is easy for me to take readings in next columns when this data frame is
> printed.
> It would be great if you could tell me how this can be done.
>
>
Hi Meghana,
Try this:
spaceBlocks<-function(x,spacevar) {
thisblock<-x[1,spacevar]
for(row in 1:dim(x)[1]) {
if(thisblock != x[row,spacevar]) cat("\n")
for(col in 1:length(unlist(x[row,])))
cat(as.character(x[row,col])," ")
cat("\n")
thisblock<-x[row,spacevar]
}
}
Jim
More information about the R-help
mailing list