[R] reading files with name columns and row columns

2015-09-02 Thread Bogdan Tanasa
Dear all,

would appreciate a piece of help with a simple question: I am reading in R
a file that is formatted as a matrix (an example is shown below, although
it is more complex, a matrix of 1000 * 1000 ):

the names of the columns are 0, 1, 4, 8, etc
the names of the rows are 0, 1, 4, 8, etc

   0 20 40
0  0   0   0
20  0   0   0
40  0   0   0

shall I use the command :

y <- read.table("file",row.names=1, header=T)

the results is :

> y[1:3,1:3]
   X0 X20 X40
0   0   0   0
20  0   0   0
40  0   0   0

The question is : why R adds an X to the names of the columns eg X0,
X2, X4, when it shall be only 0, 2, 4 ? thanks !

-- bogdan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] reading files with name columns and row columns

2015-09-02 Thread Bert Gunter
Please read the Help file carefully before posting:

"read.table is not the right tool for reading large matrices,
especially those with many columns: it is designed to read data frames
which may have columns of very different classes. Use scan instead for
matrices."

But the answer to your question can be found in

?make.names

for what constitutes a syntactically valid name in R.


Cheers,
Bert

Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa  wrote:
> Dear all,
>
> would appreciate a piece of help with a simple question: I am reading in R
> a file that is formatted as a matrix (an example is shown below, although
> it is more complex, a matrix of 1000 * 1000 ):
>
> the names of the columns are 0, 1, 4, 8, etc
> the names of the rows are 0, 1, 4, 8, etc
>
>0 20 40
> 0  0   0   0
> 20  0   0   0
> 40  0   0   0
>
> shall I use the command :
>
> y <- read.table("file",row.names=1, header=T)
>
> the results is :
>
>> y[1:3,1:3]
>X0 X20 X40
> 0   0   0   0
> 20  0   0   0
> 40  0   0   0
>
> The question is : why R adds an X to the names of the columns eg X0,
> X2, X4, when it shall be only 0, 2, 4 ? thanks !
>
> -- bogdan
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] reading files with name columns and row columns

2015-09-02 Thread Bogdan Tanasa
Thanks, Bert ! I solved the situation in the meanwhile, by using :

y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))

colnames(y) <- gsub("X","", colnames(y))


On Wed, Sep 2, 2015 at 3:59 PM, Bert Gunter  wrote:

> Please read the Help file carefully before posting:
>
> "read.table is not the right tool for reading large matrices,
> especially those with many columns: it is designed to read data frames
> which may have columns of very different classes. Use scan instead for
> matrices."
>
> But the answer to your question can be found in
>
> ?make.names
>
> for what constitutes a syntactically valid name in R.
>
>
> Cheers,
> Bert
>
> Bert Gunter
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
>-- Clifford Stoll
>
>
> On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa  wrote:
> > Dear all,
> >
> > would appreciate a piece of help with a simple question: I am reading in
> R
> > a file that is formatted as a matrix (an example is shown below, although
> > it is more complex, a matrix of 1000 * 1000 ):
> >
> > the names of the columns are 0, 1, 4, 8, etc
> > the names of the rows are 0, 1, 4, 8, etc
> >
> >0 20 40
> > 0  0   0   0
> > 20  0   0   0
> > 40  0   0   0
> >
> > shall I use the command :
> >
> > y <- read.table("file",row.names=1, header=T)
> >
> > the results is :
> >
> >> y[1:3,1:3]
> >X0 X20 X40
> > 0   0   0   0
> > 20  0   0   0
> > 40  0   0   0
> >
> > The question is : why R adds an X to the names of the columns eg X0,
> > X2, X4, when it shall be only 0, 2, 4 ? thanks !
> >
> > -- bogdan
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] reading files with name columns and row columns

2015-09-02 Thread William Dunlap
  y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))
  colnames(y) <- gsub("X","", colnames(y))

Use read.table's check.names=FALSE argument so it won't mangle
the column names instead of trying to demangle them with gsub() afterwards.

E.g.,
  txt <- "   50%  100%\nA   5 8\nB  1314\n"
  cat(txt)
  #   50%  100%
  #A   5 8
  #B  1314
  read.table(text=txt, head=TRUE, row.names=1)
  #  X50. X100.
  #A5 8
  #B   1314
  read.table(text=txt, head=TRUE, row.names=1, check.names=FALSE)
  #  50% 100%
  #A   58
  #B  13   14


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Sep 2, 2015 at 4:08 PM, Bogdan Tanasa  wrote:

> Thanks, Bert ! I solved the situation in the meanwhile, by using :
>
> y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))
>
> colnames(y) <- gsub("X","", colnames(y))
>
>
> On Wed, Sep 2, 2015 at 3:59 PM, Bert Gunter 
> wrote:
>
> > Please read the Help file carefully before posting:
> >
> > "read.table is not the right tool for reading large matrices,
> > especially those with many columns: it is designed to read data frames
> > which may have columns of very different classes. Use scan instead for
> > matrices."
> >
> > But the answer to your question can be found in
> >
> > ?make.names
> >
> > for what constitutes a syntactically valid name in R.
> >
> >
> > Cheers,
> > Bert
> >
> > Bert Gunter
> >
> > "Data is not information. Information is not knowledge. And knowledge
> > is certainly not wisdom."
> >-- Clifford Stoll
> >
> >
> > On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa  wrote:
> > > Dear all,
> > >
> > > would appreciate a piece of help with a simple question: I am reading
> in
> > R
> > > a file that is formatted as a matrix (an example is shown below,
> although
> > > it is more complex, a matrix of 1000 * 1000 ):
> > >
> > > the names of the columns are 0, 1, 4, 8, etc
> > > the names of the rows are 0, 1, 4, 8, etc
> > >
> > >0 20 40
> > > 0  0   0   0
> > > 20  0   0   0
> > > 40  0   0   0
> > >
> > > shall I use the command :
> > >
> > > y <- read.table("file",row.names=1, header=T)
> > >
> > > the results is :
> > >
> > >> y[1:3,1:3]
> > >X0 X20 X40
> > > 0   0   0   0
> > > 20  0   0   0
> > > 40  0   0   0
> > >
> > > The question is : why R adds an X to the names of the columns eg X0,
> > > X2, X4, when it shall be only 0, 2, 4 ? thanks !
> > >
> > > -- bogdan
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > 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.
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] reading files with name columns and row columns

2015-09-02 Thread Bogdan Tanasa
that is great, thank you Bill for time and help ;) !

On Wed, Sep 2, 2015 at 4:36 PM, William Dunlap  wrote:

>   y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))
>   colnames(y) <- gsub("X","", colnames(y))
>
> Use read.table's check.names=FALSE argument so it won't mangle
> the column names instead of trying to demangle them with gsub()
> afterwards.
>
> E.g.,
>   txt <- "   50%  100%\nA   5 8\nB  1314\n"
>   cat(txt)
>   #   50%  100%
>   #A   5 8
>   #B  1314
>   read.table(text=txt, head=TRUE, row.names=1)
>   #  X50. X100.
>   #A5 8
>   #B   1314
>   read.table(text=txt, head=TRUE, row.names=1, check.names=FALSE)
>   #  50% 100%
>   #A   58
>   #B  13   14
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Wed, Sep 2, 2015 at 4:08 PM, Bogdan Tanasa  wrote:
>
>> Thanks, Bert ! I solved the situation in the meanwhile, by using :
>>
>> y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))
>>
>> colnames(y) <- gsub("X","", colnames(y))
>>
>>
>> On Wed, Sep 2, 2015 at 3:59 PM, Bert Gunter 
>> wrote:
>>
>> > Please read the Help file carefully before posting:
>> >
>> > "read.table is not the right tool for reading large matrices,
>> > especially those with many columns: it is designed to read data frames
>> > which may have columns of very different classes. Use scan instead for
>> > matrices."
>> >
>> > But the answer to your question can be found in
>> >
>> > ?make.names
>> >
>> > for what constitutes a syntactically valid name in R.
>> >
>> >
>> > Cheers,
>> > Bert
>> >
>> > Bert Gunter
>> >
>> > "Data is not information. Information is not knowledge. And knowledge
>> > is certainly not wisdom."
>> >-- Clifford Stoll
>> >
>> >
>> > On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa  wrote:
>> > > Dear all,
>> > >
>> > > would appreciate a piece of help with a simple question: I am reading
>> in
>> > R
>> > > a file that is formatted as a matrix (an example is shown below,
>> although
>> > > it is more complex, a matrix of 1000 * 1000 ):
>> > >
>> > > the names of the columns are 0, 1, 4, 8, etc
>> > > the names of the rows are 0, 1, 4, 8, etc
>> > >
>> > >0 20 40
>> > > 0  0   0   0
>> > > 20  0   0   0
>> > > 40  0   0   0
>> > >
>> > > shall I use the command :
>> > >
>> > > y <- read.table("file",row.names=1, header=T)
>> > >
>> > > the results is :
>> > >
>> > >> y[1:3,1:3]
>> > >X0 X20 X40
>> > > 0   0   0   0
>> > > 20  0   0   0
>> > > 40  0   0   0
>> > >
>> > > The question is : why R adds an X to the names of the columns eg X0,
>> > > X2, X4, when it shall be only 0, 2, 4 ? thanks !
>> > >
>> > > -- bogdan
>> > >
>> > > [[alternative HTML version deleted]]
>> > >
>> > > __
>> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > 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.
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] reading files with name columns and row columns

2015-09-02 Thread shawin
also the header =0

On Wed, Sep 2, 2015 at 11:52 PM, Shawin Karim  wrote:

> make row.name=0 instead to 1
>
> On Wed, Sep 2, 2015 at 11:07 PM, Bogdan Tanasa [via R] <
> ml-node+s789695n4711774...@n4.nabble.com> wrote:
>
>> Dear all,
>>
>> would appreciate a piece of help with a simple question: I am reading in
>> R
>> a file that is formatted as a matrix (an example is shown below, although
>> it is more complex, a matrix of 1000 * 1000 ):
>>
>> the names of the columns are 0, 1, 4, 8, etc
>> the names of the rows are 0, 1, 4, 8, etc
>>
>>0 20 40
>> 0  0   0   0
>> 20  0   0   0
>> 40  0   0   0
>>
>> shall I use the command :
>>
>> y <- read.table("file",row.names=1, header=T)
>>
>> the results is :
>>
>> > y[1:3,1:3]
>>X0 X20 X40
>> 0   0   0   0
>> 20  0   0   0
>> 40  0   0   0
>>
>> The question is : why R adds an X to the names of the columns eg X0,
>> X2, X4, when it shall be only 0, 2, 4 ? thanks !
>>
>> -- bogdan
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> [hidden email] 
>> mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>>
>> --
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://r.789695.n4.nabble.com/reading-files-with-name-columns-and-row-columns-tp4711774.html
>> To start a new topic under R help, email
>> ml-node+s789695n789696...@n4.nabble.com
>> To unsubscribe from R, click here
>> 
>> .
>> NAML
>> 
>>
>
>




--
View this message in context: 
http://r.789695.n4.nabble.com/reading-files-with-name-columns-and-row-columns-tp4711774p4711776.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] reading files with name columns and row columns

2015-09-02 Thread shawin
dear William ,

I have an issue with R code which is :


FCP<-as.matrix(sapply(FCPval,as.numeric))
for (i in 1:rowN){if (FCP$FC[i] >= 1.5 & FCP$FC[i]<=-1.5 & FCP$p[i]<=0.05){
dfrmPFC=data.frame(matrix(Fc=FC,p=p))}
}

the error is :Error in FCP$FC : $ operator is invalid for atomic vectors
could you please help me

On Thu, Sep 3, 2015 at 12:32 AM, William Dunlap [via R] <
ml-node+s789695n4711779...@n4.nabble.com> wrote:

>   y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))
>   colnames(y) <- gsub("X","", colnames(y))
>
> Use read.table's check.names=FALSE argument so it won't mangle
> the column names instead of trying to demangle them with gsub()
> afterwards.
>
> E.g.,
>   txt <- "   50%  100%\nA   5 8\nB  1314\n"
>   cat(txt)
>   #   50%  100%
>   #A   5 8
>   #B  1314
>   read.table(text=txt, head=TRUE, row.names=1)
>   #  X50. X100.
>   #A5 8
>   #B   1314
>   read.table(text=txt, head=TRUE, row.names=1, check.names=FALSE)
>   #  50% 100%
>   #A   58
>   #B  13   14
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Wed, Sep 2, 2015 at 4:08 PM, Bogdan Tanasa <[hidden email]
> > wrote:
>
> > Thanks, Bert ! I solved the situation in the meanwhile, by using :
> >
> > y <- as.matrix(read.table("FILE_NAME",header=T,row.names=1))
> >
> > colnames(y) <- gsub("X","", colnames(y))
> >
> >
> > On Wed, Sep 2, 2015 at 3:59 PM, Bert Gunter <[hidden email]
> >
> > wrote:
> >
> > > Please read the Help file carefully before posting:
> > >
> > > "read.table is not the right tool for reading large matrices,
> > > especially those with many columns: it is designed to read data frames
> > > which may have columns of very different classes. Use scan instead for
> > > matrices."
> > >
> > > But the answer to your question can be found in
> > >
> > > ?make.names
> > >
> > > for what constitutes a syntactically valid name in R.
> > >
> > >
> > > Cheers,
> > > Bert
> > >
> > > Bert Gunter
> > >
> > > "Data is not information. Information is not knowledge. And knowledge
> > > is certainly not wisdom."
> > >-- Clifford Stoll
> > >
> > >
> > > On Wed, Sep 2, 2015 at 3:11 PM, Bogdan Tanasa <[hidden email]
> > wrote:
> > > > Dear all,
> > > >
> > > > would appreciate a piece of help with a simple question: I am
> reading
> > in
> > > R
> > > > a file that is formatted as a matrix (an example is shown below,
> > although
> > > > it is more complex, a matrix of 1000 * 1000 ):
> > > >
> > > > the names of the columns are 0, 1, 4, 8, etc
> > > > the names of the rows are 0, 1, 4, 8, etc
> > > >
> > > >0 20 40
> > > > 0  0   0   0
> > > > 20  0   0   0
> > > > 40  0   0   0
> > > >
> > > > shall I use the command :
> > > >
> > > > y <- read.table("file",row.names=1, header=T)
> > > >
> > > > the results is :
> > > >
> > > >> y[1:3,1:3]
> > > >X0 X20 X40
> > > > 0   0   0   0
> > > > 20  0   0   0
> > > > 40  0   0   0
> > > >
> > > > The question is : why R adds an X to the names of the columns eg X0,
> > > > X2, X4, when it shall be only 0, 2, 4 ? thanks !
> > > >
> > > > -- bogdan
> > > >
> > > > [[alternative HTML version deleted]]
> > > >
> > > > __
> > > > [hidden email]
>  mailing list --
> To UNSUBSCRIBE and more, see
> > > > 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.
> > >
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > [hidden email] 
> mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> >
>
> [[alternative HTML version deleted]]
>
> __
> [hidden email] 
> mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
>
> --
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://r.789695.n4.nabble.com/reading-files-with-name-columns-and-row-columns-tp4711774p4711779.html
> To start a new topic under R help, email
> ml-node+s78