Question

I am having hard times running the lm() function and understanding the error.

So, my script is this:

#! /usr/bin/env/ Rscript

meteodata <- read.table("/path/to/dataset.txt", header=T)
meteodata
summary(meteodata)


plot(meteodata)

lmodel <- lm(temperature~altitude+sea.distance, data=meteodata)

And the console output is this:

temperature station.id latitude longtitude sea.distance altitude
1         20,1         S1      0,5        0,5          0,5        0
2         20,5         S1      0,5        0,5          0,5        0
3         19,3         S1      0,5        0,5          0,5        0
4         18,6         S1      0,5        0,5          0,5        0
5         21,5         S1      0,5        0,5          0,5        0
6         17,1         S2      3,5        2,5          1,5      200
7         18,3         S2      3,5        2,5          1,5      200
8         16,8         S2      3,5        2,5          1,5      200
9         17,5         S2      3,5        2,5          1,5      200
10        16,4         S2      3,5        2,5          1,5      200
11        18,4         S3      2,5        3,5          0,5      100
12        19,1         S3      2,5        3,5          0,5      100
13        18,9         S3      2,5        3,5          0,5      100
14        17,8         S3      2,5        3,5          0,5      100
15        17,6         S3      2,5        3,5          0,5      100
16        15,1         S4        4          0            4      400
17        15,5         S4        4          0            4      400
18        15,0         S4        4          0            4      400
19        14,9         S4        4          0            4      400
20        15,8         S4        4          0            4      400
  temperature station.id latitude longtitude sea.distance    altitude  
 14,9   : 1   S1:5       0,5:5    0  :5      0,5:10       Min.   :  0  
 15,0   : 1   S2:5       2,5:5    0,5:5      1,5: 5       1st Qu.: 75  
 15,1   : 1   S3:5       3,5:5    2,5:5      4  : 5       Median :150  
 15,5   : 1   S4:5       4  :5    3,5:5                   Mean   :175  
 15,8   : 1                                               3rd Qu.:250  
 16,4   : 1                                               Max.   :400  
 (Other):14                                                            
Warning messages:
1: In model.response(mf, "numeric") :
  using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : - not meaningful for factors

I ve read some similar questions here and there but i still can't figure out what i am doing wrong. I need temperature as my response y variable to be calculated by the independent x1,x2 altitude and sea.distance variables.

Any help will be appreciated, just try to be specific. Thanks in advance

Was it helpful?

Solution

R uses . as the decimal separator. Your data uses , and R interprets the data as characters, which are made factor variables by default. Use dec="," to tell read.table that the data is numeric with , as the decimal separator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top